Re: [SQL] PL/pgSQL examples NOT involving functions

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: "Aasmund Midttun Godal" <postgresql(at)envisity(dot)com>, <roland(at)astrofoto(dot)org>
Cc: <pgsql-docs(at)postgresql(dot)org>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: [SQL] PL/pgSQL examples NOT involving functions
Date: 2001-11-20 04:32:44
Message-ID: GNELIHDDFBOCMGBFGEFOGEHLCAAA.chriskl@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs 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

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Roland Roberts 2001-11-20 05:00:22 Re: [DOCS] PL/pgSQL examples NOT involving functions
Previous Message Roland Roberts 2001-11-19 14:42:26 Re: PL/pgSQL examples NOT involving functions

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2001-11-20 04:40:16 Re: How to use COPY in a function ?
Previous Message Tom Lane 2001-11-20 04:11:31 Re: Foreign Key Constraint Deletion Order