Re: Insert data in two columns same table

Поиск
Список
Период
Сортировка
От Andreas Kretschmer
Тема Re: Insert data in two columns same table
Дата
Msg-id 118471091.16197.1458179361626.JavaMail.open-xchange@oxweb01.ims-firmen.de
обсуждение исходный текст
Ответ на Insert data in two columns same table  ("drum.lucas@gmail.com" <drum.lucas@gmail.com>)
Ответы Re: Insert data in two columns same table  ("drum.lucas@gmail.com" <drum.lucas@gmail.com>)
Re: Insert data in two columns same table  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general

> "drum.lucas@gmail.com" <drum.lucas@gmail.com> hat am 17. März 2016 um 02:34
> geschrieben:
>
>
> I'm trying to insert data from TABLE A to TABLE B.
>
> 1 - Select billable_id from dm.billable
> 2 - Select mobiuser_id from ja_mobiusers
> 3 - Insert the billable_id and the mobiuser_id to the dm.billables_links
> table.
>
>
> *FYI -* It has to be in the same transaction because the mobiuser_id must
> go to the selected billable_id on the first select.
>
> Well... Would be something like:
>
> > INSERT INTO dm.billables_links (billable_id) VALUES ((SELECT billable_id
> > FROM junk.wm_260_billables2 WHERE info ilike '%Alisha%')),
> > INSERT INTO dm.billables_links (mobiuser_id) VALUES ((SELECT id FROM
> > public.ja_mobiusers WHERE name_first LIKE 'Alisha%' AND name_last LIKE
> > 'Dson%'))
>
>
>
> The problem is that I need to do that at the same time, because of a
> constraint:
>
> ALTER TABLE dm.billables_links
>   ADD CONSTRAINT cc_one_and_only_one_target CHECK ((("customer_id" IS
> NOT NULL)::integer + ("role_id" IS NOT NULL)::integer + ("mobiuser_id"
> IS NOT NULL)::integer) = 1);
>
> I'm having trouble by creating that SQL... can anyone help please?


I see a lot of other problems: you have 3 independet tables. Your 2 queries
(selects) returns 2 independet results, you can't use that for insert into the
3rd table. And i think, you are looking for an update, not insert. So you have
to define how your tables are linked together (join).

Can you explain how these tables are linked together?



--
Andreas Kretschmer
http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


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

Предыдущее
От: "drum.lucas@gmail.com"
Дата:
Сообщение: Re: Deleting schema - saving up space - PostgreSQL 9.2
Следующее
От: "drum.lucas@gmail.com"
Дата:
Сообщение: Re: Insert data in two columns same table