UPDATE enum Field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

UPDATE enum Field

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: UPDATE enum Field

Post 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
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Re: UPDATE enum Field

Post by ddragas »

I want to update a row with 3 values so lets say

UPDATE table SET field = 'value1','value2','value3' where bla
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: UPDATE enum Field

Post 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
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Re: UPDATE enum Field

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: UPDATE enum Field

Post 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
Post Reply