Commit 147aa84c authored by Bruce Momjian's avatar Bruce Momjian

http://archives.postgresql.org/pgsql-bugs/2002-06/msg00086.php and never

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
parent db147006
......@@ -289,23 +289,26 @@ get_type_array(PGresult *result, int nfields)
{
case INT2OID:
case INT4OID:
case INT8OID:
case OIDOID:
typ[j] = 1;
break;
case INT8OID:
typ[j] = 2;
break;
case FLOAT4OID:
case FLOAT8OID:
case NUMERICOID:
typ[j] = 2;
typ[j] = 3;
break;
case CASHOID:
typ[j] = 3;
typ[j] = 4;
break;
default:
typ[j] = 4;
typ[j] = 5;
break;
}
}
......@@ -1797,23 +1800,26 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
{
case INT2OID:
case INT4OID:
case INT8OID:
case OIDOID:
typ[j] = 1;
break;
case INT8OID:
typ[j] = 2;
break;
case FLOAT4OID:
case FLOAT8OID:
case NUMERICOID:
typ[j] = 2;
typ[j] = 3;
break;
case CASHOID:
typ[j] = 3;
typ[j] = 4;
break;
default:
typ[j] = 4;
typ[j] = 5;
break;
}
}
......@@ -1846,10 +1852,14 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
break;
case 2:
val = PyFloat_FromDouble(strtod(s, NULL));
val = PyLong_FromLong(strtol(s, NULL, 10));
break;
case 3:
val = PyFloat_FromDouble(strtod(s, NULL));
break;
case 4:
{
int mult = 1;
......@@ -1946,11 +1956,14 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
{
case INT2OID:
case INT4OID:
case INT8OID:
case OIDOID:
typ[j] = 1;
break;
case INT8OID:
typ[j] = 2;
break;
case FLOAT4OID:
case FLOAT8OID:
case NUMERICOID:
......@@ -1995,10 +2008,14 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
break;
case 2:
val = PyFloat_FromDouble(strtod(s, NULL));
val = PyLong_FromLong(strtol(s, NULL, 10));
break;
case 3:
val = PyFloat_FromDouble(strtod(s, NULL));
break;
case 4:
{
int mult = 1;
......
......@@ -109,11 +109,13 @@ def array_demo(pgcnx):
print "CREATE TABLE sal_emp ("
print " name text,"
print " pay_by_quarter int4[],"
print " pay_by_extra_quarter int8[],"
print " schedule text[][]"
print ")"
pgcnx.query("""CREATE TABLE sal_emp (
name text,
pay_by_quarter int4[],
pay_by_extra_quarter int8[],
schedule text[][])""")
wait_key()
print
......@@ -123,18 +125,22 @@ def array_demo(pgcnx):
print "INSERT INTO sal_emp VALUES ("
print " 'Bill',"
print " '{10000,10000,10000,10000}',"
print " '{9223372036854775800,9223372036854775800,9223372036854775800}',"
print " '{{\"meeting\", \"lunch\"}, {}}')"
print
print "INSERT INTO sal_emp VALUES ("
print " 'Carol',"
print " '{20000,25000,25000,25000}',"
print " '{9223372036854775807,9223372036854775807,9223372036854775807}',"
print " '{{\"talk\", \"consult\"}, {\"meeting\"}}')"
print
pgcnx.query("""INSERT INTO sal_emp VALUES (
'Bill', '{10000,10000,10000,10000}',
'{9223372036854775800,9223372036854775800,9223372036854775800}',
'{{\"meeting\", \"lunch\"}, {}}')""")
pgcnx.query("""INSERT INTO sal_emp VALUES (
'Carol', '{20000,25000,25000,25000}',
'{9223372036854775807,9223372036854775807,9223372036854775807}',
'{{\"talk\", \"consult\"}, {\"meeting\"}}')""")
wait_key()
print
......@@ -148,12 +154,26 @@ def array_demo(pgcnx):
print pgcnx.query("""SELECT name FROM sal_emp WHERE
sal_emp.pay_by_quarter[1] <> sal_emp.pay_by_quarter[2]""")
print
print pgcnx.query("""SELECT name FROM sal_emp WHERE
sal_emp.pay_by_extra_quarter[1] <> sal_emp.pay_by_extra_quarter[2]""")
print
print "-- retrieve third quarter pay of all employees"
print
print "SELECT sal_emp.pay_by_quarter[3] FROM sal_emp"
print
print pgcnx.query("SELECT sal_emp.pay_by_quarter[3] FROM sal_emp")
print
print "-- retrieve third quarter extra pay of all employees"
print
print "SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp"
print pgcnx.query("SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp")
print
print "-- retrieve first two quarters of extra quarter pay of all employees"
print
print "SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp"
print
print pgcnx.query("SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp")
print
print "-- select subarrays"
print
print "SELECT sal_emp.schedule[1:2][1:1] FROM sal_emp WHERE"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment