Search Postgresql Archives

Re: Getting json-value as varchar

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



På torsdag 06. januar 2022 kl. 14:42:21, skrev Pavel Stehule <pavel.stehule@xxxxxxxxx>:
Hi
 
čt 6. 1. 2022 v 14:33 odesílatel Andreas Joseph Krogh <andreas@xxxxxxxxxx> napsal:
På torsdag 06. januar 2022 kl. 14:29:12, skrev David G. Johnston <david.g.johnston@xxxxxxxxx>:
[..]
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$
 
postgres=# select to_text((jsonb '{"a":"Ahoj"}')['a']);
┌─────────┐
│ to_text │
╞═════════╡
│ Ahoj    │
└─────────┘
(1 row)
 
Regards
 
Pavel
 
Thanks!
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
andreas@xxxxxxxxxx
www.visena.com
 

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux