Re: Need help. Getting an error in my function when I do a select * from foo_bar()

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Need help. Getting an error in my function when I do a select * from foo_bar()
Date: 2014-06-11 16:25:37
Message-ID: 1402503937253-5806854.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Shubhra Sharma wrote
> ERROR: subquery must return only one column
> LINE 1: SELECT outer_query || 'UNION' || (select

A scalar sub-query can only return a single row and column. Somewhere in
that jumble of text you have a scalar sub-query returning more than one
column.

i.e.:
SELECT ...,
(SELECT one_column_only FROM ... LIMIT 1) AS valid_scalar_subquery
FROM ...

SELECT ...,
(SELECT col1, col2 FROM ... LIMIT 1) AS invalid_scalar_subquery
FROM ...

I am thinking your "per_inventory_query:=quote_literal((SELECT ...))"
statement may be the culprit since a query result being fed into a function
is an instance of a scalar sub-query. I have no way to test/prove since
your example is not self-contained.

I've spent as much time as I am willing to try and spot it but cannot.

You can wait and see if anyone else has better luck/more patience or you can
try greatly simplifying and formatting the query which you can either
re-post here or in the process of doing discover where the error is
yourself.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Need-help-Getting-an-error-in-my-function-when-I-do-a-select-from-foo-bar-tp5806849p5806854.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Markus Neumann 2014-06-11 19:55:01 I probably don't understand aggregates.
Previous Message Shubhra Sharma 2014-06-11 16:08:33 Need help. Getting an error in my function when I do a select * from foo_bar()