Appears there is a problem finding the opclass when indexing a domain.

CREATE DOMAIN newint as int4;
CREATE TABLE tab (col newint unique);
ERROR:  data type newint has no default operator class for access method
"btree"
        You must specify an operator class for the index or define a
        default operator class for the data type


Specifically, GetDefaultOpClass() finds 0 exact matches and 3 binary
compatible matches.  Fetching getBaseType() of the attribute fixes the
problem for domains (see attachment).

However, I have to wonder why GetDefaultOpClass doesn't simply use the
first Binary Compatible opclass.  When there is more than one usable it
doesn't do anything useful.


Index: src/backend/commands/indexcmds.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/commands/indexcmds.c,v
retrieving revision 1.80
diff -c -r1.80 indexcmds.c
*** src/backend/commands/indexcmds.c	2002/08/02 18:15:06	1.80
--- src/backend/commands/indexcmds.c	2002/08/11 21:14:13
***************
*** 482,487 ****
--- 482,490 ----
  	Oid			exactOid = InvalidOid;
  	Oid			compatibleOid = InvalidOid;
  
+ 	/* It could be a domain */
+ 	attrType = getBaseType(attrType);
+ 
  	/*
  	 * We scan through all the opclasses available for the access method,
  	 * looking for one that is marked default and matches the target type

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to