f9f73d2d62
This fix was already present at one point in cartodb/lib/sql (where the code was copied from) but in a different branch than the one the code was initially copied from. The fix depends on plpython language which becomes a new dependency.
15 lines
503 B
PL/PgSQL
15 lines
503 B
PL/PgSQL
-- Return an array of statements found in the given query text
|
|
--
|
|
-- Regexp curtesy of Hubert Lubaczewski (depesz)
|
|
-- Implemented in plpython for performance reasons
|
|
--
|
|
CREATE OR REPLACE FUNCTION CDB_QueryStatements(query text)
|
|
RETURNS SETOF TEXT AS $$
|
|
import re
|
|
pat = re.compile( r'''((?:[^'"$;]+|"[^"]*"|'[^']*'|(\$[^$]*\$).*?\2)+)''', re.DOTALL )
|
|
for match in pat.findall(query):
|
|
cleaned = match[0].strip()
|
|
if ( cleaned ):
|
|
yield cleaned
|
|
$$ language 'plpythonu' IMMUTABLE STRICT;
|