HI everyone,
I'm trying to use sqlalchemy (0.9.10) to retrieve the number of rows of
table in PostgreSQL, here a stub of the code:
import sqlalchemy
from sqlalchemy import select, create_engine, MetaData, Table, Column
import datetime
engine =
create_engine('postgresql+pg8000://postgres:password@localhost/mydb')
metadata = MetaData(engine)
tab = Table('test', metadata,
Column('c1', sqlalchemy.INTEGER)
)
tab.create()
tab.insert().values(c1=123456).execute()
res = select([sqlalchemy.func.count('*')], None,
from_obj=[tab]).execute().fetchall()
print res
And here is the error I get:
Traceback (most recent call last):
File "C:\Users\Impara 01\Desktop\t.py", line 13, in <module>
res = select([sqlalchemy.func.count('*')], None,
from_obj=[tab]).execute().fetchall()
File "C:\Python27\lib\site-packages\sqlalchemy\sql\base.py", line 386, in
execute
return e._execute_clauseelement(self, multiparams, params)
File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line
1868, in _execute_clauseelement
return connection._execute_clauseelement(elem, multiparams, params)
File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 938,
in _execute_clauseelement
compiled_sql, distilled_params
File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line
1070, in _execute_context
context)
File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line
1271, in _handle_dbapi_exception
exc_info
File "C:\Python27\lib\site-packages\sqlalchemy\util\compat.py", line 199,
in raise_from_cause
reraise(type(exception), exception, tb=exc_tb)
File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line
1063, in _execute_context
context)
File "C:\Python27\lib\site-packages\sqlalchemy\engine\default.py", line
442, in do_execute
cursor.execute(statement, parameters)
File "C:\Python27\lib\site-packages\pg8000\core.py", line 568, in execute
self._c.execute(self, operation, args)
File "C:\Python27\lib\site-packages\pg8000\core.py", line 1613, in execute
self.handle_messages(cursor)
File "C:\Python27\lib\site-packages\pg8000\core.py", line 1761, in
handle_messages
raise self.error
sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('ERROR', '42P18',
'could not determine data type of parameter $1') u'SELECT count(%s) AS
count_1 \nFROM test' ('*',)
It seems that somehow the query is not formatted correctly....any hint?
Thanks in advance!
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.