Invalid literal for Decimal

1,112 views
Skip to first unread message

V N

unread,
Jun 9, 2012, 10:30:04 PM6/9/12
to pyo...@googlegroups.com
Machine:  RHEL 5.3 x86_64 / Python 2.7.3 / pyodbc-3.0.3
Database: IBM Netezza TwinFin Appliance
ODBC:     NZ odbc client for Linux

Instance
    create table tst(a double, b numeric(9,4), c varchar(10), d char(4));
    insert into tst select 1.01, 1.01, 'aa', 'aa';
    
    select * from tst;
      A   |   B    | C  |  D
    ------+--------+----+------
     1.01 | 1.0100 | aa | aa


TEST
    import pyodbc
    conn = pyodbc.connect("DSN=vntest")
    cursor = conn.cursor()

Test 1
    cursor.execute("select a,c,d from tst")
    for row in cursor:
        print row

OUTPUT: (1.01, 'aa', 'aa  ')

Test 2
    cursor.execute("select b from tst")
    for row in cursor:
        print row

OUTPUT:
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/Python-2.7.3/lib/python2.7/decimal.py", line 548, in __new__
        "Invalid literal for Decimal: %r" % value)
      File "/usr/local/Python-2.7.3/lib/python2.7/decimal.py", line 3866, in _raise_error
        raise error(explanation)
    decimal.InvalidOperation: Invalid literal for Decimal: u''

I would appreciate any help with this.  Thanks.

vijay...@gmail.com

unread,
Jun 9, 2012, 10:36:34 PM6/9/12
to pyo...@googlegroups.com
I can connect to the same db from windows and it seems to work:

Test 3:
cursor.execute("select a,b,c,d from tst")
for row in cursor:
   print row

OUTPUT:  (1.01, Decimal('1.0100'), 'aa', 'aa  ')


Bruce

unread,
Jul 23, 2012, 1:26:46 PM7/23/12
to pyo...@googlegroups.com
I'm seeing this as well on SLES 11.2 linux 2.6.32, pyodbc 3.0.6, unixodbc 2.2.12, libnzodbc.so for Netezza client version 4.6.8.

Any word on this?

miki....@demandmedia.com

unread,
Sep 18, 2013, 4:01:24 PM9/18/13
to pyo...@googlegroups.com
I have the same problem, did you manage to solve this?

rahul...@gmail.com

unread,
Nov 9, 2013, 4:11:39 PM11/9/13
to pyo...@googlegroups.com
I am having the exactly same problem. If the result has 0.00, the pyodbc is failing. If it is any other number then pyodbc seems to be working fine. 

cursor.execute("select 0.00 from temp_view_table limit 1")

row = cursor.fetchone() 

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/local/lib/python2.7/decimal.py", line 548, in __new__

    "Invalid literal for Decimal: %r" % value)

  File "/usr/local/lib/python2.7/decimal.py", line 3844, in _raise_error

    raise error(explanation)

decimal.InvalidOperation: Invalid literal for Decimal: u'.'



netez...@gmail.com

unread,
Jan 14, 2014, 4:01:11 PM1/14/14
to pyo...@googlegroups.com
Did anyone find the solution of this problem? The issue is on Linux box, not on windows. The same code works fine on Windows.
 

gas...@gmail.com

unread,
Jan 30, 2014, 5:50:23 PM1/30/14
to pyo...@googlegroups.com
Having precisely the same issue. Anyone?

kesten.b...@gmail.com

unread,
May 8, 2014, 6:26:55 PM5/8/14
to pyo...@googlegroups.com
Same here.

pyodbc 3.0.7
unixodbc 2.3.2
macosx maverics
python 2.7.6 via homebrew and via anaconda
connecting to vertica 6.1.2
Reply all
Reply to author
Forward
0 new messages