470,647 Members | 1,209 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

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

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
0 1704

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Matthew Houseman | last post: by
1 post views Thread by Jim Garrison | last post: by
reply views Thread by Geraint Evans | last post: by
32 posts views Thread by lovecreatesbea... | last post: by
1 post views Thread by endriu | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.