pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tim Landscheidt <tim@tim-landscheidt.de>
To: pgsql-sql@postgresql.org
Subject: Re: How to select text field as interger
Date: Tue, 29 Jun 2010 21:06:26 +0000
Message-ID: <m31vbpsg4t.fsf@passepartout.tim-landscheidt.de> (raw)
References: <4C2A5CB4.3000601@s-wise.nl>

Jerrel Kemper <jerrel@s-wise.nl> 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




view thread (4+ messages)  latest in thread

Message-ID: <m31vbpsg4t.fsf@passepartout.tim-landscheidt.de>
Permalink:  ../m31vbpsg4t.fsf@passepartout.tim-landscheidt.de/
Also on:    postgresql.org/message-id/m31vbpsg4t.fsf@passepartout.tim-landscheidt.de

 · 

reply

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: tim@tim-landscheidt.de
  Subject: Re: How to select text field as interger
  In-Reply-To: <m31vbpsg4t.fsf@passepartout.tim-landscheidt.de>

* 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