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.
This commit is contained in:
parent
25d2e64891
commit
7b9dbaf9f7
@ -12,9 +12,8 @@ Provides a nodejs based API for running SQL queries against CartoDB.
|
||||
|
||||
core requirements
|
||||
-------------
|
||||
* postgres 9.0+
|
||||
* postgres 9.0+ (with plpythonu extension for ``CDB_QueryTables``)
|
||||
* postgis 2.0+
|
||||
* cartodb 0.9.5+ (for ``CDB_QueryTables``)
|
||||
* GDAL 1.9.2+ (bin utils)
|
||||
* zip commandline tool
|
||||
* redis
|
||||
|
@ -75,6 +75,9 @@ if test x"$PREPARE_PGSQL" = xyes; then
|
||||
psql -U postgres -v ON_ERROR_STOP=1 ${TEST_DB} || exit 1
|
||||
|
||||
# TODO: send in a single run, togheter with test.sql
|
||||
psql -U postgres -c "CREATE EXTENSION plpythonu;" ${TEST_DB}
|
||||
curl -L -s https://github.com/CartoDB/cartodb-postgresql/raw/cdb/scripts-available/CDB_QueryStatements.sql -o support/CDB_QueryStatements.sql
|
||||
curl -L -s https://github.com/CartoDB/cartodb-postgresql/raw/cdb/scripts-available/CDB_QueryTables.sql -o support/CDB_QueryTables.sql
|
||||
psql -U postgres -f support/CDB_QueryStatements.sql ${TEST_DB}
|
||||
psql -U postgres -f support/CDB_QueryTables.sql ${TEST_DB}
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
-- Return an array of statements found in the given query text
|
||||
--
|
||||
-- Curtesy of Hubert Lubaczewski (depesz)
|
||||
-- Regexp curtesy of Hubert Lubaczewski (depesz)
|
||||
-- Implemented in plpython for performance reasons
|
||||
--
|
||||
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;
|
||||
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;
|
||||
|
@ -39,7 +39,7 @@ BEGIN
|
||||
inp AS (
|
||||
SELECT
|
||||
xpath('//x:Relation-Name/text()', exp, ARRAY[ARRAY['x', 'http://www.postgresql.org/2009/explain']]) as x,
|
||||
xpath('//x:Schema/text()', exp, ARRAY[ARRAY['x', 'http://www.postgresql.org/2009/explain']]) as s
|
||||
xpath('//x:Relation-Name/../x:Schema/text()', exp, ARRAY[ARRAY['x', 'http://www.postgresql.org/2009/explain']]) as s
|
||||
)
|
||||
SELECT unnest(x)::name as p, unnest(s)::name as sc from inp
|
||||
LOOP
|
||||
|
Loading…
Reference in New Issue
Block a user