From: | "Hitoshi Harada" <hitoshi_harada(at)forcia(dot)com> |
---|---|
To: | "'SunWuKung'" <Balazs(dot)Klein(at)t-online(dot)hu>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: calculated default |
Date: | 2006-11-16 14:06:22 |
Message-ID: | 006701c70988$6571fd80$5f01a8c0@daraha |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> I have a table with a sequence as its primary key.
> On insert I would like to have all its fields (except the primary key)
> default to the last one in the table (order by id desc limit 1).
> I guess I should use a trigger to do this but I don't know how.
How about this:
INSERT INTO table
SELECT nextval('seq'), col1, col2...
FROM table
WHERE pkey = curval('seq');
Regards,
Hitoshi Harada
> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org
> [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of SunWuKung
> Sent: Thursday, November 16, 2006 5:48 PM
> To: pgsql-general(at)postgresql(dot)org
> Subject: [GENERAL] calculated default
>
> I have a table with a sequence as its primary key.
> On insert I would like to have all its fields (except the primary key)
> default to the last one in the table (order by id desc limit 1).
> I guess I should use a trigger to do this but I don't know how.
>
> Thanks for the help.
> SWK
>
>
> ---------------------------(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
From | Date | Subject | |
---|---|---|---|
Next Message | Florian G. Pflug | 2006-11-16 14:30:58 | Re: Recovering deleted or updated rows |
Previous Message | A. Kretschmer | 2006-11-16 13:22:37 | Re: problem in to_char() function |