I have a problem with cleaning comments and empty lines from an existing sql file. A file has more than 10 thousand lines, so cleaning it manually is not an option.
I have a little python script, but I have no idea how to handle comments inside multi-line inserts.
The code:
f = file( 'file.sql', 'r' ) t = filter( lambda x: not x.startswith('--') \ and not x.isspace() , f.readlines() ) f.close() t
How it should work:
This needs to be cleared:
-- normal sql comment
This should remain like this:
CREATE FUNCTION func1(a integer) RETURNS void LANGUAGE plpgsql AS $$ BEGIN
Szymon lukaszczyk
source share