Re: Getting json-value as varchar
От | Thomas Markus |
---|---|
Тема | Re: Getting json-value as varchar |
Дата | |
Msg-id | fea89b01-5429-4328-c705-5bcd41a91322@proventis.net обсуждение исходный текст |
Ответ на | Re: Getting json-value as varchar (Andreas Joseph Krogh <andreas@visena.com>) |
Список | pgsql-general |
Hi,
complicated but this should do:
SELECT jsonb_build_array( ('{"key":"value"}'::jsonb)['key'] ) ->> 0;
Am 06.01.22 um 13:36 schrieb Andreas Joseph Krogh:
yeah right :(På torsdag 06. januar 2022 kl. 13:31:19, skrev Thomas Markus <t.markus@proventis.net>:Hi,
Am 06.01.22 um 13:28 schrieb Andreas Joseph Krogh:simply cast your valueHi, 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?
SELECT (('{"key":"value"}'::jsonb)->> 'key')::text;
best regards
ThomaI 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" │
└─────────┘
complicated but this should do:
SELECT jsonb_build_array( ('{"key":"value"}'::jsonb)['key'] ) ->> 0;
--Andreas Joseph KroghCTO / Partner - Visena ASMobile: +47 909 56 963
Вложения
В списке pgsql-general по дате отправления: