Why is JSONB field automatically cast as TEXT?

From: Ben Uphoff <buphoff(at)villagemd(dot)com>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Why is JSONB field automatically cast as TEXT?
Date: 2018-09-17 18:03:47
Message-ID: AE11EB59-2FAC-4BD6-ABE0-BE40D5131CE4@villagemd.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2018-09-17 18:11:42 Re: Why is JSONB field automatically cast as TEXT?
Previous Message Chris Travers 2018-09-17 17:27:18 Re: Logical locking beyond pg_advisory