From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Durumdara <durumdara(at)gmail(dot)com> |
Cc: | Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to convert escaped text column - force E prefix |
Date: | 2021-01-06 08:43:55 |
Message-ID: | CAFj8pRD+dZpTd--g0YdAEyJvSFTv+zndgZaxtkAH=-Kmdm8sBw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi
st 6. 1. 2021 v 8:55 odesílatel Durumdara <durumdara(at)gmail(dot)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
https://commitfest.postgresql.org/31/2613/
Regards
Pavel
> Thank you for the help!
>
> Best regards
> dd
>
>
>
>
>
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Gavan Schneider | 2021-01-06 09:53:53 | Re: How to convert escaped text column - force E prefix |
Previous Message | Artur Zakirov | 2021-01-06 08:02:16 | Re: FTS and tri-grams |