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 20:23:11
Message-ID: CACjxUsN5bS8kMjGZ_nsw-X8=tVuOEHC=HVg3JdSnKwk8pJofUw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

[sel is a relation which can have multiple rows; the fact that it
is being generated in a CTE isn't relevant for purposes of the
error.]

>>>> UPDATE table_2 SET c_id =
>>>> (
>>>> SELECT c_id
>>>> FROM sel
>>>> ORDER BY c_id
>>>> )
>>>> WHERE clientid = 124312;

>>>> ERROR: more than one row returned by a subquery used as an expression

> isn't clear what I'm trying to achieve?

Nope.

> That's what I need, I just want a way to do that, as the way I'm
> doing isn't working.

You are specifying that you want to assign all the "c_id" values
from the "sel" relation to the "c_id" column in "table2" for any
and all rows which have a "clientid" value of 124312. Effectively
the database is complaining that it can only store one value, not a
set of values. I can only guess at what you might be intending to
ask the database to do. Can you explain what you are trying to do?

--
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 Patrick B 2016-09-27 20:33:39 Re: Update two tables returning id from insert CTE Query
Previous Message David G. Johnston 2016-09-27 20:19:56 Re: Update two tables returning id from insert CTE Query