pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedhow does one replace a row in Postgresql? (ala MySQL REPLACE)
3+ messages / 3 participants
[nested] [flat]
* how does one replace a row in Postgresql? (ala MySQL REPLACE)
@ 2001-12-11 22:09 Terrence Brannon <metaperl@mac.com>
0 siblings, 2 replies; 3+ messages in thread
From: Terrence Brannon @ 2001-12-11 22:09 UTC (permalink / raw)
To: pgsql-sql
A common task is to check to see if a row with a certain primary
key exists before inserting it. If the row exists, then you
simply update/overwrite its contents with the new row data.
Otherwise you insert it.
MySQL has a REPLACE command which does this.
I didn't see one in the Postgresql manual. How do you do this in
Postgresql?
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: how does one replace a row in Postgresql? (ala MySQL REPLACE)
@ 2001-12-12 00:39 Philip Hallstrom <philip@adhesivemedia.com>
parent: Terrence Brannon <metaperl@mac.com>
1 sibling, 0 replies; 3+ messages in thread
From: Philip Hallstrom @ 2001-12-12 00:39 UTC (permalink / raw)
To: Terrence Brannon <metaperl@mac.com>; +Cc: pgsql-sql
Try to UPDATE the row. If that fails, then insert it.
There's no REPLACE in postgresql (unless someone added it and forgot to
tell me :)
On Tue, 11 Dec 2001, Terrence Brannon wrote:
> A common task is to check to see if a row with a certain primary
> key exists before inserting it. If the row exists, then you
> simply update/overwrite its contents with the new row data.
> Otherwise you insert it.
>
> MySQL has a REPLACE command which does this.
>
> I didn't see one in the Postgresql manual. How do you do this in
> Postgresql?
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: how does one replace a row in Postgresql? (ala MySQL REPLACE)
@ 2001-12-12 12:45 Bruno Wolff III <bruno@[66.92.219.49]>
parent: Terrence Brannon <metaperl@mac.com>
1 sibling, 0 replies; 3+ messages in thread
From: Bruno Wolff III @ 2001-12-12 12:45 UTC (permalink / raw)
To: Terrence Brannon <metaperl@mac.com>; +Cc: pgsql-sql
On Tue, Dec 11, 2001 at 02:09:19PM -0800,
Terrence Brannon <metaperl@mac.com> wrote:
> A common task is to check to see if a row with a certain primary
> key exists before inserting it. If the row exists, then you
> simply update/overwrite its contents with the new row data.
> Otherwise you insert it.
>
> MySQL has a REPLACE command which does this.
>
> I didn't see one in the Postgresql manual. How do you do this in
> Postgresql?
Another option that doesn't require testing of the response from one
sql statement before executing another is to delete rows with the
matching primary key. Then do an insert.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-12-12 12:45 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-12-11 22:09 how does one replace a row in Postgresql? (ala MySQL REPLACE) Terrence Brannon <metaperl@mac.com>
2001-12-12 00:39 ` Philip Hallstrom <philip@adhesivemedia.com>
2001-12-12 12:45 ` Bruno Wolff III <bruno@[66.92.219.49]>
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