Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a6BSj-0005MP-Ed for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Dec 2015 06:09:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a6BSi-0003A0-MR for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Dec 2015 06:09:20 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a6BS7-0002OP-6d for pgsql-bugs@postgresql.org; Tue, 08 Dec 2015 06:08:43 +0000 Received: from d.mail.sonic.net ([64.142.111.50]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a6BS4-0003TO-FQ for pgsql-bugs@postgresql.org; Tue, 08 Dec 2015 06:08:42 +0000 Received: from engels (162-236-13-58.lightspeed.sntcca.sbcglobal.net [162.236.13.58]) (authenticated bits=0) by d.mail.sonic.net (8.15.1/8.15.1) with ESMTPSA id tB868bEL020480 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA256 bits=128 verify=NOT); Mon, 7 Dec 2015 22:08:37 -0800 Date: Mon, 7 Dec 2015 22:08:47 -0800 From: David Gould To: amutu@amutu.com Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13805: plpgsql execute using expression evaluate wrong Message-ID: <20151207220847.4da716e1@engels> In-Reply-To: <20151208035444.5253.30717@wrigleys.postgresql.org> References: <20151208035444.5253.30717@wrigleys.postgresql.org> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Sonic-CAuth: UmFuZG9tSVZ8SSG5j2gTBOT4qMRI9zxl9URrPlVQCIpR9hGPHVpB4G/asf+wGuyXtIOZz++IGDIl5D6isUqopwngK/+5uGrS X-Sonic-ID: C;bgHGHnKd5RGO68gxU3XIUw== M;lrP1HnKd5RGO68gxU3XIUw== X-Spam-Flag: No X-Sonic-Spam-Details: 0.0/5.0 by cerberusd X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On Tue, 08 Dec 2015 03:54:44 +0000 amutu@amutu.com wrote: > execute $$select ('$1 month')::interval $$ into rt2 using n; > raise notice 'rt2 : %',rt2; >=20 > execute $$select ($1::varchar || ' month')::interval $$ into rt2 using n; > raise notice 'rt2 : %',rt2; > end; > NOTICE: rt2 : 1 mon-----wrong=EF=BC=8Cshould 4 mons > NOTICE: rt2 : 4 mons You may have found a bug, but if so, it is not where you think it is. The expression: '$1 month' is a text literal. PL/PGsql does not interpolate $n like a shell, it only does the substitution where a variable could ordinarily exist. However, it does seem a little odd that the literal syntax for intervals accepts the '$': postgres=3D# select '$1 month'::interval, '$4 month'::interval; interval | interval=20 ----------+---------- 1 mon | 4 mons (1 row) I would have expected it to raise an error. The documentation does not shed any light on this. Anyone? -dg=20 --=20 David Gould 510 282 0869 daveg@sonic.net If simplicity worked, the world would be overrun with insects. --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs