Permalink
Browse files

Fix postgres lazy import, and unknown type bug

  • Loading branch information...
saulpw committed Oct 24, 2017
1 parent 93a6015 commit 45a2ec37b0b5c84db871ddf8e2d2831734995b9b
Showing with 16 additions and 7 deletions.
  1. +5 −0 requirements.txt
  2. +11 −7 visidata/loaders/postgres.py
View
@@ -1 +1,6 @@
python-dateutil
openpyxl
xlrd
h5py
psycopg2
@@ -1,11 +1,15 @@
from visidata import *
def codeToType(type_code):
tname = psycopg2._psycopg.string_types[type_code].name
if 'INTEGER' in tname:
return int
if 'STRING' in tname:
return str
def codeToType(type_code, colname):
import psycopg2
try:
tname = psycopg2._psycopg.string_types[type_code].name
if 'INTEGER' in tname:
return int
if 'STRING' in tname:
return str
except KeyError:
status('unknown postgres type_code %s for %s' % (type_code, colname))
return anytype
@@ -43,7 +47,7 @@ def query_async(self, qstr, callback=None):
def cursorToColumns(cur):
cols = []
for i, coldesc in enumerate(cur.description):
c = ColumnItem(coldesc.name, i, type=codeToType(coldesc.type_code))
c = ColumnItem(coldesc.name, i, type=codeToType(coldesc.type_code, coldesc.name))
cols.append(c)
return cols

0 comments on commit 45a2ec3

Please sign in to comment.