summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--lib/sqlalchemy/databases/postgres.py21
2 files changed, 19 insertions, 5 deletions
diff --git a/CHANGES b/CHANGES
index f0cd2fbc4..5a749f131 100644
--- a/CHANGES
+++ b/CHANGES
@@ -25,7 +25,8 @@ check when object attributes are modified or the object is deleted
- added "convert_unicode" flag to SQLEngine, will treat all String/CHAR types
as Unicode types, with raw-byte/utf-8 translation on the bind parameter and
result set side.
-
+- postgres maintains a list of ANSI functions that must have no parenthesis so
+function calls with no arguments work consistently
0.1.2
- fixed a recursive call in schema that was somehow running 994 times then returning
normally. broke nothing, slowed down everything. thanks to jpellerin for finding this.
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index 67e3d5cf5..13714ba3e 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -6,6 +6,7 @@
import sys, StringIO, string, types, re
+import sqlalchemy.util as util
import sqlalchemy.sql as sql
import sqlalchemy.engine as engine
import sqlalchemy.schema as schema
@@ -101,7 +102,18 @@ class PGBinary(sqltypes.Binary):
class PGBoolean(sqltypes.Boolean):
def get_col_spec(self):
return "BOOLEAN"
-
+
+ANSI_FUNCS = util.HashSet([
+'CURRENT_TIME',
+'CURRENT_TIMESTAMP',
+'CURRENT_DATE',
+'LOCAL_TIME',
+'LOCAL_TIMESTAMP',
+'CURRENT_USER',
+'SESSION_USER',
+'USER'
+])
+
pg2_colspecs = {
sqltypes.Integer : PGInteger,
sqltypes.Smallinteger : PGSmallInteger,
@@ -270,10 +282,11 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
class PGCompiler(ansisql.ANSICompiler):
def visit_function(self, func):
- if len(func.clauses):
- super(PGCompiler, self).visit_function(func)
- else:
+ # PG has a bunch of funcs that explicitly need no parenthesis
+ if func.name.upper() in ANSI_FUNCS and not len(func.clauses):
self.strings[func] = func.name
+ else:
+ super(PGCompiler, self).visit_function(func)
def visit_insert_column(self, column):
# Postgres advises against OID usage and turns it off in 8.1,