List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:February 17 2002 6:11am
Subject:Re: inserting into sets
View as plain text  
At 22:47 -0500 2/16/02, John Fulton wrote:
>Would someone please tell me how to insert sets into a MySQL DB? 
>e.g. insert into table_name (x) values ("'a', 'b', 'c', 'd'"); ,
>where x is a set.  I am unsure on what should be inside of the second
>set of parentheses.

A SET value is a single string constructed from individual SET members
separated by commas.

INSERT INTO table_name (x) VALUES('a,b,c,d');


>
>Sorry to be posting a syntax question to the list, but I don't see it
>spelled out in the manual, or at least I am unable to figure it out if
>it is there, and I thought that it would be easy to answer for one of
>you.  I have wasted lots of time searching the web for the syntax, as
>well as experimenting, with no results. 
>
>Thanks,
>   John 
>
>PS:  Here is what I am trying to do in more detail if it helps. 
>
>mysql> describe applicant_ext_skills;
>+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------+-----+---------+-------+
>| Field         | Type
>| Null | Key | Default | Extra |
>+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------+-----+---------+-------+
>| applicant_num |
>int(5) 
>|
>| PRI | 0       |       |
>| unix_arr      |
>set('rlogin','ls','cd','more','kill','cp','mv','rm','mkdir','pwd','rmdir','chmod','quota','du','lprm','man','ftp','grep','ps','lpq','lpr','pipe','redirect','mpage','newuser')
> 
>|
>YES  |     | NULL    |       |
>+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------+-----+---------+-------+
>
>mysql> insert into applicant_ext_skills (applicant_num, unix_arr) values
>(3, "'rlogin', 'ls', 'cd', 'more', 'kill', 'cp', 'mv', 'rm', 'mkdir'");
>Query OK, 1 row affected (0.00 sec)
>
>mysql>
>
>Where the collection of unix commands is the set I am trying to insert. 
>However, nothing seems to be getting stored. 
>
>mysql> select applicant_num from applicant_ext_skills;
>+---------------+
>| applicant_num |
>+---------------+
>|             0 |
>|             1 |
>|             2 |
>|             3 |
>+---------------+
>4 rows in set (0.00 sec)
>
>mysql> select unix_arr from applicant_ext_skills;
>+----------+
>| unix_arr |
>+----------+
>| NULL     |
>|          |
>|          |
>|          |
>+----------+
>4 rows in set (0.00 sec)
>
>mysql>

Thread
inserting into setsJohn Fulton17 Feb
  • Re: inserting into setsPaul DuBois17 Feb