/usr/share/postgresql/10/extension/pgtap--0.92.0--0.93.0.sql is in postgresql-10-pgtap 0.97.0-3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 | CREATE OR REPLACE FUNCTION pgtap_version()
RETURNS NUMERIC AS 'SELECT 0.93;'
LANGUAGE SQL IMMUTABLE;
-- _get_schema_owner( schema )
CREATE OR REPLACE FUNCTION _get_schema_owner( NAME )
RETURNS NAME AS $$
SELECT pg_catalog.pg_get_userbyid(nspowner)
FROM pg_catalog.pg_namespace
WHERE nspname = $1;
$$ LANGUAGE SQL;
-- schema_owner_is ( schema, user, description )
CREATE OR REPLACE FUNCTION schema_owner_is ( NAME, NAME, TEXT )
RETURNS TEXT AS $$
DECLARE
owner NAME := _get_schema_owner($1);
BEGIN
-- Make sure the schema exists.
IF owner IS NULL THEN
RETURN ok(FALSE, $3) || E'\n' || diag(
E' Schema ' || quote_ident($1) || ' does not exist'
);
END IF;
RETURN is(owner, $2, $3);
END;
$$ LANGUAGE plpgsql;
-- schema_owner_is ( schema, user )
CREATE OR REPLACE FUNCTION schema_owner_is ( NAME, NAME )
RETURNS TEXT AS $$
SELECT schema_owner_is(
$1, $2,
'Schema ' || quote_ident($1) || ' should be owned by ' || quote_ident($2)
);
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION _constraint ( NAME, NAME, CHAR, NAME[], TEXT, TEXT )
RETURNS TEXT AS $$
DECLARE
akey NAME[];
keys TEXT[] := '{}';
have TEXT;
BEGIN
FOR akey IN SELECT * FROM _keys($1, $2, $3) LOOP
IF akey = $4 THEN RETURN pass($5); END IF;
keys = keys || akey::text;
END LOOP;
IF array_upper(keys, 0) = 1 THEN
have := 'No ' || $6 || ' constraints';
ELSE
have := array_to_string(keys, E'\n ');
END IF;
RETURN fail($5) || E'\n' || diag(
' have: ' || have
|| E'\n want: ' || CASE WHEN $4 IS NULL THEN 'NULL' ELSE $4::text END
);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION _constraint ( NAME, CHAR, NAME[], TEXT, TEXT )
RETURNS TEXT AS $$
DECLARE
akey NAME[];
keys TEXT[] := '{}';
have TEXT;
BEGIN
FOR akey IN SELECT * FROM _keys($1, $2) LOOP
IF akey = $3 THEN RETURN pass($4); END IF;
keys = keys || akey::text;
END LOOP;
IF array_upper(keys, 0) = 1 THEN
have := 'No ' || $5 || ' constraints';
ELSE
have := array_to_string(keys, E'\n ');
END IF;
RETURN fail($4) || E'\n' || diag(
' have: ' || have
|| E'\n want: ' || CASE WHEN $3 IS NULL THEN 'NULL' ELSE $3::text END
);
END;
$$ LANGUAGE plpgsql;
-- fk_ok( fk_table, fk_column[], pk_table, pk_column[], description )
CREATE OR REPLACE FUNCTION fk_ok ( NAME, NAME[], NAME, NAME[], TEXT )
RETURNS TEXT AS $$
DECLARE
tab name;
cols name[];
BEGIN
SELECT pk_table_name, pk_columns
FROM pg_all_foreign_keys
WHERE fk_table_name = $1
AND fk_columns = $2
AND pg_catalog.pg_table_is_visible(fk_table_oid)
INTO tab, cols;
RETURN is(
-- have
$1 || '(' || _ident_array_to_string( $2, ', ' )
|| ') REFERENCES ' || COALESCE( tab || '(' || _ident_array_to_string( cols, ', ' ) || ')', 'NOTHING'),
-- want
$1 || '(' || _ident_array_to_string( $2, ', ' )
|| ') REFERENCES ' ||
$3 || '(' || _ident_array_to_string( $4, ', ' ) || ')',
$5
);
END;
$$ LANGUAGE plpgsql;
-- _keys( table, constraint_type )
CREATE OR REPLACE FUNCTION _keys ( NAME, CHAR )
RETURNS SETOF NAME[] AS $$
SELECT _pg_sv_column_array(x.conrelid,x.conkey)
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_constraint x ON c.oid = x.conrelid
AND c.relname = $1
AND x.contype = $2
WHERE pg_catalog.pg_table_is_visible(c.oid)
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION _trig ( NAME, NAME )
RETURNS BOOLEAN AS $$
SELECT EXISTS(
SELECT true
FROM pg_catalog.pg_trigger t
JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid
WHERE c.relname = $1
AND t.tgname = $2
AND pg_catalog.pg_table_is_visible(c.oid)
);
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION _fkexists ( NAME, NAME[] )
RETURNS BOOLEAN AS $$
SELECT EXISTS(
SELECT TRUE
FROM pg_all_foreign_keys
WHERE quote_ident(fk_table_name) = quote_ident($1)
AND pg_catalog.pg_table_is_visible(fk_table_oid)
AND fk_columns = $2
);
$$ LANGUAGE SQL;
DROP FUNCTION display_type ( OID, INTEGER );
DROP FUNCTION display_type ( NAME, OID, INTEGER );
CREATE OR REPLACE FUNCTION _get_col_type ( NAME, NAME, NAME )
RETURNS TEXT AS $$
SELECT pg_catalog.format_type(a.atttypid, a.atttypmod)
FROM pg_catalog.pg_namespace n
JOIN pg_catalog.pg_class c ON n.oid = c.relnamespace
JOIN pg_catalog.pg_attribute a ON c.oid = a.attrelid
WHERE n.nspname = $1
AND c.relname = $2
AND a.attname = $3
AND attnum > 0
AND NOT a.attisdropped
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION _get_col_type ( NAME, NAME )
RETURNS TEXT AS $$
SELECT pg_catalog.format_type(a.atttypid, a.atttypmod)
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
WHERE pg_catalog.pg_table_is_visible(c.oid)
AND c.relname = $1
AND a.attname = $2
AND attnum > 0
AND NOT a.attisdropped
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION _get_col_ns_type ( NAME, NAME, NAME )
RETURNS TEXT AS $$
-- Always include the namespace.
SELECT CASE WHEN pg_catalog.pg_type_is_visible(t.oid)
THEN quote_ident(tn.nspname) || '.'
ELSE ''
END || pg_catalog.format_type(a.atttypid, a.atttypmod)
FROM pg_catalog.pg_namespace n
JOIN pg_catalog.pg_class c ON n.oid = c.relnamespace
JOIN pg_catalog.pg_attribute a ON c.oid = a.attrelid
JOIN pg_catalog.pg_type t ON a.atttypid = t.oid
JOIN pg_catalog.pg_namespace tn ON t.typnamespace = tn.oid
WHERE n.nspname = $1
AND c.relname = $2
AND a.attname = $3
AND attnum > 0
AND NOT a.attisdropped
$$ LANGUAGE SQL;
-- _cdi( schema, table, column, default, description )
CREATE OR REPLACE FUNCTION _cdi ( NAME, NAME, NAME, anyelement, TEXT )
RETURNS TEXT AS $$
BEGIN
IF NOT _cexists( $1, $2, $3 ) THEN
RETURN fail( $5 ) || E'\n'
|| diag (' Column ' || quote_ident($1) || '.' || quote_ident($2) || '.' || quote_ident($3) || ' does not exist' );
END IF;
IF NOT _has_def( $1, $2, $3 ) THEN
RETURN fail( $5 ) || E'\n'
|| diag (' Column ' || quote_ident($1) || '.' || quote_ident($2) || '.' || quote_ident($3) || ' has no default' );
END IF;
RETURN _def_is(
pg_catalog.pg_get_expr(d.adbin, d.adrelid),
pg_catalog.format_type(a.atttypid, a.atttypmod),
$4, $5
)
FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c, pg_catalog.pg_attribute a,
pg_catalog.pg_attrdef d
WHERE n.oid = c.relnamespace
AND c.oid = a.attrelid
AND a.atthasdef
AND a.attrelid = d.adrelid
AND a.attnum = d.adnum
AND n.nspname = $1
AND c.relname = $2
AND a.attnum > 0
AND NOT a.attisdropped
AND a.attname = $3;
END;
$$ LANGUAGE plpgsql;
-- _cdi( table, column, default, description )
CREATE OR REPLACE FUNCTION _cdi ( NAME, NAME, anyelement, TEXT )
RETURNS TEXT AS $$
BEGIN
IF NOT _cexists( $1, $2 ) THEN
RETURN fail( $4 ) || E'\n'
|| diag (' Column ' || quote_ident($1) || '.' || quote_ident($2) || ' does not exist' );
END IF;
IF NOT _has_def( $1, $2 ) THEN
RETURN fail( $4 ) || E'\n'
|| diag (' Column ' || quote_ident($1) || '.' || quote_ident($2) || ' has no default' );
END IF;
RETURN _def_is(
pg_catalog.pg_get_expr(d.adbin, d.adrelid),
pg_catalog.format_type(a.atttypid, a.atttypmod),
$3, $4
)
FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a, pg_catalog.pg_attrdef d
WHERE c.oid = a.attrelid
AND pg_table_is_visible(c.oid)
AND a.atthasdef
AND a.attrelid = d.adrelid
AND a.attnum = d.adnum
AND c.relname = $1
AND a.attnum > 0
AND NOT a.attisdropped
AND a.attname = $2;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION _cmp_types(oid, name)
RETURNS BOOLEAN AS $$
DECLARE
dtype TEXT := pg_catalog.format_type($1, NULL);
BEGIN
RETURN dtype = _quote_ident_like($2, dtype);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION _get_dtype( NAME, TEXT, BOOLEAN )
RETURNS TEXT AS $$
SELECT CASE WHEN $3 AND pg_catalog.pg_type_is_visible(t.oid)
THEN quote_ident(tn.nspname) || '.'
ELSE ''
END || pg_catalog.format_type(t.oid, t.typtypmod)
FROM pg_catalog.pg_type d
JOIN pg_catalog.pg_namespace dn ON d.typnamespace = dn.oid
JOIN pg_catalog.pg_type t ON d.typbasetype = t.oid
JOIN pg_catalog.pg_namespace tn ON t.typnamespace = tn.oid
WHERE d.typisdefined
AND dn.nspname = $1
AND d.typname = LOWER($2)
AND d.typtype = 'd'
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION _get_dtype( NAME )
RETURNS TEXT AS $$
SELECT pg_catalog.format_type(t.oid, t.typtypmod)
FROM pg_catalog.pg_type d
JOIN pg_catalog.pg_type t ON d.typbasetype = t.oid
WHERE d.typisdefined
AND pg_catalog.pg_type_is_visible(d.oid)
AND d.typname = LOWER($1)
AND d.typtype = 'd'
$$ LANGUAGE sql;
-- casts_are( casts[], description )
CREATE OR REPLACE FUNCTION casts_are ( TEXT[], TEXT )
RETURNS TEXT AS $$
SELECT _areni(
'casts',
ARRAY(
SELECT pg_catalog.format_type(castsource, NULL)
|| ' AS ' || pg_catalog.format_type(casttarget, NULL)
FROM pg_catalog.pg_cast c
EXCEPT
SELECT $1[i]
FROM generate_series(1, array_upper($1, 1)) s(i)
),
ARRAY(
SELECT $1[i]
FROM generate_series(1, array_upper($1, 1)) s(i)
EXCEPT
SELECT pg_catalog.format_type(castsource, NULL)
|| ' AS ' || pg_catalog.format_type(casttarget, NULL)
FROM pg_catalog.pg_cast c
),
$2
);
$$ LANGUAGE sql;
-- _get_tablespace_owner( tablespace )
CREATE OR REPLACE FUNCTION _get_tablespace_owner( NAME )
RETURNS NAME AS $$
SELECT pg_catalog.pg_get_userbyid(spcowner)
FROM pg_catalog.pg_tablespace
WHERE spcname = $1;
$$ LANGUAGE SQL;
-- tablespace_owner_is ( tablespace, user, description )
CREATE OR REPLACE FUNCTION tablespace_owner_is ( NAME, NAME, TEXT )
RETURNS TEXT AS $$
DECLARE
owner NAME := _get_tablespace_owner($1);
BEGIN
-- Make sure the tablespace exists.
IF owner IS NULL THEN
RETURN ok(FALSE, $3) || E'\n' || diag(
E' Tablespace ' || quote_ident($1) || ' does not exist'
);
END IF;
RETURN is(owner, $2, $3);
END;
$$ LANGUAGE plpgsql;
-- tablespace_owner_is ( tablespace, user )
CREATE OR REPLACE FUNCTION tablespace_owner_is ( NAME, NAME )
RETURNS TEXT AS $$
SELECT tablespace_owner_is(
$1, $2,
'Tablespace ' || quote_ident($1) || ' should be owned by ' || quote_ident($2)
);
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION _have_index( NAME, NAME, NAME)
RETURNS BOOLEAN AS $$
SELECT EXISTS (
SELECT TRUE
FROM pg_catalog.pg_index x
JOIN pg_catalog.pg_class ct ON ct.oid = x.indrelid
JOIN pg_catalog.pg_class ci ON ci.oid = x.indexrelid
JOIN pg_catalog.pg_namespace n ON n.oid = ct.relnamespace
WHERE n.nspname = $1
AND ct.relname = $2
AND ci.relname = $3
);
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION _have_index( NAME, NAME)
RETURNS BOOLEAN AS $$
SELECT EXISTS (
SELECT TRUE
FROM pg_catalog.pg_index x
JOIN pg_catalog.pg_class ct ON ct.oid = x.indrelid
JOIN pg_catalog.pg_class ci ON ci.oid = x.indexrelid
WHERE ct.relname = $1
AND ci.relname = $2
AND pg_catalog.pg_table_is_visible(ct.oid)
);
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION _get_index_owner( NAME, NAME, NAME )
RETURNS NAME AS $$
SELECT pg_catalog.pg_get_userbyid(ci.relowner)
FROM pg_catalog.pg_index x
JOIN pg_catalog.pg_class ct ON ct.oid = x.indrelid
JOIN pg_catalog.pg_class ci ON ci.oid = x.indexrelid
JOIN pg_catalog.pg_namespace n ON n.oid = ct.relnamespace
WHERE n.nspname = $1
AND ct.relname = $2
AND ci.relname = $3;
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION _get_index_owner( NAME, NAME )
RETURNS NAME AS $$
SELECT pg_catalog.pg_get_userbyid(ci.relowner)
FROM pg_catalog.pg_index x
JOIN pg_catalog.pg_class ct ON ct.oid = x.indrelid
JOIN pg_catalog.pg_class ci ON ci.oid = x.indexrelid
WHERE ct.relname = $1
AND ci.relname = $2
AND pg_catalog.pg_table_is_visible(ct.oid);
$$ LANGUAGE sql;
-- index_owner_is ( schema, table, index, user, description )
CREATE OR REPLACE FUNCTION index_owner_is ( NAME, NAME, NAME, NAME, TEXT )
RETURNS TEXT AS $$
DECLARE
owner NAME := _get_index_owner($1, $2, $3);
BEGIN
-- Make sure the index exists.
IF owner IS NULL THEN
RETURN ok(FALSE, $5) || E'\n' || diag(
E' Index ' || quote_ident($3) || ' ON '
|| quote_ident($1) || '.' || quote_ident($2) || ' not found'
);
END IF;
RETURN is(owner, $4, $5);
END;
$$ LANGUAGE plpgsql;
-- index_owner_is ( schema, table, index, user )
CREATE OR REPLACE FUNCTION index_owner_is ( NAME, NAME, NAME, NAME )
RETURNS TEXT AS $$
SELECT index_owner_is(
$1, $2, $3, $4,
'Index ' || quote_ident($3) || ' ON '
|| quote_ident($1) || '.' || quote_ident($2)
|| ' should be owned by ' || quote_ident($4)
);
$$ LANGUAGE sql;
-- index_owner_is ( table, index, user, description )
CREATE OR REPLACE FUNCTION index_owner_is ( NAME, NAME, NAME, TEXT )
RETURNS TEXT AS $$
DECLARE
owner NAME := _get_index_owner($1, $2);
BEGIN
-- Make sure the index exists.
IF owner IS NULL THEN
RETURN ok(FALSE, $4) || E'\n' || diag(
E' Index ' || quote_ident($2) || ' ON ' || quote_ident($1) || ' not found'
);
END IF;
RETURN is(owner, $3, $4);
END;
$$ LANGUAGE plpgsql;
-- index_owner_is ( table, index, user )
CREATE OR REPLACE FUNCTION index_owner_is ( NAME, NAME, NAME )
RETURNS TEXT AS $$
SELECT index_owner_is(
$1, $2, $3,
'Index ' || quote_ident($2) || ' ON '
|| quote_ident($1) || ' should be owned by ' || quote_ident($3)
);
$$ LANGUAGE sql;
-- _get_language_owner( language )
CREATE OR REPLACE FUNCTION _get_language_owner( NAME )
RETURNS NAME AS $$
SELECT pg_catalog.pg_get_userbyid(lanowner)
FROM pg_catalog.pg_language
WHERE lanname = $1;
$$ LANGUAGE SQL;
-- language_owner_is ( language, user, description )
CREATE OR REPLACE FUNCTION language_owner_is ( NAME, NAME, TEXT )
RETURNS TEXT AS $$
DECLARE
owner NAME := _get_language_owner($1);
BEGIN
-- Make sure the language exists.
IF owner IS NULL THEN
RETURN ok(FALSE, $3) || E'\n' || diag(
E' Language ' || quote_ident($1) || ' does not exist'
);
END IF;
RETURN is(owner, $2, $3);
END;
$$ LANGUAGE plpgsql;
-- language_owner_is ( language, user )
CREATE OR REPLACE FUNCTION language_owner_is ( NAME, NAME )
RETURNS TEXT AS $$
SELECT language_owner_is(
$1, $2,
'Language ' || quote_ident($1) || ' should be owned by ' || quote_ident($2)
);
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION _get_opclass_owner ( NAME, NAME )
RETURNS NAME AS $$
SELECT pg_catalog.pg_get_userbyid(opcowner)
FROM pg_catalog.pg_opclass oc
JOIN pg_catalog.pg_namespace n ON oc.opcnamespace = n.oid
WHERE n.nspname = $1
AND opcname = $2;
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION _get_opclass_owner ( NAME )
RETURNS NAME AS $$
SELECT pg_catalog.pg_get_userbyid(opcowner)
FROM pg_catalog.pg_opclass
WHERE opcname = $1
AND pg_catalog.pg_opclass_is_visible(oid);
$$ LANGUAGE SQL;
-- opclass_owner_is( schema, opclass, user, description )
CREATE OR REPLACE FUNCTION opclass_owner_is ( NAME, NAME, NAME, TEXT )
RETURNS TEXT AS $$
DECLARE
owner NAME := _get_opclass_owner($1, $2);
BEGIN
-- Make sure the opclass exists.
IF owner IS NULL THEN
RETURN ok(FALSE, $4) || E'\n' || diag(
E' Operator class ' || quote_ident($1) || '.' || quote_ident($2)
|| ' not found'
);
END IF;
RETURN is(owner, $3, $4);
END;
$$ LANGUAGE plpgsql;
-- opclass_owner_is( schema, opclass, user )
CREATE OR REPLACE FUNCTION opclass_owner_is( NAME, NAME, NAME )
RETURNS TEXT AS $$
SELECT opclass_owner_is(
$1, $2, $3,
'Operator class ' || quote_ident($1) || '.' || quote_ident($2) ||
' should be owned by ' || quote_ident($3)
);
$$ LANGUAGE sql;
-- opclass_owner_is( opclass, user, description )
CREATE OR REPLACE FUNCTION opclass_owner_is ( NAME, NAME, TEXT )
RETURNS TEXT AS $$
DECLARE
owner NAME := _get_opclass_owner($1);
BEGIN
-- Make sure the opclass exists.
IF owner IS NULL THEN
RETURN ok(FALSE, $3) || E'\n' || diag(
E' Operator class ' || quote_ident($1) || ' not found'
);
END IF;
RETURN is(owner, $2, $3);
END;
$$ LANGUAGE plpgsql;
-- opclass_owner_is( opclass, user )
CREATE OR REPLACE FUNCTION opclass_owner_is( NAME, NAME )
RETURNS TEXT AS $$
SELECT opclass_owner_is(
$1, $2,
'Operator class ' || quote_ident($1) || ' should be owned by ' || quote_ident($2)
);
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION _opc_exists( NAME, NAME )
RETURNS BOOLEAN AS $$
SELECT EXISTS (
SELECT TRUE
FROM pg_catalog.pg_opclass oc
JOIN pg_catalog.pg_namespace n ON oc.opcnamespace = n.oid
WHERE n.nspname = $1
AND oc.opcname = $2
);
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION _opc_exists( NAME )
RETURNS BOOLEAN AS $$
SELECT EXISTS (
SELECT TRUE
FROM pg_catalog.pg_opclass oc
WHERE oc.opcname = $1
AND pg_opclass_is_visible(oid)
);
$$ LANGUAGE SQL;
-- has_opclass( name, description )
CREATE OR REPLACE FUNCTION has_opclass( NAME, TEXT )
RETURNS TEXT AS $$
SELECT ok( _opc_exists( $1 ), $2)
$$ LANGUAGE SQL;
-- has_opclass( name )
CREATE OR REPLACE FUNCTION has_opclass( NAME )
RETURNS TEXT AS $$
SELECT ok( _opc_exists( $1 ), 'Operator class ' || quote_ident($1) || ' should exist' );
$$ LANGUAGE SQL;
-- hasnt_opclass( name, description )
CREATE OR REPLACE FUNCTION hasnt_opclass( NAME, TEXT )
RETURNS TEXT AS $$
SELECT ok( NOT _opc_exists( $1 ), $2)
$$ LANGUAGE SQL;
-- hasnt_opclass( name )
CREATE OR REPLACE FUNCTION hasnt_opclass( NAME )
RETURNS TEXT AS $$
SELECT ok( NOT _opc_exists( $1 ), 'Operator class ' || quote_ident($1) || ' should exist' );
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION _get_type_owner ( NAME, NAME )
RETURNS NAME AS $$
SELECT pg_catalog.pg_get_userbyid(t.typowner)
FROM pg_catalog.pg_type t
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
WHERE n.nspname = $1
AND t.typname = $2
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION _get_type_owner ( NAME )
RETURNS NAME AS $$
SELECT pg_catalog.pg_get_userbyid(typowner)
FROM pg_catalog.pg_type
WHERE typname = $1
AND pg_catalog.pg_type_is_visible(oid)
$$ LANGUAGE SQL;
-- type_owner_is ( schema, type, user, description )
CREATE OR REPLACE FUNCTION type_owner_is ( NAME, NAME, NAME, TEXT )
RETURNS TEXT AS $$
DECLARE
owner NAME := _get_type_owner($1, $2);
BEGIN
-- Make sure the type exists.
IF owner IS NULL THEN
RETURN ok(FALSE, $4) || E'\n' || diag(
E' Type ' || quote_ident($1) || '.' || quote_ident($2) || ' not found'
);
END IF;
RETURN is(owner, $3, $4);
END;
$$ LANGUAGE plpgsql;
-- type_owner_is ( schema, type, user )
CREATE OR REPLACE FUNCTION type_owner_is ( NAME, NAME, NAME )
RETURNS TEXT AS $$
SELECT type_owner_is(
$1, $2, $3,
'Type ' || quote_ident($1) || '.' || quote_ident($2) || ' should be owned by ' || quote_ident($3)
);
$$ LANGUAGE sql;
-- type_owner_is ( type, user, description )
CREATE OR REPLACE FUNCTION type_owner_is ( NAME, NAME, TEXT )
RETURNS TEXT AS $$
DECLARE
owner NAME := _get_type_owner($1);
BEGIN
-- Make sure the type exists.
IF owner IS NULL THEN
RETURN ok(FALSE, $3) || E'\n' || diag(
E' Type ' || quote_ident($1) || ' not found'
);
END IF;
RETURN is(owner, $2, $3);
END;
$$ LANGUAGE plpgsql;
-- type_owner_is ( type, user )
CREATE OR REPLACE FUNCTION type_owner_is ( NAME, NAME )
RETURNS TEXT AS $$
SELECT type_owner_is(
$1, $2,
'Type ' || quote_ident($1) || ' should be owned by ' || quote_ident($2)
);
$$ LANGUAGE sql;
|