On 8/10/15 4:27 PM, Van Klaveren, Brian N. wrote:
Hi,

I want to get extra type information from a given column after performing a 
query like the following:

results = engine.execute(text("SELECT a, b FROM Attributes"))

It seems the only way to really do this is to use cursor from 
results.cursor.description.

Is this the preferred method, or is there a better alternative?
if you are invoking SQL as strings to the DBAPI, that's the only authoritative source of typing information. This is pretty limited so SQLAlchemy's architecture is oriented towards that of bundling the column typing information with the statement ahead of time, which is carried along and matched up when the result is returned, such as:

execute(text("select a, b from table").columns(a=Numeric, b=Integer)).

That would ensure Numeric and Integer are applied to the result rows as they are returned. To see those types, you'd probably want to look at the original statement:

stmt = text("select a, b from table").columns(a=Numeric, b=Integer)
stmt.c.a.type
stmt.c.b.type


I ask because my database may have decimals larger than double precision, and 
integers larger than 64 bits, and I'm confused as to what the call:
type(row[0]).

...would return in this case.

you're going to get back a symbol that is specific to the DBAPI in use, such as psycopg2.NUMERIC. These aren't the SQLAlchemy type objects.





Brian


--
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.

Reply via email to