Unix Technical Forum

Relationship beween sequences (serial) and tables

This is a discussion on Relationship beween sequences (serial) and tables within the pgsql Admins forums, part of the PostgreSQL category; --> Hi, I use Postgres 7.4.5 on Linux In many of my tables the primary key is bigserial for which ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Admins

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 06:13 AM
Thusitha Kodikara
 
Posts: n/a
Default Relationship beween sequences (serial) and tables

Hi,

I use Postgres 7.4.5 on Linux

In many of my tables the primary key is bigserial for which sequences are automatcially generated. Through pg_catalog tables how can I find the relationship petween each table and its corresponding sequence ?

Thanks.

-Thusitha


---------------------------------
Click here to donate to the Hurricane Katrina relief effort.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 06:13 AM
Michael Fuhr
 
Posts: n/a
Default Re: Relationship beween sequences (serial) and tables

On Thu, Sep 08, 2005 at 01:03:26AM -0700, Thusitha Kodikara wrote:
> In many of my tables the primary key is bigserial for which
> sequences are automatcially generated. Through pg_catalog tables
> how can I find the relationship petween each table and its corresponding
> sequence ?


Depending on what information you're looking for, you might need
to query any of the following tables:

pg_attrdef
pg_attribute
pg_class
pg_constraint
pg_depend
pg_index

See also "Miscellaneous Functions" ("System Information Functions"
in 8.x) in the "Functions and Operators" chapter of the documentation.
It can also be useful to run "psql -E" or use "\set ECHO_HIDDEN"
in psql to show the SQL queries that psql makes for \d commands.

--
Michael Fuhr

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 06:14 AM
Jim C. Nasby
 
Posts: n/a
Default Re: Relationship beween sequences (serial) and tables

On Thu, Sep 08, 2005 at 01:03:26AM -0700, Thusitha Kodikara wrote:
> Hi,
>
> I use Postgres 7.4.5 on Linux
>
> In many of my tables the primary key is bigserial for which sequences are automatcially generated. Through pg_catalog tables how can I find the relationship petween each table and its corresponding sequence ?


If you install newsysviews (http://pgfoundry.org/projects/newsysviews/),
the following query will give you all table columns that are using a
sequence for their default value:

select * from pg_user_table_columns where default_value like 'nextval(%';
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:49 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com