pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Carlos Mennens <carlos.mennens@gmail.com>
Cc: Viktor Bojović <viktor.bojovic@gmail.com>
Cc: PostgreSQL (SQL) <pgsql-sql@postgresql.org>
Subject: Re: Finding Max Value in a Row
Date: Sun, 13 May 2012 23:11:43 -0400
Message-ID: <2250.1336965103@sss.pgh.pa.us> (raw)
In-Reply-To: <CAAQLLO4Q=d-HaoDen00yFprqwcu0zmqS30-E+6u55vCFAW2TNQ@mail.gmail.com>
References: <CAAQLLO6EhUi0OUi38BiH+qmgKqY+mY27_hGBQJiC5rbWorXQbw@mail.gmail.com>
	<00ee01cd2fab$1b528b80$51f7a280$@yahoo.com>
	<CAAQLLO7-O26xpisutPoud__iDaco6WtZCr6CBG5OgiwpgvWd6g@mail.gmail.com>
	<CAJu1cLZkviTdxDhY1LynMbuqueCdcQUd5_1Yx+FLD+gVNHqtXA@mail.gmail.com>
	<CAAQLLO4Q=d-HaoDen00yFprqwcu0zmqS30-E+6u55vCFAW2TNQ@mail.gmail.com>

Carlos Mennens <carlos.mennens@gmail.com> writes:
> I'm not understanding why I'm not able to change this column type from
> char to integer?

> forza=# ALTER TABLE customers
> ALTER COLUMN cust_id TYPE integer;
> ERROR:  column "cust_id" cannot be cast to type integer

Try "ALTER ... cust_id TYPE integer USING cust_id::integer".

If you don't specify a USING expression, the command requires an
implicit coercion from one type to the other, and there is none from
char(n) to int.  You can force it with an explicit coercion, though.

It strikes me that "cannot be cast" is a poor choice of words here,
since the types *can* be cast if you try.  Would it be better if the
message said "cannot be cast implicitly to type foo"?  We could also
consider a HINT mentioning use of USING.

			regards, tom lane



view thread (18+ messages)  latest in thread

Message-ID: <2250.1336965103@sss.pgh.pa.us>
Permalink:  ../2250.1336965103@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2250.1336965103@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, carlos.mennens@gmail.com, viktor.bojovic@gmail.com
  Subject: Re: Finding Max Value in a Row
  In-Reply-To: <2250.1336965103@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