why am I told "subquery must return only one column"

From: John Gunther <postgresql(at)bucksvsbytes(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: why am I told "subquery must return only one column"
Date: 2008-05-05 14:53:31
Message-ID: 481F1F6B.1070103@bucksvsbytes.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I'm sure I'm making some bonehead syntax error but after an hour of
reading, searching, and experimenting it's time to ask wiser heads:

I've defined a type m
create type m as (m1 int,m2 int,m3 int,m4 int);

and a function sub:
create function sub(m) returns int as 'select (2*$1.m1 +3*$1.m2 +4*$1.m3
+ 5*$1.m4);' language sql;

and trying to create a second function mstr that calls the sub function
using a select statement as sub's argument:
create function mstr(text,text) returns int as 'select sub((select
5,6,7,8)::m);' language sql;

The last operation (and many variations of it) yields:
ERROR: subquery must return only one column

My question is this:
(select 5,6,7,8)::m returns a single entity of composite type m and sub
takes one argument of type m. So why the error? I don't even think the
::m is required.

Thanks in advance.

John Gunther
Bucks vs Bytes Inc.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2008-05-05 17:01:04 Re: why am I told "subquery must return only one column"
Previous Message Tom Lane 2008-05-05 14:08:25 Re: Schema/Trigger help