Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-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>

pgsql-bugs by date

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

pgsql-patches by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group