Re: if exists...does it exists for insert statments?

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: PgSQL General ML <pgsql-general(at)postgresql(dot)org>, Pau Marc Munoz Torres <paumarc(at)gmail(dot)com>
Subject: Re: if exists...does it exists for insert statments?
Date: 2007-12-11 17:13:51
Message-ID: 852435.1540.qm@web31806.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

--- On Tue, 12/11/07, Pau Marc Munoz Torres <paumarc(at)gmail(dot)com> wrote:
> could i use a sentence similar to the mysql sentence
>
> insert if not exist into SP values
> ('cesp','sp');
>
> in postgresql?

Using standard ANSI-SQL the statement could be re-written:

INSERT INTO SP
SELECT a, b
FROM VALUES ( 'cesp', 'sp' ) AS tmp( a, b )
LEFT JOIN Sp
ON (Sp.col1,Sp.col2)=(tmp.a,tmp.b)
WHERE (Sp.col1,Sp.col2) IS NULL;

Regards,
Richard Broersma Jr.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Hart 2007-12-11 17:15:36 Re: top posting
Previous Message Joshua D. Drake 2007-12-11 17:13:26 Re: top posting