pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-general@lists.postgresql.org
Subject: Getting json-value as varchar
Date: Thu, 6 Jan 2022 13:28:26 +0100 (CET)
Message-ID: <VisenaEmail.2e.372da85b7b7aed09.17e2f59771e@tc7-visena> (raw)


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 Iknow the JSON-field is a String? 



-- 
Andreas Joseph Krogh 
CTO / Partner - Visena AS 
Mobile: +47 909 56 963 
andreas@visena.com <mailto:andreas@visena.com> 
www.visena.com <https://www.visena.com; 
 <https://www.visena.com; 

view thread (11+ messages)  latest in thread

Message-ID: <VisenaEmail.2e.372da85b7b7aed09.17e2f59771e@tc7-visena>
Permalink:  ../VisenaEmail.2e.372da85b7b7aed09.17e2f59771e@tc7-visena/
Also on:    postgresql.org/message-id/VisenaEmail.2e.372da85b7b7aed09.17e2f59771e@tc7-visena

 · 

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: andreas@visena.com
  Subject: Re: Getting json-value as varchar
  In-Reply-To: <VisenaEmail.2e.372da85b7b7aed09.17e2f59771e@tc7-visena>
  References: <VisenaEmail.2e.372da85b7b7aed09.17e2f59771e@tc7-visena>

* 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