diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2019-10-24 14:17:33 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2019-10-24 14:17:33 +0000 |
commit | 12ba7b002a567836697c36bd9da3285b1ade5ace (patch) | |
tree | aec90de08bc1fe6e1e5cc80420b3a98289b53792 /lib/sqlalchemy/sql/elements.py | |
parent | 38b695748557f4987ef79600ee6267725c0db6dc (diff) | |
parent | 174f6c0605b309f9a430d7b1d355281c9bfbd054 (diff) | |
download | sqlalchemy-12ba7b002a567836697c36bd9da3285b1ade5ace.tar.gz |
Merge "Document unique bound parameters for text()"
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 78c434cff..204530ccd 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -1667,6 +1667,35 @@ class TextClause( timestamp=datetime.datetime(2012, 10, 8, 15, 12, 5) ) + The :meth:`.TextClause.bindparams` method also supports the concept of + **unique** bound parameters. These are parameters that are + "uniquified" on name at statement compilation time, so that multiple + :func:`.text` constructs may be combined together without the names + conflicting. To use this feature, specify the + :paramref:`.BindParameter.unique` flag on each :func:`.bindparam` + object:: + + stmt1 = text("select id from table where name=:name").bindparams( + bindparam("name", value='name1', unique=True) + ) + stmt2 = text("select id from table where name=:name").bindparams( + bindparam("name", value='name2', unique=True) + ) + + union = union_all( + stmt1.columns(column("id")), + stmt2.columns(column("id")) + ) + + The above statement will render as:: + + select id from table where name=:name_1 + UNION ALL select id from table where name=:name_2 + + .. versionadded:: 1.3.11 Added support for the + :paramref:`.BindParameter.unique` flag to work with :func:`.text` + constructs. + """ self._bindparams = new_params = self._bindparams.copy() |