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

Re: please help me with text cast to int ....

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Theodore Petrosky <tedpet5(at)yahoo(dot)com>
Cc: postgres SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: please help me with text cast to int ....
Date: 2004-07-11 17:06:06
Message-ID: 20040711100337.Y854@megazone.bigpanda.com (view raw or flat)
Thread:
Lists: 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.


In response to

Responses

pgsql-sql by date

Next:From: Theodore PetroskyDate: 2004-07-11 18:52:16
Subject: Re: please help me with text cast to int ....
Previous:From: Phil EndecottDate: 2004-07-11 17:01:45
Subject: Re: please help me with text cast to int ....

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