Re: how to correctly cast json value to text?

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: how to correctly cast json value to text?
Дата
Msg-id CAFj8pRBDwnvr0Ars292jK44Y+6_nPySvNBAg=WAVCWZOOpmW0g@mail.gmail.com
обсуждение исходный текст
Ответ на Re: how to correctly cast json value to text?  (Marko Tiikkaja <marko@joh.to>)
Список pgsql-hackers


po 3. 5. 2021 v 11:26 odesílatel Marko Tiikkaja <marko@joh.to> napsal:
On Mon, May 3, 2021 at 12:24 PM Pavel Stehule <pavel.stehule@gmail.com> wrote:
Is it possible to do this with built functionality?

I miss the cast function for json scalar string value to string.

#>>'{}'

It is working. Thank you. But this syntax is a little bit scary.  Maybe we can introduce some functions for this case. Until to pg 14 this functionality was not necessary, but now it can be nice to have it.

DO $$
DECLARE v jsonb;
BEGIN
  -- hodnota musi byt validni json
  v['a'] = '"Ahoj"';
  RAISE NOTICE '%', v['a'] #>> '{}';
END;
$$;
NOTICE:  Ahoj
DO

Some ideas about the name of this function?

CREATE OR REPLACE FUNCTION jsonscalar_to_text(jsonb)
RETURNS text AS $$
SELECT $1 #>> '{}'
$$ LANGUAGE sql;




.m

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Marko Tiikkaja
Дата:
Сообщение: Re: how to correctly cast json value to text?
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: strange error reporting