From: Luke Pascoe <luke.p@kmg.co.nz>
To: Bhuvan A <bhuvansql@myrealbox.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: CAST from VARCHAR to INT
Date: Tue, 28 Jan 2003 09:11:21 +1300
Message-ID: <00b401c2c640$42d272d0$3200000a@K2> (raw)
References: <Pine.LNX.4.44.0301241126510.2081-100000@Bhuvan.bksys.co.in>
Sweet, worked the charm, thanks!
P.S. Anyone know why it takes several hours[1] for my posts to come through
the list?
[1] Posted a message at ~9am friday, it got back to me ~4pm!
----- Original Message -----
From: "Bhuvan A" <bhuvansql@myrealbox.com>
To: "Luke Pascoe" <luke.p@kmg.co.nz>
Cc: <pgsql-sql@postgresql.org>
Sent: Friday, January 24, 2003 6:58 PM
Subject: Re: [SQL] CAST from VARCHAR to INT
>
> > (Postgres 7.2.1)
> >
> > I screwed up when I was designing a table a while back and made a column
a
> > VARCHAR that referenced (and should have been) an INT.
> >
> > Now I'm trying to correct my mistake, I've created a new table and I'm
> > trying to INSERT INTO...SELECT the data into it, but it's complaining
that
> > it can't stick a VARCHAR into an INT. All the values in the column are
valid
> > integers (the foreign key sees to that) but even a CAST won't do it.
> >
> > How can I force it to copy/change the values?
> >
>
> varchar cannot be casted to integer directly. Rather we can do it this
> way:
>
> => select your_varchar_field::text::int from your_table;
>
> regards,
> bhuvaneswaran
>
>
>
>
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: luke.p@kmg.co.nz, bhuvansql@myrealbox.com
Subject: Re: CAST from VARCHAR to INT
In-Reply-To: <00b401c2c640$42d272d0$3200000a@K2>
* 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