From: Gavan Schneider <list.pg.gavan@pendari.org>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: Durumdara <durumdara@gmail.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: How to convert escaped text column - force E prefix
Date: Wed, 06 Jan 2021 20:53:53 +1100
Message-ID: <EDDF234B-B9C8-4812-BEB7-929E8756DC43@pendari.org> (raw)
In-Reply-To: <CAFj8pRD+dZpTd--g0YdAEyJvSFTv+zndgZaxtkAH=-Kmdm8sBw@mail.gmail.com>
References: <CAEcMXhkfup6xm9ipbFybwquhMkgLEt4G_3Ypv7_HiLnpz0mZUg@mail.gmail.com>
<CAFj8pRD+dZpTd--g0YdAEyJvSFTv+zndgZaxtkAH=-Kmdm8sBw@mail.gmail.com>
On 6 Jan 2021, at 19:43, Pavel Stehule wrote:
> 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''' || quote_literal($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://www.postgresql.org/docs/current/functions-string.html
quote_literal ( text ) → text
Returns the given string suitably quoted to be used as a string
literal in an SQL statement string.
Embedded single-quotes and backslashes are properly doubled.
Note that quote_literal returns null on null input; if the argument
might be null, quote_nullable is often more suitable.
See also Example 42.1. quote_literal(E'O\'Reilly') → 'O''Reilly'
It is even more ugly but would it at least help with the SQL injection
risk?
Gavan Schneider
——
Gavan Schneider, Sodwalls, NSW, Australia
Explanations exist; they have existed for all time; there is always a
well-known solution to every human problem — neat, plausible, and
wrong.
— H. L. Mencken, 1920
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: list.pg.gavan@pendari.org, pavel.stehule@gmail.com, durumdara@gmail.com
Subject: Re: How to convert escaped text column - force E prefix
In-Reply-To: <EDDF234B-B9C8-4812-BEB7-929E8756DC43@pendari.org>
References: <CAEcMXhkfup6xm9ipbFybwquhMkgLEt4G_3Ypv7_HiLnpz0mZUg@mail.gmail.com> <CAFj8pRD+dZpTd--g0YdAEyJvSFTv+zndgZaxtkAH=-Kmdm8sBw@mail.gmail.com> <EDDF234B-B9C8-4812-BEB7-929E8756DC43@pendari.org>
* 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