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 095963A25B5 for ; Thu, 30 Dec 2004 17:01:45 +0000 (GMT) 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 16456-08 for ; Thu, 30 Dec 2004 17:01:24 +0000 (GMT) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by svr1.postgresql.org (Postfix) with ESMTP id 3D2483A1D3B for ; Thu, 30 Dec 2004 17:01:25 +0000 (GMT) Received: from hotmail.com (bay18-f34.bay18.hotmail.com [65.54.187.84]) by svr4.postgresql.org (Postfix) with ESMTP id 417815AF4CC for ; Thu, 30 Dec 2004 15:02:46 +0000 (GMT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Thu, 30 Dec 2004 07:02:01 -0800 Message-ID: Received: from 216.115.176.7 by by18fd.bay18.hotmail.msn.com with HTTP; Thu, 30 Dec 2004 15:01:48 GMT X-Originating-IP: [216.115.176.7] X-Originating-Email: [nathanpickett@hotmail.com] X-Sender: nathanpickett@hotmail.com From: "Nathan Pickett" To: pgsql-sql@postgresql.org Subject: Making a prepared statement in a stored procedure Date: Thu, 30 Dec 2004 15:01:48 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 30 Dec 2004 15:02:01.0559 (UTC) FILETIME=[84458670:01C4EE80] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.376 tagged_above=0 required=5 tests=DNS_FROM_RFC_POST, MSGID_FROM_MTA_HEADER X-Spam-Level: * X-Archive-Number: 200412/165 X-Sequence-Number: 19785 Hi, I am trying to convert the following function below: ---START FUNCTION create or replace function update_tmp_sales_report_from_archive_with_prospects() returns integer as ' declare row_data record; begin for row_data in select partner_id, count(*) as prospects from prospects_2004_09_01 group by partner_id loop update tmp_sales_report_from_archive set prospects = row_data.prospects where partner_id = row_data.partner_id; end loop; return 1; end; ' language 'plpgsql'; --- END FUNCTION to be able to pass in the table named prospects_2004_09_01, to be prospects_ concatanated with the date, so prospects_2004_08_01, prospects_2004_07_01, etc. I tried the following: -- START TEST FUCTION drop function update_tmp_sales_report_from_archive_with_prospects(text); create or replace function update_tmp_sales_report_from_archive_with_prospects(text) returns integer as ' declare in_t ALIAS FOR $1; row_data record; begin for row_data in select partner_id, count(*) as prospects in_t group by partner_id loop update tmp_sales_report_from_archive set prospects = row_data.prospects where partner_id = row_data.partner_id; end loop; return 1; end; ' language 'plpgsql'; -- END TEST FUNCTION but go the following errors: DROP FUNCTION CREATE FUNCTION You are now connected as new user bp_sales_match_user. psql:scratch.postgresql:36: WARNING: Error occurred while executing PL/pgSQL function update_tmp_sales_report_from_archive_with_prospects psql:scratch.postgresql:36: WARNING: line 5 at for over select rows psql:scratch.postgresql:36: ERROR: parser: parse error at or near "$1" at character 44 Any suggestions? Thanks! -Nate