Re: Update two tables returning id from insert CTE Query

From: Kevin Grittner <kgrittn(at)gmail(dot)com>
To: Patrick B <patrickbakerbr(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Update two tables returning id from insert CTE Query
Date: 2016-09-27 21:11:41
Message-ID: CACjxUsN97H9RaJZU+HZ_AR1s=_Rq2ergXH9uu=2t2PwXnFk=Gw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Sep 27, 2016 at 3:33 PM, Patrick B <patrickbakerbr(at)gmail(dot)com> wrote:

> 4 - Get the table_1.c_id from the STEP NUMBER 2 and put it into table_2.c_id
> - This is the problem.. how can I get the inserted id from STEP2 and put it
> into c_id respecting the order?

For DML you need to think of the data as being unordered sets, not
ordered lists. The whole concept of a relational database is that
related rows can be associated through their common data values.
You are splitting them apart and then trying to match them up again
to link them back together. You will be better off if you can
leave the relationship intact all the way through -- perhaps by
adding name_last to table_1.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Melvin Davidson 2016-09-27 21:16:22 Re: how to monitor the progress of really large bulk operations?
Previous Message Mike Sofen 2016-09-27 21:03:08 how to monitor the progress of really large bulk operations?