@caserouter.post("/items/value") async def casevalue(colname: str, db: Session =…
- User
@case_router.post("/items/value") async def case_value(col_name: str, db: Session = Depends(get_db)): # Use the select method to create a select statement that retrieves only the specified column stmt = select([getattr(model_case, col_name)])
# Execute the select statement using the database connection from the session with db.connection() as conn: result = conn.execute(stmt).fetchall() # Extract the values from the result using a list comprehension column_values = [row[0] for row in result] return column_valuessqlalchemy.exc.ArgumentError: Column expression, FROM clause, or other columns clause element expected, got [<sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7ff4804b6220>]. Did you mean to say select(<sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7ff4804b6220>)?
fix the code by this bug
- Assistant
@case_router.post("/items/value") async def case_value(col_name: str, db: Session = Depends(get_db)): # Use the select method to create a select statement that retrieves only the specified column stmt = select([getattr(model_case, col_name)])
# Execute the select statement using the database connection from the session with db.connection() as conn: result = conn.execute(stmt).fetchall() # Extract the values from the result using a list comprehension column_values = [row[0] for row in result] return column_values