sequences and pg_type

Started by pwover 22 years ago3 messageshackers
Jump to latest
#1pw
p.willis@telus.net

Hello,

I have a table with a serial type in it as a record id.
The type of this object comes back as int4 when I query via
pg_type.

How can I distinguish this counter type from just a plain int4?

Peter

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: pw (#1)
Re: sequences and pg_type

pw <p.willis@telus.net> writes:

I have a table with a serial type in it as a record id.
The type of this object comes back as int4 when I query via
pg_type.
How can I distinguish this counter type from just a plain int4?

Well, you can't, because serial isn't actually a type in Postgres.
As the manual tries to explain, serial is just a shorthand for creating
an integer column whose default is a nextval() call on a sequence.
So the way to tell is to look for a default expression of that kind.

regards, tom lane

#3pw
p.willis@telus.net
In reply to: Tom Lane (#2)
Re: sequences and pg_type

I think I found a solution. Hopefully the system tables don't change
too much in the future.I just used pg_attrdef to tell me which columns
*not* to use.

I hope that's right. It seems to work.

Peter

On Sat, 2003-09-06 at 18:19, Tom Lane wrote:

pw <p.willis@telus.net> writes:

I have a table with a serial type in it as a record id.
The type of this object comes back as int4 when I query via
pg_type.
How can I distinguish this counter type from just a plain int4?

Well, you can't, because serial isn't actually a type in Postgres.
As the manual tries to explain, serial is just a shorthand for

creating

Show quoted text

an integer column whose default is a nextval() call on a sequence.
So the way to tell is to look for a default expression of that kind.

regards, tom lane