Re: [DOCS] PL/pgSQL examples NOT involving functions - Mailing list pgsql-sql

From Christopher Kings-Lynne
Subject Re: [DOCS] PL/pgSQL examples NOT involving functions
Date
Msg-id GNELIHDDFBOCMGBFGEFOGEHLCAAA.chriskl@familyhealth.com.au
Whole thread Raw
In response to Re: PL/pgSQL examples NOT involving functions  ("Aasmund Midttun Godal" <postgresql@envisity.com>)
List pgsql-sql
> > How can I write a few lines of PL/pgSQL which do not involve creating
> > a function?  I can find no examples of this in the docs, but say I
> > would like to do something like
> >
> >     BEGIN
> >     IF EXISTS (SELECT * FROM foo WHERE idx = 27)
> >     THEN
> >         UPDATE foo SET var='some value' WHERE idx=27;
> >     ELSE
> >         INSERT INTO foo (idx, var) VALUES (27, 'some value');
> >     END IF
> >     END;

Interesting.  I see you are trying to simulate MySQL's 'REPLACE INTO'
syntax.

On an aside, I was recently asked to convert this MySQL code to PGSQL code
for the GeekLog project.  I gave up:

REPLACE INTO $table ($fields) SELECT $values FROM $tablefrom;

Evil!

Chris


pgsql-sql by date:

Previous
From: Andriy Pyrozhenko
Date:
Subject: Question
Next
From: "Marc G. Fournier"
Date:
Subject: INDEXng date_trunc ...