On Tue, Sep 6, 2011 at 1:43 PM, Bruce Momjian <bruce@momjian.us> wrote:
> Well, this problem isn't isolated to WITH queries:
>
> =A0 =A0 =A0 =A0test=3D> do
> =A0 =A0 =A0 =A0$$begin
> =A0 =A0 =A0 =A0perform(
> =A0 =A0 =A0 =A0select 1 UNION ALL select 1
> =A0 =A0 =A0 =A0);
> =A0 =A0 =A0 =A0end$$;
> =A0 =A0 =A0 =A0ERROR: =A0more than one row returned by a subquery used as=
an expression
>
> =A0 =A0 =A0 =A0test=3D> do
> =A0 =A0 =A0 =A0$$begin
> =A0 =A0 =A0 =A0perform(
> =A0 =A0 =A0 =A0select relname from pg_class
> =A0 =A0 =A0 =A0);
> =A0 =A0 =A0 =A0end$$;
> =A0 =A0 =A0 =A0ERROR: =A0more than one row returned by a subquery used as=
an expression
>
Based on previous experience with PL/pgsql, my understanding is that
PL/pgsql basically replaces "perform" with "select" to get the query
that it actually runs. You'd get the same error from:
rhaas=3D# select (select relname from pg_class);
ERROR: more than one row returned by a subquery used as an expression
I've never really liked this behavior, but I don't have a clear idea
what to do about it.
--=20
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company