Skip to content

Commit

Permalink
Refactoring of the function col_is_pk to accept a null test description.
Browse files Browse the repository at this point in the history
This allows for the automatic overloading of the function, implementing
therefore the col_is_pk( name, name, name[] ) as requested in issue theory#133.

See issue theory#133.
  • Loading branch information
fluca1978 committed Oct 2, 2018
1 parent 267081f commit ec9ed8c
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions sql/pgtap.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -1952,15 +1952,33 @@ RETURNS NAME[] AS $$
$$ LANGUAGE sql;

-- col_is_pk( schema, table, column, description )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[], TEXT )
-- col_is_pk( schema, table, column )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[], TEXT DEFAULT NULL )
RETURNS TEXT AS $$
SELECT is( _ckeys( $1, $2, 'p' ), $3, $4 );
SELECT is( _ckeys( $1, $2, 'p' ), $3,
coalesce( $4,
format( 'Columns %I.%I(%s) should be a primary key',
$1, $2
_ident_array_to_string( $3, ', ' ) ) ) );
$$ LANGUAGE sql;


-- col_is_pk( schema, table, column )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME )
RETURNS TEXT AS $$
SELECT is( _ckeys( $1, $2, 'p' ), ARRAY[ $3 ]::NAME[],
coalesce( $4,
format( 'Column %I.%I(%s) should be a primary key',
$1, $2, $3 ) ) );
$$ LANGUAGE sql;

-- col_is_pk( table, column, description )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME[], TEXT )
-- col_is_pk( table, column )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME[], TEXT DEFAULT NULL )
RETURNS TEXT AS $$
SELECT is( _ckeys( $1, 'p' ), $2, $3 );
SELECT is( _ckeys( $1, 'p' ), $2,
coalesce( $3, format( 'Columns %I(%s) should be a primary key',
$1, _ident_array_to_string( $3, ', ' ) ) ) );
$$ LANGUAGE sql;

-- col_is_pk( table, column[] )
Expand Down Expand Up @@ -10035,4 +10053,4 @@ RETURNS text AS $$
FROM generate_series(1, array_upper($1, 1)) s(i)
ORDER BY $1[i]
), $2);
$$ LANGUAGE SQL immutable;
$$ LANGUAGE SQL immutable;

0 comments on commit ec9ed8c

Please sign in to comment.