Re: How to select text field as interger

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to select text field as interger
Date: 2010-06-29 22:07:08
Message-ID: 25124.1277849228@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tim Landscheidt <tim(at)tim-landscheidt(dot)de> writes:
> Jerrel Kemper <jerrel(at)s-wise(dot)nl> 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message silly sad 2010-06-30 08:12:46 Re: How to select text field as interger
Previous Message Tim Landscheidt 2010-06-29 21:06:26 Re: How to select text field as interger