summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-11-29 10:13:03 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2018-11-29 23:46:42 -0500
commit3ff39757673b6c1aa8c96c4b951d39afd8e3e379 (patch)
treec44e1bebe0350f04ba81abe69ef4a46ca9878055 /lib/sqlalchemy/sql/compiler.py
parent576b33d46a9418424e94926bf9f02bdad3fc593f (diff)
downloadsqlalchemy-3ff39757673b6c1aa8c96c4b951d39afd8e3e379.tar.gz
Allow optional *args with base AnsiFunction
Amended the :class:`.AnsiFunction` class, the base of common SQL functions like ``CURRENT_TIMESTAMP``, to accept positional arguments like a regular ad-hoc function. This to suit the case that many of these functions on specific backends accept arguments such as "fractional seconds" precision and such. If the function is created with arguments, it renders the the parenthesis and the arguments. If no arguents are present, the compiler generates the non-parenthesized form. Fixes: #4386 Change-Id: Ic492ef177e4987cec99ec4d95f55292be8daa087
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index c2a23a758..80ed707ed 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -111,20 +111,20 @@ OPERATORS = {
}
FUNCTIONS = {
- functions.coalesce: 'coalesce%(expr)s',
+ functions.coalesce: 'coalesce',
functions.current_date: 'CURRENT_DATE',
functions.current_time: 'CURRENT_TIME',
functions.current_timestamp: 'CURRENT_TIMESTAMP',
functions.current_user: 'CURRENT_USER',
functions.localtime: 'LOCALTIME',
functions.localtimestamp: 'LOCALTIMESTAMP',
- functions.random: 'random%(expr)s',
+ functions.random: 'random',
functions.sysdate: 'sysdate',
functions.session_user: 'SESSION_USER',
functions.user: 'USER',
- functions.cube: 'CUBE%(expr)s',
- functions.rollup: 'ROLLUP%(expr)s',
- functions.grouping_sets: 'GROUPING SETS%(expr)s',
+ functions.cube: 'CUBE',
+ functions.rollup: 'ROLLUP',
+ functions.grouping_sets: 'GROUPING SETS',
}
EXTRACT_MAP = {
@@ -927,7 +927,12 @@ class SQLCompiler(Compiled):
if disp:
return disp(func, **kwargs)
else:
- name = FUNCTIONS.get(func.__class__, func.name + "%(expr)s")
+ name = FUNCTIONS.get(func.__class__, None)
+ if name:
+ if func._has_args:
+ name += "%(expr)s"
+ else:
+ name = func.name + "%(expr)s"
return ".".join(list(func.packagenames) + [name]) % \
{'expr': self.function_argspec(func, **kwargs)}