D
D
d3coy_002019-10-16 15:59:55
PostgreSQL
d3coy_00, 2019-10-16 15:59:55

Analogue of query to PostgreSQL in sqlalchemy?

Hello, how to translate a query to the database of the form:

select * from db_users where nnr_us = '22' order by nnr_filial, nnr_cod;

In a sqlalchemy query?
Same with the second request: I translated it like this:
SELECT datname FROM pg_database;
table_init = db.Table("pg_database", metadata, autoload=True, autoload_with=engine)
query = db.select([db.text("datname"), table_init])   # select [what] from [where] like in RAW
connection.execute(query)

But I get an error of the form (although the request is working correctly):

C:\Users\123\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\dialects\postgresql\base.py:2972: SAWarning: Did not recognize type 'xid' of column 'datfrozenxid '
"Did not recognize type '%s' of column '%s'" % (attype, name)
C:\Users\123\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\ dialects\postgresql\base.py:2972: SAWarning: Did not recognize type 'xid' of column 'datminmxid'
"Did not recognize type '%s' of column '%s'" % (attype, name)
C:\Users \123\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\dialects\postgresql\base.py:2972: SAWarning: Did not recognize type 'aclitem' of column 'datacl'
"Did not recognize type '%s' of column '%s'" % (attype, name)
C:\Users\123\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\reflection.py:919: SAWarning: index key 'oid' was not located in columns for table ' pg_database'
"columns for table '%s'" % (flavor, c, table_name)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d3coy_00, 2019-10-16
@d3coy_00

engine = db.create_engine(f'postgresql://{username}:{password}@{ip}/db_test')
table_init = db.Table('table_users', metadata, autoload=True, autoload_with=engine)

query = db.select([db.text("*"), table_init]).where(table_init.columns.nnr_us == '22').order_by(table_init.columns.nnr_filial)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question