]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
postgres leaves parenthesis off functions only for no-argument ANSI functions accordi...
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 1 Mar 2006 19:43:07 +0000 (19:43 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 1 Mar 2006 19:43:07 +0000 (19:43 +0000)
CHANGES
lib/sqlalchemy/databases/postgres.py

diff --git a/CHANGES b/CHANGES
index f0cd2fbc4197ddc10ea52f0e97f06df99bea2e5a..5a749f13103b01f42774db606608b177f98bfb58 100644 (file)
--- 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.
index 67e3d5cf57a0f6e16c1d3a0014598b5d7bf17fa3..13714ba3e6c672911584aa8686ae5a6baca64172 100644 (file)
@@ -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,