Re: substring replacement

From: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>
To: Oleg Lebedev <olebedev(at)waterford(dot)org>, Postgres SQL Mailing List <pgsql-sql(at)postgresql(dot)org>
Subject: Re: substring replacement
Date: 2001-11-09 16:35:42
Message-ID: 20011109163542.41082.qmail@web20805.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I assume you mean that '\n' and '\t' exist as literal
characters in your data, and you simply want to delete
them.
There is no builtin function in PostgreSQL which will
delete a substring ("translate" works for characters,
in the manner of Unix "tr"). You will need to write
one for yourself. A generic function would be
something like this:
CREATE FUNCTION s(text, text, text)
RETURNS text as '
$_[0] =~ s/$_[1]/$_[2]/;
return $_[0];
' LANGUAGE 'plperl';
Substitute whatever datatype you are using.

--- Oleg Lebedev <olebedev(at)waterford(dot)org> wrote:
> Hi everybody,
> I am wondering if there is an efficient way to get
> rid of line breaks
> ('\n') and tabs ('\t') from a string. Suppose, I
> have the following
> query:
> SELECT description
> FROM device;
> I don't want the returned description column to
> contain '\n' and '\t'.
> Is it possible to do it efficiently?
> thanks,
>
> Oleg
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html

__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jason Earl 2001-11-09 18:22:06 Re: Optimization, etc
Previous Message Roberto Mello 2001-11-09 15:58:31 Re: Increasing MAX_ARGS