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.96) (envelope-from ) id 1wi5wx-0000lN-20 for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2026 07:47:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wi5wv-00Gc67-2h for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2026 07:47:06 +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.96) (envelope-from ) id 1wi5wv-00Gc5y-1d for pgsql-hackers@lists.postgresql.org; Fri, 10 Jul 2026 07:47:06 +0000 Received: from udcm-wwu2.uni-muenster.de ([128.176.118.28]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wi5wr-00000000cGG-16Qh for pgsql-hackers@postgresql.org; Fri, 10 Jul 2026 07:47:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=uni-muenster.de; i=@uni-muenster.de; q=dns/txt; s=uniout; t=1783669622; x=1815205622; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=7RB+xgACPCPVC5bY5Q/LX64X2LsyOUrCTYKwg+p3saI=; b=BfmbSJtqn98V7WU5C2Zc0r198Xn9GY/ezVdRP/2wSL+kBaj80xz/W7se RhTitEvVlIcjXV8597N+dJf5WgEL8TrVzgYGStNn/APe4XU9tlRHiGBzr lHElcS1NW95RGbRb1u6zzJJ2WjHZPR2hsgmAxmX+p3/jqzyQzBJmeBtbc nI/aP7czxRIUTjdF5Bn3aZeTwHgjoVzJTcmiftsxthkh00ZoiEOguruAj jegx9MUGfq3ZjSviXUrXUIjhjDsjqyJAuK9Kmo59GMXU/sVUzgGSRx+wu XspHfivr0HwdxBOn5Iz6gL4aG3ozTm9XWoS5spFHo9afIXak3di3OODTU Q==; X-CSE-ConnectionGUID: WIeycdT1Q3e/aMdJouanRA== X-CSE-MsgGUID: q+4+nX+uT3SXgo2zmDMy1w== X-IronPort-AV: E=Sophos;i="6.25,154,1779141600"; d="scan'208";a="400561833" Received: from secmail.uni-muenster.de ([128.176.118.4]) by UDCM-RELAY2.UNI-MUENSTER.DE with ESMTP; 10 Jul 2026 09:47:00 +0200 Received: from [192.168.178.52] (dynamic-077-176-143-085.77.176.pool.telefonica.de [77.176.143.85]) by SECMAIL.UNI-MUENSTER.DE (Postfix) with ESMTPSA id 9C76D20ADF03; Fri, 10 Jul 2026 09:46:59 +0200 (CEST) Message-ID: Date: Fri, 10 Jul 2026 09:46:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Proposal: INSERT ... BY NAME To: Ayush Tiwari , PostgreSQL Hackers Cc: Peter Eisentraut References: Content-Language: en-US, de-DE From: Jim Jones In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Ayush On 03/07/2026 13:07, Ayush Tiwari wrote: > Attached is a draft patch for INSERT ... BY NAME.  It matches the result > columns of a source query to target columns by name instead of by position, > which is useful when the source and target columns are written in different > orders.  Similar syntax exists in DuckDB [1] and Oracle [2]: > >     INSERT INTO t1 (c1, c2) >         BY NAME >         SELECT c1 * 10 AS c2, c2 + 5 AS c1 FROM t2; Thanks for the patch! I've tested the feature and it's doing what it intends to. Apparently DuckDB does not support specific target columns: memory D CREATE TABLE t (a int, b int); memory D INSERT INTO t (a,b) BY NAME SELECT 37 AS b, 42 AS a; Parser Error: syntax error at or near "BY" LINE 1: INSERT INTO t (a,b) BY NAME SELECT 37 AS b, 42 AS a; ^ memory D INSERT INTO t BY NAME SELECT 37 AS b, 42 AS a; memory D SELECT * FROM t; ┌───────┬───────┐ │ a │ b │ │ int32 │ int32 │ ├───────┼───────┤ │ 42 │ 37 │ └───────┴───────┘ But your patch allows it: psql (20devel) Type "help" for help. postgres=# CREATE TABLE t (a int, b int); CREATE TABLE postgres=# INSERT INTO t (a,b) BY NAME SELECT 37 AS b, 42 AS a; INSERT 0 1 postgres=# SELECT * FROM t; a | b ----+---- 42 | 37 (1 row) Since I don't have a copy of the SQL spec, I can't tell if this is a feature gap from DuckDB or if you just added this feature yourself. What does the spec say about it? Thanks! Best, Jim