CartoDB-SQL-API/test/support/CDB_QueryStatements.sql
Sandro Santilli 9c72f66fb3 Put a copy of CDB_* functions from cartodb to this repo
One day we should source those script directly from the cartodb repo
2012-10-15 13:15:48 +02:00

14 lines
437 B
PL/PgSQL

-- Return an array of statements found in the given query text
--
-- Curtesy of Hubert Lubaczewski (depesz)
--
CREATE OR REPLACE FUNCTION CDB_QueryStatements(query text)
RETURNS SETOF TEXT AS $$
SELECT stmt FROM (
SELECT btrim(q[1], E' \n\t\r;') as stmt FROM (
SELECT regexp_matches( $1, $REG$((?:[^'"$;]+|"[^"]*"|'(?:[^']*|'')*'|(\$[^$]*\$).*?\2)+)$REG$, 'g' ) as q
) i
) j
WHERE stmt <> '';
$$ language sql;