Implement CDB_QueryStatements as SQL language function
Do not relies on cartodb-postgresql extension which relies on plpythonu language. That avoid installing it in travis-ci.
This commit is contained in:
parent
6c3fde70e8
commit
f19c1a34ec
@ -78,8 +78,6 @@ if test x"$PREPARE_PGSQL" = xyes; then
|
|||||||
sed "s/:TESTPASS/${TESTPASS}/" |
|
sed "s/:TESTPASS/${TESTPASS}/" |
|
||||||
psql -v ON_ERROR_STOP=1 ${TEST_DB} || exit 1
|
psql -v ON_ERROR_STOP=1 ${TEST_DB} || exit 1
|
||||||
|
|
||||||
psql -c "CREATE LANGUAGE plpythonu;" ${TEST_DB}
|
|
||||||
curl -L -s https://github.com/CartoDB/cartodb-postgresql/raw/cdb/scripts-available/CDB_QueryStatements.sql -o sql/CDB_QueryStatements.sql
|
|
||||||
curl -L -s https://github.com/CartoDB/cartodb-postgresql/raw/cdb/scripts-available/CDB_QueryTables.sql -o sql/CDB_QueryTables.sql
|
curl -L -s https://github.com/CartoDB/cartodb-postgresql/raw/cdb/scripts-available/CDB_QueryTables.sql -o sql/CDB_QueryTables.sql
|
||||||
cat sql/CDB_QueryStatements.sql sql/CDB_QueryTables.sql sql/CDB_Overviews.sql |
|
cat sql/CDB_QueryStatements.sql sql/CDB_QueryTables.sql sql/CDB_Overviews.sql |
|
||||||
psql -v ON_ERROR_STOP=1 ${TEST_DB} || exit 1
|
psql -v ON_ERROR_STOP=1 ${TEST_DB} || exit 1
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
-- DUMMY IMPLEMENTATION
|
||||||
|
-- Ref: https://github.com/CartoDB/cartodb-postgresql/blob/master/scripts-available/CDB_QueryStatements.sql
|
||||||
|
|
||||||
-- Return an array of statements found in the given query text
|
-- Return an array of statements found in the given query text
|
||||||
--
|
--
|
||||||
-- Regexp curtesy of Hubert Lubaczewski (depesz)
|
-- Regexp curtesy of Hubert Lubaczewski (depesz)
|
||||||
@ -5,10 +8,9 @@
|
|||||||
--
|
--
|
||||||
CREATE OR REPLACE FUNCTION CDB_QueryStatements(query text)
|
CREATE OR REPLACE FUNCTION CDB_QueryStatements(query text)
|
||||||
RETURNS SETOF TEXT AS $$
|
RETURNS SETOF TEXT AS $$
|
||||||
import re
|
with matches as (
|
||||||
pat = re.compile( r'''((?:[^'"$;]+|"[^"]*"|'[^']*'|(\$[^$]*\$).*?\2)+)''', re.DOTALL )
|
select regexp_matches($1, $regexp$((?:[^'"$;]+|"[^"]*"|'[^']*'|(\$[^$]*\$).*?\2)+)$regexp$, 'g') as m
|
||||||
for match in pat.findall(query):
|
)
|
||||||
cleaned = match[0].strip()
|
select btrim(m[1]) from matches
|
||||||
if ( cleaned ):
|
$$
|
||||||
yield cleaned
|
LANGUAGE SQL IMMUTABLE STRICT;
|
||||||
$$ language 'plpythonu' IMMUTABLE STRICT;
|
|
||||||
|
Loading…
Reference in New Issue
Block a user