"Argument error" in Python using sqlalchemy

Question:

I’m trying to fetch data from database using sqlalchemy in but i get the following error

sqlalchemy.exc.ArgumentError: Column expression, FROM clause, or other columns clause element expected, got [Table(‘params’, MetaData(), Column(‘paramID’, Integer(), table=, primary_key=True, nullable=False), Column(‘item’, String(), table=), Column(‘value’, Float(), table=), schema=None)]. Did you mean to say select(Table(‘params’, MetaData(), Column(‘paramID’, Integer(), table=, primary_key=True, nullable=False), Column(‘item’, String(), table=), Column(‘value’, Float(), table=), schema=None))?

Code:

metadata = MetaData()
    params = Table('params', metadata,
       Column('paramID', Integer(), primary_key=True),
       Column('item', String),
       Column('value', Float),
       Column('buttongroup', String),
       Column('fg_color', String),
       Column('bg_color', String))
                          
            engine = create_engine('...')
            con = engine.connect()
            selpar = select([params]).order_by(params.c.paramID)
            rppar = con.execute(selpar).fetchall()

Why is this happening? Is it an error with the database table or with the python script?

Asked By: qwerty

||

Answers:

As of SQLAlchemy 2.0, select no longer accepts a list as an argument. Provide individual positional arguments instead:

select(params).order_by(params.c.paramID)

select(params.c.item, params.c.value)

select(some_table, some_other_table)
Answered By: snakecharmerb
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.