dbTalk Databases Forums  

[BUGS] datatype.sgml misleading regclass example

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] datatype.sgml misleading regclass example in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michael Fuhr
 
Posts: n/a

Default [BUGS] datatype.sgml misleading regclass example - 10-09-2004 , 11:22 AM






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:id;
oid
-------
26664
(1 row)

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

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] datatype.sgml misleading regclass example - 10-09-2004 , 12:02 PM






Michael Fuhr <mike (AT) fuhr (DOT) org> writes:
Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.