Author: cito
Date: Tue Jan 19 12:00:26 2016
New Revision: 769
Log:
Removed misleading sentence from docs
The insert() method does in fact support inserting into views in newer
PostgreSQL versions or when the necessary rules have been created.
Modified:
branches/4.x/docs/contents/pg/db_wrapper.rst
branches/4.x/pg.py
trunk/docs/contents/pg/db_wrapper.rst
trunk/pg.py
trunk/tests/test_classic_dbwrapper.py
Modified: branches/4.x/docs/contents/pg/db_wrapper.rst
==============================================================================
--- branches/4.x/docs/contents/pg/db_wrapper.rst Tue Jan 19 10:19:38
2016 (r768)
+++ branches/4.x/docs/contents/pg/db_wrapper.rst Tue Jan 19 12:00:26
2016 (r769)
@@ -328,9 +328,6 @@
The dictionary is then, if possible, reloaded with the values actually
inserted in order to pick up values modified by rules, triggers, etc.
-Note: The method currently doesn't support insert into views
-although PostgreSQL does.
-
update -- update a row in a database table
------------------------------------------
Modified: branches/4.x/pg.py
==============================================================================
--- branches/4.x/pg.py Tue Jan 19 10:19:38 2016 (r768)
+++ branches/4.x/pg.py Tue Jan 19 12:00:26 2016 (r769)
@@ -938,9 +938,6 @@
The dictionary is then, if possible, reloaded with the values actually
inserted in order to pick up values modified by rules, triggers, etc.
- Note: The method currently doesn't support insert into views
- although PostgreSQL does.
-
"""
qcl = self._add_schema(cl)
qoid = _oid_key(qcl)
Modified: trunk/docs/contents/pg/db_wrapper.rst
==============================================================================
--- trunk/docs/contents/pg/db_wrapper.rst Tue Jan 19 10:19:38 2016
(r768)
+++ trunk/docs/contents/pg/db_wrapper.rst Tue Jan 19 12:00:26 2016
(r769)
@@ -334,9 +334,6 @@
The dictionary is then reloaded with the values actually inserted in order
to pick up values modified by rules, triggers, etc.
-Note: The method currently doesn't support insert into views
-although PostgreSQL does.
-
update -- update a row in a database table
------------------------------------------
Modified: trunk/pg.py
==============================================================================
--- trunk/pg.py Tue Jan 19 10:19:38 2016 (r768)
+++ trunk/pg.py Tue Jan 19 12:00:26 2016 (r769)
@@ -851,9 +851,6 @@
The dictionary is then reloaded with the values actually inserted in
order to pick up values modified by rules, triggers, etc.
-
- Note: The method currently doesn't support insert into views
- although PostgreSQL does.
"""
if table.endswith('*'): # hint for descendant tables can be ignored
table = table[:-1].rstrip()
Modified: trunk/tests/test_classic_dbwrapper.py
==============================================================================
--- trunk/tests/test_classic_dbwrapper.py Tue Jan 19 10:19:38 2016
(r768)
+++ trunk/tests/test_classic_dbwrapper.py Tue Jan 19 12:00:26 2016
(r769)
@@ -1359,6 +1359,38 @@
self.assertEqual(r['much space'], 2002)
self.assertEqual(r['Questions?'], 'What?')
+ def testInsertIntoView(self):
+ insert = self.db.insert
+ query = self.db.query
+ query("truncate test")
+ q = 'select * from test_view order by i4 limit 3'
+ r = query(q).getresult()
+ self.assertEqual(r, [])
+ r = dict(i4=1234, v4='abcd')
+ insert('test', r)
+ self.assertIsNone(r['i2'])
+ self.assertEqual(r['i4'], 1234)
+ self.assertIsNone(r['i8'])
+ self.assertEqual(r['v4'], 'abcd')
+ self.assertIsNone(r['c4'])
+ r = query(q).getresult()
+ self.assertEqual(r, [(1234, 'abcd')])
+ r = dict(i4=5678, v4='efgh')
+ try:
+ insert('test_view', r)
+ except pg.ProgrammingError as error:
+ if self.db.server_version < 90300:
+ # must setup rules in older PostgreSQL versions
+ self.skipTest('database cannot insert into view')
+ self.fail(str(error))
+ self.assertNotIn('i2', r)
+ self.assertEqual(r['i4'], 5678)
+ self.assertNotIn('i8', r)
+ self.assertEqual(r['v4'], 'efgh')
+ self.assertNotIn('c4', r)
+ r = query(q).getresult()
+ self.assertEqual(r, [(1234, 'abcd'), (5678, 'efgh')])
+
def testUpdate(self):
update = self.db.update
query = self.db.query
@@ -1614,7 +1646,12 @@
self.assertIn('m', self.db.get_attnames('test_table', flush=True))
self.assertEqual('n', self.db.pkey('test_table', flush=True))
s = dict(n=2)
- r = upsert('test_table', s)
+ try:
+ r = upsert('test_table', s)
+ except pg.ProgrammingError as error:
+ if self.db.server_version < 90500:
+ self.skipTest('database does not support upsert')
+ self.fail(str(error))
self.assertIs(r, s)
self.assertEqual(r['n'], 2)
self.assertIsNone(r['m'])
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql