Skip to content

Improved col_is{nt}_X implementation - #369

Open
RampantDespair wants to merge 5 commits into
theory:mainfrom
RampantDespair:dev1
Open

Improved col_is{nt}_X implementation#369
RampantDespair wants to merge 5 commits into
theory:mainfrom
RampantDespair:dev1

Conversation

@RampantDespair

@RampantDespair RampantDespair commented Jul 23, 2026

Copy link
Copy Markdown

Closes #363 [1/3]

As discussed this is the first part of the PR split -> implementation symmetry.

All 3 now follow:

-- col_is{nt}_X( schema, table, column[], description ) -- ( NAME, NAME, NAME[], TEXT )
-- col_is{nt}_X( schema, table, column[] )              -- ( NAME, NAME, NAME[] )
-- col_is{nt}_X( table, column[], description )         -- ( NAME, NAME[], TEXT )
-- col_is{nt}_X( table, column[] )                      -- ( NAME, NAME[] )
-- col_is{nt}_X( schema, table, column, description )   -- ( NAME, NAME, NAME, TEXT )
-- col_is{nt}_X( schema, table, column )                -- ( NAME, NAME, NAME )
-- col_is{nt}_X( table, column, description )           -- ( NAME, NAME, TEXT )
-- col_is{nt}_X( table, column )                        -- ( NAME, NAME )

EDIT: col_is_null isn't in scope because you went the is/not instead of is/isnt so I didn't think it was pertinent. If you disagree I can conform it as well I suppose.

@theory

theory commented Jul 26, 2026

Copy link
Copy Markdown
Owner

EDIT: col_is_null isn't in scope because you went the is/not instead of is/isnt so I didn't think it was pertinent. If you disagree I can conform it as well I suppose.

No, I think it's the same, it's just named differently because SQL has a NOT NULL expression.

@RampantDespair

Copy link
Copy Markdown
Author

@theory Understood, I'll conform it right now, one moment

Comment thread doc/pgtap.md
Comment thread sql/pgtap.sql.in Outdated
Comment thread sql/pgtap.sql.in
$$ LANGUAGE sql;

-- col_isnt_pk( schema, table, column )
CREATE OR REPLACE FUNCTION col_isnt_pk ( NAME, NAME, NAME )

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this means existing use of col_isnt_pk ( NAME, NAME, TEXT ) may no longer work unless or until users cast that final argument. IOW, this would fail:

SELECT col_isnt_pk( 'x', 'y', 'z');

They'll have to instead use one of these two:

SELECT col_isnt_pk( 'x', 'y', 'z'::name);
SELECT col_isnt_pk( 'x', 'y', 'z'::text);

Which will be confusing because the types don't really tell you much.

Comment thread test/sql/fktap.sql
);

SELECT * FROM check_test(
col_is_fk( 'public', 'fk', 'pk_id'::name ),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so the existing tests, which don't cast the third argument, still pass? Okay then it seems like it will be backward compatible after all.

Comment thread doc/pgtap.md
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 );

@theory theory Jul 26, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of this, please follow the example of functions like col_is_unique() and add a note like this for each function that may now have ambiguity:

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 );

@theory

theory commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Also: Please use the 50/72 rule in the commit message.

@theory

theory commented Jul 26, 2026

Copy link
Copy Markdown
Owner

@theory Understood, I'll conform it right now, one moment

Sorry, don't know what this responds to.

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()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants