cartodb-postgresql/scripts-available/CDB_QueryStatements.sql

15 lines
533 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
--
2019-05-31 21:29:28 +08:00
CREATE OR REPLACE FUNCTION @extschema@.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
2019-12-27 00:48:12 +08:00
$$ language '@@plpythonu@@' IMMUTABLE STRICT PARALLEL SAFE;