pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedchanging varchar to int
4+ messages / 3 participants
[nested] [flat]
* changing varchar to int
@ 2015-07-23 07:23 Ankur Kaushik <ankurkaushik@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Ankur Kaushik @ 2015-07-23 07:23 UTC (permalink / raw)
To: pgsql-admin
Original column
Column
model | character varying(50) | default
NULL::character varying
^ permalink raw reply [nested|flat] 4+ messages in thread
* changing varchar to int
@ 2015-07-23 07:27 Ankur Kaushik <ankurkaushik@gmail.com>
2015-07-23 09:41 ` Re: changing varchar to int Ian Barwick <ian@2ndquadrant.com>
0 siblings, 1 reply; 4+ messages in thread
From: Ankur Kaushik @ 2015-07-23 07:27 UTC (permalink / raw)
To: pgsql-admin
Original column
Column Type Modifiers
model | character varying(50) | default
NULL::character varying
Required Column
Model integer
=========
ALTER TABLE device ALTER COLUMN model TYPE integer USING (model::integer);
getting below error
ERROR: default for column "model" cannot be cast automatically to type
integer
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: changing varchar to int
2015-07-23 07:27 changing varchar to int Ankur Kaushik <ankurkaushik@gmail.com>
@ 2015-07-23 09:41 ` Ian Barwick <ian@2ndquadrant.com>
2015-07-23 12:55 ` Re: changing varchar to int Matheus de Oliveira <matioli.matheus@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Ian Barwick @ 2015-07-23 09:41 UTC (permalink / raw)
To: Ankur Kaushik <ankurkaushik@gmail.com>; pgsql-admin
On 15/07/23 16:27, Ankur Kaushik wrote:
> Original column
>
>
>
> Column Type Modifiers
> model | character varying(50) | default NULL::character varying
>
>
> Required Column
>
> Model integer
>
>
> =========
> ALTER TABLE device ALTER COLUMN model TYPE integer USING (model::integer);
>
>
> getting below error
>
> ERROR: default for column "model" cannot be cast automatically to type integer
You'll need to drop the column default and re-add it after converting the
column.
Regards
Ian Barwick
--
Ian Barwick http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, RemoteDBA, Training & Services
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: changing varchar to int
2015-07-23 07:27 changing varchar to int Ankur Kaushik <ankurkaushik@gmail.com>
2015-07-23 09:41 ` Re: changing varchar to int Ian Barwick <ian@2ndquadrant.com>
@ 2015-07-23 12:55 ` Matheus de Oliveira <matioli.matheus@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Matheus de Oliveira @ 2015-07-23 12:55 UTC (permalink / raw)
To: Ian Barwick <ian@2ndquadrant.com>; +Cc: Ankur Kaushik <ankurkaushik@gmail.com>; pgsql-admin
On Thu, Jul 23, 2015 at 6:41 AM, Ian Barwick <ian@2ndquadrant.com> wrote:
> > model | character varying(50) | default
> NULL::character varying
> >
> >
> > Required Column
> >
> > Model integer
> >
> >
> > =========
> > ALTER TABLE device ALTER COLUMN model TYPE integer USING
> (model::integer);
> >
> >
> > getting below error
> >
> > ERROR: default for column "model" cannot be cast automatically to type
> integer
>
> You'll need to drop the column default and re-add it after converting the
> column.
You are correct, but in this specific case I don't see much point of having
a DEFAULT NULL anyway (NULL is already the default, when there is no
DEFAULT [confusing? xD ]). I'd just drop the DEFAULT and then change the
type:
ALTER TABLE device
ALTER model DROP DEFAULT,
ALTER model TYPE integer USING (model::integer);
Regards,
--
Matheus de Oliveira
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2015-07-23 12:55 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-07-23 07:23 changing varchar to int Ankur Kaushik <ankurkaushik@gmail.com>
2015-07-23 07:27 changing varchar to int Ankur Kaushik <ankurkaushik@gmail.com>
2015-07-23 09:41 ` Ian Barwick <ian@2ndquadrant.com>
2015-07-23 12:55 ` Matheus de Oliveira <matioli.matheus@gmail.com>
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