On 2012-02-15, Chris Angelico ros...@gmail.com wrote:
Periodically I find myself wanting to insert into some table,
specifying the primary key column(s), but to simply ignore the request
if it's already there. Currently I have two options:
1) Do the insert as normal, but suppress errors.
This must be a function or trigger to break one statement into two. You
could of course simply use two separate statements in PHP as long as
they are in the same transaction. If you're going to perform this
action in two steps then putting both in a function or trigger is often
preferable.
Chris Angelico wrote:
On Wed, Feb 15, 2012 at 5:26 PM, Bartosz Dmytrakbdmyt...@eranet.pl wrote:
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;
I wonder
Maybe to show how found works and how to ignore errors - that is my
assumption only.
Regards,
Bartek
2012/2/15 Berend Tober bto...@broadstripe.net
Chris Angelico wrote:
On Wed, Feb 15, 2012 at 5:26 PM, Bartosz Dmytrakbdmyt...@eranet.pl
wrote:
e.g. You can use BEGIN... EXCEPTION
Periodically I find myself wanting to insert into some table,
specifying the primary key column(s), but to simply ignore the request
if it's already there. Currently I have two options:
1) Do the insert as normal, but suppress errors.
SAVEPOINT foo;
INSERT INTO table (col1,col2,col3) VALUES
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
;
On Wed, Feb 15, 2012 at 5:26 PM, Bartosz Dmytrak bdmyt...@eranet.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:
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