SELECT using RegEx inside a POSITION function

From: "Danny Stewart" <dstewart(at)pcfa(dot)org>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: SELECT using RegEx inside a POSITION function
Date: 2003-04-25 16:26:18
Message-ID: NEBBKEGFOMBMIIIBLOIEKEAADJAA.dstewart@pcfa.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I'm trying to retrieve just the numeric portion of the field named 'id' from
a table named 'resources'. The data looks something like:
DEF 345
#234
Folder 567 Section 6
123
NDD #456
ABC (no numbers)

Based on the information contained in
http://techdocs.postgresql.org/guides/RegularExpressionIntro (which does not
mention the position function), I am trying to use
SELECT substring(id from position(~ '[0-9]' in id)) FROM resources ;
but that returns:
Unable to identify a prefix operator '~' for type 'unknown'
You may need to add parentheses or an explicit cast
Is regex not supported inside the position() function? Or, am I missing
something?

Eventually, I want to be able to sort so the records appear in the order
that contains these numbers:
blank or null
123
234
345
456
567
using a statement similar to:
SELECT * FROM resources WHERE somefield='limitingphrase' ORDER BY
whateverthecorrectsubstringstatement

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message M. Bastin 2003-04-25 17:59:16 StartupPacket
Previous Message M. Bastin 2003-04-25 16:25:53 Re: Starting postgres with a password