From: | Andreas Joseph Krogh <andreas(at)visena(dot)com> |
---|---|
To: | Thomas Markus <t(dot)markus(at)proventis(dot)net> |
Cc: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Getting json-value as varchar |
Date: | 2022-01-06 12:36:28 |
Message-ID: | VisenaEmail.32.ec0b963b4e92d37.17e2f6228cb@tc7-visena |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
På torsdag 06. januar 2022 kl. 13:31:19, skrev Thomas Markus <
t(dot)markus(at)proventis(dot)net <mailto:t(dot)markus(at)proventis(dot)net>>: Hi,
Am 06.01.22 um 13:28 schrieb Andreas Joseph Krogh:
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? simply cast your value
SELECT (('{"key":"value"}'::jsonb)->> 'key')::text;
best regards
Thoma
I think you misread my message. What I want is for the subscript-version:
('{"key":"value"}'::jsonb)['key']
to return:
┌──────────┐
│ ?column? │
├──────────┤
│ value │
└──────────┘
instead of
┌─────────┐
│ jsonb │
├─────────┤
│ "value" │
└─────────┘
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
andreas(at)visena(dot)com <mailto:andreas(at)visena(dot)com>
www.visena.com <https://www.visena.com>
<https://www.visena.com>
From | Date | Subject | |
---|---|---|---|
Next Message | Levente Birta | 2022-01-06 12:53:21 | Recommended storage hardware |
Previous Message | Thomas Markus | 2022-01-06 12:31:19 | Re: Getting json-value as varchar |