Skip site navigation (1) Skip section navigation (2)

retrieving a serial number

From: "Lea, Michael" <MLea(at)mpi(dot)mb(dot)ca>
To: "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org>
Subject: retrieving a serial number
Date: 2000-06-28 17:35:49
Message-ID: C0E5077572DCD211812B00A0C95A0A1F03A934F7@ntexch01 (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
I have one table (call it "master") that, among other things, contains a
serial number. I have a number of other tables (call them "slaves") that,
among other things, contain a foreign key referring to the serial number in
the first table. I will be inserting one row into the master table, and one
row into zero or more slave tables in each transaction.

What I want to do is use a sequence in the master table to let PostgreSQL
automatically generate a unique serial number for me, but I need to know the
serial number in order to insert the corresponding rows into the slave
table(s). Is there any way of retrieving the serial number that will be used
before the transaction has been committed? Or will I have to generate my own
serial numbers?

Michael Lea
Information Security
Manitoba Public Insurance
Phone: (204) 985-8224


pgsql-sql by date

Next:From: AndreyDate: 2000-06-28 17:43:05
Subject: Procedures cannot take more than 16 arguments
Previous:From: Erik TennantDate: 2000-06-28 15:36:24
Subject: Re: finding (and recycling) holes in sequences

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group