Re: [SQL] insert or update within transaction

2011-09-17 Thread Josh Kupershmidt
On Sat, Sep 17, 2011 at 10:52 AM, Andreas wrote: > Instead of the update the query fails with an double key value error for the > primary key. > Shouldn't the insert fail, get rolled back and then exercute an update > instead successfully? Yes, and that is indeed what I see when I run your exampl

[SQL] insert or update within transaction

2011-09-17 Thread Andreas
Hi, http://www.postgresql.org/docs/current/static/sql-update.html has an example where an either an insert or update is done according if a key already exists. The example is about wines. I did it with numbers. drop table if exists tbl; create table tbl ( key int primary key, val int ); insert

Re: [SQL] INSERT or UPDATE

2008-08-18 Thread A. Kretschmer
am Mon, dem 18.08.2008, um 9:44:48 +0200 mailte Andreas Kraftl folgendes: > But there is also the possibility, that one row is available. Means that > i need an UPDATE instead of the INSERT. > > Is it in SQL possible to decide if there is an UPDATE or an INSERT or > must i program something with

[SQL] INSERT or UPDATE

2008-08-18 Thread Andreas Kraftl
Hello I have an XML file, which i must import into the database. I transform this XML File with xslt to sql INSERTS. But there is also the possibility, that one row is available. Means that i need an UPDATE instead of the INSERT. Is it in SQL possible to decide if there is an UPDATE or an INSERT

Re: [SQL] insert or update violates foreign key constraint.why?

2004-05-31 Thread Tom Lane
Oleg Mayevskiy <[EMAIL PROTECTED]> writes: > it seems to be a simple problem, but it is not. Yes it is ... you're expecting the RI triggers to fire during the plpgsql function, but in fact they fire at completion of the outer statement that called the plpgsql function. There's been some debate ab

[SQL] insert or update violates foreign key constraint.why?

2004-05-31 Thread Oleg Mayevskiy
it seems to be a simple problem, but it is not. i have declared 2 simple tables: CREATE TABLE public.test1 ( id int4 NOT NULL, data float4, CONSTRAINT mytest_pkey PRIMARY KEY (id) ) WITH OIDS; CREATE TABLE public.test2 ( id1 int4 NOT NULL, data1 float4, CONSTRAINT test2_pkey PRIMARY K