Re: How to convert escaped text column - force E prefix

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: How to convert escaped text column - force E prefix
Дата
Msg-id CAFj8pRD+dZpTd--g0YdAEyJvSFTv+zndgZaxtkAH=-Kmdm8sBw@mail.gmail.com
обсуждение исходный текст
Ответ на How to convert escaped text column - force E prefix  (Durumdara <durumdara@gmail.com>)
Ответы Re: How to convert escaped text column - force E prefix  ("Gavan Schneider" <list.pg.gavan@pendari.org>)
Список pgsql-general
Hi

st 6. 1. 2021 v 8:55 odesílatel Durumdara <durumdara@gmail.com> napsal:
Dear Members!

A web developer stores JSON like strings in a text column.

With E prefix we can get the real text:

Select E'Az ad\u00f3kulcsonk\u00e9nti' 

Hungarian: "Az adókulcsonkénti" (ISO-8859-2)

How to get the same result from a table column?

select WhatAFunction( ATable.JSONLikeTextColumn) from ATable

What function do we need to use to "simulate" E prefix?

Currently there are not any functions that you need. You need to write your own.

CREATE OR REPLACE FUNCTION public.unistr(text)
 RETURNS text
 LANGUAGE plpgsql
 IMMUTABLE STRICT
AS $function$
declare r text;
begin
  execute 'select e''' || $1 || '''' into r;
  return r;
end;
$function$;

Attention: This is ugly and possible sql injection vulnerable!!! But there is not another way. The fix is in queue


Regards

Pavel




Thank you for the help!

Best regards
dd







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

Предыдущее
От: Artur Zakirov
Дата:
Сообщение: Re: FTS and tri-grams
Следующее
От: "Gavan Schneider"
Дата:
Сообщение: Re: How to convert escaped text column - force E prefix