Re: Getting json-value as varchar
| От | Pavel Stehule |
|---|---|
| Тема | Re: Getting json-value as varchar |
| Дата | |
| Msg-id | CAFj8pRCkbeCO81R9yRQAKzZQb55UjfEa0aUH81RCAfT0_b49OA@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: Getting json-value as varchar (Andreas Joseph Krogh <andreas@visena.com>) |
| Ответы |
Re: Getting json-value as varchar
|
| Список | pgsql-general |
Hi
čt 6. 1. 2022 v 14:33 odesílatel Andreas Joseph Krogh <andreas@visena.com> napsal:
På torsdag 06. januar 2022 kl. 14:29:12, skrev David G. Johnston <david.g.johnston@gmail.com>:[..]The fact is that the ‘ - - > ‘ operator gives you the needed output.David J.Yeah, I think that's the correct answer for this use-case.
It is true that some other casting function is missing. I am not sure if this is part of ANSI/SQL json support.
Now, you can use helper function
CREATE OR REPLACE FUNCTION public.to_text(jsonb)
RETURNS text
LANGUAGE sql
AS $function$
select jsonb_array_element_text($1, 0)
$function$
RETURNS text
LANGUAGE sql
AS $function$
select jsonb_array_element_text($1, 0)
$function$
postgres=# select to_text((jsonb '{"a":"Ahoj"}')['a']);
┌─────────┐
│ to_text │
╞═════════╡
│ Ahoj │
└─────────┘
(1 row)
┌─────────┐
│ to_text │
╞═════════╡
│ Ahoj │
└─────────┘
(1 row)
Regards
Pavel
--Andreas Joseph KroghCTO / Partner - Visena ASMobile: +47 909 56 963
Вложения
В списке pgsql-general по дате отправления: