Re: please help me with text cast to int .... - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: please help me with text cast to int ....
Date
Msg-id 20040711100337.Y854@megazone.bigpanda.com
Whole thread Raw
In response to please help me with text cast to int ....  (Theodore Petrosky <tedpet5@yahoo.com>)
Responses Re: please help me with text cast to int ....  (Theodore Petrosky <tedpet5@yahoo.com>)
List pgsql-sql
On Sun, 11 Jul 2004, Theodore Petrosky wrote:

> I give up.. what don't I understand about casting and
> ints and text..
>
> i have a table jobinfo with:
>
> acode text,
> jobnumber text default
> nextval('public.jobinfo_seq'::text),
> jobtitle text
>
> I have about 3000 rows starting with jobnumber = 1000.
>
> SELECT jobnumber, jobtitle FROM jobinfo WHERE
> jobnumber >= 999 ORDER BY jobnumber ASC;

This is going to do a textual comparison, not an integer one.
So it's looking for jobnumbers greater than the string '999'.

If you want to treat jobnumber as an integer, CAST(jobnumber as integer)
>= 999 may be what you want.  Note, however that it will fail if there are
any non-numeric jobnumber rows.  In general, storing numbers in strings
that you want to act upon as numbers is a bad idea.



pgsql-sql by date:

Previous
From: Phil Endecott
Date:
Subject: Re: please help me with text cast to int ....
Next
From: Theodore Petrosky
Date:
Subject: Re: please help me with text cast to int ....