Manipulating MySQL Sets

Carsten Haese carsten.haese at gmail.com
Sat Dec 12 17:11:17 EST 2009


Victor Subervi wrote:
> Hi;
> What type does python consider a MySQL Set??

Let's take a look:

>>> import MySQLdb
>>> conn = MySQLdb.connect(db="carsten", user="blah", passwd="blah")
>>> cur = conn.cursor()
>>> cur.execute("""
...     create table pizza (
...         id integer,
...         toppings set('cheese','sauce','peperoni','mushrooms')
...     )
... """)
0L
>>> cur.execute("""
...     insert into pizza values(1, 'cheese,sauce,peperoni')
... """)
1L
>>> cur.execute("select * from pizza")
1L
>>> rows = cur.fetchall()
>>> toppings = rows[0][1]
>>> print toppings
cheese,sauce,peperoni
>>> print type(toppings)
<type 'str'>


Looks like a string to me.

--
Carsten Haese
http://informixdb.sourceforge.net




More information about the Python-list mailing list