Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 571619FB631 for ; Wed, 21 Feb 2007 07:31:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 40647-03 for ; Wed, 21 Feb 2007 07:31:04 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from bay0-omc1-s7.bay0.hotmail.com (bay0-omc1-s7.bay0.hotmail.com [65.54.246.79]) by postgresql.org (Postfix) with ESMTP id 69F0F9FB403 for ; Wed, 21 Feb 2007 07:31:08 -0400 (AST) Received: from hotmail.com ([64.4.54.98]) by bay0-omc1-s7.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Wed, 21 Feb 2007 03:31:07 -0800 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Wed, 21 Feb 2007 03:31:06 -0800 Message-ID: Received: from 85.102.254.48 by by20fd.bay20.hotmail.msn.com with HTTP; Wed, 21 Feb 2007 11:31:02 GMT X-Originating-IP: [85.102.254.48] X-Originating-Email: [definite_ocean@hotmail.com] X-Sender: definite_ocean@hotmail.com From: "devil live" To: pgsql-sql@postgresql.org Subject: Problem with Temp Table and Result Set from PL Function... Date: Wed, 21 Feb 2007 11:31:02 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 21 Feb 2007 11:31:06.0845 (UTC) FILETIME=[C6EBA8D0:01C755AB] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.908 tagged_above=0 required=5 tests=BAYES_50, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, MSGID_FROM_MTA_HEADER, SPF_PASS X-Spam-Level: * X-Archive-Number: 200702/212 X-Sequence-Number: 27546 When I run following Function with the following SETOF table... it says: NOTICE: table "temp_production_product_operations" does not exist, skipping CONTEXT: SQL statement "drop table if exists temp_production_product_operations " PL/pgSQL function "pb_report_temp_gerceklesme12" line 11 at execute statement ERROR: set-valued function called in context that cannot accept a set SQL state: 0A000 Context: PL/pgSQL function "pb_report_temp_gerceklesme12" line 56 at return next Where is the error? I could not determined... CREATE TABLE temp_temp_production_operations ( product_code character varying(25), product_name character varying(255), production_order bigint, stock_code character varying(25), operation_code bigint ) ; =================================================== DROP FUNCTION pb_report_temp_gerceklesme12 ( character varying, character varying); CREATE OR REPLACE FUNCTION pb_report_temp_gerceklesme12(character varying, character varying) RETURNS SETOF temp_temp_production_operations AS $BODY$ DECLARE tmp RECORD; var_stock_code ALIAS FOR $1; var_production_order ALIAS FOR $2 ; BEGIN -- drop temp table, if it exists (ignore exception if it doesn't) begin execute 'drop table if exists temp_production_product_operations ' ; exception when undefined_table then null; -- do nothing end; EXECUTE 'create temp table temp_production_product_operations AS ' || ' SELECT stk.stock_code AS product_code, stk.stock_name AS product_name, ' || ' NULL::integer AS production_order, pot.stock_code, pot.operation_code ' || ' FROM stock stk, production_operations_template pot ' || ' WHERE stk.stock_code = ' || '''' || var_stock_code || '''' || ' AND stk.stock_code = ' || ' CASE ' || ' WHEN (( SELECT ds.production_order ' || ' FROM production_operations_details ds ' || ' WHERE ds.product_code = stk.stock_code AND ds.production_order = ' || '''' || var_production_order || '''' || ' LIMIT 1)) IS NULL THEN pot.product_code ' || ' ELSE ''''::varchar ' || ' END ' || ' UNION ' || ' SELECT stk.stock_code AS product_code, stk.stock_name AS product_name, ' || ' pot.production_order, pot.stock_code, pot.operation_code ' || ' FROM stock stk, production_operations_details pot ' || ' WHERE stk.stock_code = ' || '''' || var_stock_code || '''' || ' AND stk.stock_code = ' || ' CASE ' || ' WHEN (( SELECT ds.production_order ' || ' FROM production_operations_details ds ' || ' WHERE ds.product_code = stk.stock_code AND ' || ' ds.production_order = ' || '''' || var_production_order || '''' || ' LIMIT 1)) IS NOT NULL ' || ' THEN pot.product_code ' || ' ELSE ''''::varchar ' || ' END ORDER BY 1, 2, 4 '; -- temp_production_product_operations : WE created as temp above... FOR tmp IN EXECUTE 'SELECT * FROM temp_production_product_operations' LOOP RETURN NEXT tmp; END LOOP; RETURN; end; $BODY$ LANGUAGE 'plpgsql'; =============================================== _________________________________________________________________ En etkili ve güvenilir PC Korumayi tercih edin, rahat edin! http://www.msn.com.tr/security/