datatype.sgml misleading regclass example

Started by Michael Fuhrover 21 years ago2 messagesbugs
Jump to latest
#1Michael Fuhr
mike@fuhr.org

PostgreSQL 7.4.5, 8.0.0beta3

The Object Identifier Types section of the PostgreSQL documentation
contains the following:

for example, one may write 'mytable'::regclass to get the OID
of table mytable, rather than SELECT oid FROM pg_class WHERE
relname = 'mytable'.

To get the OID, don't we then need to cast to the oid type?

test=> SELECT 'mytable'::regclass;
regclass
----------
mytable
(1 row)

test=> SELECT 'mytable'::regclass::oid;
oid
-------
26664
(1 row)

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Fuhr (#1)
Re: datatype.sgml misleading regclass example

Michael Fuhr <mike@fuhr.org> writes:

for example, one may write 'mytable'::regclass to get the OID
of table mytable, rather than SELECT oid FROM pg_class WHERE
relname = 'mytable'.
To get the OID, don't we then need to cast to the oid type?

If you want to see it as a numeric value, yeah, but you can for example
compare it to an OID column without doing that.

SELECT attname FROM pg_attribute WHERE attrelid = 'mytable'::regclass;

Most of the time when I'm using a regxxx cast, it's because I *don't*
want to be bothered with the numeric value.

regards, tom lane