| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Charlie Toohey <ctoohey(at)pacbell(dot)net> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: serial column vs. explicit sequence question |
| Date: | 2002-06-13 21:13:16 |
| Message-ID: | 29716.1024002796@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
Charlie Toohey <ctoohey(at)pacbell(dot)net> writes:
> A better solution would seem to use a sequence explicitly, rather than a id
> column of type serial. I would obtain the id value from the sequence, and
> then insert this id into the master table and into the detail table.
Yup. But there's no need to change how you create the id column; serial
is just fine, since all it is is a sequence and a DEFAULT nextval('foo').
You just do something like
select nextval('name-of-id-columns-sequence') into $masterid;
insert into master(id, ...) values ($masterid, ...);
insert into detail ... $masterid ...;
rather than letting the default expression do it for you.
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Oliver Elphick | 2002-06-13 21:30:37 | Re: Another postgres 'file not found' error |
| Previous Message | Stephan Szabo | 2002-06-13 21:06:06 | Re: serial column vs. explicit sequence question |