Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rOEJA-002WIZ-Iz for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jan 2024 09:58:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rOEJ8-000oID-Q9 for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jan 2024 09:58:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rOEJ7-000oGR-5i for pgsql-hackers@lists.postgresql.org; Fri, 12 Jan 2024 09:58:34 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rOEJ2-001AMV-Dg for pgsql-hackers@postgresql.org; Fri, 12 Jan 2024 09:58:31 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 98CD63200B1F; Fri, 12 Jan 2024 04:58:23 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 12 Jan 2024 04:58:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1705053503; x= 1705139903; bh=jsTyHCRXLm1noUk6FSlnjkinN5KM4fo2HB6vzQzL2p4=; b=Y w5ArE9HfY2AxO3YfKYv0D/9tmY6D7f6LJlDSoC5OBKk74Ut7jv9gQC9KykKGdgwJ PUx/KNrUAxVc7TaOASuMm6BwUWIYhczUK2OBTTGuCcbZurHB1HBKyN6XwD0DeBhr 3/n3UhKktBEG8ivZHW5lGFe7gKREWTLtWJ88mST2GUzPQXC9g6f9UJq2ysC6VdD+ bXloPX7v7QW2uc6rCI1ip0z8UPQmX4iWa+wziGXeNflDd+HuNXlWN8CDvww617PX zP0HApa2+utiF75zElK9SbIf8C5eoJpcZvULqIQcAiyFnGtdPY+seuK+UQCsiRFP kf274SKarvZ/7GK4e/Xyw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdeihedgtdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfggtggugfgjsehtke ertddttdejnecuhfhrohhmpeetlhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhr vgesrghlvhhhrdhnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpedvkedtffduff dtffffheffhfejjefhgfeiueeukeejkeffgfdufffhudffffeuveenucffohhmrghinhep vghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhr gh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 12 Jan 2024 04:58:22 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1705053501; bh=OvjuPCY1TwnV5W+kA6VF7BAOZDqCERSnlki+l7P0MEY=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=W5CwRLdI0D4AaP3ZwruBA3m3BFNi/hK93bzC6xFryRx8IrGpRKpw6crdwm2LUXFO7 O6AvvM+pUENbxox52hSuFY9Sj+OHJu+Gub/HrLw4PjCkMz8Pl5akZdPGU1vmUjCffe LSCoH9nHxrO5h07wckju58GxNqZu79MUeRnwlYzDxjVwvxoAZH25iNpD752mptgdeV 27eqQBMxwDAZ0SWTcErZ110i9XFoBbG3QJbNTeQGvm9fbQOkIOiluh9jJ5TYM0dq9Z qpzPqCGoKRzUspnH5PE3AjN1yvJWvubj601pRmAqX/gIprzQWuZwK1PEPOT7DrJaOt CVmKDEGSqSfNw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 069C79D; Fri, 12 Jan 2024 10:58:21 +0100 (CET) Date: Fri, 12 Jan 2024 10:58:21 +0100 From: Alvaro Herrera To: jian he Cc: PostgreSQL-development Subject: Re: alter table add x wrong error position Message-ID: <202401120958.2axtexbxpigq@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-Jan-08, jian he wrote: > hi. > Maybe this is a small printout err_position bug. > > create table atacc2 ( test int, a int, b int) ; > success tests: > alter table atacc2 add CONSTRAINT x PRIMARY KEY (id, b ); > alter table atacc2 add CONSTRAINT x PRIMARY KEY (id, b a); > alter table atacc2 add CONSTRAINT x PRIMARY KEYa (id, b); > > tests have problem: > alter table atacc2 add constraints x unique (test, a, b); > ERROR: syntax error at or near "(" > LINE 1: alter table atacc2 add constraints x unique (test, a, b); > > ^ > ADD either following with the optional keyword "COLUMN" or > "CONSTRAINT" as the doc. > so I should expect the '^' point at "constraints"? Here you're saying to add a column called constraints, of type x; then UNIQUE is parsed by columnDef as ColQualList, which goes to the ColConstraintElem production starting with the UNIQUE keyword: | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace so the next thing could be opt_unique_null_treatment or opt_definition or OptConsTableSpace or going back to ColQualList, but none of those start with a '(' parens. So the ( doesn't have a match and you get the syntax error. If you don't misspell CONSTRAINT as "constraints", there's no issue. I don't see any way to improve this. You can't forbid misspellings of the keyword CONSTRAINT, because they can be column names. alter table atacc2 add cnstrnt x unique (test, a, b); ERROR: error de sintaxis en o cerca de «(» LÍNEA 1: alter table atacc2 add cnstrnt x unique (test, a, b); ^ -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/