diff --git a/scripts-available/CDB_QueryTables.sql b/scripts-available/CDB_QueryTables.sql index b3b81dc..2fb9532 100644 --- a/scripts-available/CDB_QueryTables.sql +++ b/scripts-available/CDB_QueryTables.sql @@ -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 diff --git a/test/organization/test.sh b/test/organization/test.sh index 081e221..c713afa 100644 --- a/test/organization/test.sh +++ b/test/organization/test.sh @@ -325,6 +325,27 @@ function test_user_can_read_when_it_has_permission_after_organization_permission drop_role_and_schema cdb_testmember_3 } +function test_cdb_querytables_returns_schema_and_table_name() { + sql "CREATE EXTENSION plpythonu;" + ${CMD} -d ${DATABASE} -f scripts-available/CDB_QueryStatements.sql + ${CMD} -d ${DATABASE} -f scripts-available/CDB_QueryTables.sql + sql cdb_testmember_1 "select * from CDB_QueryTables('select * from foo');" should "{cdb_testmember_1.foo}" +} + +function test_cdb_querytables_returns_schema_and_table_name_for_several_schemas() { + sql "CREATE EXTENSION plpythonu;" + ${CMD} -d ${DATABASE} -f scripts-available/CDB_QueryStatements.sql + ${CMD} -d ${DATABASE} -f scripts-available/CDB_QueryTables.sql + sql postgres "select * from CDB_QueryTables('select * from cdb_testmember_1.foo, cdb_testmember_2.bar');" should "{cdb_testmember_1.foo,cdb_testmember_2.bar}" +} + +function test_cdb_querytables_does_not_return_functions_as_part_of_the_resultset() { + sql "CREATE EXTENSION plpythonu;" + ${CMD} -d ${DATABASE} -f scripts-available/CDB_QueryStatements.sql + ${CMD} -d ${DATABASE} -f scripts-available/CDB_QueryTables.sql + sql postgres "select * from CDB_QueryTables('select * from cdb_testmember_1.foo, cdb_testmember_2.bar, plainto_tsquery(''foo'')');" should "{cdb_testmember_1.foo,cdb_testmember_2.bar}" +} + #################################################### TESTS END HERE ####################################################