Mike Bayer  committed ccbf357

postgres leaves parenthesis off functions only for no-argument ANSI functions according to a list

  • Participants
  • Parent commits 59f5bfb

Comments (0)

Files changed (2)

 - 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
 - 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.

File lib/sqlalchemy/databases/

 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
 class PGBoolean(sqltypes.Boolean):
     def get_col_spec(self):
         return "BOOLEAN"
+ANSI_FUNCS = util.HashSet([
 pg2_colspecs = {
     sqltypes.Integer : PGInteger,
     sqltypes.Smallinteger : PGSmallInteger,
 class PGCompiler(ansisql.ANSICompiler):
     def visit_function(self, func):
-        if len(func.clauses):
+        # PG has a bunch of funcs that explicitly need no parenthesis
+        if in ANSI_FUNCS and not len(func.clauses):
+            self.strings[func] =
+        else:
             super(PGCompiler, self).visit_function(func)
-        else:
-            self.strings[func] =
     def visit_insert_column(self, column):
         # Postgres advises against OID usage and turns it off in 8.1,