Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make sure tables are visible when checking indexes.

Also try to use parameters in the order in which they are passed.
  • Loading branch information...
commit e2b34682e1f6c5967b35b97ebb5a2fb33f4d694d 1 parent 4e425da
@theory authored
Showing with 32 additions and 4 deletions.
  1. +2 −2 Changes
  2. +27 −0 sql/pgtap--0.92.0--0.93.0.sql
  3. +3 −2 sql/pgtap.sql.in
View
4 Changes
@@ -9,8 +9,8 @@ Revision history for pgTAP
* Fixed misselling of "constraint" in constraint test diagnostic output.
* Fixed `fk_ok()` so that the table must be visible in the search path when
the schema name is not specified.
-* Fixed constraint, trigger, and foreign key-checking functions so that they
- only look at tables visible in the search path unles the schema is
+* Fixed constraint, trigger, index, and foreign key-checking functions so that
+ they only look at tables visible in the search path unles the schema is
specified.
* Fixed `col_type_is()` so that it won't report the column as not existing
when the column's data type is not in the search path.
View
27 sql/pgtap--0.92.0--0.93.0.sql
@@ -364,3 +364,30 @@ RETURNS TEXT AS $$
'Tablespace ' || quote_ident($1) || ' should be owned by ' || quote_ident($2)
);
$$ LANGUAGE sql;
+
+CREATE OR REPLACE FUNCTION _have_index( NAME, NAME, NAME)
+RETURNS BOOLEAN AS $$
+ SELECT EXISTS (
+ SELECT TRUE
+ FROM pg_catalog.pg_index x
+ JOIN pg_catalog.pg_class ct ON ct.oid = x.indrelid
+ JOIN pg_catalog.pg_class ci ON ci.oid = x.indexrelid
+ JOIN pg_catalog.pg_namespace n ON n.oid = ct.relnamespace
+ WHERE n.nspname = $1
+ AND ct.relname = $2
+ AND ci.relname = $3
+ );
+$$ LANGUAGE sql;
+
+CREATE OR REPLACE FUNCTION _have_index( NAME, NAME)
+RETURNS BOOLEAN AS $$
+ SELECT EXISTS (
+ SELECT TRUE
+ FROM pg_catalog.pg_index x
+ JOIN pg_catalog.pg_class ct ON ct.oid = x.indrelid
+ JOIN pg_catalog.pg_class ci ON ci.oid = x.indexrelid
+ WHERE ct.relname = $1
+ AND ci.relname = $2
+ AND pg_catalog.pg_table_is_visible(ct.oid)
+ );
+$$ LANGUAGE sql;
View
5 sql/pgtap.sql.in
@@ -2587,9 +2587,9 @@ RETURNS BOOLEAN AS $$
JOIN pg_catalog.pg_class ct ON ct.oid = x.indrelid
JOIN pg_catalog.pg_class ci ON ci.oid = x.indexrelid
JOIN pg_catalog.pg_namespace n ON n.oid = ct.relnamespace
- WHERE ct.relname = $2
+ WHERE n.nspname = $1
+ AND ct.relname = $2
AND ci.relname = $3
- AND n.nspname = $1
);
$$ LANGUAGE sql;
@@ -2602,6 +2602,7 @@ RETURNS BOOLEAN AS $$
JOIN pg_catalog.pg_class ci ON ci.oid = x.indexrelid
WHERE ct.relname = $1
AND ci.relname = $2
+ AND pg_catalog.pg_table_is_visible(ct.oid)
);
$$ LANGUAGE sql;
Please sign in to comment.
Something went wrong with that request. Please try again.