KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have problem with cleaning comments and empty lines from already existing sql file. The file has over 10k 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. Code: f = file( 'file.sql', 'r' ) t = filter( lambda x: not x.startswith('--') \ and not x.isspace() , f.readlines() ) f.close() t #<- here the cleaned data should be How it should work: This should be cleaned: -- normal sql comment This should stay as it is: CREATE FUNCTION func1(a integer) RETURNS void LANGUAGE plpgsql AS $$ BEGIN -- comment [...] END; $$; INSERT INTO public.texts (multilinetext) VALUES (' and more lines here \' -- part of text \' [...] ');
Tags (comma-separated)
Save Edits
Cancel