Why is JSONB field automatically cast as TEXT? - Mailing list pgsql-general

From Ben Uphoff
Subject Why is JSONB field automatically cast as TEXT?
Date
Msg-id AE11EB59-2FAC-4BD6-ABE0-BE40D5131CE4@villagemd.com
Whole thread Raw
Responses Re: Why is JSONB field automatically cast as TEXT?  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general

First post here at PostgreSQL; please forgive any etiquette mistakes…

 

I have a query that extracts a field from a JSONB column, e.g.:

 

SELECT (((mytable.ajsonbcolumn -> ‘somedata’) -> ‘nested’) ->> ‘first_name’) AS fname FROM mytable

 

When I save it into a view, PostgreSQL transforms it thusly:

 

SELECT (((mytable.ajsonbcolumn -> ‘somedata’::text) -> ‘nested’::text) ->> ‘first_name’::text) AS fname FROM mytable

 

(note the ::text casts).

 

Why does it do this? It seems unnecessary and pollutes my SQL with a ton of extra text.

 

Thanks for your thoughts. -Ben

 

******************* PLEASE NOTE ******************* This E-Mail/telefax message and any documents accompanying this transmission may contain information that is privileged, confidential, and/or exempt from disclosure under applicable law and is intended solely for the addressee(s) named above. If you are not the intended addressee/recipient, you are hereby notified that any use of, disclosure, copying, distribution, or reliance on the contents of this E-Mail/telefax information is strictly prohibited and may result in legal action against you. Please reply to the sender advising of the error in transmission and immediately delete/destroy the message and any accompanying documents. Thank you.

pgsql-general by date:

Previous
From: Chris Travers
Date:
Subject: Re: Logical locking beyond pg_advisory
Next
From: "David G. Johnston"
Date:
Subject: Re: Why is JSONB field automatically cast as TEXT?