diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-02 17:45:10 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-02 17:45:10 -0400 |
commit | 724012541b7db981efe089f9d4fdc8b944dba267 (patch) | |
tree | 08d12c9780dab8c06ce1b472dbc0e1f2f48f2adf /lib/sqlalchemy/ext/compiler.py | |
parent | e1c47d12bf871bf30a149c7fc167d5d22ddaa222 (diff) | |
download | sqlalchemy-724012541b7db981efe089f9d4fdc8b944dba267.tar.gz |
add FunctionElement example
Diffstat (limited to 'lib/sqlalchemy/ext/compiler.py')
-rw-r--r-- | lib/sqlalchemy/ext/compiler.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/sqlalchemy/ext/compiler.py b/lib/sqlalchemy/ext/compiler.py index dde49e232..20d6aa05f 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 <some function>" ``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``. |