X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3FD59329E8F for ; Mon, 20 Sep 2004 21:40:45 +0100 (BST) 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 04965-08 for ; Mon, 20 Sep 2004 20:40:33 +0000 (GMT) Received: from bcbssc.com (mail1.bcbssc.com [207.19.198.69]) by svr1.postgresql.org (Postfix) with ESMTP id 784DB329E8C for ; Mon, 20 Sep 2004 21:40:33 +0100 (BST) Received: from ([207.19.198.73]) by mail1.bcbssc.com with ESMTP id KP-TRPV8.1961911; Mon, 20 Sep 2004 16:39:58 -0400 X-Internal-ID: 4144EF290000A8FF Received: from companiongroup.com (207.19.198.73) by companion1.companiongroup.com (NPlex 2.0.108) for pgsql-sql@postgresql.org; 20 Sep 2004 16:40:06 -0400 Message-ID: Date: Mon, 20 Sep 2004 16:36:00 -0400 From: "CHRIS HOOVER" To: pgsql-sql@postgresql.org Subject: Help with function X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/168 X-Sequence-Number: 19014 I need some help writing a simple function. Due to some program limitations for a program I run the db's for, I'm having to write some simple functions to run some selects. However, I am not sure how to have them correctly return the record(s) selected and/or how to properly call them from sql. Would someone be so kind as to help me with this. Here is an example function: CREATE OR REPLACE FUNCTION "public"."test_func" (varchar) RETURNS SETOF "public"."test_tbl" AS' Declare PCN varchar; test_tbl_rec clmhdr%ROWTYPE; Begin PCN := $1; select into test_tbl_rec * from test_tbl where test_tbl.pcn = PCN; return test_tbl_rec; end; 'LANGUAGE 'plpgsql' VOLATILE RETURNS NULL ON NULL INPUT SECURITY INVOKER; I was trying to call this function from psql using: select test_func('asdf'); Which returned: ERROR: Set-valued function called in context that cannot accept a set WARNING: Error occurred while executing PL/pgSQL function test_func WARNING: while casting return value to function's return type What am I doing wrong? I'm in fairly new territory with this type of functions. I normally have just written simple trigger function that log table changes. Thanks for any and all help. Chris P.S. Is there a good website and/or book for learning the intricacies of pgsql?