Getting json-value as varchar - Mailing list pgsql-general

From Andreas Joseph Krogh
Subject Getting json-value as varchar
Date
Msg-id VisenaEmail.2e.372da85b7b7aed09.17e2f59771e@tc7-visena
Whole thread Raw
Responses Re: Getting json-value as varchar
Re: Getting json-value as varchar
List pgsql-general
Hi, in PG-14 this query returns "value" (with double-quotes):
SELECT ('{"key":"value"}'::jsonb)['key'];
┌─────────┐
│  jsonb  │
├─────────┤
│ "value" │
└─────────┘
(1 row)


 
and this returns 'value' (without the quotes):
SELECT ('{"key":"value"}'::jsonb)->> 'key';
┌──────────┐
│ ?column? │
├──────────┤
│ value    │
└──────────┘
(1 row)


How to I use the subscript syntax and get the result as varchar instead of JSONB, assuming I know the JSON-field is a String?
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
Attachment

pgsql-general by date:

Previous
From: Michael Paquier
Date:
Subject: Re: md5 issues Postgres14 on OL7
Next
From: Thomas Markus
Date:
Subject: Re: Getting json-value as varchar