Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 97C596329C7 for ; Tue, 29 Jun 2010 19:07:17 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 74819-02 for ; Tue, 29 Jun 2010 22:07:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 82599632516 for ; Tue, 29 Jun 2010 19:07:09 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o5TM780f025125 for ; Tue, 29 Jun 2010 18:07:08 -0400 (EDT) To: pgsql-sql@postgresql.org Subject: Re: How to select text field as interger In-reply-to: References: <4C2A5CB4.3000601@s-wise.nl> Comments: In-reply-to Tim Landscheidt message dated "Tue, 29 Jun 2010 21:06:26 -0000" Date: Tue, 29 Jun 2010 18:07:08 -0400 Message-ID: <25124.1277849228@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-5 required=5 tests=BAYES_40=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/119 X-Sequence-Number: 34310 Tim Landscheidt writes: > Jerrel Kemper wrote: >> How can I have the same result set as above >> Name >> 001 >> 01 >> 1 >> with the name field defined as character varying. > Ah! Your excentric formatting and the reference to "serial" > had me wondering if the indentation had any meaning. You can > select the rows where the "Name" field is numerically equal > to 1 by casting it to an integer and then comparing it to 1, > i. e.: > | SELECT Name FROM Test WHERE Name::INT = 1; But note that this is going to throw an error if there are any table rows where the name field *doesn't* contain a valid integer. regards, tom lane