From 2715f47a224cf21b94867f5fba1abd9e2f40c63b Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Wed, 24 Jun 2015 19:07:41 +0200 Subject: [PATCH] Points CDB_QueryTables script to the branch with CDB_QueryTablesText --- test/support/prepare_db.sh | 2 +- test/support/sql/CDB_QueryTables.sql | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/test/support/prepare_db.sh b/test/support/prepare_db.sh index 8185da4d..3b827f40 100755 --- a/test/support/prepare_db.sh +++ b/test/support/prepare_db.sh @@ -80,7 +80,7 @@ if test x"$PREPARE_PGSQL" = xyes; then psql -c "CREATE EXTENSION 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/86-CDB_QueryTables-fix-long-names/scripts-available/CDB_QueryTables.sql -o sql/CDB_QueryTables.sql cat sql/CDB_QueryStatements.sql sql/CDB_QueryTables.sql | psql -v ON_ERROR_STOP=1 ${TEST_DB} || exit 1 diff --git a/test/support/sql/CDB_QueryTables.sql b/test/support/sql/CDB_QueryTables.sql index cd8b51b4..ac61281d 100644 --- a/test/support/sql/CDB_QueryTables.sql +++ b/test/support/sql/CDB_QueryTables.sql @@ -2,12 +2,12 @@ -- -- Requires PostgreSQL 9.x+ -- -CREATE OR REPLACE FUNCTION CDB_QueryTables(query text) -RETURNS name[] +CREATE OR REPLACE FUNCTION CDB_QueryTablesText(query text) +RETURNS text[] AS $$ DECLARE exp XML; - tables NAME[]; + tables text[]; rec RECORD; rec2 RECORD; BEGIN @@ -41,11 +41,11 @@ BEGIN xpath('//x:Relation-Name/text()', exp, ARRAY[ARRAY['x', 'http://www.postgresql.org/2009/explain']]) as x, 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 + SELECT unnest(x) as p, unnest(s) as sc from inp LOOP -- RAISE DEBUG 'tab: %', rec2.p; -- RAISE DEBUG 'sc: %', rec2.sc; - tables := array_append(tables, (rec2.sc || '.' || rec2.p)::name); + tables := array_append(tables, (rec2.sc || '.' || rec2.p)); END LOOP; -- RAISE DEBUG 'Tables: %', tables; @@ -65,3 +65,14 @@ BEGIN return tables; END $$ LANGUAGE 'plpgsql' VOLATILE STRICT; + + +-- Keep CDB_QueryTables with same signature for backwards compatibility. +-- It should probably be removed in the future. +CREATE OR REPLACE FUNCTION CDB_QueryTables(query text) +RETURNS name[] +AS $$ +BEGIN + RETURN CDB_QueryTablesText(query)::name[]; +END +$$ LANGUAGE 'plpgsql' VOLATILE STRICT;