2012-10-15 19:15:48 +08:00
|
|
|
-- Return an array of statements found in the given query text
|
|
|
|
--
|
2014-09-22 19:16:11 +08:00
|
|
|
-- Regexp curtesy of Hubert Lubaczewski (depesz)
|
|
|
|
-- Implemented in plpython for performance reasons
|
2012-10-15 19:15:48 +08:00
|
|
|
--
|
|
|
|
CREATE OR REPLACE FUNCTION CDB_QueryStatements(query text)
|
|
|
|
RETURNS SETOF TEXT AS $$
|
2014-09-22 19:16:11 +08:00
|
|
|
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;
|