I have created a table (MySQL 5.1)
from sqlalchemy import *
def get():
db = create_engine('mysql://user:password@localhost/database')
db.echo = True
metadata = MetaData(db)
feeds = Table('feeds', metadata,
Column('id', Integer, primary_key=True),
Column('title', String(100)),
Column('link', String(255)),
Column('description', String(255)),
)
entries = Table('entries', metadata,
Column('id', Integer, primary_key=True),
Column('fid', Integer),
Column('url', String(255)),
Column('title', String(255)),
Column('content', String(5000)),
Column('date', DateTime),
)
feeds.create()
entries.create()
But when I try to query it:
from sqlalchemy import *
db = create_engine('mysql://user:password@localhost/database')
metadata = MetaData(db)
feeds = Table('feeds', metadata)
s = feeds.select()
result = db.execute(s)
I get an error on the result = db.execute(s) line indicating the following:
sqlalchemy.exc.ProgrammingError: (ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM feeds' at line 2") 'SELECT \nFROM feeds' ()
I'm obviously new to SQLAlchemy, and I have no idea what I'm doing wrong, despite having googled every tutorial on the web and changed this a million times. Any help?
2 Answers 2
I suspect Table.select()
is only for selecting specific columns. For SELECT *
, the expression language tutorial uses this syntax instead:
from sqlalchemy.sql import select
s = select([feeds])
result = db.execute(s)
-
Any progress? We can't really help you more if you don't respond to our first suggestions.ssokolow– ssokolow2010年09月20日 09:44:05 +00:00Commented Sep 20, 2010 at 9:44
there's something missing probably from your feeds.select() call, I'd have another look at the API documentation for this function.