Re: Easy form of "insert if it isn't already there"?

From: Bartosz Dmytrak <bdmytrak(at)eranet(dot)pl>
To: Chris Angelico <rosuav(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Easy form of "insert if it isn't already there"?
Date: 2012-02-15 07:14:59
Message-ID: CAD8_UcZY0_V8R5HDt_nFGWnax5aLuze_uR5LEGExNH1+r2SuKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yes it is.
You can implement trigger on table to check if inserted record is new.
Still it is on DB side.
I don't know PHP well enough but I think You can call function e.g. SELECT
myschema."InsertWhenNew" ("val1", "val2", "val3"); in the same way as You
call INSERTS

Regards,
Bartek

2012/2/15 Chris Angelico <rosuav(at)gmail(dot)com>

> On Wed, Feb 15, 2012 at 5:26 PM, Bartosz Dmytrak <bdmytrak(at)eranet(dot)pl>
> wrote:
> > Hi,
> > similar topic is in NOVICE mailing
> > list: http://archives.postgresql.org/pgsql-novice/2012-02/msg00034.php
> >
> > e.g. You can use BEGIN... EXCEPTION.... END, good example of
> > such approach is
> > there:
> http://www.postgresql.org/docs/9.1/static/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE
> ;
>
> Ah, thanks for that!
>
> Currently the query is a single PHP pg_query_params() call, and it's
> inside a larger transaction. By the look of it, this requires writing
> a function to do the job, rather than embedding the logic straight
> into the query - is this correct?
>
> ChrisA
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Berend Tober 2012-02-15 07:37:00 Re: Easy form of "insert if it isn't already there"?
Previous Message Scott Marlowe 2012-02-15 06:51:51 Re: High checkpoint_segments