By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,302 Members | 1,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,302 IT Pros & Developers. It's quick & easy.

Returned more than one row error message in a FOR IN EXECUTE loop

P: n/a
I wrote a function that basically executes a dynamic query and returns
True if there is at least one record and false in not.

CREATE OR REPLACE FUNCTION RecordHasChild (table1, CHARACTER,
CHARACTER) RETURNS BOOLEAN AS '
DECLARE
childrec RECORD;
sqlquery text;
BEGIN
sqlquery = ''SELECT field1 FROM '' || $2 || '' WHERE ('' || $2
|| ''.account_no = '' || quote_literal(table1.account_no) || '') AND
('' || $3 || '') LIMIT 1'';

FOR childrec IN EXECUTE sqlquery LOOP
RETURN True;
END LOOP;

RETURN False;

END;
' LANGUAGE 'plpgsql';
I use this function in a where clause like RecordHasChild(table1,
'relatedtable', 'relatedtable.somefield = \'some value\'')

The problem I have is I get this error "query "SELECT ..." returned
more than one row". Why is there a problem if the query returns more
than one row ? That's why there is a loop. Any ideas ?

Thanks,
George
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.