[Tutor] Python in Vertica

Dave Angel d at davea.name
Tue Sep 11 02:24:11 CEST 2012

On 09/10/2012 04:49 PM, C.L. Shetline wrote:
> Python 2.4.3 with Vertica Database on Linux.
> We are migrating from an Informix database to Vertica. We have C code and a lot of
> SQL Stored procedures in our Informix db that are not viable in Vertica. We are trying
> to convert them to Python.
> My first questions is:
> I am using pyodbc to connect to the Vertica database. When I do a select on count and
> print the result it displays as (for example) 4L (which is the row count plus the
> data type). If I try to use the variable in a conditional it does not work. I have no idea how
> to have data value simply be 4 !

Have you  tried printing  type(number_of_rows) ?

> cursor.execute("SELECT COUNT(*) from cv_gls_wkly_misc")
> result = cursor.fetchone()
> number_of_rows = result[0]
> print `number_of_rows

Please copy/paste the code and other messages.  That last line has a
syntax error.

> The data display is the (select count(*)) and a selected row.
And who printed that line out?

> 4L

If you're claiming that's coming from the above print statement (after
fixing the syntax error), then the variable number_of_rows is NOT a long
or an int.  Perhaps it's a string.  Without knowing that, we can't tell
you the best way to fix it.

Perhaps you're not printing it at all, but just entering 
number_of_rows  in the interactive interpreter.  In that case, the
variable might be a long object of value 4.   IF that's the case, then
you can convert it back to an int by   something like number_of_rows =

> [(5185L, 93L, Decimal("42.50"), Decimal("50.36"), Decimal("3406.35"), Decimal("0"), Decimal("78.00"), Decimal("0"), Decimal("66.00"), Decimal("0"), Decimal("12.73"), Decimal("0"), Decimal("0"), Decimal("311.00"))]

And what's that supposed to represent?  And displayed by what means?




More information about the Tutor mailing list