I created a small development database for practice. It has a table cities
with columns cityname
and state
. The cityname
in there is 'Cincinnati', long name right?
mytestdb=# SELECT * FROM cities;
cityid | cityname | state
--------+------------+-------
12345 | Cincinnati | Ohio
(1 row)
I am unclear as to how and why I am getting this error message upon attempting to add 'San Francisco'.
mytestdb=# INSERT INTO cities VALUES ('San Francisco','CA'); ERROR: value too long for type character varying(5)
Best Answer
So first, what's the difference..
Here is the output
So..
And further, if
Cincinnati
was in avarchar(5)
, it'd have to get truncated.So the problem is your
cityid
. It isvarchar(5)
. you probably want that to be anint
anyway -- it'll be more compact and faster. SoALTER
the table and fix it.As a side note... maybe someday PostgreSQL will speak column names in error messages. until then at least it's more verbose than SQL Server.