X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 98228D1B1C8 for ; Sun, 11 Jul 2004 14:02:40 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 81660-02 for ; Sun, 11 Jul 2004 17:02:36 +0000 (GMT) Received: from mta04-svc.ntlworld.com (mta04-svc.ntlworld.com [62.253.162.44]) by svr1.postgresql.org (Postfix) with ESMTP id 8FC90D1B174 for ; Sun, 11 Jul 2004 14:02:33 -0300 (ADT) Received: from chezphil.org ([82.4.146.209]) by mta04-svc.ntlworld.com (InterMail vM.4.01.03.37 201-229-121-137-20020806) with ESMTP id <20040711170123.GXAA7691.mta04-svc.ntlworld.com@chezphil.org> for ; Sun, 11 Jul 2004 18:01:23 +0100 Received: from [127.0.0.1] ([127.0.0.1]) by andorra with smtp (dmsmtpd 0.00001); Sun, 11 Jul 2004 18:02:31 +0100 Message-ID: <40F17279.4080204@chezphil.org> Date: Sun, 11 Jul 2004 18:01:45 +0100 User-Agent: Mozilla Thunderbird 0.6 (X11/20040605) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Theodore Petrosky Cc: postgres SQL Subject: Re: please help me with text cast to int .... References: <20040711162246.34618.qmail@web41004.mail.yahoo.com> In-Reply-To: <20040711162246.34618.qmail@web41004.mail.yahoo.com> Content-Type: text/plain; charset="us-ascii"; format="flowed" Content-Transfer-Encoding: 7bit From: Phil Endecott X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200407/60 X-Sequence-Number: 18312 Theodore, Because jobnumber is declared as text, you are getting "dictionary order" (lexicographic) ordering on the values. In a dictionary, "abc" comes after "aaaaaaaaa", obviously. So indeed "999" will come after "1000". To get the effect that you want you need to treat jobnumber as a number. The easiest thing to do would be to change the declaration of the table. If for some reason you can't do that, you need to do a cast in the query; that would make your WHERE expression work, but I don't know about ORDER BY (look it up). For example: SELECT jobnumber, jobtitle FROM jobinfo WHERE jobnumber::integer >= 200 ORDER BY jobnumber ASC; Do you ever have non-numeric values in the jobnumber field? (Is that why it's declared as text?) If you do you will get problems because they cannot be converted to integers in order to perform the comparison. Regards, --Phil. 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; > > The above SQL produces no rows. however... > > SELECT jobnumber, jobtitle FROM jobinfo WHERE > jobnumber >= 200 ORDER BY jobnumber ASC; > > produces rows with jobnumber >= 2000 > > if I change the query with jobnumber >= 201, I get > rows >= 2010. > > it is as if there was a silent zero being appended to > the end of my int in the query. What am I missing, > please.