sqlparse
sqlparse copied to clipboard
Incorrect splitting of postgres function containing dollar-quoted semicolon
In the python console:
>>> sqlparse.split('''CREATE OR REPLACE FUNCTION public.bug() RETURNS text
... LANGUAGE sql
... AS $func$
... select $string$ Run this query: SELECT 123; $string$::text;
... $func$;''')
[u'CREATE OR REPLACE FUNCTION public.bug() RETURNS text\nLANGUAGE sql\nAS $func$\nselect $string$ Run this query: SELECT 123;', u'$string$::text;\n$func$;']
It works as expected with regular quotes:
>>> sqlparse.split('''CREATE OR REPLACE FUNCTION public.bug() RETURNS text
... LANGUAGE sql
... AS $func$
... select ' Run this query: SELECT 123; '::text;
... $func$;''')
[u"CREATE OR REPLACE FUNCTION public.bug() RETURNS text\nLANGUAGE sql\nAS $func$\nselect ' Run this query: SELECT 123; '::text;\n$func$;"]
This seems to be resolved with v0.4.4
>>> sqlparse.split('''CREATE OR REPLACE FUNCTION public.bug() RETURNS text
... LANGUAGE sql
... AS $func$
... select $string$ Run this query: SELECT 123; $string$::text;
... $func$;''')
['CREATE OR REPLACE FUNCTION public.bug() RETURNS text\nLANGUAGE sql\nAS $func$\nselect $string$ Run this query: SELECT 123; $string$::text;\n$func$;']
Yepp, this is fixed. Thanks for confirmation @proddata !