pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedsql statement how to do ?
2+ messages / 2 participants
[nested] [flat]
* sql statement how to do ?
@ 2002-07-05 09:02 juerg.rietmann@pup.ch
2002-07-05 12:40 ` Re: sql statement how to do ? Manfred Koizar <mkoi-pg@aon.at>
0 siblings, 1 reply; 2+ messages in thread
From: juerg.rietmann@pup.ch @ 2002-07-05 09:02 UTC (permalink / raw)
To: pgsql-sql
Hello everybody
I have a question regarding an sql statement. I need to insert a new record
into the table auftrag that is the almost the same as an existing record.
In a similar situation i I use
INSERT INTO auftrag_archiv (SELECT * FROM auftrag where a_id = '12345');
Now I need to do the following :
INSERT INTO auftrag (SELECT * FROM auftrag where a_id = '12345');
The problem is, that the table auftrag has a primay key called pk_auftrag.
Do this I get an error regarding duplicate pk_auftrag. Is there a way to
spare pk_auftrag somehow ?
Thanks in advance ... jr
__________________________________________________
PFISTER + PARTNER, SYSTEM - ENGINEERING AG
Juerg Rietmann
Grundstrasse 22a
6343 Rotkreuz
Switzerland
internet : www.pup.ch
phone : +4141 790 4040
fax : +4141 790 2545
mobile : +4179 211 0315
__________________________________________________
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: sql statement how to do ?
2002-07-05 09:02 sql statement how to do ? juerg.rietmann@pup.ch
@ 2002-07-05 12:40 ` Manfred Koizar <mkoi-pg@aon.at>
0 siblings, 0 replies; 2+ messages in thread
From: Manfred Koizar @ 2002-07-05 12:40 UTC (permalink / raw)
To: pgsql-sql
On Fri, 5 Jul 2002 09:03:38 +0000 (UTC), juerg.rietmann@pup.ch wrote:
>INSERT INTO auftrag (SELECT * FROM auftrag where a_id = '12345');
>
>The problem is, that the table auftrag has a primay key called pk_auftrag.
>Do this I get an error regarding duplicate pk_auftrag. Is there a way to
>spare pk_auftrag somehow ?
Juerg, is a_id your primary key? My examples are based on this
assumption, but if it is not, you still get the point, which is:
You can't use SELECT * here.
If you know the new a_id in advance:
INSERT INTO auftrag (a_id, col2, col3, ...)
SELECT '67890', col2, col3, ...
FROM auftrag
WHERE a_id = '12345';
If a_id is a serial or in any other way supplied automatically by a
DEFAULT clause or a trigger:
INSERT INTO auftrag (col2, col3, ...)
SELECT col2, col3, ...
FROM auftrag
WHERE a_id = '12345';
HTH.
Servus
Manfred
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-07-05 12:40 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-07-05 09:02 sql statement how to do ? juerg.rietmann@pup.ch
2002-07-05 12:40 ` Manfred Koizar <mkoi-pg@aon.at>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox