Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nQw29-0006lG-NE for pgsql-general@arkaria.postgresql.org; Sun, 06 Mar 2022 18:55:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nQw28-00048C-1n for pgsql-general@arkaria.postgresql.org; Sun, 06 Mar 2022 18:55:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nQw27-000483-JP for pgsql-general@lists.postgresql.org; Sun, 06 Mar 2022 18:55:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nQw1z-0005FC-Bj for pgsql-general@lists.postgresql.org; Sun, 06 Mar 2022 18:55:04 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 226Isw3e016490; Sun, 6 Mar 2022 13:54:58 -0500 From: Tom Lane To: =?UTF-8?Q?St=C3=A9phane_Klein?= cc: pgsql-general@lists.postgresql.org Subject: Re: Do you know a json_populate_record alternative method to create a ROW with a named field notation? In-reply-to: References: Comments: In-reply-to =?UTF-8?Q?St=C3=A9phane_Klein?= message dated "Sun, 06 Mar 2022 19:41:44 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16488.1646592898.1@sss.pgh.pa.us> Date: Sun, 06 Mar 2022 13:54:58 -0500 Message-ID: <16489.1646592898@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =?UTF-8?Q?St=C3=A9phane_Klein?= writes: > **Question:** do you know a method like json_populate_record ( > https://www.postgresql.org/docs/13/functions-json.html), which allows > creating a `ROW` with named field notation without using a json format? You mean you want to give the field names explicitly in the expression? The closest thing I can think of is to make a constructor function and invoke it with named-argument notation: regression=# CREATE TYPE contact AS ( regression(# firstname VARCHAR, regression(# lastname VARCHAR regression(# ); CREATE TYPE regression=# create function make_contact(firstname varchar, lastname varchar) regression-# returns contact as 'select row(firstname, lastname)::contact' regression-# language sql; CREATE FUNCTION regression=# select make_contact(firstname => 'John', lastname => 'Doe'); make_contact -------------- (John,Doe) (1 row) A bit tedious to set up, but it would have some advantages, eg you could provide default values. regards, tom lane