9c72f66fb3
One day we should source those script directly from the cartodb repo
14 lines
437 B
PL/PgSQL
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;
|