Hi,
> In many ways, the col_has_check() covers most of what we need. However, it seems like we should have something like:
> SELECT col_has_named_check( :schema, :table, :check_name, :description );
> Or maybe:
> SELECT col_has_named_check( :schema, :table, :column, :check_name, :description );
>
> I’m not sure what I fully need :-/ but perhaps this last one as I know the constraint name and the schema/table/column; the point is to ensure a specific check is present so maybe the column doesn't matter. Is there something already existing which I don’t see that does this (with the constraint name) or would I need to give a patch? Or is this too weird and we shouldn’t bother?
It doesn’t exist, but I’d point out that in Postgres CHECKs don’t have names, but constraints do. Thus the other constraint-checking assertions --- for primary keys, foreign keys, unique constraints --- also could use some support for checking by name.
> This query is the basis of the check such that if the output matches the “:check_name” it’s a pass or it doesn’t and fails which make this the “{have}” value:
Look at the pg_constraint table[1] to cover naming for other types of constraints. Maybe something like:
has_constraint(:schema, :table, :name, :type, :description)
has_constraint(:schema, :table, :name, :description)
has_constraint(:table, :name, :description)
And variants for the columns, too. This would avoid overloading the function signatures of the existing functions.
Best,
David
[1]:
https://www.postgresql.org/docs/current/catalog-pg-constraint.html