2014-05-05 23:13:06 +08:00
|
|
|
-- Return an array of statements found in the given query text
|
|
|
|
--
|
2014-06-05 21:00:57 +08:00
|
|
|
-- Regexp curtesy of Hubert Lubaczewski (depesz)
|
|
|
|
-- Implemented in plpython for performance reasons
|
2014-05-05 23:13:06 +08:00
|
|
|
--
|
2019-05-31 21:29:28 +08:00
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.CDB_QueryStatements(query text)
|
2014-05-05 23:13:06 +08:00
|
|
|
RETURNS SETOF TEXT AS $$
|
2014-06-05 21:00:57 +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
|
2019-12-27 00:48:12 +08:00
|
|
|
$$ language '@@plpythonu@@' IMMUTABLE STRICT PARALLEL SAFE;
|