Re: replacing single quotes

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: replacing single quotes
Дата
Msg-id D960CB61B694CF459DCFB4B0128514C25684F7@exadv11.host.magwien.gv.at
обсуждение исходный текст
Ответ на replacing single quotes  (Ow Mun Heng <Ow.Mun.Heng@wdc.com>)
Ответы Re: replacing single quotes  (Ow Mun Heng <Ow.Mun.Heng@wdc.com>)
Список pgsql-general
Ow Mun Heng wrote:
> Input is of form
>
> 'ppp','aaa','bbb'
>
> I want it to be stripped of quotes to become
>
> ppp,aaa,bbb
>
> escaping the quote would work but it means I will have
> to do some magic on the input as well to escape it prior
> to replacing it.
>
> select replace('AB\'A','\'','C') this works
>
> Can I buy a clue here?

Sorry, all the advisives are free here.

I'm a little confused that you think that you will have to
escape single quotes in the input.
What is your use case? Normally the input is in some variable
in some programming language.
Escaping single quotes is only for string literals.

Like this:

CREATE FUNCTION rep(v text) RETURNS text
  LANGUAGE sql IMMUTABLE STRICT AS
$$SELECT replace($1, '''', '')$$;

BTW, I would use '' instead of \' to escape single quotes.
It is safer and standard compliant.

Yours,
Laurenz Albe

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

Предыдущее
От: "Hiroshi Saito"
Дата:
Сообщение: Re: about Command Prompt.
Следующее
От: Ow Mun Heng
Дата:
Сообщение: Re: replacing single quotes