pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: 'UPDATE OR INSERT' command
3+ messages / 3 participants
[nested] [flat]
* 'UPDATE OR INSERT' command
@ 2004-07-15 18:20 Jeff Kowalczyk <jtk@yahoo.com>
2004-07-15 17:49 ` Re: 'UPDATE OR INSERT' command Stephen Frost <sfrost@snowman.net>
2004-07-15 17:53 ` Re: 'UPDATE OR INSERT' command Bruno Wolff III <bruno@wolff.to>
0 siblings, 2 replies; 3+ messages in thread
From: Jeff Kowalczyk @ 2004-07-15 18:20 UTC (permalink / raw)
To: pgsql-sql
Is there a postgresql SQL idiom to perform an UPDATE, which becomes an
INSERT if the primary key does not exist?
I'm not sure I *should* use it in my application, I just want to know if
it can be done. Thanks.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: 'UPDATE OR INSERT' command
2004-07-15 18:20 'UPDATE OR INSERT' command Jeff Kowalczyk <jtk@yahoo.com>
@ 2004-07-15 17:49 ` Stephen Frost <sfrost@snowman.net>
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Frost @ 2004-07-15 17:49 UTC (permalink / raw)
To: Jeff Kowalczyk <jtk@yahoo.com>; +Cc: pgsql-sql
* Jeff Kowalczyk (jtk@yahoo.com) wrote:
> Is there a postgresql SQL idiom to perform an UPDATE, which becomes an
> INSERT if the primary key does not exist?
>
> I'm not sure I *should* use it in my application, I just want to know if
> it can be done. Thanks.
Unfortunately, I don't believe there's one in PostgreSQL yet. MERGE is
similar to this, and is defined in the latest SQL spec. Hopefully it'll
be implemented in PostgreSQL sometime soon.
Stephen
Attachments:
signature.asc (application/pgp-signature, 188B) download
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: 'UPDATE OR INSERT' command
2004-07-15 18:20 'UPDATE OR INSERT' command Jeff Kowalczyk <jtk@yahoo.com>
@ 2004-07-15 17:53 ` Bruno Wolff III <bruno@wolff.to>
1 sibling, 0 replies; 3+ messages in thread
From: Bruno Wolff III @ 2004-07-15 17:53 UTC (permalink / raw)
To: Jeff Kowalczyk <jtk@yahoo.com>; +Cc: pgsql-sql
On Thu, Jul 15, 2004 at 13:20:57 -0500,
Jeff Kowalczyk <jtk@yahoo.com> wrote:
> Is there a postgresql SQL idiom to perform an UPDATE, which becomes an
> INSERT if the primary key does not exist?
>
> I'm not sure I *should* use it in my application, I just want to know if
> it can be done. Thanks.
There isn't a single statement that does this.
This has been discussed a number of times. The archives will have some
different examples.
You end up needing to either lock the table or check for failure since
postgres doesn't have predicate locking. Which technique is best will
depend on the details of your situation.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-07-15 18:20 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-07-15 18:20 'UPDATE OR INSERT' command Jeff Kowalczyk <jtk@yahoo.com>
2004-07-15 17:49 ` Stephen Frost <sfrost@snowman.net>
2004-07-15 17:53 ` Bruno Wolff III <bruno@wolff.to>
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