Do you know a json_populate_record alternative method to create a ROW with a named field notation?

From: Stéphane Klein <contact(at)stephane-klein(dot)info>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Do you know a json_populate_record alternative method to create a ROW with a named field notation?
Date: 2022-03-06 18:41:44
Message-ID: CADKxhpesteVU7GiMWqUbMKsTiRzbeXxoNGR42Hv9K7L0cduFqQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

In this example:

```
CREATE TYPE contact AS (
firstname VARCHAR,
lastname VARCHAR
);

postgres=# SELECT json_populate_record(NULL::contact,
postgres(# '{
postgres'# "firstname": "John",
postgres'# "lastname": "Doe"
postgres'# }'
postgres'# );
json_populate_record
----------------------
(John,Doe)
(1 row)
```

**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?

I know the `ROW` syntax expression:

```
postgres=# SELECT ROW('John', 'Doe')::contact;
row
------------
(John,Doe)
(1 row)
```

But I didn't find a `ROW` constructors (
https://www.postgresql.org/docs/13/sql-expressions.html#SQL-SYNTAX-ROW-CONSTRUCTORS)
syntax allowing a named field notation.

Best regards,
Stéphane
--
Stéphane Klein <contact(at)stephane-klein(dot)info>
Homepage: http://stephane-klein.info

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2022-03-06 18:54:58 Re: Do you know a json_populate_record alternative method to create a ROW with a named field notation?
Previous Message Susan Hurst 2022-03-06 16:36:18 FDW to postGIS Database