Hi.

On Thu, Jul 19, 2001 at 07:24:17PM +0100, [EMAIL PROTECTED] wrote:
> 
> I have been searching through the manual and the list archives for the last
> few days regarding a problem I have with the SET column type.
> 
[...]
> For example
> 
> UPDATE users SET user_flags = CONCAT(user_flags,'pass_renew') WHERE user_id = 1

As Don has said, there is only a comma missing. But this will issue a
warning if user_flags is empty (because there is a spare comma. The
following is a variant which doesn't show a warning, but is a bit
more complex:

UPDATE users 
   SET user_flags = CONCAT(type, IF(type=0,"",","), "pass_renew")
 WHERE user_id = 1

The equivalent for removing a flag (without warning) is:

UPDATE users
   SET user_flags = user_flags & ~(1 << FIND_IN_SET("pass_renew",user_flags)-1)
 WHERE user_id = 1

The simplier variant (with warning), would be

UPDATE users
   SET user_flags = REPLACE(user_flags, 'pass_renew', '')
 WHERE user_id = 1 

Note that this requires that there is no further flag which contains
'pass_renew' as a substring.

> Any help or pointers would be greatly appreciated.
> 
> Thanks
> 
> Nick Brandon
> P.S. Please cc my email address as I'm not subscribe to the list - Thanks

Btw, the above has been the result of a discussion on the list between
Ed Heron and me in November 1999, which can be read in the MySQL
mailing list archive:

http://lists.mysql.com/cgi-ez/ezmlm-cgi?1:msn:19582:bpheegjloglblgfaoplk
(btw, the thread is the second match when searching for "update concat set" ;-)

Bye,

        Benjamin.

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to