4

Hello I want to get only one query column using only Table.select(), but I am having a problem

guild_id= 807887608943738881
guild = meta_data.tables['guild_'+str(guild_id)] 

a= engine.execute(guild.select([guild.c.age]).where(guild.c.user_id== user_id)).fetchall()
print(a)

This code returns this

sqlalchemy.exc.ArgumentError: SQL expression for WHERE/HAVING role expected, got [Column('age', INTEGER(display_width=11), table=<guild_807887608943738881>)].

What's wrong with the age column?

1
  • You are using legacy constructs that may be confusing a more current version of SQLAlchemy. Try with engine.connect() as conn: followed by a = conn.execute(select(guild.c.age).where(guild.c.user_id == user_id)).all() Commented Jul 3, 2022 at 23:40

1 Answer 1

1

It appears you are applying an illegal comparison in your where clause, as per this note in the documentation 3rd party integration issue. My first suggestion would be to verify the type in the columns. But since they match (as per your comment), my next thought is to rearrange your query syntax – perhaps your query is attempting to apply a filter on an already instantiated query (which does not allow filtering on additional fields):

# Build your query according to v2.0 selector
q = guild.select(guild.c.age).where(guild.c.user_id== user_id)

# Get your results
res = engine.execute(q).fetchall()
4
  • no, data types are fine
    – Mr. Nom4ik
    Commented Jul 3, 2022 at 14:55
  • I updated my solution @Cergey2202 -- let me know if this solves it for you. If not, I have some other ideas. Commented Jul 3, 2022 at 20:38
  • unfortunately that didn't help either.
    – Mr. Nom4ik
    Commented Jul 3, 2022 at 20:43
  • Same error? @Cergey2202 Commented Jul 3, 2022 at 22:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.