Re: CAST from VARCHAR to INT

From: "Luke Pascoe" <luke(dot)p(at)kmg(dot)co(dot)nz>
To: "Bhuvan A" <bhuvansql(at)myrealbox(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: CAST from VARCHAR to INT
Date: 2003-01-27 20:11:21
Message-ID: 00b401c2c640$42d272d0$3200000a@K2
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)myrealbox(dot)com>
To: "Luke Pascoe" <luke(dot)p(at)kmg(dot)co(dot)nz>
Cc: <pgsql-sql(at)postgresql(dot)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
>
>
>
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2003-01-27 20:14:57 Re: [SQL] Function for adding Money type
Previous Message Marie G. Tuite 2003-01-27 20:06:10 sequence question