--- sql/pgtap--0.97.0--0.98.0.sql +++ sql/pgtap--0.97.0--0.98.0.sql @@ -292,133 +292,3 @@ 'Table ' || quote_ident($1) || ' should not be partitioned' ); $$ LANGUAGE sql; - --- _partof( child_schema, child_table, parent_schema, parent_table ) -CREATE OR REPLACE FUNCTION _partof ( NAME, NAME, NAME, NAME ) -RETURNS BOOLEAN AS $$ - SELECT EXISTS( - SELECT true - FROM pg_catalog.pg_namespace cn - JOIN pg_catalog.pg_class cc ON cn.oid = cc.relnamespace - JOIN pg_catalog.pg_inherits i ON cc.oid = i.inhrelid - JOIN pg_catalog.pg_class pc ON i.inhparent = pc.oid - JOIN pg_catalog.pg_namespace pn ON pc.relnamespace = pn.oid - WHERE cn.nspname = $1 - AND cc.relname = $2 - AND cc.relispartition - AND pn.nspname = $3 - AND pc.relname = $4 - AND pc.relkind = 'p' - ) -$$ LANGUAGE sql; - --- _partof( child_table, parent_table ) -CREATE OR REPLACE FUNCTION _partof ( NAME, NAME ) -RETURNS BOOLEAN AS $$ - SELECT EXISTS( - SELECT true - FROM pg_catalog.pg_class cc - JOIN pg_catalog.pg_inherits i ON cc.oid = i.inhrelid - JOIN pg_catalog.pg_class pc ON i.inhparent = pc.oid - WHERE cc.relname = $1 - AND cc.relispartition - AND pc.relname = $2 - AND pc.relkind = 'p' - AND pg_catalog.pg_table_is_visible(cc.oid) - AND pg_catalog.pg_table_is_visible(pc.oid) - ) -$$ LANGUAGE sql; - --- is_partition_of( child_schema, child_table, parent_schema, parent_table, description ) -CREATE OR REPLACE FUNCTION is_partition_of ( NAME, NAME, NAME, NAME, TEXT ) -RETURNS TEXT AS $$ - SELECT ok( _partof($1, $2, $3, $4), $5); -$$ LANGUAGE sql; - --- is_partition_of( child_schema, child_table, parent_schema, parent_table ) -CREATE OR REPLACE FUNCTION is_partition_of ( NAME, NAME, NAME, NAME ) -RETURNS TEXT AS $$ - SELECT ok( - _partof($1, $2, $3, $4), - 'Table ' || quote_ident($1) || '.' || quote_ident($2) || ' should be a partition of ' - || quote_ident($3) || '.' || quote_ident($4) - ); -$$ LANGUAGE sql; - --- is_partition_of( child_table, parent_table, description ) -CREATE OR REPLACE FUNCTION is_partition_of ( NAME, NAME, TEXT ) -RETURNS TEXT AS $$ - SELECT ok( _partof($1, $2), $3); -$$ LANGUAGE sql; - --- is_partition_of( child_table, parent_table ) -CREATE OR REPLACE FUNCTION is_partition_of ( NAME, NAME ) -RETURNS TEXT AS $$ - SELECT ok( - _partof($1, $2), - 'Table ' || quote_ident($1) || ' should be a partition of ' || quote_ident($2) - ); -$$ LANGUAGE sql; - --- _parts(schema, table) -CREATE OR REPLACE FUNCTION _parts( NAME, NAME ) -RETURNS SETOF NAME AS $$ - SELECT i.inhrelid::regclass::name - FROM pg_catalog.pg_namespace n - JOIN pg_catalog.pg_class c ON n.oid = c.relnamespace - JOIN pg_catalog.pg_inherits i ON c.oid = i.inhparent - WHERE n.nspname = $1 - AND c.relname = $2 - AND c.relkind = 'p' -$$ LANGUAGE SQL; - --- _parts(table) -CREATE OR REPLACE FUNCTION _parts( NAME ) -RETURNS SETOF NAME AS $$ - SELECT i.inhrelid::regclass::name - FROM pg_catalog.pg_class c - JOIN pg_catalog.pg_inherits i ON c.oid = i.inhparent - WHERE c.relname = $1 - AND c.relkind = 'p' - AND pg_catalog.pg_table_is_visible(c.oid) -$$ LANGUAGE SQL; - --- partitions_are( schema, table, partitions, description ) -CREATE OR REPLACE FUNCTION partitions_are( NAME, NAME, NAME[], TEXT ) -RETURNS TEXT AS $$ - SELECT _are( - 'partitions', - ARRAY(SELECT _parts($1, $2) EXCEPT SELECT unnest($3)), - ARRAY(SELECT unnest($3) EXCEPT SELECT _parts($1, $2)), - $4 - ); -$$ LANGUAGE SQL; - --- partitions_are( schema, table, partitions ) -CREATE OR REPLACE FUNCTION partitions_are( NAME, NAME, NAME[] ) -RETURNS TEXT AS $$ - SELECT partitions_are( - $1, $2, $3, - 'Table ' || quote_ident($1) || '.' || quote_ident($2) || ' should have the correct partitions' - ); -$$ LANGUAGE SQL; - --- partitions_are( table, partitions, description ) -CREATE OR REPLACE FUNCTION partitions_are( NAME, NAME[], TEXT ) -RETURNS TEXT AS $$ - SELECT _are( - 'partitions', - ARRAY(SELECT _parts($1) EXCEPT SELECT unnest($2)), - ARRAY(SELECT unnest($2) EXCEPT SELECT _parts($1)), - $3 - ); -$$ LANGUAGE SQL; - --- partitions_are( table, partitions ) -CREATE OR REPLACE FUNCTION partitions_are( NAME, NAME[] ) -RETURNS TEXT AS $$ - SELECT partitions_are( - $1, $2, - 'Table ' || quote_ident($1) || ' should have the correct partitions' - ); -$$ LANGUAGE SQL;