Page 1 of 1

UPDATE enum Field

Posted: Fri Sep 11, 2009 8:52 am
by ddragas
hi all

what is SQL syntax to update DB enum field

example

Table Field
someField ENUM('', 'a', 'b', 'c', 'd')

I want to update with values

update someTable SET someField = ('a','c','')

I always get error data truncated for column xxxx

Re: UPDATE enum Field

Posted: Fri Sep 11, 2009 11:22 am
by requinix
Do you want to change the list of values allowed

Code: Select all

ALTER TABLE table MODIFY COLUMN field ENUM(list,of,values) other information
or update a row with a new value?

Code: Select all

UPDATE table SET field = value WHERE condition

Re: UPDATE enum Field

Posted: Fri Sep 11, 2009 1:30 pm
by ddragas
I want to update a row with 3 values so lets say

UPDATE table SET field = 'value1','value2','value3' where bla

Re: UPDATE enum Field

Posted: Fri Sep 11, 2009 2:13 pm
by Darhazer
The column can have only one value (unless the DB does not support arrays and the column is not declared as array type - PostgreSQL support such columns)
That's why the value is truncated

Re: UPDATE enum Field

Posted: Fri Sep 11, 2009 3:23 pm
by ddragas
I understand, but in company where we are using early mentioned way of data storage, it is working in a way a have described. Don't know how to do it, but I need to update this field with multiple values separated by comma (","). Please help me by pointing me in right direction

Thank you in advance

Re: UPDATE enum Field

Posted: Fri Sep 11, 2009 7:32 pm
by requinix
It's not multiple values. It's a string. One value.

Code: Select all

UPDATE table SET field = 'value1,value2,value3' where bla