Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1arFSl-00023Q-1O for pgsql-bugs@arkaria.postgresql.org; Sat, 16 Apr 2016 01:55:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1arFSk-0000vG-Ct for pgsql-bugs@arkaria.postgresql.org; Sat, 16 Apr 2016 01:55:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1arC7i-0002Xr-BL for pgsql-bugs@postgresql.org; Fri, 15 Apr 2016 22:21:58 +0000 Received: from mail-qg0-x233.google.com ([2607:f8b0:400d:c04::233]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1arC7f-0002Yi-Qf for pgsql-bugs@postgresql.org; Fri, 15 Apr 2016 22:21:57 +0000 Received: by mail-qg0-x233.google.com with SMTP id j35so89383663qge.0 for ; Fri, 15 Apr 2016 15:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:cc; bh=8O4jf2d9vtlqR0iWO+Uf+Od/eVtjPSram4YDsiLhkNY=; b=kSXaw4DdHCxR6avo5a8EIJXvMMiEqdavTe1Spky73IKsro0ZJl1Vktyvv+n1tvNEtP A3JydC6NZrIVbkMfhMobgKBrXtXezYn/C/H5VvaOMkVSgArQqzP8Kxcsg6i1QdnT5qYx Ffwu46cDRDGoy39eh+LdMKE2/ZHcXLtXeE0kBRDj/ZfYpu2jyCc/4ibd8CFtzAD/gCZK EHVMIjNSQttZDl3XdXpoSW+SCiawRXpkoI6fpMYUxItCUvORhymLdmHdIn8tJtPnikfY D1MT90MGQB68CCleKaIv+c/0KYUsdAdSImTX4528CmXVQrBDtWMYL+4XEkeTFiJGqg+R M4ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:cc; bh=8O4jf2d9vtlqR0iWO+Uf+Od/eVtjPSram4YDsiLhkNY=; b=Po8yfGyuQvtjVhy9rGbzKVo6xHCp0qkPgXMnhKB7Z9vyfsHvpOoIdBgz+GogKX2bKh 34HpD6mCVQ4LOK/ktdYr+kPJHgKaGm8fmxuonPwk0wLSrLcr6FE+lFTWTp9sPLlY1p5V 5VXwogpHg8T4SyPbW/0z3Ns/mOcK6QTpTD7UrbgK0tFJh6QjimA8SmmIsJTPEoZ9Kfxa FZAaOibQb2eJKtu/SV3cF99LEed3RZwFLUTnFxZIpUiasyhKbIFzJzMjs4no9GZKqb7N a8mgmnASuE/Z7WMaYixSu0teK67dX8Pc1yOVzSorq6yJCn9pfZGOFV0jEvXv520ar40R P3Hw== X-Gm-Message-State: AOPr4FUf02PSTKynF4dWtZIDt2ry1j8P0b+ApLYC5t+4XG8zHNakxjXIVeNpz+zNM4PNKRZnEml6xtpBLrJJ5A== X-Received: by 10.140.34.133 with SMTP id l5mr27853116qgl.27.1460758913957; Fri, 15 Apr 2016 15:21:53 -0700 (PDT) MIME-Version: 1.0 References: <20160415213614.22913.56001@wrigleys.postgresql.org> In-Reply-To: From: Alex Bolenok Date: Fri, 15 Apr 2016 22:21:44 +0000 Message-ID: Subject: Re: BUG #14089: ON CONFLICT allows function variables in index expressions Cc: "pgsql-bugs@postgresql.org" Content-Type: multipart/alternative; boundary=001a11c0f5282b46c105308d70c1 X-Pg-Spam-Score: -1.7 (-) 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 --001a11c0f5282b46c105308d70c1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable The function should not even compile, as the INSERT query before it does not: test=3D# INSERT INTO test (value) SELECT * FROM (VALUES (1)) q (n) ON CONFL= ICT (value, (n)) DO NOTHING; ERROR: column "n" does not exist The parser should only allow the target table's column names and constants in the index expression, as it does when creating the index. A variable name is neither. =D1=81=D0=B1, 16 =D0=B0=D0=BF=D1=80. 2016 =D0=B3. =D0=B2 1:04, David G. Joh= nston : > On Fri, Apr 15, 2016 at 2:36 PM, wrote: > >> The following bug has been logged on the website: >> >> Bug reference: 14089 >> Logged by: Alex Bolenok >> Email address: quassnoi@gmail.com >> PostgreSQL version: 9.5.2 >> Operating system: CentOS 6 >> Description: >> > > =E2=80=8B[snip] > > > >> =E2=80=8B >> >> test=3D# INSERT INTO test (value) VALUES (1) ON CONFLICT (value, >> (no_such_column)) DO NOTHING; >> ERROR: column "no_such_column" does not exist >> =D0=A1=D0=A2=D0=A0=D0=9E=D0=9A=D0=90 1: ...INTO test (value) VALUES (1) = ON CONFLICT (value, >> (no_such_co... >> >> =E2=80=8B[snip] > =E2=80=8B > > >> test=3D# DROP FUNCTION IF EXISTS fn_test(INT); CREATE FUNCTION fn_test(n >> INT) >> RETURNS VOID AS $$ INSERT INTO test (value) VALUES (1) ON CONFLICT (valu= e, >> (n)) DO NOTHING; $$ LANGUAGE 'sql'; >> DROP FUNCTION >> CREATE FUNCTION >> >> test=3D# SELECT * FROM fn_test(1); >> ERROR: there is no unique or exclusion constraint matching the ON >> CONFLICT >> specification >> =D0=9A=D0=9E=D0=9D=D0=A2=D0=95=D0=9A=D0=A1=D0=A2: SQL function "fn_test= " during startup >> >> >> I expected CREATE FUNCTION to fail with the same messages as the INSERT >> query before it, because it makes no sense to reference function variabl= es >> in index inference. >> > > I'm not sure I can explain this adequately but regardless this doesn't > seem like it qualifies as a bug. > > As far as the INSERT inside the function is concerned you've provided a > constant integer in place of the "n". Since a constant integer is not a > column name any error referencing column name - which the referenced one > does - would be incorrect. > > The INSERT doesn't know where the constant integer came from and the > function interpreter doesn't understand "index inference" - it just > replaces non-string-embedded instances of a variable name with the > corresponding value. > > There is a degree of separation of concerns here this, while somewhat > problematic when it comes to accurately describing exact causes of errors= , > is desirable from an overall architecture and execution standpoint. Give= n > that both scenarios are, correctly, errors, the difference in messages ar= e > because of the execution environment and thus have every right to be > different. > > David J. > > --001a11c0f5282b46c105308d70c1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
The function should not even compile, as the INSERT query = before it does not:

test=3D# INSERT INTO test (value) SELECT * FROM (VALUES (1))= q (n) ON CONFLICT
<= span style=3D"font-size:13px;color:rgb(33,33,33)">(value, (n)) DO NOTHING;<= /span>
ERROR:=C2=A0 column "n" does not e= xist

The parser should only allow the t= arget table's column names and constants in the index expression, as it= does when creating the index. A variable name is neither.

=D1=81=D0=B1, 16 =D0=B0=D0=BF=D1=80. 201= 6 =D0=B3. =D0=B2 1:04, David G. Johnston <david.g.johnston@gmail.com>:
On Fri, Apr 15, 2016 at 2:36 PM, <quassnoi@gmail.com> wrote:
The following bug has been logged= on the website:

Bug reference:=C2=A0 =C2=A0 =C2=A0 14089
Logged by:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Alex Bolenok
Email address:=C2=A0 =C2=A0 =C2=A0 quassnoi@gmail.com
PostgreSQL version: 9.5.2
Operating system:=C2=A0 =C2=A0CentOS 6
Description:

=E2=80=8B[snip]
=C2=A0
=C2=A0
=E2=80=8B

test=3D# INSERT INTO test (value) VALUES (1) ON CONFLICT (value,
(no_such_column)) DO NOTHING;
ERROR:=C2=A0 column "no_such_column" does not exist
=D0=A1=D0=A2=D0=A0=D0=9E=D0=9A=D0=90 1: ...INTO test (value) VALUES (1) ON = CONFLICT (value,
(no_such_co...

=E2=80=8B[snip]<= /div>
=E2=80=8B
=C2=A0
test=3D# DROP FUNCTION IF EXISTS fn_test(INT); CREATE FUNCTION fn_test(n IN= T)
RETURNS VOID AS $$ INSERT INTO test (value) VALUES (1) ON CONFLICT (value,<= br> (n)) DO NOTHING; $$ LANGUAGE 'sql';
DROP FUNCTION
CREATE FUNCTION

test=3D# SELECT * FROM fn_test(1);
ERROR:=C2=A0 there is no unique or exclusion constraint matching the ON CON= FLICT
specification
=D0=9A=D0=9E=D0=9D=D0=A2=D0=95=D0=9A=D0=A1=D0=A2:=C2=A0 SQL function "= fn_test" during startup


I expected CREATE FUNCTION to fail with the same messages as the INSERT
query before it, because it makes no sense to reference function variables<= br> in index inference.

I'm not sure I ca= n explain this adequately but regardless this doesn't seem like it qual= ifies as a bug.

As far as the INSERT inside the functi= on is concerned you've provided a constant integer in place of the &quo= t;n".=C2=A0 Since a constant integer is not a column name any error re= ferencing column name - which the referenced one does - would be incorrect.=

The INSERT doesn't know where the constant intege= r came from and the function interpreter doesn't understand "index= inference" - it just replaces non-string-embedded instances of a vari= able name with the corresponding value.

There is a deg= ree of separation of concerns here this, while somewhat problematic when it= comes to accurately describing exact causes of errors, is desirable from a= n overall architecture and execution standpoint.=C2=A0 Given that both scen= arios are, correctly, errors, the difference in messages are because of the= execution environment and thus have every right to be different.
<= br>
David J.

--001a11c0f5282b46c105308d70c1--