From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-sql@postgresql.org
Subject: Re: How to select text field as interger
Date: Tue, 29 Jun 2010 18:07:08 -0400
Message-ID: <25124.1277849228@sss.pgh.pa.us> (raw)
In-Reply-To: <m31vbpsg4t.fsf@passepartout.tim-landscheidt.de>
References: <4C2A5CB4.3000601@s-wise.nl>
<m31vbpsg4t.fsf@passepartout.tim-landscheidt.de>
Tim Landscheidt <tim@tim-landscheidt.de> writes:
> Jerrel Kemper <jerrel@s-wise.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: How to select text field as interger
In-Reply-To: <25124.1277849228@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox