pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Arup Rakshit <ar@zeit.io>
To: pgsql-general@postgresql.org >> PG-General Mailing List <pgsql-general@postgresql.org>
Subject: Re: ERROR: type "myrowtype" does not exist
Date: Fri, 26 Oct 2018 06:42:44 -0700
Message-ID: <ddcfcd86-3543-6127-1a43-133b3491580d@aklaver.com> (raw)
In-Reply-To: <BB162BE8-658C-4368-987E-8D5A3944232B@zeit.io>
References: <BB162BE8-658C-4368-987E-8D5A3944232B@zeit.io>

On 10/26/18 4:54 AM, Arup Rakshit wrote:
> I was reading the json_populate_record function from the official doc 
> https://www.postgresql.org/docs/10/static/functions-json.html#FUNCTIONS-JSON-PROCESSING-TABLE. 
> The doc mentioned examples are giving me errors
> 
> psql (11.0, server 10.5)
> Type "help" for help.
> 
> aruprakshit=# select * from json_populate_record(null::extype, 
> '{"x":"foo", "y":43, "q": true}');
> ERROR:  type "extype" does not exist
> LINE 1: select * from json_populate_record(null::extype, '{"x":"foo"...
>                                                   ^
> aruprakshit=# select * from json_populate_record(null::myrowtype, '{"a": 
> 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a b c"}}');
> ERROR:  type "myrowtype" does not exist
> LINE 1: select * from json_populate_record(null::myrowtype, '{"a": 1…
> 
> What does null::extype, null::myrowtype mean here ?

See this thread:

https://www.postgresql.org/message-id/2a8ae0b7-1fd4-869a-a25e-d598968898c9%40aklaver.com

In meantime:

CREATE TABLE public.test_table (
     id integer,
     username character varying,
     fullname character varying
);


test=> \d test_table
                    Table "public.test_table"
   Column  |       Type        | Collation | Nullable | Default
----------+-------------------+-----------+----------+---------
  id       | integer           |           |          |
  username | character varying |           |          |
  fullname | character varying |           |          |


test=> select * from json_populate_record(null::test_table, '{"id": 1, 
"username": "adrian", "fullname": "adrian klaver"}')
;
  id | username |   fullname
----+----------+---------------
   1 | adrian   | adrian klaver
(1 row)


So myrowtype is just a placeholder in the docs for a rowtype that you 
need to supply.

> 
> 
> Thanks,
> 
> Arup Rakshit
> ar@zeit.io <mailto:ar@zeit.io>
> 
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (2+ messages)

Message-ID: <ddcfcd86-3543-6127-1a43-133b3491580d@aklaver.com>
Permalink:  ../ddcfcd86-3543-6127-1a43-133b3491580d@aklaver.com/
Also on:    postgresql.org/message-id/ddcfcd86-3543-6127-1a43-133b3491580d@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, ar@zeit.io
  Subject: Re: ERROR: type "myrowtype" does not exist
  In-Reply-To: <ddcfcd86-3543-6127-1a43-133b3491580d@aklaver.com>
  References: <BB162BE8-658C-4368-987E-8D5A3944232B@zeit.io> <ddcfcd86-3543-6127-1a43-133b3491580d@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox