Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 4755016196C8 for ; Tue, 8 Nov 2011 09:32:50 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 47949-03 for ; Tue, 8 Nov 2011 13:32:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sam.nabble.com (sam.nabble.com [216.139.236.26]) by mail.postgresql.org (Postfix) with ESMTP id 257E216196C7 for ; Tue, 8 Nov 2011 09:32:44 -0400 (AST) Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1RNlXp-0003Jt-KW for pgsql-sql@postgresql.org; Tue, 08 Nov 2011 05:16:53 -0800 Date: Tue, 8 Nov 2011 05:16:53 -0800 (PST) From: tlund79 To: pgsql-sql@postgresql.org Message-ID: <1320758213629-4974235.post@n5.nabble.com> Subject: Issue with a variable in a function MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.778 tagged_above=-5 required=5 tests=BAYES_00=-1.9, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201111/34 X-Sequence-Number: 36007 I've created a function which purpose is to import data to an excel report. This is however the first time I'm doing this, and I've exhausted all other options before asking the question here. I call this function with this command: select ppr_data(2011,1,52,8) The issue relates to the variable "prosjektkode" ($4). When this is a singular digit the function runs as expected and the data appears correctly in the report. The issue appears when "prosjektkode" is multiple digits, i.e. 8,3,119 (i.e. I want run a report on multiple "prosjektkode"), when I do this it fails. I've tried to declare this variable as text and tried escaping the commas, but no luck. The function: CREATE OR REPLACE FUNCTION ppr_data(aarstall int, frauke int, tiluke int, prosjektkode int) RETURNS int AS $$ DECLARE antall bigint; BEGIN --Henter Inngang Antall Kunder select count(distinct a.kundenr) into antall from aktivitet a inner join utgave u on u.utgaveid=a.utgaveid inner join prosjekt p on p.prosjektkode=u.prosjektkode where a.utfort=1 and a.aktivtypekode in (82,83) and extract(year from a.utforesdato) = $1 -- Aarstall and extract(week from a.utforesdato) >= $2 -- Fra_uke and extract(week from a.utforesdato) <= $3 -- Til_uke and p.prosjektkode in ($4) and a.kundenr in ( select o.kundenr from ordrer o inner join utgave u on u.utgaveid=o.utgaveid inner join prosjekt p on p.prosjektkode=u.prosjektkode where o.ordretypenr in (1, 3, 4, 5) /* utelater ordretypen kredittordre */ and o.kreditert is null /* utelater krediterte ordre */ and o.ordrestatus in (3, 4) /* kun ordrer med status fakturert og klar til fakturert */ and o.ordresum > 0 /* Utelater 0-ordre og f.eks. messeeksemplar */ and extract(year from o.ordredato) = ($1 - 1) and p.prosjektkode in ($4) ); RETURN antall; END; $$ LANGUAGE plpgsql; -- View this message in context: http://postgresql.1045698.n5.nabble.com/Issue-with-a-variable-in-a-function-tp4974235p4974235.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com.