PostgreSQL 8.0.0rc4 Documentation
Prev | Fast Backward | Chapter 8. Data Types | Fast Forward | Next

# 8.12. Object Identifier Types

Object identifiers (OIDs) are used internally by PostgreSQL as primary keys for various system tables. An OID system column is also added to user-created tables, unless `WITHOUT OIDS` is specified when the table is created, or the default_with_oids configuration variable is set to false. Type `oid` represents an object identifier. There are also several alias types for `oid`: `regproc`, `regprocedure`, `regoper`, `regoperator`, `regclass`, and `regtype`. Table 8-19 shows an overview.

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.

> Note: OIDs are included by default in user-created tables in PostgreSQL 8.0.0rc4. However, this behavior is likely to change in a future version of PostgreSQL. Eventually, user-created tables will not include an OID system column unless `WITH OIDS` is specified when the table is created, or the `default_with_oids` configuration variable is set to true. If your application requires the presence of an OID system column in a table, it should specify `WITH OIDS` when that table is created to ensure compatibility with future releases of PostgreSQL.

The `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, 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.)

Table 8-19. Object Identifier Types

Name | References | Description | Value Example
--- | --- | --- | ---
`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)` or `-(NONE,integer)`
`regclass` | `pg_class` | relation name | `pg_type`
`regtype` | `pg_type` | data type name | `integer`

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. 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.

Another identifier type used by the system is `xid`, or transaction (abbreviated xact) identifier. This is the data type of the system columns `xmin` and `xmax`. Transaction identifiers are 32-bit quantities.

A third identifier type used by the system is `cid`, or command identifier. This is the data type of the system columns `cmin` and `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 5.2.)

Prev | Home | Next
Composite Types | Up | Pseudo-Types