Skip to content

Commit 147aa84

Browse files
committed
saw a fix offered up. Since I'm gearing up to use Postgres and Python soon, I figured I'd have a hand at trying to get this sucker addressed. Apologies if this has already been plugged. I looked in the archives and never saw a response. At any rate, I must admit I don't think I fully understand the implications of some of the changes I made even though they appear to be straight forward. We all know the devil is in the details. Anyone more knowledgeable is requested to review my changes. :( I also updated the advanced.py script in a somewhat nonsensical fashion to make use of an int8 field in an effort to test this change. It seems to run okay, however, this is by no means an all exhaustive test. So, it's possible that a bumpy road may lay ahead for some. On the other hand...overflows (hopefully) previously lurked (long -> int conversion). Greg Copeland
1 parent db14700 commit 147aa84

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

src/interfaces/python/pgmodule.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,23 +289,26 @@ get_type_array(PGresult *result, int nfields)
289289
{
290290
case INT2OID:
291291
case INT4OID:
292-
case INT8OID:
293292
case OIDOID:
294293
typ[j] = 1;
295294
break;
296295

296+
case INT8OID:
297+
typ[j] = 2;
298+
break;
299+
297300
case FLOAT4OID:
298301
case FLOAT8OID:
299302
case NUMERICOID:
300-
typ[j] = 2;
303+
typ[j] = 3;
301304
break;
302305

303306
case CASHOID:
304-
typ[j] = 3;
307+
typ[j] = 4;
305308
break;
306309

307310
default:
308-
typ[j] = 4;
311+
typ[j] = 5;
309312
break;
310313
}
311314
}
@@ -1797,23 +1800,26 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
17971800
{
17981801
case INT2OID:
17991802
case INT4OID:
1800-
case INT8OID:
18011803
case OIDOID:
18021804
typ[j] = 1;
18031805
break;
18041806

1807+
case INT8OID:
1808+
typ[j] = 2;
1809+
break;
1810+
18051811
case FLOAT4OID:
18061812
case FLOAT8OID:
18071813
case NUMERICOID:
1808-
typ[j] = 2;
1814+
typ[j] = 3;
18091815
break;
18101816

18111817
case CASHOID:
1812-
typ[j] = 3;
1818+
typ[j] = 4;
18131819
break;
18141820

18151821
default:
1816-
typ[j] = 4;
1822+
typ[j] = 5;
18171823
break;
18181824
}
18191825
}
@@ -1846,10 +1852,14 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
18461852
break;
18471853

18481854
case 2:
1849-
val = PyFloat_FromDouble(strtod(s, NULL));
1855+
val = PyLong_FromLong(strtol(s, NULL, 10));
18501856
break;
18511857

18521858
case 3:
1859+
val = PyFloat_FromDouble(strtod(s, NULL));
1860+
break;
1861+
1862+
case 4:
18531863
{
18541864
int mult = 1;
18551865

@@ -1946,11 +1956,14 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
19461956
{
19471957
case INT2OID:
19481958
case INT4OID:
1949-
case INT8OID:
19501959
case OIDOID:
19511960
typ[j] = 1;
19521961
break;
19531962

1963+
case INT8OID:
1964+
typ[j] = 2;
1965+
break;
1966+
19541967
case FLOAT4OID:
19551968
case FLOAT8OID:
19561969
case NUMERICOID:
@@ -1995,10 +2008,14 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
19952008
break;
19962009

19972010
case 2:
1998-
val = PyFloat_FromDouble(strtod(s, NULL));
2011+
val = PyLong_FromLong(strtol(s, NULL, 10));
19992012
break;
20002013

20012014
case 3:
2015+
val = PyFloat_FromDouble(strtod(s, NULL));
2016+
break;
2017+
2018+
case 4:
20022019
{
20032020
int mult = 1;
20042021

src/interfaces/python/tutorial/advanced.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,13 @@ def array_demo(pgcnx):
109109
print "CREATE TABLE sal_emp ("
110110
print " name text,"
111111
print " pay_by_quarter int4[],"
112+
print " pay_by_extra_quarter int8[],"
112113
print " schedule text[][]"
113114
print ")"
114115
pgcnx.query("""CREATE TABLE sal_emp (
115116
name text,
116117
pay_by_quarter int4[],
118+
pay_by_extra_quarter int8[],
117119
schedule text[][])""")
118120
wait_key()
119121
print
@@ -123,18 +125,22 @@ def array_demo(pgcnx):
123125
print "INSERT INTO sal_emp VALUES ("
124126
print " 'Bill',"
125127
print " '{10000,10000,10000,10000}',"
128+
print " '{9223372036854775800,9223372036854775800,9223372036854775800}',"
126129
print " '{{\"meeting\", \"lunch\"}, {}}')"
127130
print
128131
print "INSERT INTO sal_emp VALUES ("
129132
print " 'Carol',"
130133
print " '{20000,25000,25000,25000}',"
134+
print " '{9223372036854775807,9223372036854775807,9223372036854775807}',"
131135
print " '{{\"talk\", \"consult\"}, {\"meeting\"}}')"
132136
print
133137
pgcnx.query("""INSERT INTO sal_emp VALUES (
134138
'Bill', '{10000,10000,10000,10000}',
139+
'{9223372036854775800,9223372036854775800,9223372036854775800}',
135140
'{{\"meeting\", \"lunch\"}, {}}')""")
136141
pgcnx.query("""INSERT INTO sal_emp VALUES (
137142
'Carol', '{20000,25000,25000,25000}',
143+
'{9223372036854775807,9223372036854775807,9223372036854775807}',
138144
'{{\"talk\", \"consult\"}, {\"meeting\"}}')""")
139145
wait_key()
140146
print
@@ -148,12 +154,26 @@ def array_demo(pgcnx):
148154
print pgcnx.query("""SELECT name FROM sal_emp WHERE
149155
sal_emp.pay_by_quarter[1] <> sal_emp.pay_by_quarter[2]""")
150156
print
157+
print pgcnx.query("""SELECT name FROM sal_emp WHERE
158+
sal_emp.pay_by_extra_quarter[1] <> sal_emp.pay_by_extra_quarter[2]""")
159+
print
151160
print "-- retrieve third quarter pay of all employees"
152161
print
153162
print "SELECT sal_emp.pay_by_quarter[3] FROM sal_emp"
154163
print
155164
print pgcnx.query("SELECT sal_emp.pay_by_quarter[3] FROM sal_emp")
156165
print
166+
print "-- retrieve third quarter extra pay of all employees"
167+
print
168+
print "SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp"
169+
print pgcnx.query("SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp")
170+
print
171+
print "-- retrieve first two quarters of extra quarter pay of all employees"
172+
print
173+
print "SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp"
174+
print
175+
print pgcnx.query("SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp")
176+
print
157177
print "-- select subarrays"
158178
print
159179
print "SELECT sal_emp.schedule[1:2][1:1] FROM sal_emp WHERE"

0 commit comments

Comments
 (0)