Re: Checking for a number

From: Lee Keel <lee(dot)keel(at)uai(dot)com>
To: Warren <warren(at)clarksnutrition(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Checking for a number
Date: 2007-06-27 17:39:39
Message-ID: 76758090F8686C47A44B6FF52514A1D308C9C166@hermes.uai.int
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-
> owner(at)postgresql(dot)org] On Behalf Of Warren
> Sent: Wednesday, June 27, 2007 12:31 PM
> To: pgsql-general(at)postgresql(dot)org
> Subject: [GENERAL] Checking for a number
>
> I need to check if the last two characters of a field are a number. I am
> trying something like this but it does not want to work.
>
> substring(TRIM(field8) from '..$') SIMILAR TO '\d\d'
>
> How should I do this?
>
> --
> Thanks,
>
> Warren Bell
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match

Warren,

Try this...

select substring(trim(both ' ' from field8) from E'\\d{2}$') from TABLENAME
where texticregexeq(trim(both ' ' from field8), E'\\d{2}$')

This will limit the query to only the rows that end in 2 digits as well as
return those digits for you.

Hope that helps,
Lee Keel

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.

Browse pgsql-general by date

  From Date Subject
Next Message CG 2007-06-27 18:14:19 Re: How do you handle shared memory corruption issues? (contrib/xml2)
Previous Message Warren 2007-06-27 17:30:43 Checking for a number