I've got a mostly working custom dialect for Teradata (via ODBC). One
minor issue though is that for func.count() queries the returned datatype
is Python's decimal.Decimal type. The only real issue is that it looks
"weird", to me at least. Is this behavior expected? If I run the
equivalent query in PyODBC the resulting field type is int so I am guessing
that SA is marshalling this to decimal.Decimal somewhere. If not is there
something I should be doing in my custom dialect to marshal func.count() ->
int?
etl@ichabod:~/src/etl/sqlalchemy_teradata$ python simple.py
[(Decimal('1'), 'ed'), (Decimal('1'), 'Foobar'), (Decimal('1'), 'Mike')]
rs[0]: (Decimal('1'), 'ed'), type(rs[0][0]): <class 'decimal.Decimal'>
<snip: simple.py>
import sqlalchemy
from sqlalchemy.dialects import registry
from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, func
from sqlalchemy.orm import sessionmaker
registry.register("teradata", "sqlalchemy_teradata.pyodbc",
"TeradataDialect_pyodbc")
engine = sqlalchemy.create_engine("teradata://td_testsqlatd")
conn = engine.connect()
metadata = MetaData(schema='testsqlatd')
Base = declarative_base(bind=metadata)
class TestUser(Base):
__tablename__ = 'test_user'
id = Column(sqlalchemy.Integer, primary_key=True)
name = Column(sqlalchemy.String(50), nullable=False)
fullname = Column(sqlalchemy.String(50))
pwd = Column(sqlalchemy.String(50))
def __repr__(self):
return "<TestUser(name='%s', fullname='%s', password='%s')>" % (
self.name, self.fullname, self.pwd)
Session = sessionmaker(bind=engine)
session = Session()
first_name = 'ed'; _user1 = TestUser(name=first_name, fullname=('%s Jones'
% first_name.capitalize()), pwd='password')
first_name = 'Mike'; _user2 = TestUser(name=first_name, fullname=('%s
Jones' % first_name.capitalize()), pwd='password')
first_name = 'Foobar'; _user3 = TestUser(name=first_name, fullname=('%s
Jones' % first_name.capitalize()), pwd='password')
session.add_all([_user1, _user2, _user3])
session.commit()
*rs = session.query(func.count(TestUser.name),
TestUser.name).group_by(TestUser.name).all()*
print rs
print "rs[0]: %s, type(rs[0][0]): %s" % (rs[0], type(rs[0][0]))
</snip>
--
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.