pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Joseph Krogh <andreas@visena.com>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Getting json-value as varchar
Date: Thu, 6 Jan 2022 14:48:09 +0100 (CET)
Message-ID: <VisenaEmail.47.f970b1045fe0efac.17e2fa564b6@tc7-visena> (raw)
In-Reply-To: <CAFj8pRCkbeCO81R9yRQAKzZQb55UjfEa0aUH81RCAfT0_b49OA@mail.gmail.com>
References: <VisenaEmail.2e.372da85b7b7aed09.17e2f59771e@tc7-visena>
	<e5f0a003-e4a4-38e2-404c-56e623e40d7a@proventis.net>
	<VisenaEmail.32.ec0b963b4e92d37.17e2f6228cb@tc7-visena>
	<CAKFQuwabBpxQv7YSY5mpPy2E9tqaye=7AyJSRreAn9hhtcTS_Q@mail.gmail.com>
	<VisenaEmail.39.5eee7254b64bd194.17e2f89cd27@tc7-visena>
	<CAKFQuwaRcrLBOMEb7ZNmW9_GCGARODRRtN3oOPMYLCex5MnT5g@mail.gmail.com>
	<VisenaEmail.3f.9857a9dfb28ce238.17e2f9795e1@tc7-visena>
	<CAFj8pRCkbeCO81R9yRQAKzZQb55UjfEa0aUH81RCAfT0_b49OA@mail.gmail.com>


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

Hi 

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

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@visena.com <mailto:andreas@visena.com> 
www.visena.com <https://www.visena.com; 
 <https://www.visena.com; 

view thread (11+ messages)  latest in thread

Message-ID: <VisenaEmail.47.f970b1045fe0efac.17e2fa564b6@tc7-visena>
Permalink:  ../VisenaEmail.47.f970b1045fe0efac.17e2fa564b6@tc7-visena/
Also on:    postgresql.org/message-id/VisenaEmail.47.f970b1045fe0efac.17e2fa564b6@tc7-visena

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: andreas@visena.com, pavel.stehule@gmail.com, david.g.johnston@gmail.com
  Subject: Re: Getting json-value as varchar
  In-Reply-To: <VisenaEmail.47.f970b1045fe0efac.17e2fa564b6@tc7-visena>
  References: <VisenaEmail.2e.372da85b7b7aed09.17e2f59771e@tc7-visena> <e5f0a003-e4a4-38e2-404c-56e623e40d7a@proventis.net> <VisenaEmail.32.ec0b963b4e92d37.17e2f6228cb@tc7-visena> <CAKFQuwabBpxQv7YSY5mpPy2E9tqaye=7AyJSRreAn9hhtcTS_Q@mail.gmail.com> <VisenaEmail.39.5eee7254b64bd194.17e2f89cd27@tc7-visena> <CAKFQuwaRcrLBOMEb7ZNmW9_GCGARODRRtN3oOPMYLCex5MnT5g@mail.gmail.com> <VisenaEmail.3f.9857a9dfb28ce238.17e2f9795e1@tc7-visena> <CAFj8pRCkbeCO81R9yRQAKzZQb55UjfEa0aUH81RCAfT0_b49OA@mail.gmail.com> <VisenaEmail.47.f970b1045fe0efac.17e2fa564b6@tc7-visena>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox