The next table of interest is pg_opclass
. This table defines operator class
names and input data types for each of the operator classes
supported by a given index access method. The same class name can
be used for several different access methods (for example, both
B-tree and hash access methods have operator classes named
oid_ops), but a separate pg_opclass row must appear for each access
method. The OID of the pg_opclass
row is used as a foreign key in other tables to associate
specific operators and support routines with the operator
class.
You need to add a row with your operator class name (for
example, complex_abs_ops) to
pg_opclass
:
INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype) VALUES ( (SELECT oid FROM pg_am WHERE amname = 'btree'), 'complex_abs_ops', (SELECT oid FROM pg_type WHERE typname = 'complex'), true, 0); SELECT oid, * FROM pg_opclass WHERE opcname = 'complex_abs_ops'; oid | opcamid | opcname | opcintype | opcdefault | opckeytype --------+---------+-----------------+-----------+------------+------------ 277975 | 403 | complex_abs_ops | 277946 | t | 0 (1 row)
Note that the OID for your pg_opclass
row will be different! Don't worry
about this though. We'll get this number from the system later
just like we got the OID of the type here.
The above example assumes that you want to make this new operator class the default B-tree operator class for the complex data type. If you don't, just set opcdefault to false instead. opckeytype is not described here; it should always be zero for B-tree operator classes.