cartodb-postgresql/scripts-available/CDB_QueryStatements.sql

15 lines
517 B
MySQL
Raw Normal View History

-- 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
2017-10-24 20:16:56 +08:00
$$ language 'plpythonu' IMMUTABLE STRICT PARALLEL SAFE;