Re: [HACKERS] [GENERAL] workaround for lack of REPLACE()

From: Joe Conway <mail(at)joeconway(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>, lockhart(at)fourpalms(dot)org
Subject: Re: [HACKERS] [GENERAL] workaround for lack of REPLACE()
Date: 2002-08-16 20:22:55
Message-ID: 3D5D5F1F.30407@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers pgsql-patches

Joe Conway wrote:
> I took Tom's advice and added wrapper functions around text_substr() and
> bytea_substr() to cover the 2 argument case.
>
> I also added tests to strings.sql to cover substr() on toasted columns
> of both text and bytea.
>

Please replace the original patch (substr.2002.08.14.1.patch) with the
attached. It includes everything from the previous one, plus newly
implemented builtin functions:

replace(string, from, to)
-- replaces all occurrences of "from" in "string" to "to"
split(string, fldsep, column)
-- splits "string" on "fldsep" and returns "column" number piece
to_hex(int32_num) & to_hex(int64_num)
-- takes integer number and returns as hex string

All previously discussed on the list; see thread at:
http://archives.postgresql.org/pgsql-hackers/2002-07/msg00511.php

Examples:

SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";
ya123da123doo
---------------
ya123da123doo
(1 row)

select split('joeuser(at)mydatabase','@',1) AS "joeuser";
joeuser
---------
joeuser
(1 row)

select split('joeuser(at)mydatabase','@',2) AS "mydatabase";
mydatabase
------------
mydatabase
(1 row)

select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS
"ffffffff";
ffffffff
----------
ffffffff
(1 row)

Tests have been added to the regression suite.

Passes all regression tests. I've checked the strings.sql script in a
multibyte database and it works fine also. I'd appreciate a good look by
someone more familiar with multibyte related issues though.

If it is OK, I'd like to hold off on docs until this is committed and
after beta starts.

If there are no objections, please apply.

Thanks,

Joe

Attachment Content-Type Size
str_funcs.2002.08.16.1.patch text/plain 35.0 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Justin Clift 2002-08-17 17:39:16 Quick Market Research survey now on Techdocs
Previous Message Patrick Macdonald 2002-08-16 19:30:54 Re: RHDB Explain

Browse pgsql-hackers by date

  From Date Subject
Next Message Rod Taylor 2002-08-16 21:44:50 CVS Messages
Previous Message Bruce Momjian 2002-08-16 19:58:27 Re: Open 7.3 issues

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2002-08-16 20:26:42 Re: Foreign key in pg_dump / psql
Previous Message Bruce Momjian 2002-08-16 19:50:21 Re: Foreign key in pg_dump / psql