Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id E07246335A5 for ; Tue, 29 Jun 2010 18:06:47 -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 52841-07 for ; Tue, 29 Jun 2010 21:06:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id B5E626335A8 for ; Tue, 29 Jun 2010 18:06:40 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OTi0q-0002Ie-BS for pgsql-sql@postgresql.org; Tue, 29 Jun 2010 23:06:36 +0200 Received: from e177122026.adsl.alicedsl.de ([85.177.122.26]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 29 Jun 2010 23:06:36 +0200 Received: from tim by e177122026.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 29 Jun 2010 23:06:36 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: pgsql-sql@postgresql.org To: pgsql-sql@postgresql.org From: Tim Landscheidt Subject: Re: How to select text field as interger Date: Tue, 29 Jun 2010 21:06:26 +0000 Organization: Lines: 53 Message-ID: References: <4C2A5CB4.3000601@s-wise.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: e177122026.adsl.alicedsl.de Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:iTYWobSvbMDr9TV6xO2ytHch7vc= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.79 tagged_above=-5 required=5 tests=BAYES_50=0.8, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/118 X-Sequence-Number: 34309 Jerrel Kemper wrote: > My table consist off the following fields > CREATE TABLE test > ( > id bigserial NOT NULL, > name character varying(100), > CONSTRAINT logs_pkey PRIMARY KEY (log_id) > ) > with value : > ID Name > 1 001 > 2 01 > 3 1 > 4 11 > Select name from test where name = '1' ; > results in : > Name > 1 > If the 'Name' field was define as a serial the result set ought to be > Name > 001 > 01 > 1 > Question? > 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; Tim