Re: Postgres CTE issues

From: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
To: Shekar Tippur <ctippur(at)gmail(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Postgres CTE issues
Date: 2015-05-26 17:00:13
Message-ID: B6F6FD62F2624C4C9916AC0175D56D8828BCA89E@jenmbs01.ad.intershop.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


> This is what I am trying:
>
> WITH x AS
>
> (INSERT INTO industry (name,abbr,description,cr_date,last_upd)
>
> VALUES ('df','','',now(),now()) returning id) insert into sector (name,description,cr_date,last_upd,industry_id) select 's1','',now(),now(),id from x;
>
> I get a error:
>
> ERROR: insert or update on table "sector" violates foreign key constraint "sector_id_fkey"
>
> DETAIL: Key (id)=(394) is not present in table "industry".
>
> If I execute the insert individually, I am able to insert a record. Wonder what I am doing wrong.

Hello,
Defining your FK as deferrable initially deferred should help here.
regards,

Marc Mamin

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Shekar Tippur 2015-05-26 17:07:16 Re: Postgres CTE issues
Previous Message David G. Johnston 2015-05-26 16:14:45 Fwd: Postgres CTE issues