Re: replacing single quotes

From: Ow Mun Heng <Ow(dot)Mun(dot)Heng(at)wdc(dot)com>
To: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: replacing single quotes
Date: 2007-10-10 07:31:53
Message-ID: 1192001513.442.2.camel@neuromancer.home.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2007-10-10 at 09:11 +0200, Albe Laurenz wrote:
> 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.

The input is for an SRF which accepts an array..

eg:
select * from foo(date1,date2,'{aaa,bbb,ccc}')

where the function goes..
create function foo(timestamp, timestamp, foo_list text[]) returns setof
results as
...
where foo_list = any (foo_list)
..

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ow Mun Heng 2007-10-10 07:43:13 pgodbc + Excel + msquery + background refresh
Previous Message Albe Laurenz 2007-10-10 07:11:14 Re: replacing single quotes