// data type reference

OIDs and other internal system identifiers

Engines need internal ids for their own objects and transactions: PostgreSQL's OID is the famous one, Oracle's XID names a transaction, and the others keep such bookkeeping out of your SQL.

Missing in
MySQL
Gotchas
5 listed

Engine by engine

PostgreSQL's OID is a 32-bit object id from the old days: still everywhere in system catalogs, gone from ordinary user tables. SQLite's oid is just an alias for rowid; Oracle's XID tracks transactions.

OID & system ids in SQL Server, PostgreSQL, MySQL, SQLite and Oracle: type name, storage and notes
エンジン 型 ストレージ メモ
SQL Server object_id (int) 4 bytes (int) No column-level OIDs; objects carry an int object_id in sys.objects (OBJECT_ID('dbo.t') looks it up), and transactions a bigint transaction_id in sys.dm_tran_active_transactions.
PostgreSQL OID 4 bytes Unsigned 32-bit id for every system object: tables, types, functions. WITH OIDS stopped being the default for user tables in 8.1 and was removed in 12.
MySQL none Workaround なし Objects are identified by name; InnoDB's internal TABLE_ID shows up in information_schema.INNODB_TABLES, but there is no system id type to use in SQL.
SQLite oid (rowid alias) 1-8 bytes 'oid' is only a historical alias for the rowid; SQLite has no object-id concept. Name a column oid and the alias disappears for that table.
Oracle OBJECT_ID / XID NUMBER / RAW(8) Objects have a NUMBER OBJECT_ID in USER_OBJECTS; transactions carry an 8-byte XID (undo segment, slot, sequence) visible in V$TRANSACTION.

Gotchas

Where the engines disagree. These tend to surface as bugs during a migration or a port.

  1. PostgreSQL OIDs are unsigned 32-bit and can wrap around, values below 16384 are reserved for built-in objects, and a dump and restore assigns new ones. Never store an OID as a lasting reference to a table.
  2. WITH OIDS was removed in PostgreSQL 12: a dump from an older server that creates tables WITH OIDS fails to load, and queries that read the hidden oid column need an explicit key instead.
  3. SQLite's oid alias breaks if you declare a column literally named oid: the alias is shadowed and old queries reading 'oid' as the rowid start returning your data instead.
  4. Oracle's XID identifies a transaction, not a row. ORA_ROWSCN is a row's commit SCN, but without ROWDEPENDENCIES on the table it is tracked per block, so every row in a block reports the latest change.
  5. SQL Server's object_id() returns an int that is only unique per database, not per server; joining catalogs across databases on object_id alone is a bug.

Common questions

What is an OID in PostgreSQL, in one sentence?

An unsigned 32-bit id the system assigns to every object it creates: tables, types, functions. You meet it in catalogs (pg_class.oid, regtype casts), not in your own tables, which stopped having one in PostgreSQL 12.

How do I find a table's OID?

SELECT 'mytable'::regclass::oid, or look up pg_class WHERE relname = 'mytable'. The regclass cast is the tidy way and handles schema qualification.

My old query says SELECT oid FROM mytable and now fails. Why?

On pre-12 PostgreSQL the table was created WITH OIDS and had a hidden oid column; PostgreSQL 12 and later cannot create one. Replace it with an explicit primary key.

// map types before you move data

Map a type to the other four engines

The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.