Postgres CTE issues

Поиск
Список
Период
Сортировка
От Shekar Tippur
Тема Postgres CTE issues
Дата
Msg-id CAHmfATopobYPPVb5HRS-wZfuKkXLcz7gmbcx6bFpsKs1KE92-A@mail.gmail.com
обсуждение исходный текст
Ответы Re: Postgres CTE issues  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: Postgres CTE issues  (Marc Mamin <M.Mamin@intershop.de>)
Список pgsql-sql
Hello,

I am new to postgres. I have a scenario where I need a trigger that inserts values into n tables but dome of those tables are related.

I dug up some documents and I stumbled across CTE or teh with statement.

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.

I have been stuck with this issue for over 24 hours. Appreciate any help.

- Shekar

В списке pgsql-sql по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Group By with condition
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Postgres CTE issues