Re: Bulk Insert / Update / Delete - Mailing list pgsql-general

From Doug McNaught
Subject Re: Bulk Insert / Update / Delete
Date
Msg-id m3ptj1acy2.fsf@varsoon.wireboard.com
Whole thread Raw
In response to Bulk Insert / Update / Delete  ("Philip Boonzaaier" <phil@cks.co.za>)
List pgsql-general
"Philip Boonzaaier" <phil@cks.co.za> writes:

> I want to be able to generate SQL statements that will go through a list of
> data, effectively row by row, enquire on the database if this exists in the
> selected table- If it exists, then the colums must be UPDATED, if not, they
> must be INSERTED.
>
> Logically then, I would like to SELECT * FROM <TABLE>
> WHERE ....<Values entered here>, and then IF FOUND
> UPDATE <TABLE> SET .... <Values entered here> ELSE
> INSERT INTO <TABLE> VALUES <Values entered here>
> END IF;
>
> The IF statement gets rejected by the parser. So it would appear that
> PostgreSQL does not support an IF in this type of query, or maybe not at
> all.

Nope.  I don't know of an SQL database that does, though I certainly
haven't seen all of them...

> Does anyone have any suggestions as to how I can achieve this ?

Application code that loops through the results of the first query,
and issues UPDATE/INSERT statements as needed?  Or you could do it as
a PL/pgSQL function which might be a little faster.

> This message is privileged and confidential and intended for the addressee only. If you are not the intended
recipientyou may not disclose, copy or 
> in any way use or publish the content hereof, which is subject to copyright.If you have received this in error,
pleasedestroy the original message 
> and contact us at postmaster@cks.co.za. Any views expressed in this message
> are those of the individual sender, except where the sender specifically
> states them to be the view of Computerkit Retail Systems, its subsidiaries or
> associates. Please note that the recipient must scan this e-mail and attachments for  viruses. We accept no liability
ofwhatever nature for any loss, 
> liability,damage or expense resulting directly or indirectly from this transmission
> of this message and/or attachments.

I have companies that force crap like this on mailing list postings...

-Doug

pgsql-general by date:

Previous
From: "Erwan DUROSELLE"
Date:
Subject: Re: Mailing list in French
Next
From: Doug McNaught
Date:
Subject: Re: Bulk Insert / Update / Delete