summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2017-07-06 09:03:29 -0400
committerGerrit Code Review <gerrit@awstats.zzzcomputing.com>2017-07-06 09:03:29 -0400
commit79285a0f466279f786bcfec89f5a202fb2085d9a (patch)
tree9f35173bea110aef52bd193c723f20a060f4e9f3
parent35ab498a87398e537594a639145bfbba74795476 (diff)
parentfaa6609dac2ce6e55e0f690df3ba88c13133ec5c (diff)
downloadsqlalchemy-79285a0f466279f786bcfec89f5a202fb2085d9a.tar.gz
Merge "Add support for CACHE and ORDER to sequences"
-rw-r--r--doc/build/changelog/changelog_11.rst10
-rw-r--r--lib/sqlalchemy/engine/interfaces.py2
-rw-r--r--lib/sqlalchemy/sql/compiler.py4
-rw-r--r--lib/sqlalchemy/sql/schema.py19
-rw-r--r--test/sql/test_defaults.py12
5 files changed, 44 insertions, 3 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst
index d02beef6a..602be13d2 100644
--- a/doc/build/changelog/changelog_11.rst
+++ b/doc/build/changelog/changelog_11.rst
@@ -21,6 +21,16 @@
.. changelog::
:version: 1.1.12
+ .. change:: cache_order_sequence
+ :tags: feature, oracle, posgresql
+ :versions: 1.2.0b1
+
+ Added new keywords :paramref:`.Sequence.cache` and
+ :paramref:`.Sequence.order` to :class:`.Sequence`, to allow rendering
+ of the CACHE parameter understood by Oracle and PostgreSQL, and the
+ ORDER parameter understood by Oracle. Pull request
+ courtesy David Moore.
+
.. changelog::
:version: 1.1.11
:released: Monday, June 19, 2017
diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py
index 57f8b8dda..3e09e4971 100644
--- a/lib/sqlalchemy/engine/interfaces.py
+++ b/lib/sqlalchemy/engine/interfaces.py
@@ -254,7 +254,7 @@ class Dialect(object):
a dictionary of the form
{'name' : str, 'start' :int, 'increment': int, 'minvalue': int,
'maxvalue': int, 'nominvalue': bool, 'nomaxvalue': bool,
- 'cycle': bool}
+ 'cycle': bool, 'cache': int, 'order': bool}
Additional column attributes may be present.
"""
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 6da064797..53009e2df 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -2560,6 +2560,10 @@ class DDLCompiler(Compiled):
text += " NO MINVALUE"
if create.element.nomaxvalue is not None:
text += " NO MAXVALUE"
+ if create.element.cache is not None:
+ text += " CACHE %d" % create.element.cache
+ if create.element.order is True:
+ text += " ORDER"
if create.element.cycle is not None:
text += " CYCLE"
return text
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index 3ba36e714..9b73eca63 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -2148,8 +2148,8 @@ class Sequence(DefaultGenerator):
def __init__(self, name, start=None, increment=None, minvalue=None,
maxvalue=None, nominvalue=None, nomaxvalue=None, cycle=None,
- schema=None, optional=False, quote=None, metadata=None,
- quote_schema=None,
+ schema=None, cache=None, order=None, optional=False,
+ quote=None, metadata=None, quote_schema=None,
for_update=False):
"""Construct a :class:`.Sequence` object.
@@ -2216,6 +2216,19 @@ class Sequence(DefaultGenerator):
schema name when a :class:`.MetaData` is also present are the same
as that of :paramref:`.Table.schema`.
+ :param cache: optional integer value; number of future values in the
+ sequence which are calculated in advance. Renders the CACHE keyword
+ understood by Oracle and PostgreSQL.
+
+ .. versionadded:: 1.1.12
+
+ :param order: optional boolean value; if true, renders the
+ ORDER keyword, understood by Oracle, indicating the sequence is
+ definitively ordered. May be necessary to provide deterministic
+ ordering using Oracle RAC.
+
+ .. versionadded:: 1.1.12
+
:param optional: boolean value, when ``True``, indicates that this
:class:`.Sequence` object only needs to be explicitly generated
on backends that don't provide another way to generate primary
@@ -2271,6 +2284,8 @@ class Sequence(DefaultGenerator):
self.nominvalue = nominvalue
self.nomaxvalue = nomaxvalue
self.cycle = cycle
+ self.cache = cache
+ self.order = order
self.optional = optional
if schema is BLANK_SCHEMA:
self.schema = schema = None
diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py
index 3cc7e715d..3c4ccc050 100644
--- a/test/sql/test_defaults.py
+++ b/test/sql/test_defaults.py
@@ -963,6 +963,18 @@ class SequenceDDLTest(fixtures.TestBase, testing.AssertsCompiledSQL):
)
self.assert_compile(
+ CreateSequence(Sequence(
+ 'foo_seq', cache=1000, order=True)),
+ "CREATE SEQUENCE foo_seq CACHE 1000 ORDER",
+ )
+
+ self.assert_compile(
+ CreateSequence(Sequence(
+ 'foo_seq', order=True)),
+ "CREATE SEQUENCE foo_seq ORDER",
+ )
+
+ self.assert_compile(
DropSequence(Sequence('foo_seq')),
"DROP SEQUENCE foo_seq",
)