replace function in a query

Started by Harpreet Dhaliwalalmost 19 years ago3 messagesgeneral
Jump to latest
#1Harpreet Dhaliwal
harpreet.dhaliwal01@gmail.com

Hi,

I have to write a query that does the following.

select column_x from tbl_xyz
where column_y = 'abc def ghi'

new line characters i.e. '\n' in column_y should be replaced with a space
character i.e. ' ' in this query.
Is there any replace function that when used in the query with colulmn_y
would do it?

Thanks,
~Harpreet

#2William Leite Araújo
william.bh@gmail.com
In reply to: Harpreet Dhaliwal (#1)
Re: replace function in a query

http://www.postgresql.org/docs/8.0/interactive/functions-string.html
http://www.postgresql.org/docs/8.1/interactive/functions-string.html
http://www.postgresql.org/docs/8.2/interactive/functions-string.html

2007/5/21, Harpreet Dhaliwal <harpreet.dhaliwal01@gmail.com>:

Hi,

I have to write a query that does the following.

select column_x from tbl_xyz
where column_y = 'abc def ghi'

new line characters i.e. '\n' in column_y should be replaced with a space
character i.e. ' ' in this query.
Is there any replace function that when used in the query with colulmn_y
would do it?

Thanks,
~Harpreet

--
William Leite Araújo
Analista de Banco de Dados - QualiConsult

#3Albe Laurenz
all@adv.magwien.gv.at
In reply to: Harpreet Dhaliwal (#1)
Re: replace function in a query

I have to write a query that does the following.

select column_x from tbl_xyz
where column_y = 'abc def ghi'

new line characters i.e. '\n' in column_y should be replaced
with a space character i.e. ' ' in this query.
Is there any replace function that when used in the query
with colulmn_y would do it?

Are you looking for something like this?

test=> SELECT translate ('abc
test'> def
test'> ghi', E'\n', ' ');
translate
-------------
abc def ghi
(1 row)

"translate" is described on
http://www.postgresql.org/docs/current/static/functions-string.html

Yours,
Laurenz Albe