Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
Thread:
Lists: pgsql-docspgsql-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

pgsql-docs by date

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

pgsql-sql by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group