summaryrefslogtreecommitdiff
path: root/test/dialect/test_postgresql.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-10-20 16:17:17 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-10-20 16:17:17 -0400
commit42ac34a7019edc79f204576237cce23c107c50ca (patch)
tree4040089352c24e471d40d54adfa8160b51968453 /test/dialect/test_postgresql.py
parentdb318240d12becdf183af869b5b863979c55b050 (diff)
downloadsqlalchemy-42ac34a7019edc79f204576237cce23c107c50ca.tar.gz
- Added "as_tuple" flag to pg ARRAY type, returns results
as tuples instead of lists to allow hashing.
Diffstat (limited to 'test/dialect/test_postgresql.py')
-rw-r--r--test/dialect/test_postgresql.py46
1 files changed, 40 insertions, 6 deletions
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py
index 9ad46c189..36aa7f2c6 100644
--- a/test/dialect/test_postgresql.py
+++ b/test/dialect/test_postgresql.py
@@ -1492,8 +1492,8 @@ class ArrayTest(TestBase, AssertsExecutionResults):
metadata = MetaData(testing.db)
arrtable = Table('arrtable', metadata, Column('id', Integer,
primary_key=True), Column('intarr',
- postgresql.PGArray(Integer)), Column('strarr',
- postgresql.PGArray(Unicode()), nullable=False))
+ postgresql.ARRAY(Integer)), Column('strarr',
+ postgresql.ARRAY(Unicode()), nullable=False))
metadata.create_all()
def teardown(self):
@@ -1506,8 +1506,8 @@ class ArrayTest(TestBase, AssertsExecutionResults):
def test_reflect_array_column(self):
metadata2 = MetaData(testing.db)
tbl = Table('arrtable', metadata2, autoload=True)
- assert isinstance(tbl.c.intarr.type, postgresql.PGArray)
- assert isinstance(tbl.c.strarr.type, postgresql.PGArray)
+ assert isinstance(tbl.c.intarr.type, postgresql.ARRAY)
+ assert isinstance(tbl.c.strarr.type, postgresql.ARRAY)
assert isinstance(tbl.c.intarr.type.item_type, Integer)
assert isinstance(tbl.c.strarr.type.item_type, String)
@@ -1575,7 +1575,7 @@ class ArrayTest(TestBase, AssertsExecutionResults):
footable = Table('foo', metadata, Column('id', Integer,
primary_key=True), Column('intarr',
- postgresql.PGArray(Integer), nullable=True))
+ postgresql.ARRAY(Integer), nullable=True))
mapper(Foo, footable)
metadata.create_all()
sess = create_session()
@@ -1607,7 +1607,41 @@ class ArrayTest(TestBase, AssertsExecutionResults):
foo.id = 2
sess.add(foo)
sess.flush()
-
+
+ @testing.provide_metadata
+ def test_tuple_flag(self):
+ assert_raises_message(
+ exc.ArgumentError,
+ "mutable must be set to False if as_tuple is True.",
+ postgresql.ARRAY, Integer, as_tuple=True)
+
+ t1 = Table('t1', metadata,
+ Column('id', Integer, primary_key=True),
+ Column('data', postgresql.ARRAY(String(5), as_tuple=True, mutable=False)),
+ Column('data2', postgresql.ARRAY(Numeric(asdecimal=False), as_tuple=True, mutable=False)),
+ )
+ metadata.create_all()
+ testing.db.execute(t1.insert(), id=1, data=["1","2","3"], data2=[5.4, 5.6])
+ testing.db.execute(t1.insert(), id=2, data=["4", "5", "6"], data2=[1.0])
+ testing.db.execute(t1.insert(), id=3, data=[["4", "5"], ["6", "7"]], data2=[[5.4, 5.6], [1.0, 1.1]])
+
+ r = testing.db.execute(t1.select().order_by(t1.c.id)).fetchall()
+ eq_(
+ r,
+ [
+ (1, ('1', '2', '3'), (5.4, 5.6)),
+ (2, ('4', '5', '6'), (1.0,)),
+ (3, (('4', '5'), ('6', '7')), ((5.4, 5.6), (1.0, 1.1)))
+ ]
+ )
+ # hashable
+ eq_(
+ set(row[1] for row in r),
+ set([('1', '2', '3'), ('4', '5', '6'), (('4', '5'), ('6', '7'))])
+ )
+
+
+
class TimestampTest(TestBase, AssertsExecutionResults):
__only_on__ = 'postgresql'