|PostgreSQL Reference Manual - Volume 1 - SQL Language Reference|
by The PostgreSQL Global Development Group
Paperback (6"x9"), 716 pages
RRP £32.00 ($49.95)
Sales of this book support the PostgreSQL project! Get a printed copy>>>
6.12 Object Identifier Types
Object identifiers (OIDs) are used internally by
PostgreSQL as primary keys for various
system tables. OIDs are not added to user-created tables, unless
WITH OIDS is specified when the table is
created, or the
configuration variable is enabled. Type
an object identifier. There are also several alias types for
regtype. Table 6-19 shows an
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.
oid type itself has few operations beyond 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,
to examine the
pg_attribute rows related to a table
mytable, one could write
SELECT * FROM pg_attribute WHERE attrelid = 'mytable'::regclass;
SELECT * FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'mytable');
While that doesn't look all that bad by itself, it's still oversimplified.
A far more complicated sub-select would be needed to
select the right OID if there are multiple tables named
mytable in different schemas.
regclass input converter handles the table lookup according
to the schema path setting, and so it does the “right thing”
automatically. Similarly, casting a table's OID to
regclass is handy for symbolic display of a numeric OID.
||any|| numeric object identifier|
|| || function name|
|| || function with argument types|
|| || operator name|
|| || operator with argument types|
|| || relation name|
|| || data type name|
All of the OID 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.
regoper alias types will only
accept input names that are unique (not overloaded), so they are
of limited use; for most uses
regoperator is more appropriate. For
unary operators are identified by writing
NONE for the unused
An additional property of the OID alias types is that if a
constant of one of these types appears in a stored expression
(such as a column default expression or view), it creates a dependency
on the referenced object. For example, if a column has a default
understands that the default expression depends on the sequence
my_seq; the system will not let the sequence be dropped
without first removing the default expression.
Another identifier type used by the system is
xid, or transaction
(abbreviated xact) identifier. This is the data type of the system columns
xmax. Transaction identifiers are 32-bit quantities.
A third identifier type used by the system is
command identifier. This is the data type of the system columns
cmax. Command identifiers are also 32-bit quantities.
A final identifier type used by the system is
tid, or tuple
identifier (row identifier). This is the data type of the system column
ctid. A tuple ID is a pair
(block number, tuple index within block) that identifies the
physical location of the row within its table.
(The system columns are further explained in section 3.4 System Columns.)
|ISBN 0954612027||PostgreSQL Reference Manual - Volume 1 - SQL Language Reference||See the print edition|