CartoDB-SQL-API/test/support/CDB_QueryStatements.sql
Raul Ochoa 7b9dbaf9f7 Upgrades QueryTables and QueryStatements to match with current
implementations. From now on it will re-download those functions from
https://github.com/CartoDB/cartodb-postgresql/tree/cdb when running
tests.
2014-09-22 13:16:11 +02:00

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;