sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

Incorrect splitting of postgres function containing dollar-quoted semicolon

Open koljonen opened this issue 8 years ago • 1 comments

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$;"]

koljonen avatar Nov 30 '16 15:11 koljonen

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$;']

proddata avatar Feb 03 '24 08:02 proddata

Yepp, this is fixed. Thanks for confirmation @proddata !

andialbrecht avatar Mar 12 '24 05:03 andialbrecht