Re: Getting json-value as varchar

From: Andreas Joseph Krogh <andreas(at)visena(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Getting json-value as varchar
Date: 2022-01-06 13:48:09
Message-ID: VisenaEmail.47.f970b1045fe0efac.17e2fa564b6@tc7-visena
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


På torsdag 06. januar 2022 kl. 14:42:21, skrev Pavel Stehule <
pavel(dot)stehule(at)gmail(dot)com <mailto:pavel(dot)stehule(at)gmail(dot)com>>:

Hi

čt 6. 1. 2022 v 14:33 odesílatel Andreas Joseph Krogh <andreas(at)visena(dot)com
<mailto:andreas(at)visena(dot)com>> napsal:
På torsdag 06. januar 2022 kl. 14:29:12, skrev David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com <mailto:david(dot)g(dot)johnston(at)gmail(dot)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$

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(at)visena(dot)com <mailto:andreas(at)visena(dot)com>
www.visena.com <https://www.visena.com>
<https://www.visena.com>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2022-01-06 14:37:04 Re: pg_dump parameter
Previous Message Pavel Stehule 2022-01-06 13:42:21 Re: Getting json-value as varchar