1CREATE FUNCTION alter_op_test_fn(boolean, boolean)
2RETURNS boolean AS $$ SELECT NULL::BOOLEAN; $$ LANGUAGE sql IMMUTABLE;
3
4CREATE FUNCTION customcontsel(internal, oid, internal, integer)
5RETURNS float8 AS 'contsel' LANGUAGE internal STABLE STRICT;
6
7CREATE OPERATOR === (
8    LEFTARG = boolean,
9    RIGHTARG = boolean,
10    PROCEDURE = alter_op_test_fn,
11    COMMUTATOR = ===,
12    NEGATOR = !==,
13    RESTRICT = customcontsel,
14    JOIN = contjoinsel,
15    HASHES, MERGES
16);
17
18SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
19FROM pg_depend
20WHERE classid = 'pg_operator'::regclass AND
21      objid = '===(bool,bool)'::regoperator
22ORDER BY 1;
23
24--
25-- Reset and set params
26--
27
28ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = NONE);
29ALTER OPERATOR === (boolean, boolean) SET (JOIN = NONE);
30
31SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
32  AND oprleft = 'boolean'::regtype AND oprright = 'boolean'::regtype;
33
34SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
35FROM pg_depend
36WHERE classid = 'pg_operator'::regclass AND
37      objid = '===(bool,bool)'::regoperator
38ORDER BY 1;
39
40ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = contsel);
41ALTER OPERATOR === (boolean, boolean) SET (JOIN = contjoinsel);
42
43SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
44  AND oprleft = 'boolean'::regtype AND oprright = 'boolean'::regtype;
45
46SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
47FROM pg_depend
48WHERE classid = 'pg_operator'::regclass AND
49      objid = '===(bool,bool)'::regoperator
50ORDER BY 1;
51
52ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = NONE, JOIN = NONE);
53
54SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
55  AND oprleft = 'boolean'::regtype AND oprright = 'boolean'::regtype;
56
57SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
58FROM pg_depend
59WHERE classid = 'pg_operator'::regclass AND
60      objid = '===(bool,bool)'::regoperator
61ORDER BY 1;
62
63ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = customcontsel, JOIN = contjoinsel);
64
65SELECT oprrest, oprjoin FROM pg_operator WHERE oprname = '==='
66  AND oprleft = 'boolean'::regtype AND oprright = 'boolean'::regtype;
67
68SELECT pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype
69FROM pg_depend
70WHERE classid = 'pg_operator'::regclass AND
71      objid = '===(bool,bool)'::regoperator
72ORDER BY 1;
73
74--
75-- Test invalid options.
76--
77ALTER OPERATOR === (boolean, boolean) SET (COMMUTATOR = ====);
78ALTER OPERATOR === (boolean, boolean) SET (NEGATOR = ====);
79ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = non_existent_func);
80ALTER OPERATOR === (boolean, boolean) SET (JOIN = non_existent_func);
81ALTER OPERATOR === (boolean, boolean) SET (COMMUTATOR = !==);
82ALTER OPERATOR === (boolean, boolean) SET (NEGATOR = !==);
83
84-- invalid: non-lowercase quoted identifiers
85ALTER OPERATOR & (bit, bit) SET ("Restrict" = _int_contsel, "Join" = _int_contjoinsel);
86
87--
88-- Test permission check. Must be owner to ALTER OPERATOR.
89--
90CREATE USER regress_alter_op_user;
91SET SESSION AUTHORIZATION regress_alter_op_user;
92
93ALTER OPERATOR === (boolean, boolean) SET (RESTRICT = NONE);
94
95-- Clean up
96RESET SESSION AUTHORIZATION;
97DROP USER regress_alter_op_user;
98DROP OPERATOR === (boolean, boolean);
99DROP FUNCTION customcontsel(internal, oid, internal, integer);
100DROP FUNCTION alter_op_test_fn(boolean, boolean);
101