Re: Subqueries in Non-SELECT Queries

From: Christof Glaser <gcg(at)gl(dot)aser(dot)de>
To: Frank Joerdens <frank(at)joerdens(dot)de>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Subqueries in Non-SELECT Queries
Date: 2000-12-17 18:32:50
Message-ID: 00121719325000.15220@pinguin
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Frank Joerdens wrote:

> mpi=# update index set level = 2 where parentid = ( select id from
> index where level = 1 );
> ERROR: More than one tuple returned by a subselect used as an
> expression. mpi=#
>
> This is a recursive query, on a single table. Is that not possible?

Hi Frank,

as the error message says, the subselect must return only one value,
since the where clause compares just one field for equality. You might
try IN instead of =, ie

update index set level = 2 where parentid in ( select id from
index where level = 1 );

Hope that helps.

Christof
--
gl.aser . software engineering . internet service
http://gl.aser.de/ . Planckstraße 7 . D-39104 Magdeburg
Tel. +49.391.7 44 77 10 . Fax +49.391.7 44 77 13 . Mobil 0177.77 92 84 3

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2000-12-17 18:43:28 Re: Subqueries in Non-SELECT Queries
Previous Message Frank Joerdens 2000-12-17 18:03:37 Subqueries in Non-SELECT Queries