From: Mike Bayer Date: Fri, 2 Apr 2010 21:45:10 +0000 (-0400) Subject: add FunctionElement example X-Git-Tag: rel_0_6_0~64^2~5^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=724012541b7db981efe089f9d4fdc8b944dba267;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git add FunctionElement example --- diff --git a/lib/sqlalchemy/ext/compiler.py b/lib/sqlalchemy/ext/compiler.py index dde49e232e..20d6aa05f8 100644 --- a/lib/sqlalchemy/ext/compiler.py +++ b/lib/sqlalchemy/ext/compiler.py @@ -147,8 +147,23 @@ A big part of using the compiler extension is subclassing SQLAlchemy expression function or stored procedure type of call. Since most databases support statements along the line of "SELECT FROM " ``FunctionElement`` adds in the ability to be used in the FROM clause of a - ``select()`` construct. - + ``select()`` construct:: + + from sqlalchemy.sql.expression import FunctionElement + + class coalesce(FunctionElement): + name = 'coalesce' + + @compiles(coalesce) + def compile(element, compiler, **kw): + return "coalesce(%s)" % compiler.process(element.clauses) + + @compiles(coalesce, 'oracle') + def compile(element, compiler, **kw): + if len(element.clauses) > 2: + raise TypeError("coalesce only supports two arguments on Oracle") + return "nvl(%s)" % compiler.process(element.clauses) + * :class:`~sqlalchemy.schema.DDLElement` - The root of all DDL expressions, like CREATE TABLE, ALTER TABLE, etc. Compilation of ``DDLElement`` subclasses is issued by a ``DDLCompiler`` instead of a ``SQLCompiler``.