Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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()`.

1.3.4 2025-10-04T17:20:28Z
--------------------------
Expand Down
38 changes: 38 additions & 0 deletions doc/pgtap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -5250,6 +5258,8 @@ 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( :schema, :table, :column );
SELECT col_isnt_pk( :table, :columns, :description );
SELECT col_isnt_pk( :table, :column, :description );
SELECT col_isnt_pk( :table, :columns );
Expand All @@ -5276,11 +5286,21 @@ 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
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( :schema, :table, :column );
SELECT col_is_fk( :table, :columns, :description );
SELECT col_is_fk( :table, :column, :description );
SELECT col_is_fk( :table, :columns );
Expand Down Expand Up @@ -5313,11 +5333,21 @@ 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
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( :schema, :table, :column );
SELECT col_isnt_fk( :table, :columns, :description );
SELECT col_isnt_fk( :table, :column, :description );
SELECT col_isnt_fk( :table, :columns );
Expand All @@ -5344,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
Expand Down
2 changes: 1 addition & 1 deletion sql/pgtap--0.92.0--0.93.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sql/pgtap--0.94.0--0.95.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
2 changes: 1 addition & 1 deletion sql/pgtap--1.2.0--1.3.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
36 changes: 36 additions & 0 deletions sql/pgtap--1.3.4--1.3.5.sql
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
-- Changes between pgTAP v1.3.4 and v1.3.5.

-- 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_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_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;
Loading