proper regex_replace() syntax

Started by Geoffreyalmost 15 years ago3 messagesgeneral
Jump to latest
#1Geoffrey
lists@serioustechnology.com

I want to use regex_replace() to replace characters in multiple records.

What I would like to do is this:

select regex_replace((select fname from table), 'z', 'Z'));

The problem is, the subquery returns more then one row.

So, is there a way to do what I'm trying to do? That is, replace the
same character in multiple records using regex_replace() ?

In reality, we are trying to change characters like the 1/2 character to
the three characters '1/2'.

Thanks for any assistance.

--
Until later, Geoffrey

"I predict future happiness for America if they can prevent
the government from wasting the labors of the people under
the pretense of taking care of them."
- Thomas Jefferson

#2Ken Tanzer
ken.tanzer@gmail.com
In reply to: Geoffrey (#1)
Re: proper regex_replace() syntax

I think this is the syntax you want:

SELECT regexp_replace(fname,'z','Z') FROM table;

On Wed, Jun 1, 2011 at 10:22 AM, Geoffrey Myers <lists@serioustechnology.com

Show quoted text

wrote:

I want to use regex_replace() to replace characters in multiple records.

What I would like to do is this:

select regex_replace((select fname from table), 'z', 'Z'));

The problem is, the subquery returns more then one row.

So, is there a way to do what I'm trying to do? That is, replace the same
character in multiple records using regex_replace() ?

In reality, we are trying to change characters like the 1/2 character to
the three characters '1/2'.

Thanks for any assistance.

--
Until later, Geoffrey

"I predict future happiness for America if they can prevent
the government from wasting the labors of the people under
the pretense of taking care of them."
- Thomas Jefferson

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Rick Genter
rick.genter@gmail.com
In reply to: Geoffrey (#1)
Re: proper regex_replace() syntax

On Wed, Jun 1, 2011 at 10:22 AM, Geoffrey Myers <lists@serioustechnology.com

wrote:

I want to use regex_replace() to replace characters in multiple records.

What I would like to do is this:

select regex_replace((select fname from table), 'z', 'Z'));

The problem is, the subquery returns more then one row.

So, is there a way to do what I'm trying to do? That is, replace the same
character in multiple records using regex_replace() ?

I think what you want is:

SELECT regex_replace(fname, 'z', 'Z') FROM table;

This should return a recordset where each row has one column which is the
result of regex_replace() on the corresponding row of table.
--
Rick Genter
rick.genter@gmail.com