Re: Finding Max Value in a Row

From: Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com>
To: Viktor Bojović <viktor(dot)bojovic(at)gmail(dot)com>, "PostgreSQL (SQL)" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Finding Max Value in a Row
Date: 2012-05-14 02:38:01
Message-ID: CAAQLLO4Q=d-HaoDen00yFprqwcu0zmqS30-E+6u55vCFAW2TNQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, May 11, 2012 at 4:42 PM, Viktor Bojović
<viktor(dot)bojovic(at)gmail(dot)com> wrote:
> you can convert from type to type using ::varchar or ::char(size) or
> ::integer
> so you can use sequence but you will have to convert it's result to suitable
> type (that can also be put in default value of user_id attribute)

I'm not understanding why I'm not able to change this column type from
char to integer? There are no non-numeric existing characters stored
in this particular column (cust_id). I've gone so far as to delete the
foreign key and primary key that associated with this column (cust_id)
but still I get a generic error:

forza=# \d customers
Table "public.customers"
Column | Type | Modifiers
--------------+------------------------+-----------
cust_id | character(10) |
cust_name | character varying(100) | not null
cust_address | character(50) |
cust_city | character(50) |
cust_state | character(5) |
cust_zip | character(10) |
cust_country | character(50) |
cust_contact | character(50) |
cust_email | character(255) |

All the values in the column in question:

forza=# SELECT cust_id
forza-# FROM customers
forza-# ORDER BY cust_id;
cust_id
------------
10001
10002
10003
10004
10005
(5 rows)

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

When I view the logs in /var/log/postgresql.log, I see the same exact
error printed above so I can only assume the problem is invalid SQL
statement or I'm breaking some ANSI SQL rule. Can someone please help
me understand how I can change the data type for this column? I've
deleted the primary key constraint so I don't know if that was a good
/ bad idea. Thanks for any info / help!

-Carlos

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2012-05-14 03:11:43 Re: Finding Max Value in a Row
Previous Message John Fabiani 2012-05-13 20:01:23 Re: syncing - between databases