diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-21 16:32:38 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-21 16:32:38 -0400 |
commit | d5609d77841ab4e607e6b372a15396b38ddace9a (patch) | |
tree | eb6faaeed9e58ed6d87b675eb0c27f363fc4de56 /lib/sqlalchemy/dialects/postgresql/base.py | |
parent | 2272f30af435c5283157724bbb16fb0a573159ce (diff) | |
download | sqlalchemy-d5609d77841ab4e607e6b372a15396b38ddace9a.tar.gz |
- [feature] Added "MATCH" clause to ForeignKey,
ForeignKeyConstraint, courtesy Ryan Kelly.
[ticket:2502]
- [feature] Added support for DELETE and UPDATE from
an alias of a table, which would assumedly
be related to itself elsewhere in the query,
courtesy Ryan Kelly. [ticket:2507]
- [feature] Added support for the Postgresql ONLY
keyword, which can appear corresponding to a
table in a SELECT, UPDATE, or DELETE statement.
The phrase is established using with_hint().
Courtesy Ryan Kelly [ticket:2506]
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 7363b2334..248d39ed6 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -114,6 +114,24 @@ use the :meth:`._UpdateBase.returning` method on a per-statement basis:: where(table.c.name=='foo') print result.fetchall() +FROM ONLY ... +------------------------ + +The dialect supports PostgreSQL's ONLY keyword for targeting only a particular +table in an inheritance hierarchy. This can be used to produce the +``SELECT ... FROM ONLY``, ``UPDATE ONLY ...``, and ``DELETE FROM ONLY ...`` +syntaxes. It uses SQLAlchemy's hints mechanism: + + # SELECT ... FROM ONLY ... + result = table.select().with_hint(table, 'ONLY', 'postgresql') + print result.fetchall() + + # UPDATE ONLY ... + table.update(values=dict(foo='bar')).with_hint('ONLY', + dialect_name='postgresql') + + # DELETE FROM ONLY ... + table.delete().with_hint('ONLY', dialect_name='postgresql') .. _postgresql_indexes: @@ -642,6 +660,11 @@ class PGCompiler(compiler.SQLCompiler): text += " OFFSET " + self.process(sql.literal(select._offset)) return text + def format_from_hint_text(self, sqltext, table, hint, iscrud): + if hint.upper() != 'ONLY': + raise exc.CompileError("Unrecognized hint: %r" % hint) + return "ONLY " + sqltext + def get_select_precolumns(self, select): if select._distinct is not False: if select._distinct is True: |