Re: Subqueries in Non-SELECT Queries - Mailing list pgsql-sql

From Christof Glaser
Subject Re: Subqueries in Non-SELECT Queries
Date
Msg-id 00121719325000.15220@pinguin
Whole thread Raw
In response to Subqueries in Non-SELECT Queries  (Frank Joerdens <frank@joerdens.de>)
List 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


pgsql-sql by date:

Previous
From: Frank Joerdens
Date:
Subject: Subqueries in Non-SELECT Queries
Next
From: Tom Lane
Date:
Subject: Re: Subqueries in Non-SELECT Queries