From 52200befd04b9fa71da83231c808764867079226 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 25 Apr 2002 02:56:56 +0000 Subject: [PATCH] Implement types regprocedure, regoper, regoperator, regclass, regtype per pghackers discussion. Add some more typsanity tests, and clean up some problems exposed thereby (broken or missing array types for some built-in types). Also, clean up loose ends from unknownin/out patch. --- contrib/findoidjoins/README.findoidjoins | 8 +- contrib/findoidjoins/findoidjoins.c | 6 +- doc/src/sgml/bki.sgml | 5 +- doc/src/sgml/datatype.sgml | 167 +++- src/backend/bootstrap/bootstrap.c | 30 +- src/backend/catalog/namespace.c | 43 +- src/backend/catalog/pg_operator.c | 6 +- src/backend/parser/parse_coerce.c | 102 +- src/backend/parser/parse_node.c | 5 +- src/backend/utils/adt/regproc.c | 1091 ++++++++++++++++++++- src/backend/utils/adt/ruleutils.c | 62 +- src/backend/utils/adt/selfuncs.c | 12 +- src/backend/utils/adt/varlena.c | 9 +- src/backend/utils/cache/catcache.c | 9 +- src/bin/psql/describe.c | 4 +- src/include/c.h | 10 +- src/include/catalog/catversion.h | 4 +- src/include/catalog/namespace.h | 4 +- src/include/catalog/pg_namespace.h | 6 +- src/include/catalog/pg_operator.h | 29 +- src/include/catalog/pg_proc.h | 26 +- src/include/catalog/pg_type.h | 36 +- src/include/fmgr.h | 5 +- src/include/utils/builtins.h | 19 +- src/test/regress/expected/opr_sanity.out | 42 +- src/test/regress/expected/type_sanity.out | 47 +- src/test/regress/sql/opr_sanity.sql | 42 +- src/test/regress/sql/type_sanity.sql | 38 +- 28 files changed, 1638 insertions(+), 229 deletions(-) diff --git a/contrib/findoidjoins/README.findoidjoins b/contrib/findoidjoins/README.findoidjoins index 557fd04158..14c17e1e0e 100644 --- a/contrib/findoidjoins/README.findoidjoins +++ b/contrib/findoidjoins/README.findoidjoins @@ -1,10 +1,10 @@ findoidjoins -This program scans a database, and prints oid fields (also regproc fields) -and the tables they join to. CAUTION: it is ver-r-r-y slow on a large -database, or even a not-so-large one. We don't really recommend running -it on anything but an empty database, such as template1. +This program scans a database, and prints oid fields (also regproc, regclass +and regtype fields) and the tables they join to. CAUTION: it is ver-r-r-y +slow on a large database, or even a not-so-large one. We don't really +recommend running it on anything but an empty database, such as template1. Uses pgeasy library. diff --git a/contrib/findoidjoins/findoidjoins.c b/contrib/findoidjoins/findoidjoins.c index c559b7a362..c426b5523a 100644 --- a/contrib/findoidjoins/findoidjoins.c +++ b/contrib/findoidjoins/findoidjoins.c @@ -39,7 +39,9 @@ main(int argc, char **argv) WHERE a.attnum > 0 AND \ relkind = 'r' AND \ (typname = 'oid' OR \ - typname = 'regproc') AND \ + typname = 'regproc' OR \ + typname = 'regclass' OR \ + typname = 'regtype') AND \ a.attrelid = c.oid AND \ a.atttypid = t.oid \ ORDER BY 2, a.attnum ; \ @@ -77,7 +79,7 @@ main(int argc, char **argv) DECLARE c_matches BINARY CURSOR FOR \ SELECT count(*)::int4 \ FROM \"%s\" t1, \"%s\" t2 \ - WHERE RegprocToOid(t1.\"%s\") = t2.oid ", + WHERE t1.\"%s\"::oid = t2.oid ", relname, relname2, attname); doquery(query); diff --git a/doc/src/sgml/bki.sgml b/doc/src/sgml/bki.sgml index 4ea0f5f92b..36503de659 100644 --- a/doc/src/sgml/bki.sgml +++ b/doc/src/sgml/bki.sgml @@ -1,5 +1,5 @@ @@ -122,7 +122,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/bki.sgml,v 1.10 2002/03/22 19:20:02 petere storage. The following types are allowed: bool, bytea, char (1 byte), name, int2, int2vector, - int4, regproc, text, + int4, regproc, regclass, + regtype, text, oid, tid, xid, cid, oidvector, smgr, _int4 (array), _aclitem (array). diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index aef751cbc5..4f06cee503 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -1,5 +1,5 @@ @@ -172,12 +172,6 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.89 2002/04/21 18:58:00 th exact numeric with selectable precision - - oid - - object identifier - - path @@ -2894,6 +2888,165 @@ SELECT SUBSTRING(b FROM 1 FOR 2) FROM test; + + Object Identifier Types + + + object identifier + data type + + + + oid + + + + regproc + + + + regprocedure + + + + regoper + + + + regoperator + + + + regclass + + + + regtype + + + + Object identifiers (OIDs) are used internally by + PostgreSQL as primary keys for various system + tables. Also, an OID system column is added to user-created tables + (unless WITHOUT OIDS is specified at table creation time). + Type oid represents an object identifier. There are also + several aliases for oid: regproc, regprocedure, + regoper, regoperator, regclass, + and regtype. + + + + The oid type is currently implemented as an unsigned four-byte + integer. + Therefore, it is not large enough to provide database-wide uniqueness + in large databases, or even in large individual tables. So, using a + user-created table's OID column as a primary key is discouraged. + OIDs are best used only for references to system tables. + + + + The oid type itself has few operations beyond comparison + (which is implemented as unsigned comparison). It can be cast to + integer, however, and then manipulated using the standard integer + operators. (Beware of possible signed-versus-unsigned confusion + if you do this.) + + + + The oid alias types have no operations of their own except + for specialized input and output routines. These routines are able + to accept and display symbolic names for system objects, rather than + the raw numeric value that type oid would use. The alias + types allow simplified lookup of OID values for objects: for example, + one may write 'mytable'::regclass to get the OID of table + mytable, rather than SELECT oid FROM pg_class WHERE + relname = 'mytable'. (In reality, a much more complicated SELECT would + be needed to deal with selecting the right OID when there are multiple + tables named mytable in different schemas.) + + + + + Object Identifier Types + + + + Type name + References + Description + Examples + + + + + + + oid + any + Numeric object identifier + 564182 + + + + regproc + pg_proc + Function name + sum + + + + regprocedure + pg_proc + Function with argument types + sum(int4) + + + + regoper + pg_operator + Operator name + + + + + + regoperator + pg_operator + Operator with argument types + *(integer,integer) -(NONE,integer) + + + + regclass + pg_class + Relation name + pg_type + + + + regtype + pg_type + Type name + integer + + + +
+
+ + + All of the alias types accept schema-qualified names, and will + display schema-qualified names on output if the object would not + be found in the current search path without being qualified. + The regproc and regoper alias types will only + accept input names that are unique (not overloaded), so they are + of limited use; for most uses regprocedure or + regoperator is more appropriate. For regoperator, + unary operators are identified by writing NONE for the unused + operand. + + +
+