X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 96779DB1B9 for ; Tue, 1 Nov 2005 17:41:51 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45575-09 for ; Tue, 1 Nov 2005 21:41:49 +0000 (GMT) Received: from TWMAIL.ESNCC.COM (static-66-173-159-28.t1.cavtel.net [66.173.159.28]) by svr1.postgresql.org (Postfix) with ESMTP id F19CADA9C4 for ; Tue, 1 Nov 2005 17:41:49 -0400 (AST) Received: from spawar2i8uvlb9 ([150.125.117.63]) by TWMAIL.ESNCC.COM with Microsoft SMTPSVC(5.0.2195.6713); Tue, 1 Nov 2005 16:41:51 -0500 From: "Lane Van Ingen" To: Subject: Can't Get SETOF Function to Work Date: Tue, 1 Nov 2005 16:38:12 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181 Importance: Normal X-OriginalArrivalTime: 01 Nov 2005 21:41:51.0145 (UTC) FILETIME=[11955990:01C5DF2D] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.031 required=5 tests=[AWL=0.031] X-Spam-Score: 0.031 X-Spam-Level: X-Archive-Number: 200511/12 X-Sequence-Number: 23264 Have tried perhaps 20+ alternatives on this plpgsql function, but can't get it to work. Suspect I have done something wrong either with RETURN values, creating of a type, or (most likely) use of ROW(). I am trying to fix the returned rows from enclosing reults in parenthesis; found a similar incident in archives, but there is not enough detail to help me figure out what is wrong: http://archives.postgresql.org/pgsql-sql/2005-10/threads.php#00321 Can someone spot what I am doing wrong? Here is what I have: CREATE TYPE typ_history_rec_format AS ( interface integer, updatedTime timestamp(3), rftype integer, rfspeed bigint) ; CREATE OR REPLACE FUNCTION router_history() RETURNS SETOF typ_history_rec_format AS $BODY$ DECLARE returnValue RECORD; workarea RECORD; work_interface integer; work_rftype integer; BEGIN FOR workarea IN select '1' AS seq, if_id AS interface, updated_time AS updatedTime, link_type AS rftype, 0 AS rfspeed FROM rf_type_history union select '2' AS seq, if_id AS interface, updated_time AS updatedTime, 0 AS rftype, speed AS rfspeed FROM rf_speed_history order by 2,3,1 LOOP if workarea.seq = 1 then work_interface := workarea.interface; work_rftype := workarea.rftype; else if workarea.interface = work_interface then select into returnValue ROW(workarea.interface,workarea.updatedTime, work_rftype,workarea.rfspeed); RETURN NEXT returnValue; end if; end if; END LOOP; RETURN; END $BODY$ LANGUAGE 'plpgsql' VOLATILE; WHAT GETS RETURNED: Query: select * from router_history(); Result: ERROR: wrong record type supplied in RETURN NEXT CONTEXT: PL/pgSQL function "router_history" line 29 at return next