From f03179a75ec5c0cb80e10b457f53eef8e18a23cd Mon Sep 17 00:00:00 2001 From: RampantDespair Date: Thu, 23 Jul 2026 18:52:19 -0400 Subject: [PATCH 1/5] Add missing column constraint overloads Added missing `schema, table, column[]` and `schema, table, column` variants of `col_isnt_pk()`, `col_is_fk()`, and `col_isnt_fk()`. Established a consistent overload order for `col_is_pk()`, `col_isnt_pk()`, `col_is_fk()`, `col_isnt_fk()`, and `col_is_unique()`. --- Changes | 4 + doc/pgtap.md | 30 +++-- sql/pgtap--1.3.4--1.3.5.sql | 36 ++++++ sql/pgtap.sql.in | 64 +++++++--- test/expected/fktap.out | 227 +++++++++++++++++++----------------- test/expected/pktap.out | 50 ++++---- test/sql/fktap.sql | 31 ++++- test/sql/pktap.sql | 19 ++- 8 files changed, 302 insertions(+), 159 deletions(-) diff --git a/Changes b/Changes index c344ff46..6fe2704f 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,10 @@ Revision history for pgTAP has upgraded its Markdown parser. * Added an example of an empty array, `'{}'::name[]`, to each mention in the documentation. Thanks Kevin Brannen for the suggestion (#362). +* Added missing `schema, table, column[]` and `schema, table, column` variants + of `col_isnt_pk()`, `col_is_fk()`, and `col_isnt_fk()`, and established a + consistent overload order for `col_is_pk()`, `col_isnt_pk()`, `col_is_fk()`, + `col_isnt_fk()`, and `col_is_unique()`. 1.3.4 2025-10-04T17:20:28Z -------------------------- diff --git a/doc/pgtap.md b/doc/pgtap.md index d84d1b03..24f2a3c1 100644 --- a/doc/pgtap.md +++ b/doc/pgtap.md @@ -5191,12 +5191,12 @@ foreign key does *not* exist. ```sql SELECT col_is_pk( :schema, :table, :columns, :description ); -SELECT col_is_pk( :schema, :table, :column, :description ); SELECT col_is_pk( :schema, :table, :columns ); -SELECT col_is_pk( :schema, :table, :column ); SELECT col_is_pk( :table, :columns, :description ); -SELECT col_is_pk( :table, :column, :description ); SELECT col_is_pk( :table, :columns ); +SELECT col_is_pk( :schema, :table, :column, :description ); +SELECT col_is_pk( :schema, :table, :column ); +SELECT col_is_pk( :table, :column, :description ); SELECT col_is_pk( :table, :column ); ``` @@ -5249,10 +5249,12 @@ Will produce something like this: ```sql SELECT col_isnt_pk( :schema, :table, :columns, :description ); -SELECT col_isnt_pk( :schema, :table, :column, :description ); +SELECT col_isnt_pk( :schema, :table, :columns ); SELECT col_isnt_pk( :table, :columns, :description ); -SELECT col_isnt_pk( :table, :column, :description ); SELECT col_isnt_pk( :table, :columns ); +SELECT col_isnt_pk( :schema, :table, :column, :description ); +SELECT col_isnt_pk( :schema, :table, :column ); +SELECT col_isnt_pk( :table, :column, :description ); SELECT col_isnt_pk( :table, :column ); ``` @@ -5280,10 +5282,12 @@ specified column or columns are not a primary key. ```sql SELECT col_is_fk( :schema, :table, :columns, :description ); -SELECT col_is_fk( :schema, :table, :column, :description ); +SELECT col_is_fk( :schema, :table, :columns ); SELECT col_is_fk( :table, :columns, :description ); -SELECT col_is_fk( :table, :column, :description ); SELECT col_is_fk( :table, :columns ); +SELECT col_is_fk( :schema, :table, :column, :description ); +SELECT col_is_fk( :schema, :table, :column ); +SELECT col_is_fk( :table, :column, :description ); SELECT col_is_fk( :table, :column ); ``` @@ -5317,10 +5321,12 @@ simply list all of the foreign key constraint columns, like so: ```sql SELECT col_isnt_fk( :schema, :table, :columns, :description ); -SELECT col_isnt_fk( :schema, :table, :column, :description ); +SELECT col_isnt_fk( :schema, :table, :columns ); SELECT col_isnt_fk( :table, :columns, :description ); -SELECT col_isnt_fk( :table, :column, :description ); SELECT col_isnt_fk( :table, :columns ); +SELECT col_isnt_fk( :schema, :table, :column, :description ); +SELECT col_isnt_fk( :schema, :table, :column ); +SELECT col_isnt_fk( :table, :column, :description ); SELECT col_isnt_fk( :table, :column ); ``` @@ -5467,12 +5473,12 @@ in question does not exist. ```sql SELECT col_is_unique( schema, table, columns, description ); -SELECT col_is_unique( schema, table, column, description ); SELECT col_is_unique( schema, table, columns ); -SELECT col_is_unique( schema, table, column ); SELECT col_is_unique( table, columns, description ); -SELECT col_is_unique( table, column, description ); SELECT col_is_unique( table, columns ); +SELECT col_is_unique( schema, table, column, description ); +SELECT col_is_unique( schema, table, column ); +SELECT col_is_unique( table, column, description ); SELECT col_is_unique( table, column ); ``` diff --git a/sql/pgtap--1.3.4--1.3.5.sql b/sql/pgtap--1.3.4--1.3.5.sql index e5019bc4..c0d249b6 100644 --- a/sql/pgtap--1.3.4--1.3.5.sql +++ b/sql/pgtap--1.3.4--1.3.5.sql @@ -1 +1,37 @@ -- Changes between pgTAP v1.3.4 and v1.3.5. + +-- col_isnt_pk( schema, table, column[] ) +CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_isnt_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a primary key' ); +$$ LANGUAGE sql; + +-- col_isnt_pk( schema, table, column ) +CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME ) +RETURNS TEXT AS $$ + SELECT col_isnt_pk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should not be a primary key' ); +$$ LANGUAGE sql; + +-- col_is_fk( schema, table, column[] ) +CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_is_fk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should be a foreign key' ); +$$ LANGUAGE sql; + +-- col_is_fk( schema, table, column ) +CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME ) +RETURNS TEXT AS $$ + SELECT col_is_fk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should be a foreign key' ); +$$ LANGUAGE sql; + +-- col_isnt_fk( schema, table, column[] ) +CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_isnt_fk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a foreign key' ); +$$ LANGUAGE sql; + +-- col_isnt_fk( schema, table, column ) +CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME ) +RETURNS TEXT AS $$ + SELECT col_isnt_fk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should not be a foreign key' ); +$$ LANGUAGE sql; diff --git a/sql/pgtap.sql.in b/sql/pgtap.sql.in index c1c7ed92..00ac68a8 100644 --- a/sql/pgtap.sql.in +++ b/sql/pgtap.sql.in @@ -2098,13 +2098,19 @@ RETURNS TEXT AS $$ SELECT col_is_pk( $1, $2, 'Column ' || quote_ident($1) || '(' || quote_ident($2) || ') should be a primary key' ); $$ LANGUAGE sql; --- col_isnt_pk( schema, table, column, description ) +-- col_isnt_pk( schema, table, column[], description ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT isnt( _ckeys( $1, $2, 'p' ), $3, $4 ); $$ LANGUAGE sql; --- col_isnt_pk( table, column, description ) +-- col_isnt_pk( schema, table, column[] ) +CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_isnt_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a primary key' ); +$$ LANGUAGE sql; + +-- col_isnt_pk( table, column[], description ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT isnt( _ckeys( $1, 'p' ), $2, $3 ); @@ -2122,6 +2128,12 @@ RETURNS TEXT AS $$ SELECT col_isnt_pk( $1, $2, ARRAY[$3], $4 ); $$ LANGUAGE sql; +-- col_isnt_pk( schema, table, column ) +CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME ) +RETURNS TEXT AS $$ + SELECT col_isnt_pk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should not be a primary key' ); +$$ LANGUAGE sql; + -- col_isnt_pk( table, column, description ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, TEXT ) RETURNS TEXT AS $$ @@ -2192,7 +2204,7 @@ RETURNS BOOLEAN AS $$ ); $$ LANGUAGE SQL; --- col_is_fk( schema, table, column, description ) +-- col_is_fk( schema, table, column[], description ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME[], TEXT ) RETURNS TEXT AS $$ DECLARE @@ -2225,7 +2237,13 @@ BEGIN END; $$ LANGUAGE plpgsql; --- col_is_fk( table, column, description ) +-- col_is_fk( schema, table, column[] ) +CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_is_fk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should be a foreign key' ); +$$ LANGUAGE sql; + +-- col_is_fk( table, column[], description ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME[], TEXT ) RETURNS TEXT AS $$ DECLARE @@ -2269,6 +2287,12 @@ RETURNS TEXT AS $$ SELECT col_is_fk( $1, $2, ARRAY[$3], $4 ); $$ LANGUAGE sql; +-- col_is_fk( schema, table, column ) +CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME ) +RETURNS TEXT AS $$ + SELECT col_is_fk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should be a foreign key' ); +$$ LANGUAGE sql; + -- col_is_fk( table, column, description ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, TEXT ) RETURNS TEXT AS $$ @@ -2281,13 +2305,19 @@ RETURNS TEXT AS $$ SELECT col_is_fk( $1, $2, 'Column ' || quote_ident($1) || '(' || quote_ident($2) || ') should be a foreign key' ); $$ LANGUAGE sql; --- col_isnt_fk( schema, table, column, description ) +-- col_isnt_fk( schema, table, column[], description ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT ok( NOT _fkexists( $1, $2, $3 ), $4 ); $$ LANGUAGE SQL; --- col_isnt_fk( table, column, description ) +-- col_isnt_fk( schema, table, column[] ) +CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_isnt_fk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a foreign key' ); +$$ LANGUAGE sql; + +-- col_isnt_fk( table, column[], description ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT ok( NOT _fkexists( $1, $2 ), $3 ); @@ -2305,6 +2335,12 @@ RETURNS TEXT AS $$ SELECT col_isnt_fk( $1, $2, ARRAY[$3], $4 ); $$ LANGUAGE sql; +-- col_isnt_fk( schema, table, column ) +CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME ) +RETURNS TEXT AS $$ + SELECT col_isnt_fk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should not be a foreign key' ); +$$ LANGUAGE sql; + -- col_isnt_fk( table, column, description ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, TEXT ) RETURNS TEXT AS $$ @@ -2383,7 +2419,7 @@ BEGIN END; $$ LANGUAGE plpgsql; --- col_is_unique( schema, table, column, description ) +-- col_is_unique( schema, table, column[], description ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT _constraint( $1, $2, 'u', $3, $4, 'unique' ); @@ -2395,13 +2431,7 @@ RETURNS TEXT AS $$ SELECT col_is_unique( $1, $2, $3, 'Columns ' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should have a unique constraint' ); $$ LANGUAGE sql; --- col_is_unique( scheam, table, column ) -CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, NAME ) -RETURNS TEXT AS $$ - SELECT col_is_unique( $1, $2, ARRAY[$3], 'Column ' || quote_ident($2) || '(' || quote_ident($3) || ') should have a unique constraint' ); -$$ LANGUAGE sql; - --- col_is_unique( table, column, description ) +-- col_is_unique( table, column[], description ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT _constraint( $1, 'u', $2, $3, 'unique' ); @@ -2419,6 +2449,12 @@ RETURNS TEXT AS $$ SELECT col_is_unique( $1, $2, ARRAY[$3], $4 ); $$ LANGUAGE sql; +-- col_is_unique( schema, table, column ) +CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, NAME ) +RETURNS TEXT AS $$ + SELECT col_is_unique( $1, $2, ARRAY[$3], 'Column ' || quote_ident($2) || '(' || quote_ident($3) || ') should have a unique constraint' ); +$$ LANGUAGE sql; + -- col_is_unique( table, column, description ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, TEXT ) RETURNS TEXT AS $$ diff --git a/test/expected/fktap.out b/test/expected/fktap.out index 61652c30..c895a370 100644 --- a/test/expected/fktap.out +++ b/test/expected/fktap.out @@ -1,5 +1,5 @@ \unset ECHO -1..134 +1..143 ok 1 - has_fk( schema, table, description ) should pass ok 2 - has_fk( schema, table, description ) should have the proper description ok 3 - has_fk( table, description ) should pass @@ -26,111 +26,120 @@ ok 23 - hasnt_fk( table, description ) pass should pass ok 24 - hasnt_fk( table, description ) pass should have the proper description ok 25 - col_is_fk( schema, table, column, description ) should pass ok 26 - col_is_fk( schema, table, column, description ) should have the proper description -ok 27 - col_is_fk( table, column, description ) should pass -ok 28 - col_is_fk( table, column, description ) should have the proper description -ok 29 - col_is_fk( table, column ) should pass -ok 30 - col_is_fk( table, column ) should have the proper description -ok 31 - col_is_fk( schema, table, column, description ) should fail -ok 32 - col_is_fk( schema, table, column, description ) should have the proper description -ok 33 - col_is_fk( schema, table, column, description ) should have the proper diagnostics -ok 34 - col_is_fk( table, column, description ) should fail -ok 35 - col_is_fk( table, column, description ) should have the proper description -ok 36 - col_is_fk( table, column, description ) should have the proper diagnostics -ok 37 - multi-fk col_is_fk test should pass -ok 38 - multi-fk col_is_fk test should have the proper description -ok 39 - col_is_fk with no FKs should fail -ok 40 - col_is_fk with no FKs should have the proper description -ok 41 - col_is_fk with no FKs should have the proper diagnostics -ok 42 - col_is_fk with no FKs should fail -ok 43 - col_is_fk with no FKs should have the proper description -ok 44 - col_is_fk with no FKs should have the proper diagnostics -ok 45 - col_is_fk( schema, table, column[], description ) should pass -ok 46 - col_is_fk( schema, table, column[], description ) should have the proper description -ok 47 - col_is_fk( table, column[], description ) should pass -ok 48 - col_is_fk( table, column[], description ) should have the proper description -ok 49 - col_is_fk( table, column[] ) should pass -ok 50 - col_is_fk( table, column[] ) should have the proper description -ok 51 - col_isnt_fk( schema, table, column, description ) should fail -ok 52 - col_isnt_fk( schema, table, column, description ) should have the proper description -ok 53 - col_isnt_fk( schema, table, column, description ) should have the proper diagnostics -ok 54 - col_isnt_fk( table, column, description ) should fail -ok 55 - col_isnt_fk( table, column, description ) should have the proper description -ok 56 - col_isnt_fk( table, column, description ) should have the proper diagnostics -ok 57 - col_isnt_fk( table, column ) should fail -ok 58 - col_isnt_fk( table, column ) should have the proper description -ok 59 - col_isnt_fk( table, column ) should have the proper diagnostics -ok 60 - col_isnt_fk( schema, table, column, description ) should pass -ok 61 - col_isnt_fk( schema, table, column, description ) should have the proper description -ok 62 - col_isnt_fk( schema, table, column, description ) should have the proper diagnostics -ok 63 - col_isnt_fk( table, column, description ) should pass -ok 64 - col_isnt_fk( table, column, description ) should have the proper description -ok 65 - col_isnt_fk( table, column, description ) should have the proper diagnostics -ok 66 - multi-fk col_isnt_fk test should fail -ok 67 - multi-fk col_isnt_fk test should have the proper description -ok 68 - multi-fk col_isnt_fk test should have the proper diagnostics -ok 69 - col_isnt_fk with no FKs should pass -ok 70 - col_isnt_fk with no FKs should have the proper description -ok 71 - col_isnt_fk with no FKs should have the proper diagnostics -ok 72 - col_isnt_fk with no FKs should pass -ok 73 - col_isnt_fk with no FKs should have the proper description -ok 74 - col_isnt_fk with no FKs should have the proper diagnostics -ok 75 - col_isnt_fk( schema, table, column[], description ) should fail -ok 76 - col_isnt_fk( schema, table, column[], description ) should have the proper description -ok 77 - col_isnt_fk( table, column[], description ) should fail -ok 78 - col_isnt_fk( table, column[], description ) should have the proper description -ok 79 - col_isnt_fk( table, column[] ) should fail -ok 80 - col_isnt_fk( table, column[] ) should have the proper description -ok 81 - full fk_ok array should pass -ok 82 - full fk_ok array should have the proper description -ok 83 - pg_my_temp_schema() should pass -ok 84 - pg_my_temp_schema() should have the proper description -ok 85 - multiple fk fk_ok desc should pass -ok 86 - multiple fk fk_ok desc should have the proper description -ok 87 - fk_ok array desc should pass -ok 88 - fk_ok array desc should have the proper description -ok 89 - fk_ok array noschema desc should pass -ok 90 - fk_ok array noschema desc should have the proper description -ok 91 - multiple fk fk_ok noschema desc should pass -ok 92 - multiple fk fk_ok noschema desc should have the proper description -ok 93 - fk_ok array noschema should pass -ok 94 - fk_ok array noschema should have the proper description -ok 95 - basic fk_ok should pass -ok 96 - basic fk_ok should have the proper description -ok 97 - basic fk_ok desc should pass -ok 98 - basic fk_ok desc should have the proper description -ok 99 - basic fk_ok noschema should pass -ok 100 - basic fk_ok noschema should have the proper description -ok 101 - basic fk_ok noschema desc should pass -ok 102 - basic fk_ok noschema desc should have the proper description -ok 103 - basic fk_ok noschema desc should have the proper diagnostics -ok 104 - Test should pass -ok 105 - fk_ok fail should fail -ok 106 - fk_ok fail should have the proper description -ok 107 - fk_ok fail should have the proper diagnostics -ok 108 - fk_ok fail desc should fail -ok 109 - fk_ok fail desc should have the proper description -ok 110 - fk_ok fail desc should have the proper diagnostics -ok 111 - fk_ok fail no schema should fail -ok 112 - fk_ok fail no schema should have the proper description -ok 113 - fk_ok fail no schema should have the proper diagnostics -ok 114 - fk_ok fail no schema desc should fail -ok 115 - fk_ok fail no schema desc should have the proper description -ok 116 - fk_ok fail no schema desc should have the proper diagnostics -ok 117 - fk_ok bad PK test should fail -ok 118 - fk_ok bad PK test should have the proper description -ok 119 - fk_ok bad PK test should have the proper diagnostics -ok 120 - double fk schema test should pass -ok 121 - double fk schema test should have the proper description -ok 122 - double fk schema test should have the proper diagnostics -ok 123 - double fk test should pass -ok 124 - double fk test should have the proper description -ok 125 - double fk test should have the proper diagnostics -ok 126 - double fk and col schema test should pass -ok 127 - double fk and col schema test should have the proper description -ok 128 - double fk and col schema test should have the proper diagnostics -ok 129 - missing fk test should fail -ok 130 - missing fk test should have the proper description -ok 131 - missing fk test should have the proper diagnostics -ok 132 - bad FK column test should fail -ok 133 - bad FK column test should have the proper description -ok 134 - bad FK column test should have the proper diagnostics +ok 27 - col_is_fk( schema, table, column ) should pass +ok 28 - col_is_fk( schema, table, column ) should have the proper description +ok 29 - col_is_fk( table, column, description ) should pass +ok 30 - col_is_fk( table, column, description ) should have the proper description +ok 31 - col_is_fk( table, column ) should pass +ok 32 - col_is_fk( table, column ) should have the proper description +ok 33 - col_is_fk( schema, table, column, description ) should fail +ok 34 - col_is_fk( schema, table, column, description ) should have the proper description +ok 35 - col_is_fk( schema, table, column, description ) should have the proper diagnostics +ok 36 - col_is_fk( table, column, description ) should fail +ok 37 - col_is_fk( table, column, description ) should have the proper description +ok 38 - col_is_fk( table, column, description ) should have the proper diagnostics +ok 39 - multi-fk col_is_fk test should pass +ok 40 - multi-fk col_is_fk test should have the proper description +ok 41 - col_is_fk with no FKs should fail +ok 42 - col_is_fk with no FKs should have the proper description +ok 43 - col_is_fk with no FKs should have the proper diagnostics +ok 44 - col_is_fk with no FKs should fail +ok 45 - col_is_fk with no FKs should have the proper description +ok 46 - col_is_fk with no FKs should have the proper diagnostics +ok 47 - col_is_fk( schema, table, column[], description ) should pass +ok 48 - col_is_fk( schema, table, column[], description ) should have the proper description +ok 49 - col_is_fk( schema, table, column[] ) should pass +ok 50 - col_is_fk( schema, table, column[] ) should have the proper description +ok 51 - col_is_fk( table, column[], description ) should pass +ok 52 - col_is_fk( table, column[], description ) should have the proper description +ok 53 - col_is_fk( table, column[] ) should pass +ok 54 - col_is_fk( table, column[] ) should have the proper description +ok 55 - col_isnt_fk( schema, table, column, description ) should fail +ok 56 - col_isnt_fk( schema, table, column, description ) should have the proper description +ok 57 - col_isnt_fk( schema, table, column, description ) should have the proper diagnostics +ok 58 - col_isnt_fk( schema, table, column ) should fail +ok 59 - col_isnt_fk( schema, table, column ) should have the proper description +ok 60 - col_isnt_fk( schema, table, column ) should have the proper diagnostics +ok 61 - col_isnt_fk( table, column, description ) should fail +ok 62 - col_isnt_fk( table, column, description ) should have the proper description +ok 63 - col_isnt_fk( table, column, description ) should have the proper diagnostics +ok 64 - col_isnt_fk( table, column ) should fail +ok 65 - col_isnt_fk( table, column ) should have the proper description +ok 66 - col_isnt_fk( table, column ) should have the proper diagnostics +ok 67 - col_isnt_fk( schema, table, column, description ) should pass +ok 68 - col_isnt_fk( schema, table, column, description ) should have the proper description +ok 69 - col_isnt_fk( schema, table, column, description ) should have the proper diagnostics +ok 70 - col_isnt_fk( table, column, description ) should pass +ok 71 - col_isnt_fk( table, column, description ) should have the proper description +ok 72 - col_isnt_fk( table, column, description ) should have the proper diagnostics +ok 73 - multi-fk col_isnt_fk test should fail +ok 74 - multi-fk col_isnt_fk test should have the proper description +ok 75 - multi-fk col_isnt_fk test should have the proper diagnostics +ok 76 - col_isnt_fk with no FKs should pass +ok 77 - col_isnt_fk with no FKs should have the proper description +ok 78 - col_isnt_fk with no FKs should have the proper diagnostics +ok 79 - col_isnt_fk with no FKs should pass +ok 80 - col_isnt_fk with no FKs should have the proper description +ok 81 - col_isnt_fk with no FKs should have the proper diagnostics +ok 82 - col_isnt_fk( schema, table, column[], description ) should fail +ok 83 - col_isnt_fk( schema, table, column[], description ) should have the proper description +ok 84 - col_isnt_fk( schema, table, column[] ) should fail +ok 85 - col_isnt_fk( schema, table, column[] ) should have the proper description +ok 86 - col_isnt_fk( table, column[], description ) should fail +ok 87 - col_isnt_fk( table, column[], description ) should have the proper description +ok 88 - col_isnt_fk( table, column[] ) should fail +ok 89 - col_isnt_fk( table, column[] ) should have the proper description +ok 90 - full fk_ok array should pass +ok 91 - full fk_ok array should have the proper description +ok 92 - pg_my_temp_schema() should pass +ok 93 - pg_my_temp_schema() should have the proper description +ok 94 - multiple fk fk_ok desc should pass +ok 95 - multiple fk fk_ok desc should have the proper description +ok 96 - fk_ok array desc should pass +ok 97 - fk_ok array desc should have the proper description +ok 98 - fk_ok array noschema desc should pass +ok 99 - fk_ok array noschema desc should have the proper description +ok 100 - multiple fk fk_ok noschema desc should pass +ok 101 - multiple fk fk_ok noschema desc should have the proper description +ok 102 - fk_ok array noschema should pass +ok 103 - fk_ok array noschema should have the proper description +ok 104 - basic fk_ok should pass +ok 105 - basic fk_ok should have the proper description +ok 106 - basic fk_ok desc should pass +ok 107 - basic fk_ok desc should have the proper description +ok 108 - basic fk_ok noschema should pass +ok 109 - basic fk_ok noschema should have the proper description +ok 110 - basic fk_ok noschema desc should pass +ok 111 - basic fk_ok noschema desc should have the proper description +ok 112 - basic fk_ok noschema desc should have the proper diagnostics +ok 113 - Test should pass +ok 114 - fk_ok fail should fail +ok 115 - fk_ok fail should have the proper description +ok 116 - fk_ok fail should have the proper diagnostics +ok 117 - fk_ok fail desc should fail +ok 118 - fk_ok fail desc should have the proper description +ok 119 - fk_ok fail desc should have the proper diagnostics +ok 120 - fk_ok fail no schema should fail +ok 121 - fk_ok fail no schema should have the proper description +ok 122 - fk_ok fail no schema should have the proper diagnostics +ok 123 - fk_ok fail no schema desc should fail +ok 124 - fk_ok fail no schema desc should have the proper description +ok 125 - fk_ok fail no schema desc should have the proper diagnostics +ok 126 - fk_ok bad PK test should fail +ok 127 - fk_ok bad PK test should have the proper description +ok 128 - fk_ok bad PK test should have the proper diagnostics +ok 129 - double fk schema test should pass +ok 130 - double fk schema test should have the proper description +ok 131 - double fk schema test should have the proper diagnostics +ok 132 - double fk test should pass +ok 133 - double fk test should have the proper description +ok 134 - double fk test should have the proper diagnostics +ok 135 - double fk and col schema test should pass +ok 136 - double fk and col schema test should have the proper description +ok 137 - double fk and col schema test should have the proper diagnostics +ok 138 - missing fk test should fail +ok 139 - missing fk test should have the proper description +ok 140 - missing fk test should have the proper diagnostics +ok 141 - bad FK column test should fail +ok 142 - bad FK column test should have the proper description +ok 143 - bad FK column test should have the proper diagnostics diff --git a/test/expected/pktap.out b/test/expected/pktap.out index 013ee883..f710c114 100644 --- a/test/expected/pktap.out +++ b/test/expected/pktap.out @@ -1,5 +1,5 @@ \unset ECHO -1..96 +1..102 ok 1 - has_pk( schema, table, description ) should pass ok 2 - has_pk( schema, table, description ) should have the proper description ok 3 - has_pk( schema, table, description ) should have the proper diagnostics @@ -75,24 +75,30 @@ ok 72 - col_is_pk( table, column[] ) should have the proper diagnostics ok 73 - col_isnt_pk( schema, table, column, description ) should fail ok 74 - col_isnt_pk( schema, table, column, description ) should have the proper description ok 75 - col_isnt_pk( schema, table, column, description ) should have the proper diagnostics -ok 76 - col_isnt_pk( table, column, description ) should fail -ok 77 - col_isnt_pk( table, column, description ) should have the proper description -ok 78 - col_isnt_pk( table, column, description ) should have the proper diagnostics -ok 79 - col_isnt_pk( table, column ) should fail -ok 80 - col_isnt_pk( table, column ) should have the proper description -ok 81 - col_isnt_pk( table, column ) should have the proper diagnostics -ok 82 - col_isnt_pk( schema, table, column, description ) pass should pass -ok 83 - col_isnt_pk( schema, table, column, description ) pass should have the proper description -ok 84 - col_isnt_pk( schema, table, column, description ) pass should have the proper diagnostics -ok 85 - col_isnt_pk( table, column, description ) pass should pass -ok 86 - col_isnt_pk( table, column, description ) pass should have the proper description -ok 87 - col_isnt_pk( table, column, description ) pass should have the proper diagnostics -ok 88 - col_isnt_pk( schema, table, column[], description ) should pass -ok 89 - col_isnt_pk( schema, table, column[], description ) should have the proper description -ok 90 - col_isnt_pk( schema, table, column[], description ) should have the proper diagnostics -ok 91 - col_isnt_pk( table, column[], description ) should pass -ok 92 - col_isnt_pk( table, column[], description ) should have the proper description -ok 93 - col_isnt_pk( table, column[], description ) should have the proper diagnostics -ok 94 - col_isnt_pk( table, column[] ) should pass -ok 95 - col_isnt_pk( table, column[] ) should have the proper description -ok 96 - col_isnt_pk( table, column[] ) should have the proper diagnostics +ok 76 - col_isnt_pk( schema, table, column ) should fail +ok 77 - col_isnt_pk( schema, table, column ) should have the proper description +ok 78 - col_isnt_pk( schema, table, column ) should have the proper diagnostics +ok 79 - col_isnt_pk( table, column, description ) should fail +ok 80 - col_isnt_pk( table, column, description ) should have the proper description +ok 81 - col_isnt_pk( table, column, description ) should have the proper diagnostics +ok 82 - col_isnt_pk( table, column ) should fail +ok 83 - col_isnt_pk( table, column ) should have the proper description +ok 84 - col_isnt_pk( table, column ) should have the proper diagnostics +ok 85 - col_isnt_pk( schema, table, column, description ) pass should pass +ok 86 - col_isnt_pk( schema, table, column, description ) pass should have the proper description +ok 87 - col_isnt_pk( schema, table, column, description ) pass should have the proper diagnostics +ok 88 - col_isnt_pk( table, column, description ) pass should pass +ok 89 - col_isnt_pk( table, column, description ) pass should have the proper description +ok 90 - col_isnt_pk( table, column, description ) pass should have the proper diagnostics +ok 91 - col_isnt_pk( schema, table, column[], description ) should pass +ok 92 - col_isnt_pk( schema, table, column[], description ) should have the proper description +ok 93 - col_isnt_pk( schema, table, column[], description ) should have the proper diagnostics +ok 94 - col_isnt_pk( schema, table, column[] ) should pass +ok 95 - col_isnt_pk( schema, table, column[] ) should have the proper description +ok 96 - col_isnt_pk( schema, table, column[] ) should have the proper diagnostics +ok 97 - col_isnt_pk( table, column[], description ) should pass +ok 98 - col_isnt_pk( table, column[], description ) should have the proper description +ok 99 - col_isnt_pk( table, column[], description ) should have the proper diagnostics +ok 100 - col_isnt_pk( table, column[] ) should pass +ok 101 - col_isnt_pk( table, column[] ) should have the proper description +ok 102 - col_isnt_pk( table, column[] ) should have the proper diagnostics diff --git a/test/sql/fktap.sql b/test/sql/fktap.sql index 9dcee261..2f62820f 100644 --- a/test/sql/fktap.sql +++ b/test/sql/fktap.sql @@ -1,7 +1,7 @@ \unset ECHO \i test/setup.sql -SELECT plan(134); +SELECT plan(143); --SELECT * from no_plan(); -- These will be rolled back. :-) @@ -166,6 +166,13 @@ SELECT * FROM check_test( 'public.fk.pk_id should be an fk' ); +SELECT * FROM check_test( + col_is_fk( 'public', 'fk', 'pk_id'::name ), + true, + 'col_is_fk( schema, table, column )', + 'Column public.fk(pk_id) should be a foreign key' +); + SELECT * FROM check_test( col_is_fk( 'fk', 'pk_id', 'fk.pk_id should be an fk' ), true, @@ -235,6 +242,13 @@ SELECT * FROM check_test( 'id + pk2_dot should be an fk' ); +SELECT * FROM check_test( + col_is_fk( 'public', 'fk2', ARRAY['pk2_num', 'pk2_dot']::name[] ), + true, + 'col_is_fk( schema, table, column[] )', + 'Columns public.fk2(pk2_num, pk2_dot) should be a foreign key' +); + SELECT * FROM check_test( col_is_fk( 'fk2', ARRAY['pk2_num', 'pk2_dot'], 'id + pk2_dot should be an fk' ), true, @@ -260,6 +274,14 @@ SELECT * FROM check_test( '' ); +SELECT * FROM check_test( + col_isnt_fk( 'public', 'fk', 'pk_id'::name ), + false, + 'col_isnt_fk( schema, table, column )', + 'Column public.fk(pk_id) should not be a foreign key', + '' +); + SELECT * FROM check_test( col_isnt_fk( 'fk', 'pk_id', 'fk.pk_id should not be an fk' ), false, @@ -328,6 +350,13 @@ SELECT * FROM check_test( 'id + pk2_dot should not be an fk' ); +SELECT * FROM check_test( + col_isnt_fk( 'public', 'fk2', ARRAY['pk2_num', 'pk2_dot']::name[] ), + false, + 'col_isnt_fk( schema, table, column[] )', + 'Columns public.fk2(pk2_num, pk2_dot) should not be a foreign key' +); + SELECT * FROM check_test( col_isnt_fk( 'fk2', ARRAY['pk2_num', 'pk2_dot'], 'id + pk2_dot should not be an fk' ), false, diff --git a/test/sql/pktap.sql b/test/sql/pktap.sql index e361f7dd..891eb212 100644 --- a/test/sql/pktap.sql +++ b/test/sql/pktap.sql @@ -2,7 +2,7 @@ \i test/setup.sql -- \i sql/pgtap.sql -SELECT plan(96); +SELECT plan(102); --SELECT * FROM no_plan(); -- This will be rolled back. :-) @@ -253,6 +253,15 @@ SELECT * FROM check_test( want: anything else' ); +SELECT * FROM check_test( + col_isnt_pk( 'public', 'sometab', 'id'::name ), + false, + 'col_isnt_pk( schema, table, column )', + 'Column public.sometab(id) should not be a primary key', + ' have: {id} + want: anything else' +); + SELECT * FROM check_test( col_isnt_pk( 'sometab', 'id', 'sometab.id should not be a pk' ), false, @@ -298,6 +307,14 @@ SELECT * FROM check_test( '' ); +SELECT * FROM check_test( + col_isnt_pk( 'public', 'argh', ARRAY['id', 'foo']::name[] ), + true, + 'col_isnt_pk( schema, table, column[] )', + 'Columns public.argh(id, foo) should not be a primary key', + '' +); + SELECT * FROM check_test( col_isnt_pk( 'argh', ARRAY['id', 'foo'], 'id + foo should not be a pk' ), true, From ce55a7936be32d3f95b43435e07236d6b2eb7512 Mon Sep 17 00:00:00 2001 From: RampantDespair Date: Sun, 26 Jul 2026 14:34:05 -0400 Subject: [PATCH 2/5] Updated comments from `colum[]` to `columns[]` --- Changes | 2 +- sql/pgtap--1.3.4--1.3.5.sql | 6 ++--- sql/pgtap.sql.in | 40 +++++++++++++++---------------- test/expected/fktap.out | 32 ++++++++++++------------- test/expected/pktap.out | 48 ++++++++++++++++++------------------- test/expected/unique.out | 18 +++++++------- test/sql/fktap.sql | 16 ++++++------- test/sql/pktap.sql | 16 ++++++------- test/sql/unique.sql | 6 ++--- 9 files changed, 92 insertions(+), 92 deletions(-) diff --git a/Changes b/Changes index 6fe2704f..23717491 100644 --- a/Changes +++ b/Changes @@ -7,7 +7,7 @@ Revision history for pgTAP has upgraded its Markdown parser. * Added an example of an empty array, `'{}'::name[]`, to each mention in the documentation. Thanks Kevin Brannen for the suggestion (#362). -* Added missing `schema, table, column[]` and `schema, table, column` variants +* Added missing `schema, table, columns[]` and `schema, table, column` variants of `col_isnt_pk()`, `col_is_fk()`, and `col_isnt_fk()`, and established a consistent overload order for `col_is_pk()`, `col_isnt_pk()`, `col_is_fk()`, `col_isnt_fk()`, and `col_is_unique()`. diff --git a/sql/pgtap--1.3.4--1.3.5.sql b/sql/pgtap--1.3.4--1.3.5.sql index c0d249b6..565dd6c3 100644 --- a/sql/pgtap--1.3.4--1.3.5.sql +++ b/sql/pgtap--1.3.4--1.3.5.sql @@ -1,6 +1,6 @@ -- Changes between pgTAP v1.3.4 and v1.3.5. --- col_isnt_pk( schema, table, column[] ) +-- col_isnt_pk( schema, table, columns[] ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_isnt_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a primary key' ); @@ -12,7 +12,7 @@ RETURNS TEXT AS $$ SELECT col_isnt_pk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should not be a primary key' ); $$ LANGUAGE sql; --- col_is_fk( schema, table, column[] ) +-- col_is_fk( schema, table, columns[] ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_is_fk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should be a foreign key' ); @@ -24,7 +24,7 @@ RETURNS TEXT AS $$ SELECT col_is_fk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should be a foreign key' ); $$ LANGUAGE sql; --- col_isnt_fk( schema, table, column[] ) +-- col_isnt_fk( schema, table, columns[] ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_isnt_fk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a foreign key' ); diff --git a/sql/pgtap.sql.in b/sql/pgtap.sql.in index 00ac68a8..4005acfe 100644 --- a/sql/pgtap.sql.in +++ b/sql/pgtap.sql.in @@ -2050,25 +2050,25 @@ RETURNS NAME[] AS $$ SELECT * FROM _keys($1, $2) LIMIT 1; $$ LANGUAGE sql; --- col_is_pk( schema, table, column[], description ) +-- col_is_pk( schema, table, columns[], description ) CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT is( _ckeys( $1, $2, 'p' ), $3, $4 ); $$ LANGUAGE sql; --- col_is_pk( schema, table, column[] ) +-- col_is_pk( schema, table, columns[] ) CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_is_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should be a primary key' ); $$ LANGUAGE sql; --- col_is_pk( table, column[], description ) +-- col_is_pk( table, columns[], description ) CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT is( _ckeys( $1, 'p' ), $2, $3 ); $$ LANGUAGE sql; --- col_is_pk( table, column[] ) +-- col_is_pk( table, columns[] ) CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_is_pk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should be a primary key' ); @@ -2098,25 +2098,25 @@ RETURNS TEXT AS $$ SELECT col_is_pk( $1, $2, 'Column ' || quote_ident($1) || '(' || quote_ident($2) || ') should be a primary key' ); $$ LANGUAGE sql; --- col_isnt_pk( schema, table, column[], description ) +-- col_isnt_pk( schema, table, columns[], description ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT isnt( _ckeys( $1, $2, 'p' ), $3, $4 ); $$ LANGUAGE sql; --- col_isnt_pk( schema, table, column[] ) +-- col_isnt_pk( schema, table, columns[] ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_isnt_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a primary key' ); $$ LANGUAGE sql; --- col_isnt_pk( table, column[], description ) +-- col_isnt_pk( table, columns[], description ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT isnt( _ckeys( $1, 'p' ), $2, $3 ); $$ LANGUAGE sql; --- col_isnt_pk( table, column[] ) +-- col_isnt_pk( table, columns[] ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_isnt_pk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should not be a primary key' ); @@ -2204,7 +2204,7 @@ RETURNS BOOLEAN AS $$ ); $$ LANGUAGE SQL; --- col_is_fk( schema, table, column[], description ) +-- col_is_fk( schema, table, columns[], description ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME[], TEXT ) RETURNS TEXT AS $$ DECLARE @@ -2237,13 +2237,13 @@ BEGIN END; $$ LANGUAGE plpgsql; --- col_is_fk( schema, table, column[] ) +-- col_is_fk( schema, table, columns[] ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_is_fk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should be a foreign key' ); $$ LANGUAGE sql; --- col_is_fk( table, column[], description ) +-- col_is_fk( table, columns[], description ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME[], TEXT ) RETURNS TEXT AS $$ DECLARE @@ -2275,7 +2275,7 @@ BEGIN END; $$ LANGUAGE plpgsql; --- col_is_fk( table, column[] ) +-- col_is_fk( table, columns[] ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_is_fk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should be a foreign key' ); @@ -2305,25 +2305,25 @@ RETURNS TEXT AS $$ SELECT col_is_fk( $1, $2, 'Column ' || quote_ident($1) || '(' || quote_ident($2) || ') should be a foreign key' ); $$ LANGUAGE sql; --- col_isnt_fk( schema, table, column[], description ) +-- col_isnt_fk( schema, table, columns[], description ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT ok( NOT _fkexists( $1, $2, $3 ), $4 ); $$ LANGUAGE SQL; --- col_isnt_fk( schema, table, column[] ) +-- col_isnt_fk( schema, table, columns[] ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_isnt_fk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a foreign key' ); $$ LANGUAGE sql; --- col_isnt_fk( table, column[], description ) +-- col_isnt_fk( table, columns[], description ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT ok( NOT _fkexists( $1, $2 ), $3 ); $$ LANGUAGE SQL; --- col_isnt_fk( table, column[] ) +-- col_isnt_fk( table, columns[] ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_isnt_fk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should not be a foreign key' ); @@ -2419,25 +2419,25 @@ BEGIN END; $$ LANGUAGE plpgsql; --- col_is_unique( schema, table, column[], description ) +-- col_is_unique( schema, table, columns[], description ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT _constraint( $1, $2, 'u', $3, $4, 'unique' ); $$ LANGUAGE sql; --- col_is_unique( schema, table, column[] ) +-- col_is_unique( schema, table, columns[] ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_is_unique( $1, $2, $3, 'Columns ' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should have a unique constraint' ); $$ LANGUAGE sql; --- col_is_unique( table, column[], description ) +-- col_is_unique( table, columns[], description ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME[], TEXT ) RETURNS TEXT AS $$ SELECT _constraint( $1, 'u', $2, $3, 'unique' ); $$ LANGUAGE sql; --- col_is_unique( table, column[] ) +-- col_is_unique( table, columns[] ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_is_unique( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should have a unique constraint' ); diff --git a/test/expected/fktap.out b/test/expected/fktap.out index c895a370..baf93f72 100644 --- a/test/expected/fktap.out +++ b/test/expected/fktap.out @@ -46,14 +46,14 @@ ok 43 - col_is_fk with no FKs should have the proper diagnostics ok 44 - col_is_fk with no FKs should fail ok 45 - col_is_fk with no FKs should have the proper description ok 46 - col_is_fk with no FKs should have the proper diagnostics -ok 47 - col_is_fk( schema, table, column[], description ) should pass -ok 48 - col_is_fk( schema, table, column[], description ) should have the proper description -ok 49 - col_is_fk( schema, table, column[] ) should pass -ok 50 - col_is_fk( schema, table, column[] ) should have the proper description -ok 51 - col_is_fk( table, column[], description ) should pass -ok 52 - col_is_fk( table, column[], description ) should have the proper description -ok 53 - col_is_fk( table, column[] ) should pass -ok 54 - col_is_fk( table, column[] ) should have the proper description +ok 47 - col_is_fk( schema, table, columns[], description ) should pass +ok 48 - col_is_fk( schema, table, columns[], description ) should have the proper description +ok 49 - col_is_fk( schema, table, columns[] ) should pass +ok 50 - col_is_fk( schema, table, columns[] ) should have the proper description +ok 51 - col_is_fk( table, columns[], description ) should pass +ok 52 - col_is_fk( table, columns[], description ) should have the proper description +ok 53 - col_is_fk( table, columns[] ) should pass +ok 54 - col_is_fk( table, columns[] ) should have the proper description ok 55 - col_isnt_fk( schema, table, column, description ) should fail ok 56 - col_isnt_fk( schema, table, column, description ) should have the proper description ok 57 - col_isnt_fk( schema, table, column, description ) should have the proper diagnostics @@ -81,14 +81,14 @@ ok 78 - col_isnt_fk with no FKs should have the proper diagnostics ok 79 - col_isnt_fk with no FKs should pass ok 80 - col_isnt_fk with no FKs should have the proper description ok 81 - col_isnt_fk with no FKs should have the proper diagnostics -ok 82 - col_isnt_fk( schema, table, column[], description ) should fail -ok 83 - col_isnt_fk( schema, table, column[], description ) should have the proper description -ok 84 - col_isnt_fk( schema, table, column[] ) should fail -ok 85 - col_isnt_fk( schema, table, column[] ) should have the proper description -ok 86 - col_isnt_fk( table, column[], description ) should fail -ok 87 - col_isnt_fk( table, column[], description ) should have the proper description -ok 88 - col_isnt_fk( table, column[] ) should fail -ok 89 - col_isnt_fk( table, column[] ) should have the proper description +ok 82 - col_isnt_fk( schema, table, columns[], description ) should fail +ok 83 - col_isnt_fk( schema, table, columns[], description ) should have the proper description +ok 84 - col_isnt_fk( schema, table, columns[] ) should fail +ok 85 - col_isnt_fk( schema, table, columns[] ) should have the proper description +ok 86 - col_isnt_fk( table, columns[], description ) should fail +ok 87 - col_isnt_fk( table, columns[], description ) should have the proper description +ok 88 - col_isnt_fk( table, columns[] ) should fail +ok 89 - col_isnt_fk( table, columns[] ) should have the proper description ok 90 - full fk_ok array should pass ok 91 - full fk_ok array should have the proper description ok 92 - pg_my_temp_schema() should pass diff --git a/test/expected/pktap.out b/test/expected/pktap.out index f710c114..f70ed53d 100644 --- a/test/expected/pktap.out +++ b/test/expected/pktap.out @@ -60,18 +60,18 @@ ok 57 - col_is_pk( schema, table, column, description ) fail should have the pro ok 58 - col_is_pk( table, column, description ) fail should fail ok 59 - col_is_pk( table, column, description ) fail should have the proper description ok 60 - col_is_pk( table, column, description ) fail should have the proper diagnostics -ok 61 - col_is_pk( schema, table, column[], description ) should pass -ok 62 - col_is_pk( schema, table, column[], description ) should have the proper description -ok 63 - col_is_pk( schema, table, column[], description ) should have the proper diagnostics -ok 64 - col_is_pk( schema, table, column[] ) should pass -ok 65 - col_is_pk( schema, table, column[] ) should have the proper description -ok 66 - col_is_pk( schema, table, column[] ) should have the proper diagnostics -ok 67 - col_is_pk( table, column[], description ) should pass -ok 68 - col_is_pk( table, column[], description ) should have the proper description -ok 69 - col_is_pk( table, column[], description ) should have the proper diagnostics -ok 70 - col_is_pk( table, column[] ) should pass -ok 71 - col_is_pk( table, column[] ) should have the proper description -ok 72 - col_is_pk( table, column[] ) should have the proper diagnostics +ok 61 - col_is_pk( schema, table, columns[], description ) should pass +ok 62 - col_is_pk( schema, table, columns[], description ) should have the proper description +ok 63 - col_is_pk( schema, table, columns[], description ) should have the proper diagnostics +ok 64 - col_is_pk( schema, table, columns[] ) should pass +ok 65 - col_is_pk( schema, table, columns[] ) should have the proper description +ok 66 - col_is_pk( schema, table, columns[] ) should have the proper diagnostics +ok 67 - col_is_pk( table, columns[], description ) should pass +ok 68 - col_is_pk( table, columns[], description ) should have the proper description +ok 69 - col_is_pk( table, columns[], description ) should have the proper diagnostics +ok 70 - col_is_pk( table, columns[] ) should pass +ok 71 - col_is_pk( table, columns[] ) should have the proper description +ok 72 - col_is_pk( table, columns[] ) should have the proper diagnostics ok 73 - col_isnt_pk( schema, table, column, description ) should fail ok 74 - col_isnt_pk( schema, table, column, description ) should have the proper description ok 75 - col_isnt_pk( schema, table, column, description ) should have the proper diagnostics @@ -90,15 +90,15 @@ ok 87 - col_isnt_pk( schema, table, column, description ) pass should have the p ok 88 - col_isnt_pk( table, column, description ) pass should pass ok 89 - col_isnt_pk( table, column, description ) pass should have the proper description ok 90 - col_isnt_pk( table, column, description ) pass should have the proper diagnostics -ok 91 - col_isnt_pk( schema, table, column[], description ) should pass -ok 92 - col_isnt_pk( schema, table, column[], description ) should have the proper description -ok 93 - col_isnt_pk( schema, table, column[], description ) should have the proper diagnostics -ok 94 - col_isnt_pk( schema, table, column[] ) should pass -ok 95 - col_isnt_pk( schema, table, column[] ) should have the proper description -ok 96 - col_isnt_pk( schema, table, column[] ) should have the proper diagnostics -ok 97 - col_isnt_pk( table, column[], description ) should pass -ok 98 - col_isnt_pk( table, column[], description ) should have the proper description -ok 99 - col_isnt_pk( table, column[], description ) should have the proper diagnostics -ok 100 - col_isnt_pk( table, column[] ) should pass -ok 101 - col_isnt_pk( table, column[] ) should have the proper description -ok 102 - col_isnt_pk( table, column[] ) should have the proper diagnostics +ok 91 - col_isnt_pk( schema, table, columns[], description ) should pass +ok 92 - col_isnt_pk( schema, table, columns[], description ) should have the proper description +ok 93 - col_isnt_pk( schema, table, columns[], description ) should have the proper diagnostics +ok 94 - col_isnt_pk( schema, table, columns[] ) should pass +ok 95 - col_isnt_pk( schema, table, columns[] ) should have the proper description +ok 96 - col_isnt_pk( schema, table, columns[] ) should have the proper diagnostics +ok 97 - col_isnt_pk( table, columns[], description ) should pass +ok 98 - col_isnt_pk( table, columns[], description ) should have the proper description +ok 99 - col_isnt_pk( table, columns[], description ) should have the proper diagnostics +ok 100 - col_isnt_pk( table, columns[] ) should pass +ok 101 - col_isnt_pk( table, columns[] ) should have the proper description +ok 102 - col_isnt_pk( table, columns[] ) should have the proper diagnostics diff --git a/test/expected/unique.out b/test/expected/unique.out index 44c3c43d..5c052445 100644 --- a/test/expected/unique.out +++ b/test/expected/unique.out @@ -45,12 +45,12 @@ ok 42 - col_is_unique( schema, table, column, description ) fail should have the ok 43 - col_is_unique( table, column, description ) fail should fail ok 44 - col_is_unique( table, column, description ) fail should have the proper description ok 45 - col_is_unique( table, column, description ) fail should have the proper diagnostics -ok 46 - col_is_unique( schema, table, column[], description ) should pass -ok 47 - col_is_unique( schema, table, column[], description ) should have the proper description -ok 48 - col_is_unique( schema, table, column[], description ) should have the proper diagnostics -ok 49 - col_is_unique( table, column[], description ) should pass -ok 50 - col_is_unique( table, column[], description ) should have the proper description -ok 51 - col_is_unique( table, column[], description ) should have the proper diagnostics -ok 52 - col_is_unique( table, column[] ) should pass -ok 53 - col_is_unique( table, column[] ) should have the proper description -ok 54 - col_is_unique( table, column[] ) should have the proper diagnostics +ok 46 - col_is_unique( schema, table, columns[], description ) should pass +ok 47 - col_is_unique( schema, table, columns[], description ) should have the proper description +ok 48 - col_is_unique( schema, table, columns[], description ) should have the proper diagnostics +ok 49 - col_is_unique( table, columns[], description ) should pass +ok 50 - col_is_unique( table, columns[], description ) should have the proper description +ok 51 - col_is_unique( table, columns[], description ) should have the proper diagnostics +ok 52 - col_is_unique( table, columns[] ) should pass +ok 53 - col_is_unique( table, columns[] ) should have the proper description +ok 54 - col_is_unique( table, columns[] ) should have the proper diagnostics diff --git a/test/sql/fktap.sql b/test/sql/fktap.sql index 2f62820f..e321c001 100644 --- a/test/sql/fktap.sql +++ b/test/sql/fktap.sql @@ -238,28 +238,28 @@ SELECT * FROM check_test( SELECT * FROM check_test( col_is_fk( 'public', 'fk2', ARRAY['pk2_num', 'pk2_dot'], 'id + pk2_dot should be an fk' ), true, - 'col_is_fk( schema, table, column[], description )', + 'col_is_fk( schema, table, columns[], description )', 'id + pk2_dot should be an fk' ); SELECT * FROM check_test( col_is_fk( 'public', 'fk2', ARRAY['pk2_num', 'pk2_dot']::name[] ), true, - 'col_is_fk( schema, table, column[] )', + 'col_is_fk( schema, table, columns[] )', 'Columns public.fk2(pk2_num, pk2_dot) should be a foreign key' ); SELECT * FROM check_test( col_is_fk( 'fk2', ARRAY['pk2_num', 'pk2_dot'], 'id + pk2_dot should be an fk' ), true, - 'col_is_fk( table, column[], description )', + 'col_is_fk( table, columns[], description )', 'id + pk2_dot should be an fk' ); SELECT * FROM check_test( col_is_fk( 'fk2', ARRAY['pk2_num', 'pk2_dot'] ), true, - 'col_is_fk( table, column[] )', + 'col_is_fk( table, columns[] )', 'Columns fk2(pk2_num, pk2_dot) should be a foreign key' ); @@ -346,28 +346,28 @@ SELECT * FROM check_test( SELECT * FROM check_test( col_isnt_fk( 'public', 'fk2', ARRAY['pk2_num', 'pk2_dot'], 'id + pk2_dot should not be an fk' ), false, - 'col_isnt_fk( schema, table, column[], description )', + 'col_isnt_fk( schema, table, columns[], description )', 'id + pk2_dot should not be an fk' ); SELECT * FROM check_test( col_isnt_fk( 'public', 'fk2', ARRAY['pk2_num', 'pk2_dot']::name[] ), false, - 'col_isnt_fk( schema, table, column[] )', + 'col_isnt_fk( schema, table, columns[] )', 'Columns public.fk2(pk2_num, pk2_dot) should not be a foreign key' ); SELECT * FROM check_test( col_isnt_fk( 'fk2', ARRAY['pk2_num', 'pk2_dot'], 'id + pk2_dot should not be an fk' ), false, - 'col_isnt_fk( table, column[], description )', + 'col_isnt_fk( table, columns[], description )', 'id + pk2_dot should not be an fk' ); SELECT * FROM check_test( col_isnt_fk( 'fk2', ARRAY['pk2_num', 'pk2_dot'] ), false, - 'col_isnt_fk( table, column[] )', + 'col_isnt_fk( table, columns[] )', 'Columns fk2(pk2_num, pk2_dot) should not be a foreign key' ); diff --git a/test/sql/pktap.sql b/test/sql/pktap.sql index 891eb212..4f51c8d9 100644 --- a/test/sql/pktap.sql +++ b/test/sql/pktap.sql @@ -212,7 +212,7 @@ RESET client_min_messages; SELECT * FROM check_test( col_is_pk( 'public', 'argh', ARRAY['id', 'name'], 'id + name should be a pk' ), true, - 'col_is_pk( schema, table, column[], description )', + 'col_is_pk( schema, table, columns[], description )', 'id + name should be a pk', '' ); @@ -220,7 +220,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( col_is_pk( 'public', 'argh', ARRAY['id', 'name']::name[] ), true, - 'col_is_pk( schema, table, column[] )', + 'col_is_pk( schema, table, columns[] )', 'Columns public.argh(id, name) should be a primary key', '' ); @@ -228,7 +228,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( col_is_pk( 'argh', ARRAY['id', 'name'], 'id + name should be a pk' ), true, - 'col_is_pk( table, column[], description )', + 'col_is_pk( table, columns[], description )', 'id + name should be a pk', '' ); @@ -236,7 +236,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( col_is_pk( 'argh', ARRAY['id', 'name'] ), true, - 'col_is_pk( table, column[] )', + 'col_is_pk( table, columns[] )', 'Columns argh(id, name) should be a primary key', '' ); @@ -302,7 +302,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( col_isnt_pk( 'public', 'argh', ARRAY['id', 'foo'], 'id + foo should not be a pk' ), true, - 'col_isnt_pk( schema, table, column[], description )', + 'col_isnt_pk( schema, table, columns[], description )', 'id + foo should not be a pk', '' ); @@ -310,7 +310,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( col_isnt_pk( 'public', 'argh', ARRAY['id', 'foo']::name[] ), true, - 'col_isnt_pk( schema, table, column[] )', + 'col_isnt_pk( schema, table, columns[] )', 'Columns public.argh(id, foo) should not be a primary key', '' ); @@ -318,7 +318,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( col_isnt_pk( 'argh', ARRAY['id', 'foo'], 'id + foo should not be a pk' ), true, - 'col_isnt_pk( table, column[], description )', + 'col_isnt_pk( table, columns[], description )', 'id + foo should not be a pk', '' ); @@ -326,7 +326,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( col_isnt_pk( 'argh', ARRAY['id', 'foo'] ), true, - 'col_isnt_pk( table, column[] )', + 'col_isnt_pk( table, columns[] )', 'Columns argh(id, foo) should not be a primary key', '' ); diff --git a/test/sql/unique.sql b/test/sql/unique.sql index 1019beb2..2fbe699d 100644 --- a/test/sql/unique.sql +++ b/test/sql/unique.sql @@ -162,7 +162,7 @@ RESET client_min_messages; SELECT * FROM check_test( col_is_unique( 'public', 'argh', ARRAY['id', 'name'], 'id + name should be unique' ), true, - 'col_is_unique( schema, table, column[], description )', + 'col_is_unique( schema, table, columns[], description )', 'id + name should be unique', '' ); @@ -170,7 +170,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( col_is_unique( 'argh', ARRAY['id', 'name'], 'id + name should be unique' ), true, - 'col_is_unique( table, column[], description )', + 'col_is_unique( table, columns[], description )', 'id + name should be unique', '' ); @@ -178,7 +178,7 @@ SELECT * FROM check_test( SELECT * FROM check_test( col_is_unique( 'argh', ARRAY['id', 'name'] ), true, - 'col_is_unique( table, column[] )', + 'col_is_unique( table, columns[] )', 'Columns argh(id, name) should have a unique constraint', '' ); From 1cf73fd2f6061883aa58ece6c02b1086637250ba Mon Sep 17 00:00:00 2001 From: RampantDespair Date: Mon, 27 Jul 2026 13:11:34 -0400 Subject: [PATCH 3/5] Updated comments from `colum[]` to `columns[]` p2 --- sql/pgtap--0.92.0--0.93.0.sql | 2 +- sql/pgtap--0.94.0--0.95.0.sql | 2 +- sql/pgtap--1.2.0--1.3.0.sql | 2 +- sql/pgtap.sql.in | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sql/pgtap--0.92.0--0.93.0.sql b/sql/pgtap--0.92.0--0.93.0.sql index d4e6d4a0..7cfa26af 100644 --- a/sql/pgtap--0.92.0--0.93.0.sql +++ b/sql/pgtap--0.92.0--0.93.0.sql @@ -84,7 +84,7 @@ BEGIN END; $$ LANGUAGE plpgsql; --- fk_ok( fk_table, fk_column[], pk_table, pk_column[], description ) +-- fk_ok( fk_table, fk_columns[], pk_table, pk_columns[], description ) CREATE OR REPLACE FUNCTION fk_ok ( NAME, NAME[], NAME, NAME[], TEXT ) RETURNS TEXT AS $$ DECLARE diff --git a/sql/pgtap--0.94.0--0.95.0.sql b/sql/pgtap--0.94.0--0.95.0.sql index 90ab56ad..fafcf594 100644 --- a/sql/pgtap--0.94.0--0.95.0.sql +++ b/sql/pgtap--0.94.0--0.95.0.sql @@ -384,7 +384,7 @@ RETURNS TEXT AS $$ SELECT ok( NOT _strict($1), 'Function ' || quote_ident($1) || '() should not be strict' ); $$ LANGUAGE sql; --- col_is_unique( schema, table, column[] ) +-- col_is_unique( schema, table, columns[] ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_is_unique( $1, $2, $3, 'Columns ' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should have a unique constraint' ); diff --git a/sql/pgtap--1.2.0--1.3.0.sql b/sql/pgtap--1.2.0--1.3.0.sql index 2327e654..5d1874da 100644 --- a/sql/pgtap--1.2.0--1.3.0.sql +++ b/sql/pgtap--1.2.0--1.3.0.sql @@ -144,7 +144,7 @@ BEGIN END; $$ LANGUAGE plpgsql; --- col_is_pk( schema, table, column[] ) +-- col_is_pk( schema, table, columns[] ) CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_is_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should be a primary key' ); diff --git a/sql/pgtap.sql.in b/sql/pgtap.sql.in index 4005acfe..87efcfe7 100644 --- a/sql/pgtap.sql.in +++ b/sql/pgtap.sql.in @@ -2497,7 +2497,7 @@ RETURNS TEXT AS $$ SELECT _constraint( $1, 'c', $2, $3, 'check' ); $$ LANGUAGE sql; --- col_has_check( table, column[] ) +-- col_has_check( table, columns[] ) CREATE OR REPLACE FUNCTION col_has_check ( NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_has_check( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should have a check constraint' ); @@ -2521,7 +2521,7 @@ RETURNS TEXT AS $$ SELECT col_has_check( $1, $2, 'Column ' || quote_ident($1) || '(' || quote_ident($2) || ') should have a check constraint' ); $$ LANGUAGE sql; --- fk_ok( fk_schema, fk_table, fk_column[], pk_schema, pk_table, pk_column[], description ) +-- fk_ok( fk_schema, fk_table, fk_columns[], pk_schema, pk_table, pk_columns[], description ) CREATE OR REPLACE FUNCTION fk_ok ( NAME, NAME, NAME[], NAME, NAME, NAME[], TEXT ) RETURNS TEXT AS $$ DECLARE @@ -2549,7 +2549,7 @@ BEGIN END; $$ LANGUAGE plpgsql; --- fk_ok( fk_table, fk_column[], pk_table, pk_column[], description ) +-- fk_ok( fk_table, fk_columns[], pk_table, pk_columns[], description ) CREATE OR REPLACE FUNCTION fk_ok ( NAME, NAME[], NAME, NAME[], TEXT ) RETURNS TEXT AS $$ DECLARE @@ -2576,7 +2576,7 @@ BEGIN END; $$ LANGUAGE plpgsql; --- fk_ok( fk_schema, fk_table, fk_column[], fk_schema, pk_table, pk_column[] ) +-- fk_ok( fk_schema, fk_table, fk_columns[], fk_schema, pk_table, pk_columns[] ) CREATE OR REPLACE FUNCTION fk_ok ( NAME, NAME, NAME[], NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT fk_ok( $1, $2, $3, $4, $5, $6, @@ -2586,7 +2586,7 @@ RETURNS TEXT AS $$ ); $$ LANGUAGE sql; --- fk_ok( fk_table, fk_column[], pk_table, pk_column[] ) +-- fk_ok( fk_table, fk_columns[], pk_table, pk_columns[] ) CREATE OR REPLACE FUNCTION fk_ok ( NAME, NAME[], NAME, NAME[] ) RETURNS TEXT AS $$ SELECT fk_ok( $1, $2, $3, $4, From 956d2f7822d4e9bdc00b423fe4af70a59202baf1 Mon Sep 17 00:00:00 2001 From: RampantDespair Date: Mon, 27 Jul 2026 13:47:21 -0400 Subject: [PATCH 4/5] Reordered queries to comply with Option 3 --- doc/pgtap.md | 30 ++++---- sql/pgtap.sql.in | 180 +++++++++++++++++++++++------------------------ 2 files changed, 105 insertions(+), 105 deletions(-) diff --git a/doc/pgtap.md b/doc/pgtap.md index 24f2a3c1..c1a21c8e 100644 --- a/doc/pgtap.md +++ b/doc/pgtap.md @@ -5191,12 +5191,12 @@ foreign key does *not* exist. ```sql SELECT col_is_pk( :schema, :table, :columns, :description ); -SELECT col_is_pk( :schema, :table, :columns ); -SELECT col_is_pk( :table, :columns, :description ); -SELECT col_is_pk( :table, :columns ); SELECT col_is_pk( :schema, :table, :column, :description ); +SELECT col_is_pk( :schema, :table, :columns ); SELECT col_is_pk( :schema, :table, :column ); +SELECT col_is_pk( :table, :columns, :description ); SELECT col_is_pk( :table, :column, :description ); +SELECT col_is_pk( :table, :columns ); SELECT col_is_pk( :table, :column ); ``` @@ -5249,12 +5249,12 @@ Will produce something like this: ```sql SELECT col_isnt_pk( :schema, :table, :columns, :description ); -SELECT col_isnt_pk( :schema, :table, :columns ); -SELECT col_isnt_pk( :table, :columns, :description ); -SELECT col_isnt_pk( :table, :columns ); SELECT col_isnt_pk( :schema, :table, :column, :description ); +SELECT col_isnt_pk( :schema, :table, :columns ); SELECT col_isnt_pk( :schema, :table, :column ); +SELECT col_isnt_pk( :table, :columns, :description ); SELECT col_isnt_pk( :table, :column, :description ); +SELECT col_isnt_pk( :table, :columns ); SELECT col_isnt_pk( :table, :column ); ``` @@ -5282,12 +5282,12 @@ specified column or columns are not a primary key. ```sql SELECT col_is_fk( :schema, :table, :columns, :description ); -SELECT col_is_fk( :schema, :table, :columns ); -SELECT col_is_fk( :table, :columns, :description ); -SELECT col_is_fk( :table, :columns ); SELECT col_is_fk( :schema, :table, :column, :description ); +SELECT col_is_fk( :schema, :table, :columns ); SELECT col_is_fk( :schema, :table, :column ); +SELECT col_is_fk( :table, :columns, :description ); SELECT col_is_fk( :table, :column, :description ); +SELECT col_is_fk( :table, :columns ); SELECT col_is_fk( :table, :column ); ``` @@ -5321,12 +5321,12 @@ simply list all of the foreign key constraint columns, like so: ```sql SELECT col_isnt_fk( :schema, :table, :columns, :description ); -SELECT col_isnt_fk( :schema, :table, :columns ); -SELECT col_isnt_fk( :table, :columns, :description ); -SELECT col_isnt_fk( :table, :columns ); SELECT col_isnt_fk( :schema, :table, :column, :description ); +SELECT col_isnt_fk( :schema, :table, :columns ); SELECT col_isnt_fk( :schema, :table, :column ); +SELECT col_isnt_fk( :table, :columns, :description ); SELECT col_isnt_fk( :table, :column, :description ); +SELECT col_isnt_fk( :table, :columns ); SELECT col_isnt_fk( :table, :column ); ``` @@ -5473,12 +5473,12 @@ in question does not exist. ```sql SELECT col_is_unique( schema, table, columns, description ); -SELECT col_is_unique( schema, table, columns ); -SELECT col_is_unique( table, columns, description ); -SELECT col_is_unique( table, columns ); SELECT col_is_unique( schema, table, column, description ); +SELECT col_is_unique( schema, table, columns ); SELECT col_is_unique( schema, table, column ); +SELECT col_is_unique( table, columns, description ); SELECT col_is_unique( table, column, description ); +SELECT col_is_unique( table, columns ); SELECT col_is_unique( table, column ); ``` diff --git a/sql/pgtap.sql.in b/sql/pgtap.sql.in index 87efcfe7..69435367 100644 --- a/sql/pgtap.sql.in +++ b/sql/pgtap.sql.in @@ -2056,42 +2056,42 @@ RETURNS TEXT AS $$ SELECT is( _ckeys( $1, $2, 'p' ), $3, $4 ); $$ LANGUAGE sql; --- col_is_pk( schema, table, columns[] ) -CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[] ) -RETURNS TEXT AS $$ - SELECT col_is_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should be a primary key' ); -$$ LANGUAGE sql; - --- col_is_pk( table, columns[], description ) -CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME[], TEXT ) -RETURNS TEXT AS $$ - SELECT is( _ckeys( $1, 'p' ), $2, $3 ); -$$ LANGUAGE sql; - --- col_is_pk( table, columns[] ) -CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME[] ) -RETURNS TEXT AS $$ - SELECT col_is_pk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should be a primary key' ); -$$ LANGUAGE sql; - -- col_is_pk( schema, table, column, description ) CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME, TEXT ) RETURNS TEXT AS $$ SELECT col_is_pk( $1, $2, ARRAY[$3], $4 ); $$ LANGUAGE sql; +-- col_is_pk( schema, table, columns[] ) +CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_is_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should be a primary key' ); +$$ LANGUAGE sql; + -- col_is_pk( schema, table, column ) CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME ) RETURNS TEXT AS $$ SELECT col_is_pk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should be a primary key' ); $$ LANGUAGE sql; +-- col_is_pk( table, columns[], description ) +CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME[], TEXT ) +RETURNS TEXT AS $$ + SELECT is( _ckeys( $1, 'p' ), $2, $3 ); +$$ LANGUAGE sql; + -- col_is_pk( table, column, description ) CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, TEXT ) RETURNS TEXT AS $$ SELECT col_is_pk( $1, ARRAY[$2], $3 ); $$ LANGUAGE sql; +-- col_is_pk( table, columns[] ) +CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_is_pk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should be a primary key' ); +$$ LANGUAGE sql; + -- col_is_pk( table, column ) CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME ) RETURNS TEXT AS $$ @@ -2104,42 +2104,42 @@ RETURNS TEXT AS $$ SELECT isnt( _ckeys( $1, $2, 'p' ), $3, $4 ); $$ LANGUAGE sql; --- col_isnt_pk( schema, table, columns[] ) -CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME[] ) -RETURNS TEXT AS $$ - SELECT col_isnt_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a primary key' ); -$$ LANGUAGE sql; - --- col_isnt_pk( table, columns[], description ) -CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME[], TEXT ) -RETURNS TEXT AS $$ - SELECT isnt( _ckeys( $1, 'p' ), $2, $3 ); -$$ LANGUAGE sql; - --- col_isnt_pk( table, columns[] ) -CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME[] ) -RETURNS TEXT AS $$ - SELECT col_isnt_pk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should not be a primary key' ); -$$ LANGUAGE sql; - -- col_isnt_pk( schema, table, column, description ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME, TEXT ) RETURNS TEXT AS $$ SELECT col_isnt_pk( $1, $2, ARRAY[$3], $4 ); $$ LANGUAGE sql; +-- col_isnt_pk( schema, table, columns[] ) +CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_isnt_pk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a primary key' ); +$$ LANGUAGE sql; + -- col_isnt_pk( schema, table, column ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME ) RETURNS TEXT AS $$ SELECT col_isnt_pk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should not be a primary key' ); $$ LANGUAGE sql; +-- col_isnt_pk( table, columns[], description ) +CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME[], TEXT ) +RETURNS TEXT AS $$ + SELECT isnt( _ckeys( $1, 'p' ), $2, $3 ); +$$ LANGUAGE sql; + -- col_isnt_pk( table, column, description ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, TEXT ) RETURNS TEXT AS $$ SELECT col_isnt_pk( $1, ARRAY[$2], $3 ); $$ LANGUAGE sql; +-- col_isnt_pk( table, columns[] ) +CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_isnt_pk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should not be a primary key' ); +$$ LANGUAGE sql; + -- col_isnt_pk( table, column ) CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME ) RETURNS TEXT AS $$ @@ -2237,12 +2237,24 @@ BEGIN END; $$ LANGUAGE plpgsql; +-- col_is_fk( schema, table, column, description ) +CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME, TEXT ) +RETURNS TEXT AS $$ + SELECT col_is_fk( $1, $2, ARRAY[$3], $4 ); +$$ LANGUAGE sql; + -- col_is_fk( schema, table, columns[] ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME[] ) RETURNS TEXT AS $$ SELECT col_is_fk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should be a foreign key' ); $$ LANGUAGE sql; +-- col_is_fk( schema, table, column ) +CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME ) +RETURNS TEXT AS $$ + SELECT col_is_fk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should be a foreign key' ); +$$ LANGUAGE sql; + -- col_is_fk( table, columns[], description ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME[], TEXT ) RETURNS TEXT AS $$ @@ -2275,30 +2287,18 @@ BEGIN END; $$ LANGUAGE plpgsql; --- col_is_fk( table, columns[] ) -CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME[] ) -RETURNS TEXT AS $$ - SELECT col_is_fk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should be a foreign key' ); -$$ LANGUAGE sql; - --- col_is_fk( schema, table, column, description ) -CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME, TEXT ) -RETURNS TEXT AS $$ - SELECT col_is_fk( $1, $2, ARRAY[$3], $4 ); -$$ LANGUAGE sql; - --- col_is_fk( schema, table, column ) -CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, NAME ) -RETURNS TEXT AS $$ - SELECT col_is_fk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should be a foreign key' ); -$$ LANGUAGE sql; - -- col_is_fk( table, column, description ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME, TEXT ) RETURNS TEXT AS $$ SELECT col_is_fk( $1, ARRAY[$2], $3 ); $$ LANGUAGE sql; +-- col_is_fk( table, columns[] ) +CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_is_fk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should be a foreign key' ); +$$ LANGUAGE sql; + -- col_is_fk( table, column ) CREATE OR REPLACE FUNCTION col_is_fk ( NAME, NAME ) RETURNS TEXT AS $$ @@ -2311,42 +2311,42 @@ RETURNS TEXT AS $$ SELECT ok( NOT _fkexists( $1, $2, $3 ), $4 ); $$ LANGUAGE SQL; --- col_isnt_fk( schema, table, columns[] ) -CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME[] ) -RETURNS TEXT AS $$ - SELECT col_isnt_fk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a foreign key' ); -$$ LANGUAGE sql; - --- col_isnt_fk( table, columns[], description ) -CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME[], TEXT ) -RETURNS TEXT AS $$ - SELECT ok( NOT _fkexists( $1, $2 ), $3 ); -$$ LANGUAGE SQL; - --- col_isnt_fk( table, columns[] ) -CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME[] ) -RETURNS TEXT AS $$ - SELECT col_isnt_fk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should not be a foreign key' ); -$$ LANGUAGE sql; - -- col_isnt_fk( schema, table, column, description ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME, TEXT ) RETURNS TEXT AS $$ SELECT col_isnt_fk( $1, $2, ARRAY[$3], $4 ); $$ LANGUAGE sql; +-- col_isnt_fk( schema, table, columns[] ) +CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_isnt_fk( $1, $2, $3, 'Columns ' || quote_ident($1) || '.' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should not be a foreign key' ); +$$ LANGUAGE sql; + -- col_isnt_fk( schema, table, column ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, NAME ) RETURNS TEXT AS $$ SELECT col_isnt_fk( $1, $2, $3, 'Column ' || quote_ident($1) || '.' || quote_ident($2) || '(' || quote_ident($3) || ') should not be a foreign key' ); $$ LANGUAGE sql; +-- col_isnt_fk( table, columns[], description ) +CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME[], TEXT ) +RETURNS TEXT AS $$ + SELECT ok( NOT _fkexists( $1, $2 ), $3 ); +$$ LANGUAGE SQL; + -- col_isnt_fk( table, column, description ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME, TEXT ) RETURNS TEXT AS $$ SELECT col_isnt_fk( $1, ARRAY[$2], $3 ); $$ LANGUAGE sql; +-- col_isnt_fk( table, columns[] ) +CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_isnt_fk( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should not be a foreign key' ); +$$ LANGUAGE sql; + -- col_isnt_fk( table, column ) CREATE OR REPLACE FUNCTION col_isnt_fk ( NAME, NAME ) RETURNS TEXT AS $$ @@ -2425,42 +2425,42 @@ RETURNS TEXT AS $$ SELECT _constraint( $1, $2, 'u', $3, $4, 'unique' ); $$ LANGUAGE sql; --- col_is_unique( schema, table, columns[] ) -CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, NAME[] ) -RETURNS TEXT AS $$ - SELECT col_is_unique( $1, $2, $3, 'Columns ' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should have a unique constraint' ); -$$ LANGUAGE sql; - --- col_is_unique( table, columns[], description ) -CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME[], TEXT ) -RETURNS TEXT AS $$ - SELECT _constraint( $1, 'u', $2, $3, 'unique' ); -$$ LANGUAGE sql; - --- col_is_unique( table, columns[] ) -CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME[] ) -RETURNS TEXT AS $$ - SELECT col_is_unique( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should have a unique constraint' ); -$$ LANGUAGE sql; - -- col_is_unique( schema, table, column, description ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, NAME, TEXT ) RETURNS TEXT AS $$ SELECT col_is_unique( $1, $2, ARRAY[$3], $4 ); $$ LANGUAGE sql; +-- col_is_unique( schema, table, columns[] ) +CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_is_unique( $1, $2, $3, 'Columns ' || quote_ident($2) || '(' || _ident_array_to_string($3, ', ') || ') should have a unique constraint' ); +$$ LANGUAGE sql; + -- col_is_unique( schema, table, column ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, NAME ) RETURNS TEXT AS $$ SELECT col_is_unique( $1, $2, ARRAY[$3], 'Column ' || quote_ident($2) || '(' || quote_ident($3) || ') should have a unique constraint' ); $$ LANGUAGE sql; +-- col_is_unique( table, columns[], description ) +CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME[], TEXT ) +RETURNS TEXT AS $$ + SELECT _constraint( $1, 'u', $2, $3, 'unique' ); +$$ LANGUAGE sql; + -- col_is_unique( table, column, description ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME, TEXT ) RETURNS TEXT AS $$ SELECT col_is_unique( $1, ARRAY[$2], $3 ); $$ LANGUAGE sql; +-- col_is_unique( table, columns[] ) +CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME[] ) +RETURNS TEXT AS $$ + SELECT col_is_unique( $1, $2, 'Columns ' || quote_ident($1) || '(' || _ident_array_to_string($2, ', ') || ') should have a unique constraint' ); +$$ LANGUAGE sql; + -- col_is_unique( table, column ) CREATE OR REPLACE FUNCTION col_is_unique ( NAME, NAME ) RETURNS TEXT AS $$ From 199b87ade49266658b0ed59e3a3bc4e474dcedfc Mon Sep 17 00:00:00 2001 From: RampantDespair Date: Mon, 27 Jul 2026 13:59:04 -0400 Subject: [PATCH 5/5] Added disclaimer for 3-argument versions --- doc/pgtap.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/doc/pgtap.md b/doc/pgtap.md index c1a21c8e..192bb17b 100644 --- a/doc/pgtap.md +++ b/doc/pgtap.md @@ -5228,6 +5228,14 @@ SELECT col_is_pk( 'myschema', 'sometable', 'id' ); SELECT col_is_pk( 'persons', ARRAY['given_name', 'surname'] ); ``` +If you omit the description for the 3-argument version, you'll need to cast +the table and column parameters to the `NAME` data type so that PostgreSQL +doesn't resolve the function name as a description. For example: + +```sql +SELECT col_is_pk( 'myschema', 'sometable'::name, 'pk_name'::name ); +``` + If the schema is omitted, the table must be visible in the search path. If the test description is omitted, it will be set to "Column `:table(:column)` should be a primary key". Note that this test will fail if the table or column @@ -5278,6 +5286,14 @@ SELECT col_isnt_pk( :table, :column ); This function is the inverse of `col_is_pk()`. The test passes if the specified column or columns are not a primary key. +If you omit the description for the 3-argument version, you'll need to cast +the table and column parameters to the `NAME` data type so that PostgreSQL +doesn't resolve the function name as a description. For example: + +```sql +SELECT col_isnt_pk( 'myschema', 'sometable'::name, 'pk_name'::name ); +``` + ### `col_is_fk()` ### ```sql @@ -5317,6 +5333,14 @@ simply list all of the foreign key constraint columns, like so: # {thingy_id} # {surname,given_name} +If you omit the description for the 3-argument version, you'll need to cast +the table and column parameters to the `NAME` data type so that PostgreSQL +doesn't resolve the function name as a description. For example: + +```sql +SELECT col_is_fk( 'myschema', 'sometable'::name, 'fk_name'::name ); +``` + ### `col_isnt_fk()` ### ```sql @@ -5350,6 +5374,14 @@ SELECT col_isnt_fk( :table, :column ); This function is the inverse of `col_is_fk()`. The test passes if the specified column or columns are not a foreign key. +If you omit the description for the 3-argument version, you'll need to cast +the table and column parameters to the `NAME` data type so that PostgreSQL +doesn't resolve the function name as a description. For example: + +```sql +SELECT col_isnt_fk( 'myschema', 'sometable'::name, 'fk_name'::name ); +``` + ### `fk_ok()` ### ```sql