Correction to 'translate' function in postgresql

From: Pedro Zorzenon Neto <pzn(at)terra(dot)com(dot)br>
To: pgsql-bugs(at)postgresql(dot)org, pgsql-patches(at)postgresql(dot)org
Subject: Correction to 'translate' function in postgresql
Date: 2003-09-24 23:11:11
Message-ID: 20030924231111.GA2249@mantis.autsens.localnet
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-patches

Please send a carbon copy of replies to me, as I am not a subscriber
of any postgresql mailing list.

Hi folks,

I noticed that I can use the string function "translate" to remove
unwanted characters from strings, this way:

translate(tablefield, '-_. ', '');

This will remove all hifens, underscores, dots and spaces.

However, reading the postgres-user-guide, I noticed that this is a
undocumented feature, so I read the source codes to see if this was
desired or just a bug. In the function code of translate, I can read in
the comments that removing characters without correspondence was what
the developer desired. Then this should be add to docs, so other people
whose need this can also use it.

Below is a patch for it.

Thanks for postgresql, it is a really great software!

Bye,
Pedro

--
.''`. Pedro Zorzenon Neto <pzn(at)terra(dot)com(dot)br>
: :' : Debian GNU/Linux | GNU/Hurd: <http://www.debian.org>
`. `'` Debian BR: <http://debian-br.cipsga.org.br>
`- Be Happy! Be FREE!

--- doc/src/sgml/func.sgml.orig Wed Sep 24 19:56:38 2003
+++ doc/src/sgml/func.sgml Wed Sep 24 19:58:30 2003
@@ -1307,7 +1307,9 @@
Any character in <parameter>string</parameter> that matches a
character in the <parameter>from</parameter> set is replaced by
the corresponding character in the <parameter>to</parameter>
- set.
+ set. If <parameter>from</parameter> is longer than
+ <parameter>to</parameter>, occurrences of the extra characters
+ in <parameter>from</parameter> are deleted.
</entry>
<entry><literal>translate('12345', '14', 'ax')</literal></entry>
<entry><literal>a23x5</literal></entry>

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2003-09-25 03:13:53 Problem with domains
Previous Message Bruce Momjian 2003-09-24 19:06:02 Re: create temporary sequence and ecpg

Browse pgsql-patches by date

  From Date Subject
Next Message Hiroshi Inoue 2003-09-25 15:33:21 Re: pgsql-server/src/backend catalog/index.c comma ...
Previous Message Tom Lane 2003-09-24 22:12:58 Re: pgsql-server/src/backend catalog/index.c comma ...