Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 6AE59B5DBC0 for ; Fri, 30 Sep 2011 12:33:44 -0300 (ADT) 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 56669-03 for ; Fri, 30 Sep 2011 15:33:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id EA488B5DBBD for ; Fri, 30 Sep 2011 12:33:37 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p8UFXZ2P007768; Fri, 30 Sep 2011 11:33:35 -0400 (EDT) To: "Boris Matkov" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6236: Query execution bug In-reply-to: <201109301141.p8UBfPFc054882@wwwmaster.postgresql.org> References: <201109301141.p8UBfPFc054882@wwwmaster.postgresql.org> Comments: In-reply-to "Boris Matkov" message dated "Fri, 30 Sep 2011 11:41:25 +0000" Date: Fri, 30 Sep 2011 11:33:35 -0400 Message-ID: <7767.1317396815@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/250 X-Sequence-Number: 31267 "Boris Matkov" writes: > INSERT INTO btest0 (id, name) VALUES ((SELECT DISTINCT id FROM btest0 WHERE > name = $1 LIMIT 1), $1) - was executed successfully > INSERT INTO btest0 (name,id) VALUES ($1, (SELECT DISTINCT id FROM btest0 > WHERE name = $1 LIMIT 1)) - I got error: > --------------------------- > inconsistent types deduced for parameter $1 > --------------------------- > Script for the btest0 table creating: > CREATE TABLE btest0 > ( > id integer NOT NULL, > name character varying(50) NOT NULL, > value double precision, > CONSTRAINT pk_btest0 PRIMARY KEY (id) > ) It may be annoying, but it's not a bug. The equality test uses the "text = text" operator, so if that's seen first then the parameter gets resolved as text. You'd be better off to declare the type of the parameter instead of assuming that it will always be resolved the way you want ... but if you can't be bothered to do that, using text instead of varchar as the column type would avoid most of the cases where you'll see something like this. regards, tom lane