pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steve Frampton <frampton@LinuxNinja.com>
To: pgsql-sql@postgresql.org
Subject: Doing a regexp-based search/replace?
Date: Thu, 18 Oct 2001 12:03:28 -0400 (EDT)
Message-ID: <Pine.LNX.4.33.0110181156220.29176-100000@astro.phpwebhosting.com> (raw)
In-Reply-To: <E2870D8CE1CCD311BAF50008C71EDE8E01F746FF@MAIL_EXCHANGE>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello:

I've got a table containing property_id's with values of the form
###-####.  I would like to discard the slash onwards (and I can't use a
substr() because I am not guaranteed if a) the -#### portion exists, b)
what position it exists from.

If this were a text file, I would use a sed expression such as:

cat textfile | sed 's/-.*$//'

I've been looking for a way to do this with PostgreSQL but so far haven't
found a function that seems to be suitable.  I thought maybe I could do it
with translate, but translate doesn't appear to work with regular
expressions.  So far I've tried things like:

select translate(property_id, '-.*', '') from mytable;

I need to do this, because the -.* portion of my property_id was entered
in error, and I would like to do an update on the entire table and just
have the left-hand side of the property_id column remaining.

Any ideas?  Thank you in advance.

- ---------------< LINUX: The choice of a GNU generation. >-------------
Steve Frampton   <frampton@LinuxNinja.com>   http://www.LinuxNinja.com
GNU Privacy Guard ID: D055EBC5  (see http://www.gnupg.org for details)
GNU-PG Fingerprint: EEFB F03D 29B6 07E8 AF73  EF6A 9A72 F1F5 D055 EBC5
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.0 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7zv1TmnLx9dBV68URAisEAJ4nNYz4lxpgWojULE/Xo9SUb5IexgCfS9At
J6kAVn/3vFHeJkl9bjr4AcQ=
=W4xQ
-----END PGP SIGNATURE-----




view thread (5+ messages)  latest in thread

Message-ID: <Pine.LNX.4.33.0110181156220.29176-100000@astro.phpwebhosting.com>
Permalink:  ../Pine.LNX.4.33.0110181156220.29176-100000@astro.phpwebhosting.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.33.0110181156220.29176-100000@astro.phpwebhosting.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: frampton@LinuxNinja.com
  Subject: Re: Doing a regexp-based search/replace?
  In-Reply-To: <Pine.LNX.4.33.0110181156220.29176-100000@astro.phpwebhosting.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox