~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to doc/core/selectable.html

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2013-10-28 22:29:40 UTC
  • mfrom: (1.4.24)
  • Revision ID: package-import@ubuntu.com-20131028222940-wvyqffl4g617caun
Tags: 0.8.3-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
2
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
3
 
 
4
<html xmlns="http://www.w3.org/1999/xhtml">
 
5
    <head>
 
6
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
7
        
 
8
        <title>
 
9
            
 
10
    
 
11
                Selectables, Tables, FROM objects
 
12
             &mdash; 
 
13
    SQLAlchemy 0.8 Documentation
 
14
 
 
15
        </title>
 
16
        
 
17
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
 
18
    <link rel="stylesheet" href="../_static/docs.css" type="text/css" />
 
19
 
 
20
    <script type="text/javascript">
 
21
      var DOCUMENTATION_OPTIONS = {
 
22
          URL_ROOT:    '../',
 
23
          VERSION:     '0.8.3',
 
24
          COLLAPSE_MODINDEX: false,
 
25
          FILE_SUFFIX: '.html'
 
26
      };
 
27
    </script>
 
28
        <script type="text/javascript" src="../_static/jquery.js"></script>
 
29
        <script type="text/javascript" src="../_static/underscore.js"></script>
 
30
        <script type="text/javascript" src="../_static/doctools.js"></script>
 
31
    <script type="text/javascript" src="../_static/init.js"></script>
 
32
    <link rel="index" title="Index" href="../genindex.html" />
 
33
    <link rel="search" title="Search" href="../search.html" />
 
34
        <link rel="copyright" title="Copyright" href="../copyright.html" />
 
35
    <link rel="top" title="SQLAlchemy 0.8 Documentation" href="../index.html" />
 
36
        <link rel="up" title="SQL Statements and Expressions API" href="expression_api.html" />
 
37
        <link rel="next" title="Insert, Updates, Deletes" href="dml.html" />
 
38
        <link rel="prev" title="Column Elements and Expressions" href="sqlelement.html" />
 
39
 
 
40
    </head>
 
41
    <body>
 
42
        
 
43
 
 
44
 
 
45
 
 
46
 
 
47
 
 
48
 
 
49
 
 
50
 
 
51
 
 
52
 
 
53
<div id="docs-container">
 
54
 
 
55
 
 
56
 
 
57
<div id="docs-header">
 
58
    <h1>SQLAlchemy 0.8 Documentation</h1>
 
59
 
 
60
    <div id="docs-search">
 
61
    Search:
 
62
    <form class="search" action="../search.html" method="get">
 
63
      <input type="text" name="q" size="18" /> <input type="submit" value="Search" />
 
64
      <input type="hidden" name="check_keywords" value="yes" />
 
65
      <input type="hidden" name="area" value="default" />
 
66
    </form>
 
67
    </div>
 
68
 
 
69
    <div id="docs-version-header">
 
70
        Release: <span class="version-num">0.8.3</span> | Release Date: October 26, 2013
 
71
 
 
72
 
 
73
    </div>
 
74
 
 
75
</div>
 
76
 
 
77
<div id="docs-top-navigation">
 
78
    <div id="docs-top-page-control" class="docs-navigation-links">
 
79
        <ul>
 
80
            <li>Prev:
 
81
            <a href="sqlelement.html" title="previous chapter">Column Elements and Expressions</a>
 
82
            </li>
 
83
            <li>Next:
 
84
            <a href="dml.html" title="next chapter">Insert, Updates, Deletes</a>
 
85
            </li>
 
86
 
 
87
        <li>
 
88
            <a href="../contents.html">Table of Contents</a> |
 
89
            <a href="../genindex.html">Index</a>
 
90
            | <a href="../_sources/core/selectable.txt">view source
 
91
        </li>
 
92
        </ul>
 
93
    </div>
 
94
 
 
95
    <div id="docs-navigation-banner">
 
96
        <a href="../index.html">SQLAlchemy 0.8 Documentation</a>
 
97
                » <a href="index.html" title="SQLAlchemy Core">SQLAlchemy Core</a>
 
98
                » <a href="expression_api.html" title="SQL Statements and Expressions API">SQL Statements and Expressions API</a>
 
99
        » 
 
100
                Selectables, Tables, FROM objects
 
101
             
 
102
 
 
103
        <h2>
 
104
            
 
105
                Selectables, Tables, FROM objects
 
106
            
 
107
        </h2>
 
108
    </div>
 
109
 
 
110
</div>
 
111
 
 
112
<div id="docs-body-container">
 
113
 
 
114
    <div id="docs-sidebar">
 
115
    <h3><a href="../index.html">Table of Contents</a></h3>
 
116
    <ul>
 
117
<li><a class="reference internal" href="#">Selectables, Tables, FROM objects</a></li>
 
118
</ul>
 
119
 
 
120
 
 
121
    <h4>Previous Topic</h4>
 
122
    <p>
 
123
    <a href="sqlelement.html" title="previous chapter">Column Elements and Expressions</a>
 
124
    </p>
 
125
    <h4>Next Topic</h4>
 
126
    <p>
 
127
    <a href="dml.html" title="next chapter">Insert, Updates, Deletes</a>
 
128
    </p>
 
129
 
 
130
 
 
131
    <h4>Quick Search</h4>
 
132
    <p>
 
133
    <form class="search" action="../search.html" method="get">
 
134
      <input type="text" name="q" size="18" /> <input type="submit" value="Search" />
 
135
      <input type="hidden" name="check_keywords" value="yes" />
 
136
      <input type="hidden" name="area" value="default" />
 
137
    </form>
 
138
    </p>
 
139
 
 
140
    </div>
 
141
 
 
142
    <div id="docs-body" class="withsidebar" >
 
143
        
 
144
<div class="section" id="selectables-tables-from-objects">
 
145
<h1>Selectables, Tables, FROM objects<a class="headerlink" href="#selectables-tables-from-objects" title="Permalink to this headline">¶</a></h1>
 
146
<p>The term &#8220;selectable&#8221; refers to any object that rows can be selected from;
 
147
in SQLAlchemy, these objects descend from <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> and their
 
148
distinguishing feature is their <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.c" title="sqlalchemy.sql.expression.FromClause.c"><tt class="xref py py-attr docutils literal"><span class="pre">FromClause.c</span></tt></a> attribute, which is
 
149
a namespace of all the columns contained within the FROM clause (these
 
150
elements are themselves <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> subclasses).</p>
 
151
<span class="target" id="module-sqlalchemy.sql.expression"></span><dl class="function">
 
152
<dt id="sqlalchemy.sql.expression.alias">
 
153
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">alias</tt><big>(</big><em>selectable</em>, <em>name=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.alias" title="Permalink to this definition">¶</a></dt>
 
154
<dd><p>Return an <a class="reference internal" href="#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a> object.</p>
 
155
<p>An <a class="reference internal" href="#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a> represents any <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>
 
156
with an alternate name assigned within SQL, typically using the <tt class="docutils literal"><span class="pre">AS</span></tt>
 
157
clause when generated, e.g. <tt class="docutils literal"><span class="pre">SELECT</span> <span class="pre">*</span> <span class="pre">FROM</span> <span class="pre">table</span> <span class="pre">AS</span> <span class="pre">aliasname</span></tt>.</p>
 
158
<p>Similar functionality is available via the
 
159
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.alias" title="sqlalchemy.sql.expression.FromClause.alias"><tt class="xref py py-meth docutils literal"><span class="pre">alias()</span></tt></a> method
 
160
available on all <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> subclasses.</p>
 
161
<p>When an <a class="reference internal" href="#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a> is created from a <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object,
 
162
this has the effect of the table being rendered
 
163
as <tt class="docutils literal"><span class="pre">tablename</span> <span class="pre">AS</span> <span class="pre">aliasname</span></tt> in a SELECT statement.</p>
 
164
<p>For <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> objects, the effect is that of creating a named
 
165
subquery, i.e. <tt class="docutils literal"><span class="pre">(select</span> <span class="pre">...)</span> <span class="pre">AS</span> <span class="pre">aliasname</span></tt>.</p>
 
166
<p>The <tt class="docutils literal"><span class="pre">name</span></tt> parameter is optional, and provides the name
 
167
to use in the rendered SQL.  If blank, an &#8220;anonymous&#8221; name
 
168
will be deterministically generated at compile time.
 
169
Deterministic means the name is guaranteed to be unique against
 
170
other constructs used in the same statement, and will also be the
 
171
same name for each successive compilation of the same statement
 
172
object.</p>
 
173
<table class="docutils field-list" frame="void" rules="none">
 
174
<col class="field-name" />
 
175
<col class="field-body" />
 
176
<tbody valign="top">
 
177
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
178
<li><strong>selectable</strong> &#8211; any <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> subclass,
 
179
such as a table, select statement, etc.</li>
 
180
<li><strong>name</strong> &#8211; string name to be assigned as the alias.
 
181
If <tt class="docutils literal"><span class="pre">None</span></tt>, a name will be deterministically generated
 
182
at compile time.</li>
 
183
</ul>
 
184
</td>
 
185
</tr>
 
186
</tbody>
 
187
</table>
 
188
</dd></dl>
 
189
 
 
190
<dl class="function">
 
191
<dt id="sqlalchemy.sql.expression.except_">
 
192
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">except_</tt><big>(</big><em>*selects</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.except_" title="Permalink to this definition">¶</a></dt>
 
193
<dd><p>Return an <tt class="docutils literal"><span class="pre">EXCEPT</span></tt> of multiple selectables.</p>
 
194
<p>The returned object is an instance of
 
195
<a class="reference internal" href="#sqlalchemy.sql.expression.CompoundSelect" title="sqlalchemy.sql.expression.CompoundSelect"><tt class="xref py py-class docutils literal"><span class="pre">CompoundSelect</span></tt></a>.</p>
 
196
<dl class="docutils">
 
197
<dt>*selects</dt>
 
198
<dd>a list of <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> instances.</dd>
 
199
<dt>**kwargs</dt>
 
200
<dd>available keyword arguments are the same as those of
 
201
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.</dd>
 
202
</dl>
 
203
</dd></dl>
 
204
 
 
205
<dl class="function">
 
206
<dt id="sqlalchemy.sql.expression.except_all">
 
207
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">except_all</tt><big>(</big><em>*selects</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.except_all" title="Permalink to this definition">¶</a></dt>
 
208
<dd><p>Return an <tt class="docutils literal"><span class="pre">EXCEPT</span> <span class="pre">ALL</span></tt> of multiple selectables.</p>
 
209
<p>The returned object is an instance of
 
210
<a class="reference internal" href="#sqlalchemy.sql.expression.CompoundSelect" title="sqlalchemy.sql.expression.CompoundSelect"><tt class="xref py py-class docutils literal"><span class="pre">CompoundSelect</span></tt></a>.</p>
 
211
<dl class="docutils">
 
212
<dt>*selects</dt>
 
213
<dd>a list of <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> instances.</dd>
 
214
<dt>**kwargs</dt>
 
215
<dd>available keyword arguments are the same as those of
 
216
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.</dd>
 
217
</dl>
 
218
</dd></dl>
 
219
 
 
220
<dl class="function">
 
221
<dt id="sqlalchemy.sql.expression.exists">
 
222
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">exists</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.exists" title="Permalink to this definition">¶</a></dt>
 
223
<dd><p>Return an <tt class="docutils literal"><span class="pre">EXISTS</span></tt> clause as applied to a <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object.</p>
 
224
<p>Calling styles are of the following forms:</p>
 
225
<div class="highlight-python"><div class="highlight"><pre><span class="c"># use on an existing select()</span>
 
226
<span class="n">s</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">col1</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">col2</span><span class="o">==</span><span class="mi">5</span><span class="p">)</span>
 
227
<span class="n">s</span> <span class="o">=</span> <span class="n">exists</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
 
228
 
 
229
<span class="c"># construct a select() at once</span>
 
230
<span class="n">exists</span><span class="p">([</span><span class="s">&#39;*&#39;</span><span class="p">],</span> <span class="o">**</span><span class="n">select_arguments</span><span class="p">)</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">criterion</span><span class="p">)</span>
 
231
 
 
232
<span class="c"># columns argument is optional, generates &quot;EXISTS (SELECT *)&quot;</span>
 
233
<span class="c"># by default.</span>
 
234
<span class="n">exists</span><span class="p">()</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">col2</span><span class="o">==</span><span class="mi">5</span><span class="p">)</span></pre></div>
 
235
</div>
 
236
</dd></dl>
 
237
 
 
238
<dl class="function">
 
239
<dt id="sqlalchemy.sql.expression.intersect">
 
240
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">intersect</tt><big>(</big><em>*selects</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.intersect" title="Permalink to this definition">¶</a></dt>
 
241
<dd><p>Return an <tt class="docutils literal"><span class="pre">INTERSECT</span></tt> of multiple selectables.</p>
 
242
<p>The returned object is an instance of
 
243
<a class="reference internal" href="#sqlalchemy.sql.expression.CompoundSelect" title="sqlalchemy.sql.expression.CompoundSelect"><tt class="xref py py-class docutils literal"><span class="pre">CompoundSelect</span></tt></a>.</p>
 
244
<dl class="docutils">
 
245
<dt>*selects</dt>
 
246
<dd>a list of <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> instances.</dd>
 
247
<dt>**kwargs</dt>
 
248
<dd>available keyword arguments are the same as those of
 
249
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.</dd>
 
250
</dl>
 
251
</dd></dl>
 
252
 
 
253
<dl class="function">
 
254
<dt id="sqlalchemy.sql.expression.intersect_all">
 
255
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">intersect_all</tt><big>(</big><em>*selects</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.intersect_all" title="Permalink to this definition">¶</a></dt>
 
256
<dd><p>Return an <tt class="docutils literal"><span class="pre">INTERSECT</span> <span class="pre">ALL</span></tt> of multiple selectables.</p>
 
257
<p>The returned object is an instance of
 
258
<a class="reference internal" href="#sqlalchemy.sql.expression.CompoundSelect" title="sqlalchemy.sql.expression.CompoundSelect"><tt class="xref py py-class docutils literal"><span class="pre">CompoundSelect</span></tt></a>.</p>
 
259
<dl class="docutils">
 
260
<dt>*selects</dt>
 
261
<dd>a list of <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> instances.</dd>
 
262
<dt>**kwargs</dt>
 
263
<dd>available keyword arguments are the same as those of
 
264
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.</dd>
 
265
</dl>
 
266
</dd></dl>
 
267
 
 
268
<dl class="function">
 
269
<dt id="sqlalchemy.sql.expression.join">
 
270
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">join</tt><big>(</big><em>left</em>, <em>right</em>, <em>onclause=None</em>, <em>isouter=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.join" title="Permalink to this definition">¶</a></dt>
 
271
<dd><p>Return a <tt class="docutils literal"><span class="pre">JOIN</span></tt> clause element (regular inner join).</p>
 
272
<p>The returned object is an instance of <a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>.</p>
 
273
<p>Similar functionality is also available via the
 
274
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.join" title="sqlalchemy.sql.expression.FromClause.join"><tt class="xref py py-meth docutils literal"><span class="pre">join()</span></tt></a> method on any
 
275
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
276
<table class="docutils field-list" frame="void" rules="none">
 
277
<col class="field-name" />
 
278
<col class="field-body" />
 
279
<tbody valign="top">
 
280
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
281
<li><strong>left</strong> &#8211; The left side of the join.</li>
 
282
<li><strong>right</strong> &#8211; The right side of the join.</li>
 
283
<li><strong>onclause</strong> &#8211; Optional criterion for the <tt class="docutils literal"><span class="pre">ON</span></tt> clause, is
 
284
derived from foreign key relationships established between
 
285
left and right otherwise.</li>
 
286
</ul>
 
287
</td>
 
288
</tr>
 
289
</tbody>
 
290
</table>
 
291
<p>To chain joins together, use the <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.join" title="sqlalchemy.sql.expression.FromClause.join"><tt class="xref py py-meth docutils literal"><span class="pre">FromClause.join()</span></tt></a> or
 
292
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.outerjoin" title="sqlalchemy.sql.expression.FromClause.outerjoin"><tt class="xref py py-meth docutils literal"><span class="pre">FromClause.outerjoin()</span></tt></a> methods on the resulting
 
293
<a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a> object.</p>
 
294
</dd></dl>
 
295
 
 
296
<dl class="function">
 
297
<dt id="sqlalchemy.sql.expression.outerjoin">
 
298
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">outerjoin</tt><big>(</big><em>left</em>, <em>right</em>, <em>onclause=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.outerjoin" title="Permalink to this definition">¶</a></dt>
 
299
<dd><p>Return an <tt class="docutils literal"><span class="pre">OUTER</span> <span class="pre">JOIN</span></tt> clause element.</p>
 
300
<p>The returned object is an instance of <a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>.</p>
 
301
<p>Similar functionality is also available via the
 
302
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.outerjoin" title="sqlalchemy.sql.expression.FromClause.outerjoin"><tt class="xref py py-meth docutils literal"><span class="pre">outerjoin()</span></tt></a> method on any
 
303
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
304
<table class="docutils field-list" frame="void" rules="none">
 
305
<col class="field-name" />
 
306
<col class="field-body" />
 
307
<tbody valign="top">
 
308
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
309
<li><strong>left</strong> &#8211; The left side of the join.</li>
 
310
<li><strong>right</strong> &#8211; The right side of the join.</li>
 
311
<li><strong>onclause</strong> &#8211; Optional criterion for the <tt class="docutils literal"><span class="pre">ON</span></tt> clause, is
 
312
derived from foreign key relationships established between
 
313
left and right otherwise.</li>
 
314
</ul>
 
315
</td>
 
316
</tr>
 
317
</tbody>
 
318
</table>
 
319
<p>To chain joins together, use the <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.join" title="sqlalchemy.sql.expression.FromClause.join"><tt class="xref py py-meth docutils literal"><span class="pre">FromClause.join()</span></tt></a> or
 
320
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.outerjoin" title="sqlalchemy.sql.expression.FromClause.outerjoin"><tt class="xref py py-meth docutils literal"><span class="pre">FromClause.outerjoin()</span></tt></a> methods on the resulting
 
321
<a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a> object.</p>
 
322
</dd></dl>
 
323
 
 
324
<dl class="function">
 
325
<dt id="sqlalchemy.sql.expression.select">
 
326
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">select</tt><big>(</big><em>columns=None</em>, <em>whereclause=None</em>, <em>from_obj=</em><span class="optional">[</span><span class="optional">]</span>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.select" title="Permalink to this definition">¶</a></dt>
 
327
<dd><p>Returns a <tt class="docutils literal"><span class="pre">SELECT</span></tt> clause element.</p>
 
328
<p>Similar functionality is also available via the <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>
 
329
method on any <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
330
<p>The returned object is an instance of <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>.</p>
 
331
<p>All arguments which accept <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> arguments also accept
 
332
string arguments, which will be converted as appropriate into
 
333
either <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.text" title="sqlalchemy.sql.expression.text"><tt class="xref py py-func docutils literal"><span class="pre">text()</span></tt></a> or <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.literal_column" title="sqlalchemy.sql.expression.literal_column"><tt class="xref py py-func docutils literal"><span class="pre">literal_column()</span></tt></a> constructs.</p>
 
334
<div class="admonition seealso">
 
335
<p class="first admonition-title">See also</p>
 
336
<p class="last"><a class="reference internal" href="tutorial.html#coretutorial-selecting"><em>Selecting</em></a> - Core Tutorial description of
 
337
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.</p>
 
338
</div>
 
339
<table class="docutils field-list" frame="void" rules="none">
 
340
<col class="field-name" />
 
341
<col class="field-body" />
 
342
<tbody valign="top">
 
343
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
344
<li><strong>columns</strong> &#8211; <p>A list of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> objects, typically
 
345
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> objects or subclasses, which will form the
 
346
columns clause of the resulting statement. For all members which are
 
347
instances of <a class="reference internal" href="#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a>, the individual <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>
 
348
members of the <a class="reference internal" href="#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a> will be added individually to the
 
349
columns clause. For example, specifying a
 
350
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> instance will result in all the
 
351
contained <a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects within to be added
 
352
to the columns clause.</p>
 
353
<p>This argument is not present on the form of <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>
 
354
available on <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>.</p>
 
355
</li>
 
356
<li><strong>whereclause</strong> &#8211; A <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> expression which will be used to form the
 
357
<tt class="docutils literal"><span class="pre">WHERE</span></tt> clause.</li>
 
358
<li><strong>from_obj</strong> &#8211; A list of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> objects which will be added to the
 
359
<tt class="docutils literal"><span class="pre">FROM</span></tt> clause of the resulting statement. Note that &#8220;from&#8221; objects are
 
360
automatically located within the columns and whereclause ClauseElements.
 
361
Use this parameter to explicitly specify &#8220;from&#8221; objects which are not
 
362
automatically locatable. This could include
 
363
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects that aren&#8217;t otherwise present,
 
364
or <a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a> objects whose presence will supercede that of the
 
365
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects already located in the other
 
366
clauses.</li>
 
367
<li><strong>autocommit</strong> &#8211; Deprecated.  Use .execution_options(autocommit=&lt;True|False&gt;)
 
368
to set the autocommit option.</li>
 
369
<li><strong>bind=None</strong> &#8211; an <tt class="xref py py-class docutils literal"><span class="pre">Engine</span></tt> or <tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt> instance
 
370
to which the
 
371
resulting <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object will be bound.  The <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>
 
372
object will otherwise automatically bind to whatever
 
373
<tt class="xref py py-class docutils literal"><span class="pre">Connectable</span></tt> instances can be located within its contained
 
374
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> members.</li>
 
375
<li><strong>correlate=True</strong> &#8211; indicates that this <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object should have its
 
376
contained <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> elements &#8220;correlated&#8221; to an enclosing
 
377
<a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object.  This means that any <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>
 
378
instance within the &#8220;froms&#8221; collection of this <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>
 
379
which is also present in the &#8220;froms&#8221; collection of an
 
380
enclosing select will not be rendered in the <tt class="docutils literal"><span class="pre">FROM</span></tt> clause
 
381
of this select statement.</li>
 
382
<li><strong>distinct=False</strong> &#8211; <p>when <tt class="docutils literal"><span class="pre">True</span></tt>, applies a <tt class="docutils literal"><span class="pre">DISTINCT</span></tt> qualifier to the columns
 
383
clause of the resulting statement.</p>
 
384
<p>The boolean argument may also be a column expression or list
 
385
of column expressions - this is a special calling form which
 
386
is understood by the Postgresql dialect to render the
 
387
<tt class="docutils literal"><span class="pre">DISTINCT</span> <span class="pre">ON</span> <span class="pre">(&lt;columns&gt;)</span></tt> syntax.</p>
 
388
<p><tt class="docutils literal"><span class="pre">distinct</span></tt> is also available via the <a class="reference internal" href="#sqlalchemy.sql.expression.Select.distinct" title="sqlalchemy.sql.expression.Select.distinct"><tt class="xref py py-meth docutils literal"><span class="pre">distinct()</span></tt></a>
 
389
generative method.</p>
 
390
</li>
 
391
<li><strong>for_update=False</strong> &#8211; <p>when <tt class="docutils literal"><span class="pre">True</span></tt>, applies <tt class="docutils literal"><span class="pre">FOR</span> <span class="pre">UPDATE</span></tt> to the end of the
 
392
resulting statement.</p>
 
393
<p>Certain database dialects also support
 
394
alternate values for this parameter:</p>
 
395
<ul>
 
396
<li>With the MySQL dialect, the value <tt class="docutils literal"><span class="pre">&quot;read&quot;</span></tt> translates to
 
397
<tt class="docutils literal"><span class="pre">LOCK</span> <span class="pre">IN</span> <span class="pre">SHARE</span> <span class="pre">MODE</span></tt>.</li>
 
398
<li>With the Oracle and Postgresql dialects, the value <tt class="docutils literal"><span class="pre">&quot;nowait&quot;</span></tt>
 
399
translates to <tt class="docutils literal"><span class="pre">FOR</span> <span class="pre">UPDATE</span> <span class="pre">NOWAIT</span></tt>.</li>
 
400
<li>With the Postgresql dialect, the values &#8220;read&#8221; and <tt class="docutils literal"><span class="pre">&quot;read_nowait&quot;</span></tt>
 
401
translate to <tt class="docutils literal"><span class="pre">FOR</span> <span class="pre">SHARE</span></tt> and <tt class="docutils literal"><span class="pre">FOR</span> <span class="pre">SHARE</span> <span class="pre">NOWAIT</span></tt>, respectively.<div class="versionadded">
 
402
<p><span>New in version 0.7.7.</span></p>
 
403
</div>
 
404
</li>
 
405
</ul>
 
406
</li>
 
407
<li><strong>group_by</strong> &#8211; a list of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> objects which will comprise the
 
408
<tt class="docutils literal"><span class="pre">GROUP</span> <span class="pre">BY</span></tt> clause of the resulting select.</li>
 
409
<li><strong>having</strong> &#8211; a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> that will comprise the <tt class="docutils literal"><span class="pre">HAVING</span></tt> clause
 
410
of the resulting select when <tt class="docutils literal"><span class="pre">GROUP</span> <span class="pre">BY</span></tt> is used.</li>
 
411
<li><strong>limit=None</strong> &#8211; a numerical value which usually compiles to a <tt class="docutils literal"><span class="pre">LIMIT</span></tt>
 
412
expression in the resulting select.  Databases that don&#8217;t
 
413
support <tt class="docutils literal"><span class="pre">LIMIT</span></tt> will attempt to provide similar
 
414
functionality.</li>
 
415
<li><strong>offset=None</strong> &#8211; a numeric value which usually compiles to an <tt class="docutils literal"><span class="pre">OFFSET</span></tt>
 
416
expression in the resulting select.  Databases that don&#8217;t
 
417
support <tt class="docutils literal"><span class="pre">OFFSET</span></tt> will attempt to provide similar
 
418
functionality.</li>
 
419
<li><strong>order_by</strong> &#8211; a scalar or list of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> objects which will
 
420
comprise the <tt class="docutils literal"><span class="pre">ORDER</span> <span class="pre">BY</span></tt> clause of the resulting select.</li>
 
421
<li><strong>use_labels=False</strong> &#8211; <p>when <tt class="docutils literal"><span class="pre">True</span></tt>, the statement will be generated using labels
 
422
for each column in the columns clause, which qualify each
 
423
column with its parent table&#8217;s (or aliases) name so that name
 
424
conflicts between columns in different tables don&#8217;t occur.
 
425
The format of the label is &lt;tablename&gt;_&lt;column&gt;.  The &#8220;c&#8221;
 
426
collection of the resulting <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object will use these
 
427
names as well for targeting column members.</p>
 
428
<p>use_labels is also available via the <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.apply_labels" title="sqlalchemy.sql.expression.SelectBase.apply_labels"><tt class="xref py py-meth docutils literal"><span class="pre">apply_labels()</span></tt></a>
 
429
generative method.</p>
 
430
</li>
 
431
</ul>
 
432
</td>
 
433
</tr>
 
434
</tbody>
 
435
</table>
 
436
</dd></dl>
 
437
 
 
438
<dl class="function">
 
439
<dt id="sqlalchemy.sql.expression.subquery">
 
440
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">subquery</tt><big>(</big><em>alias</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.subquery" title="Permalink to this definition">¶</a></dt>
 
441
<dd><p>Return an <a class="reference internal" href="#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a> object derived
 
442
from a <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>.</p>
 
443
<dl class="docutils">
 
444
<dt>name</dt>
 
445
<dd>alias name</dd>
 
446
</dl>
 
447
<p>*args, **kwargs</p>
 
448
<blockquote>
 
449
<div>all other arguments are delivered to the
 
450
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> function.</div></blockquote>
 
451
</dd></dl>
 
452
 
 
453
<dl class="function">
 
454
<dt id="sqlalchemy.sql.expression.table">
 
455
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">table</tt><big>(</big><em>name</em>, <em>*columns</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.table" title="Permalink to this definition">¶</a></dt>
 
456
<dd><p>Represent a textual table clause.</p>
 
457
<p>The object returned is an instance of <a class="reference internal" href="#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a>, which
 
458
represents the &#8220;syntactical&#8221; portion of the schema-level
 
459
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object.
 
460
It may be used to construct lightweight table constructs.</p>
 
461
<p>Note that the <a class="reference internal" href="#sqlalchemy.sql.expression.table" title="sqlalchemy.sql.expression.table"><tt class="xref py py-func docutils literal"><span class="pre">table()</span></tt></a> function is not part of
 
462
the <tt class="docutils literal"><span class="pre">sqlalchemy</span></tt> namespace.  It must be imported from the
 
463
<tt class="docutils literal"><span class="pre">sql</span></tt> package:</p>
 
464
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="kn">import</span> <span class="n">table</span><span class="p">,</span> <span class="n">column</span></pre></div>
 
465
</div>
 
466
<table class="docutils field-list" frame="void" rules="none">
 
467
<col class="field-name" />
 
468
<col class="field-body" />
 
469
<tbody valign="top">
 
470
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
471
<li><strong>name</strong> &#8211; Name of the table.</li>
 
472
<li><strong>columns</strong> &#8211; A collection of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.column" title="sqlalchemy.sql.expression.column"><tt class="xref py py-func docutils literal"><span class="pre">column()</span></tt></a> constructs.</li>
 
473
</ul>
 
474
</td>
 
475
</tr>
 
476
</tbody>
 
477
</table>
 
478
<p>See <a class="reference internal" href="#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a> for further examples.</p>
 
479
</dd></dl>
 
480
 
 
481
<dl class="function">
 
482
<dt id="sqlalchemy.sql.expression.union">
 
483
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">union</tt><big>(</big><em>*selects</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.union" title="Permalink to this definition">¶</a></dt>
 
484
<dd><p>Return a <tt class="docutils literal"><span class="pre">UNION</span></tt> of multiple selectables.</p>
 
485
<p>The returned object is an instance of
 
486
<a class="reference internal" href="#sqlalchemy.sql.expression.CompoundSelect" title="sqlalchemy.sql.expression.CompoundSelect"><tt class="xref py py-class docutils literal"><span class="pre">CompoundSelect</span></tt></a>.</p>
 
487
<p>A similar <a class="reference internal" href="#sqlalchemy.sql.expression.union" title="sqlalchemy.sql.expression.union"><tt class="xref py py-func docutils literal"><span class="pre">union()</span></tt></a> method is available on all
 
488
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> subclasses.</p>
 
489
<dl class="docutils">
 
490
<dt>*selects</dt>
 
491
<dd>a list of <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> instances.</dd>
 
492
<dt>**kwargs</dt>
 
493
<dd>available keyword arguments are the same as those of
 
494
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.</dd>
 
495
</dl>
 
496
</dd></dl>
 
497
 
 
498
<dl class="function">
 
499
<dt id="sqlalchemy.sql.expression.union_all">
 
500
<tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">union_all</tt><big>(</big><em>*selects</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.union_all" title="Permalink to this definition">¶</a></dt>
 
501
<dd><p>Return a <tt class="docutils literal"><span class="pre">UNION</span> <span class="pre">ALL</span></tt> of multiple selectables.</p>
 
502
<p>The returned object is an instance of
 
503
<a class="reference internal" href="#sqlalchemy.sql.expression.CompoundSelect" title="sqlalchemy.sql.expression.CompoundSelect"><tt class="xref py py-class docutils literal"><span class="pre">CompoundSelect</span></tt></a>.</p>
 
504
<p>A similar <a class="reference internal" href="#sqlalchemy.sql.expression.union_all" title="sqlalchemy.sql.expression.union_all"><tt class="xref py py-func docutils literal"><span class="pre">union_all()</span></tt></a> method is available on all
 
505
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> subclasses.</p>
 
506
<dl class="docutils">
 
507
<dt>*selects</dt>
 
508
<dd>a list of <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> instances.</dd>
 
509
<dt>**kwargs</dt>
 
510
<dd>available keyword arguments are the same as those of
 
511
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.</dd>
 
512
</dl>
 
513
</dd></dl>
 
514
 
 
515
<dl class="class">
 
516
<dt id="sqlalchemy.sql.expression.Alias">
 
517
<em class="property">class </em><tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">Alias</tt><big>(</big><em>selectable</em>, <em>name=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias" title="Permalink to this definition">¶</a></dt>
 
518
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.FromClause</span></tt></a></p>
 
519
<p>Represents an table or selectable alias (AS).</p>
 
520
<p>Represents an alias, as typically applied to any table or
 
521
sub-select within a SQL statement using the <tt class="docutils literal"><span class="pre">AS</span></tt> keyword (or
 
522
without the keyword on certain databases such as Oracle).</p>
 
523
<p>This object is constructed from the <a class="reference internal" href="#sqlalchemy.sql.expression.alias" title="sqlalchemy.sql.expression.alias"><tt class="xref py py-func docutils literal"><span class="pre">alias()</span></tt></a> module level
 
524
function as well as the <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.alias" title="sqlalchemy.sql.expression.FromClause.alias"><tt class="xref py py-meth docutils literal"><span class="pre">FromClause.alias()</span></tt></a> method available on all
 
525
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> subclasses.</p>
 
526
<dl class="method">
 
527
<dt id="sqlalchemy.sql.expression.Alias.alias">
 
528
<tt class="descname">alias</tt><big>(</big><em>name=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.alias" title="Permalink to this definition">¶</a></dt>
 
529
<dd><div class="inherited-member container">
 
530
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.alias" title="sqlalchemy.sql.expression.FromClause.alias"><tt class="xref py py-meth docutils literal"><span class="pre">alias()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
531
<p>return an alias of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
532
<p>This is shorthand for calling:</p>
 
533
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">alias</span>
 
534
<span class="n">a</span> <span class="o">=</span> <span class="n">alias</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></pre></div>
 
535
</div>
 
536
<p>See <a class="reference internal" href="#sqlalchemy.sql.expression.alias" title="sqlalchemy.sql.expression.alias"><tt class="xref py py-func docutils literal"><span class="pre">alias()</span></tt></a> for details.</p>
 
537
</dd></dl>
 
538
 
 
539
<dl class="attribute">
 
540
<dt id="sqlalchemy.sql.expression.Alias.c">
 
541
<tt class="descname">c</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.c" title="Permalink to this definition">¶</a></dt>
 
542
<dd><div class="inherited-member container">
 
543
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.c" title="sqlalchemy.sql.expression.FromClause.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
544
<p>An alias for the <a class="reference internal" href="#sqlalchemy.sql.expression.Alias.columns" title="sqlalchemy.sql.expression.Alias.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> attribute.</p>
 
545
</dd></dl>
 
546
 
 
547
<dl class="attribute">
 
548
<dt id="sqlalchemy.sql.expression.Alias.columns">
 
549
<tt class="descname">columns</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.columns" title="Permalink to this definition">¶</a></dt>
 
550
<dd><div class="inherited-member container">
 
551
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.columns" title="sqlalchemy.sql.expression.FromClause.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
552
<p>A named-based collection of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> objects
 
553
maintained by this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
554
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.Alias.columns" title="sqlalchemy.sql.expression.Alias.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a>, or <a class="reference internal" href="#sqlalchemy.sql.expression.Alias.c" title="sqlalchemy.sql.expression.Alias.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> collection, is the gateway
 
555
to the construction of SQL expressions using table-bound or
 
556
other selectable-bound columns:</p>
 
557
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">mytable</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">somecolumn</span> <span class="o">==</span> <span class="mi">5</span><span class="p">)</span></pre></div>
 
558
</div>
 
559
</dd></dl>
 
560
 
 
561
<dl class="method">
 
562
<dt id="sqlalchemy.sql.expression.Alias.compare">
 
563
<tt class="descname">compare</tt><big>(</big><em>other</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.compare" title="Permalink to this definition">¶</a></dt>
 
564
<dd><div class="inherited-member container">
 
565
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compare" title="sqlalchemy.sql.expression.ClauseElement.compare"><tt class="xref py py-meth docutils literal"><span class="pre">compare()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
566
<p>Compare this ClauseElement to the given ClauseElement.</p>
 
567
<p>Subclasses should override the default behavior, which is a
 
568
straight identity comparison.</p>
 
569
<p>**kw are arguments consumed by subclass compare() methods and
 
570
may be used to modify the criteria for comparison.
 
571
(see <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>)</p>
 
572
</dd></dl>
 
573
 
 
574
<dl class="method">
 
575
<dt id="sqlalchemy.sql.expression.Alias.compile">
 
576
<tt class="descname">compile</tt><big>(</big><em>bind=None</em>, <em>dialect=None</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.compile" title="Permalink to this definition">¶</a></dt>
 
577
<dd><div class="inherited-member container">
 
578
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compile" title="sqlalchemy.sql.expression.ClauseElement.compile"><tt class="xref py py-meth docutils literal"><span class="pre">compile()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
579
<p>Compile this SQL expression.</p>
 
580
<p>The return value is a <a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object.
 
581
Calling <tt class="docutils literal"><span class="pre">str()</span></tt> or <tt class="docutils literal"><span class="pre">unicode()</span></tt> on the returned value will yield a
 
582
string representation of the result. The
 
583
<a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object also can return a
 
584
dictionary of bind parameter names and values
 
585
using the <tt class="docutils literal"><span class="pre">params</span></tt> accessor.</p>
 
586
<table class="docutils field-list" frame="void" rules="none">
 
587
<col class="field-name" />
 
588
<col class="field-body" />
 
589
<tbody valign="top">
 
590
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
591
<li><strong>bind</strong> &#8211; An <tt class="docutils literal"><span class="pre">Engine</span></tt> or <tt class="docutils literal"><span class="pre">Connection</span></tt> from which a
 
592
<tt class="docutils literal"><span class="pre">Compiled</span></tt> will be acquired. This argument takes precedence over
 
593
this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if any.</li>
 
594
<li><strong>column_keys</strong> &#8211; Used for INSERT and UPDATE statements, a list of
 
595
column names which should be present in the VALUES clause of the
 
596
compiled statement. If <tt class="docutils literal"><span class="pre">None</span></tt>, all columns from the target table
 
597
object are rendered.</li>
 
598
<li><strong>dialect</strong> &#8211; A <tt class="docutils literal"><span class="pre">Dialect</span></tt> instance from which a <tt class="docutils literal"><span class="pre">Compiled</span></tt>
 
599
will be acquired. This argument takes precedence over the <cite>bind</cite>
 
600
argument as well as this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if
 
601
any.</li>
 
602
<li><strong>inline</strong> &#8211; Used for INSERT statements, for a dialect which does
 
603
not support inline retrieval of newly generated primary key
 
604
columns, will force the expression used to create the new primary
 
605
key value to be rendered inline within the INSERT statement&#8217;s
 
606
VALUES clause. This typically refers to Sequence execution but may
 
607
also refer to any server-side default generation function
 
608
associated with a primary key <cite>Column</cite>.</li>
 
609
</ul>
 
610
</td>
 
611
</tr>
 
612
</tbody>
 
613
</table>
 
614
</dd></dl>
 
615
 
 
616
<dl class="method">
 
617
<dt id="sqlalchemy.sql.expression.Alias.correspond_on_equivalents">
 
618
<tt class="descname">correspond_on_equivalents</tt><big>(</big><em>column</em>, <em>equivalents</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.correspond_on_equivalents" title="Permalink to this definition">¶</a></dt>
 
619
<dd><div class="inherited-member container">
 
620
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.correspond_on_equivalents" title="sqlalchemy.sql.expression.FromClause.correspond_on_equivalents"><tt class="xref py py-meth docutils literal"><span class="pre">correspond_on_equivalents()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
621
<p>Return corresponding_column for the given column, or if None
 
622
search for a match in the given dictionary.</p>
 
623
</dd></dl>
 
624
 
 
625
<dl class="method">
 
626
<dt id="sqlalchemy.sql.expression.Alias.corresponding_column">
 
627
<tt class="descname">corresponding_column</tt><big>(</big><em>column</em>, <em>require_embedded=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.corresponding_column" title="Permalink to this definition">¶</a></dt>
 
628
<dd><div class="inherited-member container">
 
629
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.corresponding_column" title="sqlalchemy.sql.expression.FromClause.corresponding_column"><tt class="xref py py-meth docutils literal"><span class="pre">corresponding_column()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
630
<p>Given a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, return the exported
 
631
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> object from this <a class="reference internal" href="#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a>
 
632
which corresponds to that original
 
633
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> via a common ancestor
 
634
column.</p>
 
635
<table class="docutils field-list" frame="void" rules="none">
 
636
<col class="field-name" />
 
637
<col class="field-body" />
 
638
<tbody valign="top">
 
639
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
640
<li><strong>column</strong> &#8211; the target <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> to be matched</li>
 
641
<li><strong>require_embedded</strong> &#8211; only return corresponding columns for</li>
 
642
</ul>
 
643
</td>
 
644
</tr>
 
645
</tbody>
 
646
</table>
 
647
<p>the given <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, if the given
 
648
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> is actually present within a sub-element
 
649
of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.  Normally the column will match if
 
650
it merely shares a common ancestor with one of the exported
 
651
columns of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
652
</dd></dl>
 
653
 
 
654
<dl class="method">
 
655
<dt id="sqlalchemy.sql.expression.Alias.count">
 
656
<tt class="descname">count</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.count" title="Permalink to this definition">¶</a></dt>
 
657
<dd><div class="inherited-member container">
 
658
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.count" title="sqlalchemy.sql.expression.FromClause.count"><tt class="xref py py-meth docutils literal"><span class="pre">count()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
659
<p>return a SELECT COUNT generated against this
 
660
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
661
</dd></dl>
 
662
 
 
663
<dl class="attribute">
 
664
<dt id="sqlalchemy.sql.expression.Alias.foreign_keys">
 
665
<tt class="descname">foreign_keys</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.foreign_keys" title="Permalink to this definition">¶</a></dt>
 
666
<dd><div class="inherited-member container">
 
667
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.foreign_keys" title="sqlalchemy.sql.expression.FromClause.foreign_keys"><tt class="xref py py-attr docutils literal"><span class="pre">foreign_keys</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
668
<p>Return the collection of ForeignKey objects which this
 
669
FromClause references.</p>
 
670
</dd></dl>
 
671
 
 
672
<dl class="method">
 
673
<dt id="sqlalchemy.sql.expression.Alias.join">
 
674
<tt class="descname">join</tt><big>(</big><em>right</em>, <em>onclause=None</em>, <em>isouter=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.join" title="Permalink to this definition">¶</a></dt>
 
675
<dd><div class="inherited-member container">
 
676
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.join" title="sqlalchemy.sql.expression.FromClause.join"><tt class="xref py py-meth docutils literal"><span class="pre">join()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
677
<p>return a join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
678
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
679
</dd></dl>
 
680
 
 
681
<dl class="method">
 
682
<dt id="sqlalchemy.sql.expression.Alias.outerjoin">
 
683
<tt class="descname">outerjoin</tt><big>(</big><em>right</em>, <em>onclause=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.outerjoin" title="Permalink to this definition">¶</a></dt>
 
684
<dd><div class="inherited-member container">
 
685
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.outerjoin" title="sqlalchemy.sql.expression.FromClause.outerjoin"><tt class="xref py py-meth docutils literal"><span class="pre">outerjoin()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
686
<p>return an outer join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
687
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
688
</dd></dl>
 
689
 
 
690
<dl class="method">
 
691
<dt id="sqlalchemy.sql.expression.Alias.params">
 
692
<tt class="descname">params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.params" title="Permalink to this definition">¶</a></dt>
 
693
<dd><div class="inherited-member container">
 
694
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.params" title="sqlalchemy.sql.expression.ClauseElement.params"><tt class="xref py py-meth docutils literal"><span class="pre">params()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
695
<p>Return a copy with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a> elements replaced.</p>
 
696
<p>Returns a copy of this ClauseElement with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a>
 
697
elements replaced with values taken from the given dictionary:</p>
 
698
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">clause</span> <span class="o">=</span> <span class="n">column</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">bindparam</span><span class="p">(</span><span class="s">&#39;foo&#39;</span><span class="p">)</span>
 
699
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">clause</span><span class="o">.</span><span class="n">compile</span><span class="p">()</span><span class="o">.</span><span class="n">params</span>
 
700
<span class="go">{&#39;foo&#39;:None}</span>
 
701
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">clause</span><span class="o">.</span><span class="n">params</span><span class="p">({</span><span class="s">&#39;foo&#39;</span><span class="p">:</span><span class="mi">7</span><span class="p">})</span><span class="o">.</span><span class="n">compile</span><span class="p">()</span><span class="o">.</span><span class="n">params</span>
 
702
<span class="go">{&#39;foo&#39;:7}</span></pre></div>
 
703
</div>
 
704
</dd></dl>
 
705
 
 
706
<dl class="attribute">
 
707
<dt id="sqlalchemy.sql.expression.Alias.primary_key">
 
708
<tt class="descname">primary_key</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.primary_key" title="Permalink to this definition">¶</a></dt>
 
709
<dd><div class="inherited-member container">
 
710
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.primary_key" title="sqlalchemy.sql.expression.FromClause.primary_key"><tt class="xref py py-attr docutils literal"><span class="pre">primary_key</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
711
<p>Return the collection of Column objects which comprise the
 
712
primary key of this FromClause.</p>
 
713
</dd></dl>
 
714
 
 
715
<dl class="method">
 
716
<dt id="sqlalchemy.sql.expression.Alias.replace_selectable">
 
717
<tt class="descname">replace_selectable</tt><big>(</big><em>old</em>, <em>alias</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.replace_selectable" title="Permalink to this definition">¶</a></dt>
 
718
<dd><div class="inherited-member container">
 
719
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.replace_selectable" title="sqlalchemy.sql.expression.FromClause.replace_selectable"><tt class="xref py py-meth docutils literal"><span class="pre">replace_selectable()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
720
<p>replace all occurrences of FromClause &#8216;old&#8217; with the given Alias
 
721
object, returning a copy of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
722
</dd></dl>
 
723
 
 
724
<dl class="method">
 
725
<dt id="sqlalchemy.sql.expression.Alias.select">
 
726
<tt class="descname">select</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.select" title="Permalink to this definition">¶</a></dt>
 
727
<dd><div class="inherited-member container">
 
728
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.select" title="sqlalchemy.sql.expression.FromClause.select"><tt class="xref py py-meth docutils literal"><span class="pre">select()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
729
<p>return a SELECT of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
730
<div class="admonition seealso">
 
731
<p class="first admonition-title">See also</p>
 
732
<p class="last"><a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> - general purpose
 
733
method which allows for arbitrary column lists.</p>
 
734
</div>
 
735
</dd></dl>
 
736
 
 
737
<dl class="method">
 
738
<dt id="sqlalchemy.sql.expression.Alias.self_group">
 
739
<tt class="descname">self_group</tt><big>(</big><em>against=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.self_group" title="Permalink to this definition">¶</a></dt>
 
740
<dd><div class="inherited-member container">
 
741
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.self_group" title="sqlalchemy.sql.expression.ClauseElement.self_group"><tt class="xref py py-meth docutils literal"><span class="pre">self_group()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
742
<p>Apply a &#8216;grouping&#8217; to this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>.</p>
 
743
<p>This method is overridden by subclasses to return a
 
744
&#8220;grouping&#8221; construct, i.e. parenthesis.   In particular
 
745
it&#8217;s used by &#8220;binary&#8221; expressions to provide a grouping
 
746
around themselves when placed into a larger expression,
 
747
as well as by <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> constructs when placed into
 
748
the FROM clause of another <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.  (Note that
 
749
subqueries should be normally created using the
 
750
<tt class="xref py py-func docutils literal"><span class="pre">Select.alias()</span></tt> method, as many platforms require
 
751
nested SELECT statements to be named).</p>
 
752
<p>As expressions are composed together, the application of
 
753
<a class="reference internal" href="#sqlalchemy.sql.expression.Alias.self_group" title="sqlalchemy.sql.expression.Alias.self_group"><tt class="xref py py-meth docutils literal"><span class="pre">self_group()</span></tt></a> is automatic - end-user code should never
 
754
need to use this method directly.  Note that SQLAlchemy&#8217;s
 
755
clause constructs take operator precedence into account -
 
756
so parenthesis might not be needed, for example, in
 
757
an expression like <tt class="docutils literal"><span class="pre">x</span> <span class="pre">OR</span> <span class="pre">(y</span> <span class="pre">AND</span> <span class="pre">z)</span></tt> - AND takes precedence
 
758
over OR.</p>
 
759
<p>The base <a class="reference internal" href="#sqlalchemy.sql.expression.Alias.self_group" title="sqlalchemy.sql.expression.Alias.self_group"><tt class="xref py py-meth docutils literal"><span class="pre">self_group()</span></tt></a> method of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>
 
760
just returns self.</p>
 
761
</dd></dl>
 
762
 
 
763
<dl class="method">
 
764
<dt id="sqlalchemy.sql.expression.Alias.unique_params">
 
765
<tt class="descname">unique_params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Alias.unique_params" title="Permalink to this definition">¶</a></dt>
 
766
<dd><div class="inherited-member container">
 
767
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.unique_params" title="sqlalchemy.sql.expression.ClauseElement.unique_params"><tt class="xref py py-meth docutils literal"><span class="pre">unique_params()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
768
<p>Return a copy with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a> elements replaced.</p>
 
769
<p>Same functionality as <tt class="docutils literal"><span class="pre">params()</span></tt>, except adds <cite>unique=True</cite>
 
770
to affected bind parameters so that multiple statements can be
 
771
used.</p>
 
772
</dd></dl>
 
773
 
 
774
</dd></dl>
 
775
 
 
776
<dl class="class">
 
777
<dt id="sqlalchemy.sql.expression.CompoundSelect">
 
778
<em class="property">class </em><tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">CompoundSelect</tt><big>(</big><em>keyword</em>, <em>*selects</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect" title="Permalink to this definition">¶</a></dt>
 
779
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.SelectBase</span></tt></a></p>
 
780
<dl class="docutils">
 
781
<dt>Forms the basis of <tt class="docutils literal"><span class="pre">UNION</span></tt>, <tt class="docutils literal"><span class="pre">UNION</span> <span class="pre">ALL</span></tt>, and other</dt>
 
782
<dd>SELECT-based set operations.</dd>
 
783
</dl>
 
784
<div class="admonition seealso">
 
785
<p class="first admonition-title">See also</p>
 
786
<p><a class="reference internal" href="#sqlalchemy.sql.expression.union" title="sqlalchemy.sql.expression.union"><tt class="xref py py-func docutils literal"><span class="pre">union()</span></tt></a></p>
 
787
<p><a class="reference internal" href="#sqlalchemy.sql.expression.union_all" title="sqlalchemy.sql.expression.union_all"><tt class="xref py py-func docutils literal"><span class="pre">union_all()</span></tt></a></p>
 
788
<p><a class="reference internal" href="#sqlalchemy.sql.expression.intersect" title="sqlalchemy.sql.expression.intersect"><tt class="xref py py-func docutils literal"><span class="pre">intersect()</span></tt></a></p>
 
789
<p><a class="reference internal" href="#sqlalchemy.sql.expression.intersect_all" title="sqlalchemy.sql.expression.intersect_all"><tt class="xref py py-func docutils literal"><span class="pre">intersect_all()</span></tt></a></p>
 
790
<p><tt class="xref py py-func docutils literal"><span class="pre">except()</span></tt></p>
 
791
<p class="last"><a class="reference internal" href="#sqlalchemy.sql.expression.except_all" title="sqlalchemy.sql.expression.except_all"><tt class="xref py py-func docutils literal"><span class="pre">except_all()</span></tt></a></p>
 
792
</div>
 
793
<dl class="method">
 
794
<dt id="sqlalchemy.sql.expression.CompoundSelect.alias">
 
795
<tt class="descname">alias</tt><big>(</big><em>name=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.alias" title="Permalink to this definition">¶</a></dt>
 
796
<dd><div class="inherited-member container">
 
797
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.alias" title="sqlalchemy.sql.expression.FromClause.alias"><tt class="xref py py-meth docutils literal"><span class="pre">alias()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
798
<p>return an alias of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
799
<p>This is shorthand for calling:</p>
 
800
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">alias</span>
 
801
<span class="n">a</span> <span class="o">=</span> <span class="n">alias</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></pre></div>
 
802
</div>
 
803
<p>See <a class="reference internal" href="#sqlalchemy.sql.expression.alias" title="sqlalchemy.sql.expression.alias"><tt class="xref py py-func docutils literal"><span class="pre">alias()</span></tt></a> for details.</p>
 
804
</dd></dl>
 
805
 
 
806
<dl class="method">
 
807
<dt id="sqlalchemy.sql.expression.CompoundSelect.append_group_by">
 
808
<tt class="descname">append_group_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.append_group_by" title="Permalink to this definition">¶</a></dt>
 
809
<dd><div class="inherited-member container">
 
810
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.append_group_by" title="sqlalchemy.sql.expression.SelectBase.append_group_by"><tt class="xref py py-meth docutils literal"><span class="pre">append_group_by()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
811
<p>Append the given GROUP BY criterion applied to this selectable.</p>
 
812
<p>The criterion will be appended to any pre-existing GROUP BY criterion.</p>
 
813
<p>This is an <strong>in-place</strong> mutation method; the
 
814
<a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.group_by" title="sqlalchemy.sql.expression.SelectBase.group_by"><tt class="xref py py-meth docutils literal"><span class="pre">group_by()</span></tt></a> method is preferred, as it provides standard
 
815
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
816
</dd></dl>
 
817
 
 
818
<dl class="method">
 
819
<dt id="sqlalchemy.sql.expression.CompoundSelect.append_order_by">
 
820
<tt class="descname">append_order_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.append_order_by" title="Permalink to this definition">¶</a></dt>
 
821
<dd><div class="inherited-member container">
 
822
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.append_order_by" title="sqlalchemy.sql.expression.SelectBase.append_order_by"><tt class="xref py py-meth docutils literal"><span class="pre">append_order_by()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
823
<p>Append the given ORDER BY criterion applied to this selectable.</p>
 
824
<p>The criterion will be appended to any pre-existing ORDER BY criterion.</p>
 
825
<p>This is an <strong>in-place</strong> mutation method; the
 
826
<a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.order_by" title="sqlalchemy.sql.expression.SelectBase.order_by"><tt class="xref py py-meth docutils literal"><span class="pre">order_by()</span></tt></a> method is preferred, as it provides standard
 
827
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
828
</dd></dl>
 
829
 
 
830
<dl class="method">
 
831
<dt id="sqlalchemy.sql.expression.CompoundSelect.apply_labels">
 
832
<tt class="descname">apply_labels</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.apply_labels" title="Permalink to this definition">¶</a></dt>
 
833
<dd><div class="inherited-member container">
 
834
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.apply_labels" title="sqlalchemy.sql.expression.SelectBase.apply_labels"><tt class="xref py py-meth docutils literal"><span class="pre">apply_labels()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
835
<p>return a new selectable with the &#8216;use_labels&#8217; flag set to True.</p>
 
836
<p>This will result in column expressions being generated using labels
 
837
against their table name, such as &#8220;SELECT somecolumn AS
 
838
tablename_somecolumn&#8221;. This allows selectables which contain multiple
 
839
FROM clauses to produce a unique set of column names regardless of
 
840
name conflicts among the individual FROM clauses.</p>
 
841
</dd></dl>
 
842
 
 
843
<dl class="method">
 
844
<dt id="sqlalchemy.sql.expression.CompoundSelect.as_scalar">
 
845
<tt class="descname">as_scalar</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.as_scalar" title="Permalink to this definition">¶</a></dt>
 
846
<dd><div class="inherited-member container">
 
847
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.as_scalar" title="sqlalchemy.sql.expression.SelectBase.as_scalar"><tt class="xref py py-meth docutils literal"><span class="pre">as_scalar()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
848
<p>return a &#8216;scalar&#8217; representation of this selectable, which can be
 
849
used as a column expression.</p>
 
850
<p>Typically, a select statement which has only one column in its columns
 
851
clause is eligible to be used as a scalar expression.</p>
 
852
<p>The returned object is an instance of
 
853
<tt class="xref py py-class docutils literal"><span class="pre">ScalarSelect</span></tt>.</p>
 
854
</dd></dl>
 
855
 
 
856
<dl class="method">
 
857
<dt id="sqlalchemy.sql.expression.CompoundSelect.autocommit">
 
858
<tt class="descname">autocommit</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.autocommit" title="Permalink to this definition">¶</a></dt>
 
859
<dd><div class="inherited-member container">
 
860
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.autocommit" title="sqlalchemy.sql.expression.SelectBase.autocommit"><tt class="xref py py-meth docutils literal"><span class="pre">autocommit()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
861
<p>return a new selectable with the &#8216;autocommit&#8217; flag set to</p>
 
862
<div class="deprecated">
 
863
<p><span>Deprecated since version 0.6: </span><tt class="xref py py-func docutils literal"><span class="pre">autocommit()</span></tt> is deprecated. Use <tt class="xref py py-func docutils literal"><span class="pre">Executable.execution_options()</span></tt> with the &#8216;autocommit&#8217; flag.</p>
 
864
</div>
 
865
<p>True.</p>
 
866
</dd></dl>
 
867
 
 
868
<dl class="attribute">
 
869
<dt id="sqlalchemy.sql.expression.CompoundSelect.c">
 
870
<tt class="descname">c</tt><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.c" title="Permalink to this definition">¶</a></dt>
 
871
<dd><div class="inherited-member container">
 
872
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.c" title="sqlalchemy.sql.expression.FromClause.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
873
<p>An alias for the <a class="reference internal" href="#sqlalchemy.sql.expression.CompoundSelect.columns" title="sqlalchemy.sql.expression.CompoundSelect.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> attribute.</p>
 
874
</dd></dl>
 
875
 
 
876
<dl class="attribute">
 
877
<dt id="sqlalchemy.sql.expression.CompoundSelect.columns">
 
878
<tt class="descname">columns</tt><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.columns" title="Permalink to this definition">¶</a></dt>
 
879
<dd><div class="inherited-member container">
 
880
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.columns" title="sqlalchemy.sql.expression.FromClause.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
881
<p>A named-based collection of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> objects
 
882
maintained by this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
883
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.CompoundSelect.columns" title="sqlalchemy.sql.expression.CompoundSelect.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a>, or <a class="reference internal" href="#sqlalchemy.sql.expression.CompoundSelect.c" title="sqlalchemy.sql.expression.CompoundSelect.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> collection, is the gateway
 
884
to the construction of SQL expressions using table-bound or
 
885
other selectable-bound columns:</p>
 
886
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">mytable</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">somecolumn</span> <span class="o">==</span> <span class="mi">5</span><span class="p">)</span></pre></div>
 
887
</div>
 
888
</dd></dl>
 
889
 
 
890
<dl class="method">
 
891
<dt id="sqlalchemy.sql.expression.CompoundSelect.compare">
 
892
<tt class="descname">compare</tt><big>(</big><em>other</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.compare" title="Permalink to this definition">¶</a></dt>
 
893
<dd><div class="inherited-member container">
 
894
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compare" title="sqlalchemy.sql.expression.ClauseElement.compare"><tt class="xref py py-meth docutils literal"><span class="pre">compare()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
895
<p>Compare this ClauseElement to the given ClauseElement.</p>
 
896
<p>Subclasses should override the default behavior, which is a
 
897
straight identity comparison.</p>
 
898
<p>**kw are arguments consumed by subclass compare() methods and
 
899
may be used to modify the criteria for comparison.
 
900
(see <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>)</p>
 
901
</dd></dl>
 
902
 
 
903
<dl class="method">
 
904
<dt id="sqlalchemy.sql.expression.CompoundSelect.compile">
 
905
<tt class="descname">compile</tt><big>(</big><em>bind=None</em>, <em>dialect=None</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.compile" title="Permalink to this definition">¶</a></dt>
 
906
<dd><div class="inherited-member container">
 
907
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compile" title="sqlalchemy.sql.expression.ClauseElement.compile"><tt class="xref py py-meth docutils literal"><span class="pre">compile()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
908
<p>Compile this SQL expression.</p>
 
909
<p>The return value is a <a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object.
 
910
Calling <tt class="docutils literal"><span class="pre">str()</span></tt> or <tt class="docutils literal"><span class="pre">unicode()</span></tt> on the returned value will yield a
 
911
string representation of the result. The
 
912
<a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object also can return a
 
913
dictionary of bind parameter names and values
 
914
using the <tt class="docutils literal"><span class="pre">params</span></tt> accessor.</p>
 
915
<table class="docutils field-list" frame="void" rules="none">
 
916
<col class="field-name" />
 
917
<col class="field-body" />
 
918
<tbody valign="top">
 
919
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
920
<li><strong>bind</strong> &#8211; An <tt class="docutils literal"><span class="pre">Engine</span></tt> or <tt class="docutils literal"><span class="pre">Connection</span></tt> from which a
 
921
<tt class="docutils literal"><span class="pre">Compiled</span></tt> will be acquired. This argument takes precedence over
 
922
this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if any.</li>
 
923
<li><strong>column_keys</strong> &#8211; Used for INSERT and UPDATE statements, a list of
 
924
column names which should be present in the VALUES clause of the
 
925
compiled statement. If <tt class="docutils literal"><span class="pre">None</span></tt>, all columns from the target table
 
926
object are rendered.</li>
 
927
<li><strong>dialect</strong> &#8211; A <tt class="docutils literal"><span class="pre">Dialect</span></tt> instance from which a <tt class="docutils literal"><span class="pre">Compiled</span></tt>
 
928
will be acquired. This argument takes precedence over the <cite>bind</cite>
 
929
argument as well as this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if
 
930
any.</li>
 
931
<li><strong>inline</strong> &#8211; Used for INSERT statements, for a dialect which does
 
932
not support inline retrieval of newly generated primary key
 
933
columns, will force the expression used to create the new primary
 
934
key value to be rendered inline within the INSERT statement&#8217;s
 
935
VALUES clause. This typically refers to Sequence execution but may
 
936
also refer to any server-side default generation function
 
937
associated with a primary key <cite>Column</cite>.</li>
 
938
</ul>
 
939
</td>
 
940
</tr>
 
941
</tbody>
 
942
</table>
 
943
</dd></dl>
 
944
 
 
945
<dl class="method">
 
946
<dt id="sqlalchemy.sql.expression.CompoundSelect.correspond_on_equivalents">
 
947
<tt class="descname">correspond_on_equivalents</tt><big>(</big><em>column</em>, <em>equivalents</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.correspond_on_equivalents" title="Permalink to this definition">¶</a></dt>
 
948
<dd><div class="inherited-member container">
 
949
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.correspond_on_equivalents" title="sqlalchemy.sql.expression.FromClause.correspond_on_equivalents"><tt class="xref py py-meth docutils literal"><span class="pre">correspond_on_equivalents()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
950
<p>Return corresponding_column for the given column, or if None
 
951
search for a match in the given dictionary.</p>
 
952
</dd></dl>
 
953
 
 
954
<dl class="method">
 
955
<dt id="sqlalchemy.sql.expression.CompoundSelect.corresponding_column">
 
956
<tt class="descname">corresponding_column</tt><big>(</big><em>column</em>, <em>require_embedded=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.corresponding_column" title="Permalink to this definition">¶</a></dt>
 
957
<dd><div class="inherited-member container">
 
958
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.corresponding_column" title="sqlalchemy.sql.expression.FromClause.corresponding_column"><tt class="xref py py-meth docutils literal"><span class="pre">corresponding_column()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
959
<p>Given a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, return the exported
 
960
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> object from this <a class="reference internal" href="#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a>
 
961
which corresponds to that original
 
962
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> via a common ancestor
 
963
column.</p>
 
964
<table class="docutils field-list" frame="void" rules="none">
 
965
<col class="field-name" />
 
966
<col class="field-body" />
 
967
<tbody valign="top">
 
968
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
969
<li><strong>column</strong> &#8211; the target <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> to be matched</li>
 
970
<li><strong>require_embedded</strong> &#8211; only return corresponding columns for</li>
 
971
</ul>
 
972
</td>
 
973
</tr>
 
974
</tbody>
 
975
</table>
 
976
<p>the given <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, if the given
 
977
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> is actually present within a sub-element
 
978
of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.  Normally the column will match if
 
979
it merely shares a common ancestor with one of the exported
 
980
columns of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
981
</dd></dl>
 
982
 
 
983
<dl class="method">
 
984
<dt id="sqlalchemy.sql.expression.CompoundSelect.count">
 
985
<tt class="descname">count</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.count" title="Permalink to this definition">¶</a></dt>
 
986
<dd><div class="inherited-member container">
 
987
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.count" title="sqlalchemy.sql.expression.FromClause.count"><tt class="xref py py-meth docutils literal"><span class="pre">count()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
988
<p>return a SELECT COUNT generated against this
 
989
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
990
</dd></dl>
 
991
 
 
992
<dl class="method">
 
993
<dt id="sqlalchemy.sql.expression.CompoundSelect.cte">
 
994
<tt class="descname">cte</tt><big>(</big><em>name=None</em>, <em>recursive=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.cte" title="Permalink to this definition">¶</a></dt>
 
995
<dd><div class="inherited-member container">
 
996
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.cte" title="sqlalchemy.sql.expression.SelectBase.cte"><tt class="xref py py-meth docutils literal"><span class="pre">cte()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
997
<p>Return a new <a class="reference internal" href="#sqlalchemy.sql.expression.CTE" title="sqlalchemy.sql.expression.CTE"><tt class="xref py py-class docutils literal"><span class="pre">CTE</span></tt></a>, or Common Table Expression instance.</p>
 
998
<p>Common table expressions are a SQL standard whereby SELECT
 
999
statements can draw upon secondary statements specified along
 
1000
with the primary statement, using a clause called &#8220;WITH&#8221;.
 
1001
Special semantics regarding UNION can also be employed to
 
1002
allow &#8220;recursive&#8221; queries, where a SELECT statement can draw
 
1003
upon the set of rows that have previously been selected.</p>
 
1004
<p>SQLAlchemy detects <a class="reference internal" href="#sqlalchemy.sql.expression.CTE" title="sqlalchemy.sql.expression.CTE"><tt class="xref py py-class docutils literal"><span class="pre">CTE</span></tt></a> objects, which are treated
 
1005
similarly to <a class="reference internal" href="#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a> objects, as special elements
 
1006
to be delivered to the FROM clause of the statement as well
 
1007
as to a WITH clause at the top of the statement.</p>
 
1008
<div class="versionadded">
 
1009
<p><span>New in version 0.7.6.</span></p>
 
1010
</div>
 
1011
<table class="docutils field-list" frame="void" rules="none">
 
1012
<col class="field-name" />
 
1013
<col class="field-body" />
 
1014
<tbody valign="top">
 
1015
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
1016
<li><strong>name</strong> &#8211; name given to the common table expression.  Like
 
1017
<tt class="xref py py-meth docutils literal"><span class="pre">_FromClause.alias()</span></tt>, the name can be left as <tt class="docutils literal"><span class="pre">None</span></tt>
 
1018
in which case an anonymous symbol will be used at query
 
1019
compile time.</li>
 
1020
<li><strong>recursive</strong> &#8211; if <tt class="docutils literal"><span class="pre">True</span></tt>, will render <tt class="docutils literal"><span class="pre">WITH</span> <span class="pre">RECURSIVE</span></tt>.
 
1021
A recursive common table expression is intended to be used in
 
1022
conjunction with UNION ALL in order to derive rows
 
1023
from those already selected.</li>
 
1024
</ul>
 
1025
</td>
 
1026
</tr>
 
1027
</tbody>
 
1028
</table>
 
1029
<p>The following examples illustrate two examples from
 
1030
Postgresql&#8217;s documentation at
 
1031
<a class="reference external" href="http://www.postgresql.org/docs/8.4/static/queries-with.html">http://www.postgresql.org/docs/8.4/static/queries-with.html</a>.</p>
 
1032
<p>Example 1, non recursive:</p>
 
1033
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Table</span><span class="p">,</span> <span class="n">Column</span><span class="p">,</span> <span class="n">String</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">MetaData</span><span class="p">,</span> \
 
1034
    <span class="n">select</span><span class="p">,</span> <span class="n">func</span>
 
1035
 
 
1036
<span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
 
1037
 
 
1038
<span class="n">orders</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">&#39;orders&#39;</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
 
1039
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;region&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
1040
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;amount&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
 
1041
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;product&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
1042
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;quantity&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">)</span>
 
1043
<span class="p">)</span>
 
1044
 
 
1045
<span class="n">regional_sales</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
1046
                    <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">,</span>
 
1047
                    <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">amount</span><span class="p">)</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s">&#39;total_sales&#39;</span><span class="p">)</span>
 
1048
                <span class="p">])</span><span class="o">.</span><span class="n">group_by</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">)</span><span class="o">.</span><span class="n">cte</span><span class="p">(</span><span class="s">&quot;regional_sales&quot;</span><span class="p">)</span>
 
1049
 
 
1050
 
 
1051
<span class="n">top_regions</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">regional_sales</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">])</span><span class="o">.</span>\
 
1052
        <span class="n">where</span><span class="p">(</span>
 
1053
            <span class="n">regional_sales</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">total_sales</span> <span class="o">&gt;</span>
 
1054
            <span class="n">select</span><span class="p">([</span>
 
1055
                <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">regional_sales</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">total_sales</span><span class="p">)</span><span class="o">/</span><span class="mi">10</span>
 
1056
            <span class="p">])</span>
 
1057
        <span class="p">)</span><span class="o">.</span><span class="n">cte</span><span class="p">(</span><span class="s">&quot;top_regions&quot;</span><span class="p">)</span>
 
1058
 
 
1059
<span class="n">statement</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
1060
            <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">,</span>
 
1061
            <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">product</span><span class="p">,</span>
 
1062
            <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span><span class="p">)</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s">&quot;product_units&quot;</span><span class="p">),</span>
 
1063
            <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">amount</span><span class="p">)</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s">&quot;product_sales&quot;</span><span class="p">)</span>
 
1064
    <span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="o">.</span><span class="n">in_</span><span class="p">(</span>
 
1065
        <span class="n">select</span><span class="p">([</span><span class="n">top_regions</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">])</span>
 
1066
    <span class="p">))</span><span class="o">.</span><span class="n">group_by</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">,</span> <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">product</span><span class="p">)</span>
 
1067
 
 
1068
<span class="n">result</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">statement</span><span class="p">)</span><span class="o">.</span><span class="n">fetchall</span><span class="p">()</span></pre></div>
 
1069
</div>
 
1070
<p>Example 2, WITH RECURSIVE:</p>
 
1071
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Table</span><span class="p">,</span> <span class="n">Column</span><span class="p">,</span> <span class="n">String</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">MetaData</span><span class="p">,</span> \
 
1072
    <span class="n">select</span><span class="p">,</span> <span class="n">func</span>
 
1073
 
 
1074
<span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
 
1075
 
 
1076
<span class="n">parts</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">&#39;parts&#39;</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
 
1077
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;part&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
1078
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;sub_part&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
1079
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;quantity&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
 
1080
<span class="p">)</span>
 
1081
 
 
1082
<span class="n">included_parts</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
1083
                    <span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">,</span>
 
1084
                    <span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="p">,</span>
 
1085
                    <span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span><span class="p">])</span><span class="o">.</span>\
 
1086
                    <span class="n">where</span><span class="p">(</span><span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="o">==</span><span class="s">&#39;our part&#39;</span><span class="p">)</span><span class="o">.</span>\
 
1087
                    <span class="n">cte</span><span class="p">(</span><span class="n">recursive</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
 
1088
 
 
1089
 
 
1090
<span class="n">incl_alias</span> <span class="o">=</span> <span class="n">included_parts</span><span class="o">.</span><span class="n">alias</span><span class="p">()</span>
 
1091
<span class="n">parts_alias</span> <span class="o">=</span> <span class="n">parts</span><span class="o">.</span><span class="n">alias</span><span class="p">()</span>
 
1092
<span class="n">included_parts</span> <span class="o">=</span> <span class="n">included_parts</span><span class="o">.</span><span class="n">union_all</span><span class="p">(</span>
 
1093
    <span class="n">select</span><span class="p">([</span>
 
1094
        <span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="p">,</span>
 
1095
        <span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">,</span>
 
1096
        <span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span>
 
1097
    <span class="p">])</span><span class="o">.</span>
 
1098
        <span class="n">where</span><span class="p">(</span><span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="o">==</span><span class="n">incl_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">)</span>
 
1099
<span class="p">)</span>
 
1100
 
 
1101
<span class="n">statement</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
1102
            <span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">,</span>
 
1103
            <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span><span class="p">)</span><span class="o">.</span>
 
1104
              <span class="n">label</span><span class="p">(</span><span class="s">&#39;total_quantity&#39;</span><span class="p">)</span>
 
1105
        <span class="p">])</span><span class="o">.</span>                    <span class="n">select_from</span><span class="p">(</span><span class="n">included_parts</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">parts</span><span class="p">,</span>
 
1106
                    <span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="o">==</span><span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="p">))</span><span class="o">.</span>\
 
1107
        <span class="n">group_by</span><span class="p">(</span><span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">)</span>
 
1108
 
 
1109
<span class="n">result</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">statement</span><span class="p">)</span><span class="o">.</span><span class="n">fetchall</span><span class="p">()</span></pre></div>
 
1110
</div>
 
1111
<div class="admonition seealso">
 
1112
<p class="first admonition-title">See also</p>
 
1113
<p class="last"><a class="reference internal" href="../orm/query.html#sqlalchemy.orm.query.Query.cte" title="sqlalchemy.orm.query.Query.cte"><tt class="xref py py-meth docutils literal"><span class="pre">orm.query.Query.cte()</span></tt></a> - ORM version of <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.cte" title="sqlalchemy.sql.expression.SelectBase.cte"><tt class="xref py py-meth docutils literal"><span class="pre">SelectBase.cte()</span></tt></a>.</p>
 
1114
</div>
 
1115
</dd></dl>
 
1116
 
 
1117
<dl class="attribute">
 
1118
<dt id="sqlalchemy.sql.expression.CompoundSelect.description">
 
1119
<tt class="descname">description</tt><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.description" title="Permalink to this definition">¶</a></dt>
 
1120
<dd><div class="inherited-member container">
 
1121
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.description" title="sqlalchemy.sql.expression.FromClause.description"><tt class="xref py py-attr docutils literal"><span class="pre">description</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1122
<p>a brief description of this FromClause.</p>
 
1123
<p>Used primarily for error message formatting.</p>
 
1124
</dd></dl>
 
1125
 
 
1126
<dl class="method">
 
1127
<dt id="sqlalchemy.sql.expression.CompoundSelect.execute">
 
1128
<tt class="descname">execute</tt><big>(</big><em>*multiparams</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.execute" title="Permalink to this definition">¶</a></dt>
 
1129
<dd><div class="inherited-member container">
 
1130
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable.execute" title="sqlalchemy.sql.expression.Executable.execute"><tt class="xref py py-meth docutils literal"><span class="pre">execute()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a></div>
 
1131
<p>Compile and execute this <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a>.</p>
 
1132
</dd></dl>
 
1133
 
 
1134
<dl class="method">
 
1135
<dt id="sqlalchemy.sql.expression.CompoundSelect.execution_options">
 
1136
<tt class="descname">execution_options</tt><big>(</big><em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.execution_options" title="Permalink to this definition">¶</a></dt>
 
1137
<dd><div class="inherited-member container">
 
1138
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable.execution_options" title="sqlalchemy.sql.expression.Executable.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">execution_options()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a></div>
 
1139
<p>Set non-SQL options for the statement which take effect during
 
1140
execution.</p>
 
1141
<p>Execution options can be set on a per-statement or
 
1142
per <a class="reference internal" href="connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> basis.   Additionally, the
 
1143
<a class="reference internal" href="connections.html#sqlalchemy.engine.Engine" title="sqlalchemy.engine.Engine"><tt class="xref py py-class docutils literal"><span class="pre">Engine</span></tt></a> and ORM <a class="reference internal" href="../orm/query.html#sqlalchemy.orm.query.Query" title="sqlalchemy.orm.query.Query"><tt class="xref py py-class docutils literal"><span class="pre">Query</span></tt></a> objects provide
 
1144
access to execution options which they in turn configure upon
 
1145
connections.</p>
 
1146
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.CompoundSelect.execution_options" title="sqlalchemy.sql.expression.CompoundSelect.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">execution_options()</span></tt></a> method is generative.  A new
 
1147
instance of this statement is returned that contains the options:</p>
 
1148
<div class="highlight-python"><div class="highlight"><pre><span class="n">statement</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">y</span><span class="p">])</span>
 
1149
<span class="n">statement</span> <span class="o">=</span> <span class="n">statement</span><span class="o">.</span><span class="n">execution_options</span><span class="p">(</span><span class="n">autocommit</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span></pre></div>
 
1150
</div>
 
1151
<p>Note that only a subset of possible execution options can be applied
 
1152
to a statement - these include &#8220;autocommit&#8221; and &#8220;stream_results&#8221;,
 
1153
but not &#8220;isolation_level&#8221; or &#8220;compiled_cache&#8221;.
 
1154
See <a class="reference internal" href="connections.html#sqlalchemy.engine.Connection.execution_options" title="sqlalchemy.engine.Connection.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">Connection.execution_options()</span></tt></a> for a full list of
 
1155
possible options.</p>
 
1156
<div class="admonition seealso">
 
1157
<p class="first admonition-title">See also</p>
 
1158
<p><a class="reference internal" href="connections.html#sqlalchemy.engine.Connection.execution_options" title="sqlalchemy.engine.Connection.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">Connection.execution_options()</span></tt></a></p>
 
1159
<p class="last"><a class="reference internal" href="../orm/query.html#sqlalchemy.orm.query.Query.execution_options" title="sqlalchemy.orm.query.Query.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">Query.execution_options()</span></tt></a></p>
 
1160
</div>
 
1161
</dd></dl>
 
1162
 
 
1163
<dl class="attribute">
 
1164
<dt id="sqlalchemy.sql.expression.CompoundSelect.foreign_keys">
 
1165
<tt class="descname">foreign_keys</tt><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.foreign_keys" title="Permalink to this definition">¶</a></dt>
 
1166
<dd><div class="inherited-member container">
 
1167
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.foreign_keys" title="sqlalchemy.sql.expression.FromClause.foreign_keys"><tt class="xref py py-attr docutils literal"><span class="pre">foreign_keys</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1168
<p>Return the collection of ForeignKey objects which this
 
1169
FromClause references.</p>
 
1170
</dd></dl>
 
1171
 
 
1172
<dl class="method">
 
1173
<dt id="sqlalchemy.sql.expression.CompoundSelect.group_by">
 
1174
<tt class="descname">group_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.group_by" title="Permalink to this definition">¶</a></dt>
 
1175
<dd><div class="inherited-member container">
 
1176
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.group_by" title="sqlalchemy.sql.expression.SelectBase.group_by"><tt class="xref py py-meth docutils literal"><span class="pre">group_by()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
1177
<p>return a new selectable with the given list of GROUP BY
 
1178
criterion applied.</p>
 
1179
<p>The criterion will be appended to any pre-existing GROUP BY
 
1180
criterion.</p>
 
1181
</dd></dl>
 
1182
 
 
1183
<dl class="method">
 
1184
<dt id="sqlalchemy.sql.expression.CompoundSelect.join">
 
1185
<tt class="descname">join</tt><big>(</big><em>right</em>, <em>onclause=None</em>, <em>isouter=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.join" title="Permalink to this definition">¶</a></dt>
 
1186
<dd><div class="inherited-member container">
 
1187
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.join" title="sqlalchemy.sql.expression.FromClause.join"><tt class="xref py py-meth docutils literal"><span class="pre">join()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1188
<p>return a join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
1189
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1190
</dd></dl>
 
1191
 
 
1192
<dl class="method">
 
1193
<dt id="sqlalchemy.sql.expression.CompoundSelect.label">
 
1194
<tt class="descname">label</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.label" title="Permalink to this definition">¶</a></dt>
 
1195
<dd><div class="inherited-member container">
 
1196
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.label" title="sqlalchemy.sql.expression.SelectBase.label"><tt class="xref py py-meth docutils literal"><span class="pre">label()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
1197
<p>return a &#8216;scalar&#8217; representation of this selectable, embedded as a
 
1198
subquery with a label.</p>
 
1199
<div class="admonition seealso">
 
1200
<p class="first admonition-title">See also</p>
 
1201
<p class="last"><a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.as_scalar" title="sqlalchemy.sql.expression.SelectBase.as_scalar"><tt class="xref py py-meth docutils literal"><span class="pre">as_scalar()</span></tt></a>.</p>
 
1202
</div>
 
1203
</dd></dl>
 
1204
 
 
1205
<dl class="method">
 
1206
<dt id="sqlalchemy.sql.expression.CompoundSelect.limit">
 
1207
<tt class="descname">limit</tt><big>(</big><em>limit</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.limit" title="Permalink to this definition">¶</a></dt>
 
1208
<dd><div class="inherited-member container">
 
1209
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.limit" title="sqlalchemy.sql.expression.SelectBase.limit"><tt class="xref py py-meth docutils literal"><span class="pre">limit()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
1210
<p>return a new selectable with the given LIMIT criterion
 
1211
applied.</p>
 
1212
</dd></dl>
 
1213
 
 
1214
<dl class="method">
 
1215
<dt id="sqlalchemy.sql.expression.CompoundSelect.offset">
 
1216
<tt class="descname">offset</tt><big>(</big><em>offset</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.offset" title="Permalink to this definition">¶</a></dt>
 
1217
<dd><div class="inherited-member container">
 
1218
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.offset" title="sqlalchemy.sql.expression.SelectBase.offset"><tt class="xref py py-meth docutils literal"><span class="pre">offset()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
1219
<p>return a new selectable with the given OFFSET criterion
 
1220
applied.</p>
 
1221
</dd></dl>
 
1222
 
 
1223
<dl class="method">
 
1224
<dt id="sqlalchemy.sql.expression.CompoundSelect.order_by">
 
1225
<tt class="descname">order_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.order_by" title="Permalink to this definition">¶</a></dt>
 
1226
<dd><div class="inherited-member container">
 
1227
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.order_by" title="sqlalchemy.sql.expression.SelectBase.order_by"><tt class="xref py py-meth docutils literal"><span class="pre">order_by()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
1228
<p>return a new selectable with the given list of ORDER BY
 
1229
criterion applied.</p>
 
1230
<p>The criterion will be appended to any pre-existing ORDER BY
 
1231
criterion.</p>
 
1232
</dd></dl>
 
1233
 
 
1234
<dl class="method">
 
1235
<dt id="sqlalchemy.sql.expression.CompoundSelect.outerjoin">
 
1236
<tt class="descname">outerjoin</tt><big>(</big><em>right</em>, <em>onclause=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.outerjoin" title="Permalink to this definition">¶</a></dt>
 
1237
<dd><div class="inherited-member container">
 
1238
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.outerjoin" title="sqlalchemy.sql.expression.FromClause.outerjoin"><tt class="xref py py-meth docutils literal"><span class="pre">outerjoin()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1239
<p>return an outer join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
1240
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1241
</dd></dl>
 
1242
 
 
1243
<dl class="method">
 
1244
<dt id="sqlalchemy.sql.expression.CompoundSelect.params">
 
1245
<tt class="descname">params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.params" title="Permalink to this definition">¶</a></dt>
 
1246
<dd><div class="inherited-member container">
 
1247
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.params" title="sqlalchemy.sql.expression.ClauseElement.params"><tt class="xref py py-meth docutils literal"><span class="pre">params()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
1248
<p>Return a copy with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a> elements replaced.</p>
 
1249
<p>Returns a copy of this ClauseElement with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a>
 
1250
elements replaced with values taken from the given dictionary:</p>
 
1251
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">clause</span> <span class="o">=</span> <span class="n">column</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">bindparam</span><span class="p">(</span><span class="s">&#39;foo&#39;</span><span class="p">)</span>
 
1252
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">clause</span><span class="o">.</span><span class="n">compile</span><span class="p">()</span><span class="o">.</span><span class="n">params</span>
 
1253
<span class="go">{&#39;foo&#39;:None}</span>
 
1254
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">clause</span><span class="o">.</span><span class="n">params</span><span class="p">({</span><span class="s">&#39;foo&#39;</span><span class="p">:</span><span class="mi">7</span><span class="p">})</span><span class="o">.</span><span class="n">compile</span><span class="p">()</span><span class="o">.</span><span class="n">params</span>
 
1255
<span class="go">{&#39;foo&#39;:7}</span></pre></div>
 
1256
</div>
 
1257
</dd></dl>
 
1258
 
 
1259
<dl class="attribute">
 
1260
<dt id="sqlalchemy.sql.expression.CompoundSelect.primary_key">
 
1261
<tt class="descname">primary_key</tt><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.primary_key" title="Permalink to this definition">¶</a></dt>
 
1262
<dd><div class="inherited-member container">
 
1263
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.primary_key" title="sqlalchemy.sql.expression.FromClause.primary_key"><tt class="xref py py-attr docutils literal"><span class="pre">primary_key</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1264
<p>Return the collection of Column objects which comprise the
 
1265
primary key of this FromClause.</p>
 
1266
</dd></dl>
 
1267
 
 
1268
<dl class="method">
 
1269
<dt id="sqlalchemy.sql.expression.CompoundSelect.replace_selectable">
 
1270
<tt class="descname">replace_selectable</tt><big>(</big><em>old</em>, <em>alias</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.replace_selectable" title="Permalink to this definition">¶</a></dt>
 
1271
<dd><div class="inherited-member container">
 
1272
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.replace_selectable" title="sqlalchemy.sql.expression.FromClause.replace_selectable"><tt class="xref py py-meth docutils literal"><span class="pre">replace_selectable()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1273
<p>replace all occurrences of FromClause &#8216;old&#8217; with the given Alias
 
1274
object, returning a copy of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1275
</dd></dl>
 
1276
 
 
1277
<dl class="method">
 
1278
<dt id="sqlalchemy.sql.expression.CompoundSelect.scalar">
 
1279
<tt class="descname">scalar</tt><big>(</big><em>*multiparams</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.scalar" title="Permalink to this definition">¶</a></dt>
 
1280
<dd><div class="inherited-member container">
 
1281
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable.scalar" title="sqlalchemy.sql.expression.Executable.scalar"><tt class="xref py py-meth docutils literal"><span class="pre">scalar()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a></div>
 
1282
<p>Compile and execute this <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a>, returning the
 
1283
result&#8217;s scalar representation.</p>
 
1284
</dd></dl>
 
1285
 
 
1286
<dl class="method">
 
1287
<dt id="sqlalchemy.sql.expression.CompoundSelect.select">
 
1288
<tt class="descname">select</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.select" title="Permalink to this definition">¶</a></dt>
 
1289
<dd><div class="inherited-member container">
 
1290
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.select" title="sqlalchemy.sql.expression.FromClause.select"><tt class="xref py py-meth docutils literal"><span class="pre">select()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1291
<p>return a SELECT of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1292
<div class="admonition seealso">
 
1293
<p class="first admonition-title">See also</p>
 
1294
<p class="last"><a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> - general purpose
 
1295
method which allows for arbitrary column lists.</p>
 
1296
</div>
 
1297
</dd></dl>
 
1298
 
 
1299
<dl class="method">
 
1300
<dt id="sqlalchemy.sql.expression.CompoundSelect.unique_params">
 
1301
<tt class="descname">unique_params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CompoundSelect.unique_params" title="Permalink to this definition">¶</a></dt>
 
1302
<dd><div class="inherited-member container">
 
1303
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.unique_params" title="sqlalchemy.sql.expression.ClauseElement.unique_params"><tt class="xref py py-meth docutils literal"><span class="pre">unique_params()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
1304
<p>Return a copy with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a> elements replaced.</p>
 
1305
<p>Same functionality as <tt class="docutils literal"><span class="pre">params()</span></tt>, except adds <cite>unique=True</cite>
 
1306
to affected bind parameters so that multiple statements can be
 
1307
used.</p>
 
1308
</dd></dl>
 
1309
 
 
1310
</dd></dl>
 
1311
 
 
1312
<dl class="class">
 
1313
<dt id="sqlalchemy.sql.expression.CTE">
 
1314
<em class="property">class </em><tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">CTE</tt><big>(</big><em>selectable</em>, <em>name=None</em>, <em>recursive=False</em>, <em>_cte_alias=None</em>, <em>_restates=frozenset([])</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE" title="Permalink to this definition">¶</a></dt>
 
1315
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.Alias</span></tt></a></p>
 
1316
<p>Represent a Common Table Expression.</p>
 
1317
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.CTE" title="sqlalchemy.sql.expression.CTE"><tt class="xref py py-class docutils literal"><span class="pre">CTE</span></tt></a> object is obtained using the
 
1318
<a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.cte" title="sqlalchemy.sql.expression.SelectBase.cte"><tt class="xref py py-meth docutils literal"><span class="pre">SelectBase.cte()</span></tt></a> method from any selectable.
 
1319
See that method for complete examples.</p>
 
1320
<div class="versionadded">
 
1321
<p><span>New in version 0.7.6.</span></p>
 
1322
</div>
 
1323
<dl class="attribute">
 
1324
<dt id="sqlalchemy.sql.expression.CTE.c">
 
1325
<tt class="descname">c</tt><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.c" title="Permalink to this definition">¶</a></dt>
 
1326
<dd><div class="inherited-member container">
 
1327
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.c" title="sqlalchemy.sql.expression.FromClause.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1328
<p>An alias for the <a class="reference internal" href="#sqlalchemy.sql.expression.CTE.columns" title="sqlalchemy.sql.expression.CTE.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> attribute.</p>
 
1329
</dd></dl>
 
1330
 
 
1331
<dl class="attribute">
 
1332
<dt id="sqlalchemy.sql.expression.CTE.columns">
 
1333
<tt class="descname">columns</tt><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.columns" title="Permalink to this definition">¶</a></dt>
 
1334
<dd><div class="inherited-member container">
 
1335
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.columns" title="sqlalchemy.sql.expression.FromClause.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1336
<p>A named-based collection of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> objects
 
1337
maintained by this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1338
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.CTE.columns" title="sqlalchemy.sql.expression.CTE.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a>, or <a class="reference internal" href="#sqlalchemy.sql.expression.CTE.c" title="sqlalchemy.sql.expression.CTE.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> collection, is the gateway
 
1339
to the construction of SQL expressions using table-bound or
 
1340
other selectable-bound columns:</p>
 
1341
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">mytable</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">somecolumn</span> <span class="o">==</span> <span class="mi">5</span><span class="p">)</span></pre></div>
 
1342
</div>
 
1343
</dd></dl>
 
1344
 
 
1345
<dl class="method">
 
1346
<dt id="sqlalchemy.sql.expression.CTE.compare">
 
1347
<tt class="descname">compare</tt><big>(</big><em>other</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.compare" title="Permalink to this definition">¶</a></dt>
 
1348
<dd><div class="inherited-member container">
 
1349
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compare" title="sqlalchemy.sql.expression.ClauseElement.compare"><tt class="xref py py-meth docutils literal"><span class="pre">compare()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
1350
<p>Compare this ClauseElement to the given ClauseElement.</p>
 
1351
<p>Subclasses should override the default behavior, which is a
 
1352
straight identity comparison.</p>
 
1353
<p>**kw are arguments consumed by subclass compare() methods and
 
1354
may be used to modify the criteria for comparison.
 
1355
(see <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>)</p>
 
1356
</dd></dl>
 
1357
 
 
1358
<dl class="method">
 
1359
<dt id="sqlalchemy.sql.expression.CTE.compile">
 
1360
<tt class="descname">compile</tt><big>(</big><em>bind=None</em>, <em>dialect=None</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.compile" title="Permalink to this definition">¶</a></dt>
 
1361
<dd><div class="inherited-member container">
 
1362
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compile" title="sqlalchemy.sql.expression.ClauseElement.compile"><tt class="xref py py-meth docutils literal"><span class="pre">compile()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
1363
<p>Compile this SQL expression.</p>
 
1364
<p>The return value is a <a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object.
 
1365
Calling <tt class="docutils literal"><span class="pre">str()</span></tt> or <tt class="docutils literal"><span class="pre">unicode()</span></tt> on the returned value will yield a
 
1366
string representation of the result. The
 
1367
<a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object also can return a
 
1368
dictionary of bind parameter names and values
 
1369
using the <tt class="docutils literal"><span class="pre">params</span></tt> accessor.</p>
 
1370
<table class="docutils field-list" frame="void" rules="none">
 
1371
<col class="field-name" />
 
1372
<col class="field-body" />
 
1373
<tbody valign="top">
 
1374
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
1375
<li><strong>bind</strong> &#8211; An <tt class="docutils literal"><span class="pre">Engine</span></tt> or <tt class="docutils literal"><span class="pre">Connection</span></tt> from which a
 
1376
<tt class="docutils literal"><span class="pre">Compiled</span></tt> will be acquired. This argument takes precedence over
 
1377
this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if any.</li>
 
1378
<li><strong>column_keys</strong> &#8211; Used for INSERT and UPDATE statements, a list of
 
1379
column names which should be present in the VALUES clause of the
 
1380
compiled statement. If <tt class="docutils literal"><span class="pre">None</span></tt>, all columns from the target table
 
1381
object are rendered.</li>
 
1382
<li><strong>dialect</strong> &#8211; A <tt class="docutils literal"><span class="pre">Dialect</span></tt> instance from which a <tt class="docutils literal"><span class="pre">Compiled</span></tt>
 
1383
will be acquired. This argument takes precedence over the <cite>bind</cite>
 
1384
argument as well as this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if
 
1385
any.</li>
 
1386
<li><strong>inline</strong> &#8211; Used for INSERT statements, for a dialect which does
 
1387
not support inline retrieval of newly generated primary key
 
1388
columns, will force the expression used to create the new primary
 
1389
key value to be rendered inline within the INSERT statement&#8217;s
 
1390
VALUES clause. This typically refers to Sequence execution but may
 
1391
also refer to any server-side default generation function
 
1392
associated with a primary key <cite>Column</cite>.</li>
 
1393
</ul>
 
1394
</td>
 
1395
</tr>
 
1396
</tbody>
 
1397
</table>
 
1398
</dd></dl>
 
1399
 
 
1400
<dl class="method">
 
1401
<dt id="sqlalchemy.sql.expression.CTE.correspond_on_equivalents">
 
1402
<tt class="descname">correspond_on_equivalents</tt><big>(</big><em>column</em>, <em>equivalents</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.correspond_on_equivalents" title="Permalink to this definition">¶</a></dt>
 
1403
<dd><div class="inherited-member container">
 
1404
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.correspond_on_equivalents" title="sqlalchemy.sql.expression.FromClause.correspond_on_equivalents"><tt class="xref py py-meth docutils literal"><span class="pre">correspond_on_equivalents()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1405
<p>Return corresponding_column for the given column, or if None
 
1406
search for a match in the given dictionary.</p>
 
1407
</dd></dl>
 
1408
 
 
1409
<dl class="method">
 
1410
<dt id="sqlalchemy.sql.expression.CTE.corresponding_column">
 
1411
<tt class="descname">corresponding_column</tt><big>(</big><em>column</em>, <em>require_embedded=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.corresponding_column" title="Permalink to this definition">¶</a></dt>
 
1412
<dd><div class="inherited-member container">
 
1413
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.corresponding_column" title="sqlalchemy.sql.expression.FromClause.corresponding_column"><tt class="xref py py-meth docutils literal"><span class="pre">corresponding_column()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1414
<p>Given a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, return the exported
 
1415
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> object from this <a class="reference internal" href="#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a>
 
1416
which corresponds to that original
 
1417
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> via a common ancestor
 
1418
column.</p>
 
1419
<table class="docutils field-list" frame="void" rules="none">
 
1420
<col class="field-name" />
 
1421
<col class="field-body" />
 
1422
<tbody valign="top">
 
1423
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
1424
<li><strong>column</strong> &#8211; the target <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> to be matched</li>
 
1425
<li><strong>require_embedded</strong> &#8211; only return corresponding columns for</li>
 
1426
</ul>
 
1427
</td>
 
1428
</tr>
 
1429
</tbody>
 
1430
</table>
 
1431
<p>the given <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, if the given
 
1432
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> is actually present within a sub-element
 
1433
of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.  Normally the column will match if
 
1434
it merely shares a common ancestor with one of the exported
 
1435
columns of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1436
</dd></dl>
 
1437
 
 
1438
<dl class="method">
 
1439
<dt id="sqlalchemy.sql.expression.CTE.count">
 
1440
<tt class="descname">count</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.count" title="Permalink to this definition">¶</a></dt>
 
1441
<dd><div class="inherited-member container">
 
1442
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.count" title="sqlalchemy.sql.expression.FromClause.count"><tt class="xref py py-meth docutils literal"><span class="pre">count()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1443
<p>return a SELECT COUNT generated against this
 
1444
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1445
</dd></dl>
 
1446
 
 
1447
<dl class="attribute">
 
1448
<dt id="sqlalchemy.sql.expression.CTE.foreign_keys">
 
1449
<tt class="descname">foreign_keys</tt><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.foreign_keys" title="Permalink to this definition">¶</a></dt>
 
1450
<dd><div class="inherited-member container">
 
1451
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.foreign_keys" title="sqlalchemy.sql.expression.FromClause.foreign_keys"><tt class="xref py py-attr docutils literal"><span class="pre">foreign_keys</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1452
<p>Return the collection of ForeignKey objects which this
 
1453
FromClause references.</p>
 
1454
</dd></dl>
 
1455
 
 
1456
<dl class="method">
 
1457
<dt id="sqlalchemy.sql.expression.CTE.join">
 
1458
<tt class="descname">join</tt><big>(</big><em>right</em>, <em>onclause=None</em>, <em>isouter=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.join" title="Permalink to this definition">¶</a></dt>
 
1459
<dd><div class="inherited-member container">
 
1460
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.join" title="sqlalchemy.sql.expression.FromClause.join"><tt class="xref py py-meth docutils literal"><span class="pre">join()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1461
<p>return a join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
1462
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1463
</dd></dl>
 
1464
 
 
1465
<dl class="method">
 
1466
<dt id="sqlalchemy.sql.expression.CTE.outerjoin">
 
1467
<tt class="descname">outerjoin</tt><big>(</big><em>right</em>, <em>onclause=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.outerjoin" title="Permalink to this definition">¶</a></dt>
 
1468
<dd><div class="inherited-member container">
 
1469
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.outerjoin" title="sqlalchemy.sql.expression.FromClause.outerjoin"><tt class="xref py py-meth docutils literal"><span class="pre">outerjoin()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1470
<p>return an outer join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
1471
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1472
</dd></dl>
 
1473
 
 
1474
<dl class="method">
 
1475
<dt id="sqlalchemy.sql.expression.CTE.params">
 
1476
<tt class="descname">params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.params" title="Permalink to this definition">¶</a></dt>
 
1477
<dd><div class="inherited-member container">
 
1478
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.params" title="sqlalchemy.sql.expression.ClauseElement.params"><tt class="xref py py-meth docutils literal"><span class="pre">params()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
1479
<p>Return a copy with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a> elements replaced.</p>
 
1480
<p>Returns a copy of this ClauseElement with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a>
 
1481
elements replaced with values taken from the given dictionary:</p>
 
1482
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">clause</span> <span class="o">=</span> <span class="n">column</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">bindparam</span><span class="p">(</span><span class="s">&#39;foo&#39;</span><span class="p">)</span>
 
1483
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">clause</span><span class="o">.</span><span class="n">compile</span><span class="p">()</span><span class="o">.</span><span class="n">params</span>
 
1484
<span class="go">{&#39;foo&#39;:None}</span>
 
1485
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">clause</span><span class="o">.</span><span class="n">params</span><span class="p">({</span><span class="s">&#39;foo&#39;</span><span class="p">:</span><span class="mi">7</span><span class="p">})</span><span class="o">.</span><span class="n">compile</span><span class="p">()</span><span class="o">.</span><span class="n">params</span>
 
1486
<span class="go">{&#39;foo&#39;:7}</span></pre></div>
 
1487
</div>
 
1488
</dd></dl>
 
1489
 
 
1490
<dl class="attribute">
 
1491
<dt id="sqlalchemy.sql.expression.CTE.primary_key">
 
1492
<tt class="descname">primary_key</tt><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.primary_key" title="Permalink to this definition">¶</a></dt>
 
1493
<dd><div class="inherited-member container">
 
1494
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.primary_key" title="sqlalchemy.sql.expression.FromClause.primary_key"><tt class="xref py py-attr docutils literal"><span class="pre">primary_key</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1495
<p>Return the collection of Column objects which comprise the
 
1496
primary key of this FromClause.</p>
 
1497
</dd></dl>
 
1498
 
 
1499
<dl class="method">
 
1500
<dt id="sqlalchemy.sql.expression.CTE.replace_selectable">
 
1501
<tt class="descname">replace_selectable</tt><big>(</big><em>old</em>, <em>alias</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.replace_selectable" title="Permalink to this definition">¶</a></dt>
 
1502
<dd><div class="inherited-member container">
 
1503
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.replace_selectable" title="sqlalchemy.sql.expression.FromClause.replace_selectable"><tt class="xref py py-meth docutils literal"><span class="pre">replace_selectable()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1504
<p>replace all occurrences of FromClause &#8216;old&#8217; with the given Alias
 
1505
object, returning a copy of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1506
</dd></dl>
 
1507
 
 
1508
<dl class="method">
 
1509
<dt id="sqlalchemy.sql.expression.CTE.select">
 
1510
<tt class="descname">select</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.select" title="Permalink to this definition">¶</a></dt>
 
1511
<dd><div class="inherited-member container">
 
1512
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.select" title="sqlalchemy.sql.expression.FromClause.select"><tt class="xref py py-meth docutils literal"><span class="pre">select()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1513
<p>return a SELECT of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1514
<div class="admonition seealso">
 
1515
<p class="first admonition-title">See also</p>
 
1516
<p class="last"><a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> - general purpose
 
1517
method which allows for arbitrary column lists.</p>
 
1518
</div>
 
1519
</dd></dl>
 
1520
 
 
1521
<dl class="method">
 
1522
<dt id="sqlalchemy.sql.expression.CTE.self_group">
 
1523
<tt class="descname">self_group</tt><big>(</big><em>against=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.self_group" title="Permalink to this definition">¶</a></dt>
 
1524
<dd><div class="inherited-member container">
 
1525
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.self_group" title="sqlalchemy.sql.expression.ClauseElement.self_group"><tt class="xref py py-meth docutils literal"><span class="pre">self_group()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
1526
<p>Apply a &#8216;grouping&#8217; to this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>.</p>
 
1527
<p>This method is overridden by subclasses to return a
 
1528
&#8220;grouping&#8221; construct, i.e. parenthesis.   In particular
 
1529
it&#8217;s used by &#8220;binary&#8221; expressions to provide a grouping
 
1530
around themselves when placed into a larger expression,
 
1531
as well as by <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> constructs when placed into
 
1532
the FROM clause of another <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.  (Note that
 
1533
subqueries should be normally created using the
 
1534
<tt class="xref py py-func docutils literal"><span class="pre">Select.alias()</span></tt> method, as many platforms require
 
1535
nested SELECT statements to be named).</p>
 
1536
<p>As expressions are composed together, the application of
 
1537
<a class="reference internal" href="#sqlalchemy.sql.expression.CTE.self_group" title="sqlalchemy.sql.expression.CTE.self_group"><tt class="xref py py-meth docutils literal"><span class="pre">self_group()</span></tt></a> is automatic - end-user code should never
 
1538
need to use this method directly.  Note that SQLAlchemy&#8217;s
 
1539
clause constructs take operator precedence into account -
 
1540
so parenthesis might not be needed, for example, in
 
1541
an expression like <tt class="docutils literal"><span class="pre">x</span> <span class="pre">OR</span> <span class="pre">(y</span> <span class="pre">AND</span> <span class="pre">z)</span></tt> - AND takes precedence
 
1542
over OR.</p>
 
1543
<p>The base <a class="reference internal" href="#sqlalchemy.sql.expression.CTE.self_group" title="sqlalchemy.sql.expression.CTE.self_group"><tt class="xref py py-meth docutils literal"><span class="pre">self_group()</span></tt></a> method of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>
 
1544
just returns self.</p>
 
1545
</dd></dl>
 
1546
 
 
1547
<dl class="method">
 
1548
<dt id="sqlalchemy.sql.expression.CTE.unique_params">
 
1549
<tt class="descname">unique_params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.CTE.unique_params" title="Permalink to this definition">¶</a></dt>
 
1550
<dd><div class="inherited-member container">
 
1551
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.unique_params" title="sqlalchemy.sql.expression.ClauseElement.unique_params"><tt class="xref py py-meth docutils literal"><span class="pre">unique_params()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
1552
<p>Return a copy with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a> elements replaced.</p>
 
1553
<p>Same functionality as <tt class="docutils literal"><span class="pre">params()</span></tt>, except adds <cite>unique=True</cite>
 
1554
to affected bind parameters so that multiple statements can be
 
1555
used.</p>
 
1556
</dd></dl>
 
1557
 
 
1558
</dd></dl>
 
1559
 
 
1560
<dl class="class">
 
1561
<dt id="sqlalchemy.sql.expression.Executable">
 
1562
<em class="property">class </em><tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">Executable</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Executable" title="Permalink to this definition">¶</a></dt>
 
1563
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.Generative</span></tt></p>
 
1564
<p>Mark a ClauseElement as supporting execution.</p>
 
1565
<p><a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a> is a superclass for all &#8220;statement&#8221; types
 
1566
of objects, including <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>, <a class="reference internal" href="dml.html#sqlalchemy.sql.expression.delete" title="sqlalchemy.sql.expression.delete"><tt class="xref py py-func docutils literal"><span class="pre">delete()</span></tt></a>, <a class="reference internal" href="dml.html#sqlalchemy.sql.expression.update" title="sqlalchemy.sql.expression.update"><tt class="xref py py-func docutils literal"><span class="pre">update()</span></tt></a>,
 
1567
<a class="reference internal" href="dml.html#sqlalchemy.sql.expression.insert" title="sqlalchemy.sql.expression.insert"><tt class="xref py py-func docutils literal"><span class="pre">insert()</span></tt></a>, <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.text" title="sqlalchemy.sql.expression.text"><tt class="xref py py-func docutils literal"><span class="pre">text()</span></tt></a>.</p>
 
1568
<dl class="attribute">
 
1569
<dt id="sqlalchemy.sql.expression.Executable.bind">
 
1570
<tt class="descname">bind</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Executable.bind" title="Permalink to this definition">¶</a></dt>
 
1571
<dd><p>Returns the <a class="reference internal" href="connections.html#sqlalchemy.engine.Engine" title="sqlalchemy.engine.Engine"><tt class="xref py py-class docutils literal"><span class="pre">Engine</span></tt></a> or <a class="reference internal" href="connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> to
 
1572
which this <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a> is bound, or None if none found.</p>
 
1573
<p>This is a traversal which checks locally, then
 
1574
checks among the &#8220;from&#8221; clauses of associated objects
 
1575
until a bound engine or connection is found.</p>
 
1576
</dd></dl>
 
1577
 
 
1578
<dl class="method">
 
1579
<dt id="sqlalchemy.sql.expression.Executable.execute">
 
1580
<tt class="descname">execute</tt><big>(</big><em>*multiparams</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Executable.execute" title="Permalink to this definition">¶</a></dt>
 
1581
<dd><p>Compile and execute this <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a>.</p>
 
1582
</dd></dl>
 
1583
 
 
1584
<dl class="method">
 
1585
<dt id="sqlalchemy.sql.expression.Executable.execution_options">
 
1586
<tt class="descname">execution_options</tt><big>(</big><em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Executable.execution_options" title="Permalink to this definition">¶</a></dt>
 
1587
<dd><p>Set non-SQL options for the statement which take effect during
 
1588
execution.</p>
 
1589
<p>Execution options can be set on a per-statement or
 
1590
per <a class="reference internal" href="connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> basis.   Additionally, the
 
1591
<a class="reference internal" href="connections.html#sqlalchemy.engine.Engine" title="sqlalchemy.engine.Engine"><tt class="xref py py-class docutils literal"><span class="pre">Engine</span></tt></a> and ORM <a class="reference internal" href="../orm/query.html#sqlalchemy.orm.query.Query" title="sqlalchemy.orm.query.Query"><tt class="xref py py-class docutils literal"><span class="pre">Query</span></tt></a> objects provide
 
1592
access to execution options which they in turn configure upon
 
1593
connections.</p>
 
1594
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.Executable.execution_options" title="sqlalchemy.sql.expression.Executable.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">execution_options()</span></tt></a> method is generative.  A new
 
1595
instance of this statement is returned that contains the options:</p>
 
1596
<div class="highlight-python"><div class="highlight"><pre><span class="n">statement</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">y</span><span class="p">])</span>
 
1597
<span class="n">statement</span> <span class="o">=</span> <span class="n">statement</span><span class="o">.</span><span class="n">execution_options</span><span class="p">(</span><span class="n">autocommit</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span></pre></div>
 
1598
</div>
 
1599
<p>Note that only a subset of possible execution options can be applied
 
1600
to a statement - these include &#8220;autocommit&#8221; and &#8220;stream_results&#8221;,
 
1601
but not &#8220;isolation_level&#8221; or &#8220;compiled_cache&#8221;.
 
1602
See <a class="reference internal" href="connections.html#sqlalchemy.engine.Connection.execution_options" title="sqlalchemy.engine.Connection.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">Connection.execution_options()</span></tt></a> for a full list of
 
1603
possible options.</p>
 
1604
<div class="admonition seealso">
 
1605
<p class="first admonition-title">See also</p>
 
1606
<p><a class="reference internal" href="connections.html#sqlalchemy.engine.Connection.execution_options" title="sqlalchemy.engine.Connection.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">Connection.execution_options()</span></tt></a></p>
 
1607
<p class="last"><a class="reference internal" href="../orm/query.html#sqlalchemy.orm.query.Query.execution_options" title="sqlalchemy.orm.query.Query.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">Query.execution_options()</span></tt></a></p>
 
1608
</div>
 
1609
</dd></dl>
 
1610
 
 
1611
<dl class="method">
 
1612
<dt id="sqlalchemy.sql.expression.Executable.scalar">
 
1613
<tt class="descname">scalar</tt><big>(</big><em>*multiparams</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Executable.scalar" title="Permalink to this definition">¶</a></dt>
 
1614
<dd><p>Compile and execute this <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a>, returning the
 
1615
result&#8217;s scalar representation.</p>
 
1616
</dd></dl>
 
1617
 
 
1618
</dd></dl>
 
1619
 
 
1620
<dl class="class">
 
1621
<dt id="sqlalchemy.sql.expression.FromClause">
 
1622
<em class="property">class </em><tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">FromClause</tt><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause" title="Permalink to this definition">¶</a></dt>
 
1623
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.Selectable</span></tt></a></p>
 
1624
<p>Represent an element that can be used within the <tt class="docutils literal"><span class="pre">FROM</span></tt>
 
1625
clause of a <tt class="docutils literal"><span class="pre">SELECT</span></tt> statement.</p>
 
1626
<p>The most common forms of <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> are the
 
1627
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> and the <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> constructs.  Key
 
1628
features common to all <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> objects include:</p>
 
1629
<ul class="simple">
 
1630
<li>a <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.c" title="sqlalchemy.sql.expression.FromClause.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> collection, which provides per-name access to a collection
 
1631
of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> objects.</li>
 
1632
<li>a <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.primary_key" title="sqlalchemy.sql.expression.FromClause.primary_key"><tt class="xref py py-attr docutils literal"><span class="pre">primary_key</span></tt></a> attribute, which is a collection of all those
 
1633
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> objects that indicate the <tt class="docutils literal"><span class="pre">primary_key</span></tt> flag.</li>
 
1634
<li>Methods to generate various derivations of a &#8220;from&#8221; clause, including
 
1635
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.alias" title="sqlalchemy.sql.expression.FromClause.alias"><tt class="xref py py-meth docutils literal"><span class="pre">FromClause.alias()</span></tt></a>, <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.join" title="sqlalchemy.sql.expression.FromClause.join"><tt class="xref py py-meth docutils literal"><span class="pre">FromClause.join()</span></tt></a>,
 
1636
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.select" title="sqlalchemy.sql.expression.FromClause.select"><tt class="xref py py-meth docutils literal"><span class="pre">FromClause.select()</span></tt></a>.</li>
 
1637
</ul>
 
1638
<dl class="method">
 
1639
<dt id="sqlalchemy.sql.expression.FromClause.alias">
 
1640
<tt class="descname">alias</tt><big>(</big><em>name=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.alias" title="Permalink to this definition">¶</a></dt>
 
1641
<dd><p>return an alias of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1642
<p>This is shorthand for calling:</p>
 
1643
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">alias</span>
 
1644
<span class="n">a</span> <span class="o">=</span> <span class="n">alias</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></pre></div>
 
1645
</div>
 
1646
<p>See <a class="reference internal" href="#sqlalchemy.sql.expression.alias" title="sqlalchemy.sql.expression.alias"><tt class="xref py py-func docutils literal"><span class="pre">alias()</span></tt></a> for details.</p>
 
1647
</dd></dl>
 
1648
 
 
1649
<dl class="attribute">
 
1650
<dt id="sqlalchemy.sql.expression.FromClause.c">
 
1651
<tt class="descname">c</tt><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.c" title="Permalink to this definition">¶</a></dt>
 
1652
<dd><p>An alias for the <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.columns" title="sqlalchemy.sql.expression.FromClause.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> attribute.</p>
 
1653
</dd></dl>
 
1654
 
 
1655
<dl class="attribute">
 
1656
<dt id="sqlalchemy.sql.expression.FromClause.columns">
 
1657
<tt class="descname">columns</tt><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.columns" title="Permalink to this definition">¶</a></dt>
 
1658
<dd><p>A named-based collection of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> objects
 
1659
maintained by this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1660
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.columns" title="sqlalchemy.sql.expression.FromClause.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a>, or <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.c" title="sqlalchemy.sql.expression.FromClause.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> collection, is the gateway
 
1661
to the construction of SQL expressions using table-bound or
 
1662
other selectable-bound columns:</p>
 
1663
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">mytable</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">somecolumn</span> <span class="o">==</span> <span class="mi">5</span><span class="p">)</span></pre></div>
 
1664
</div>
 
1665
</dd></dl>
 
1666
 
 
1667
<dl class="method">
 
1668
<dt id="sqlalchemy.sql.expression.FromClause.correspond_on_equivalents">
 
1669
<tt class="descname">correspond_on_equivalents</tt><big>(</big><em>column</em>, <em>equivalents</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.correspond_on_equivalents" title="Permalink to this definition">¶</a></dt>
 
1670
<dd><p>Return corresponding_column for the given column, or if None
 
1671
search for a match in the given dictionary.</p>
 
1672
</dd></dl>
 
1673
 
 
1674
<dl class="method">
 
1675
<dt id="sqlalchemy.sql.expression.FromClause.corresponding_column">
 
1676
<tt class="descname">corresponding_column</tt><big>(</big><em>column</em>, <em>require_embedded=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.corresponding_column" title="Permalink to this definition">¶</a></dt>
 
1677
<dd><p>Given a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, return the exported
 
1678
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> object from this <a class="reference internal" href="#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a>
 
1679
which corresponds to that original
 
1680
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> via a common ancestor
 
1681
column.</p>
 
1682
<table class="docutils field-list" frame="void" rules="none">
 
1683
<col class="field-name" />
 
1684
<col class="field-body" />
 
1685
<tbody valign="top">
 
1686
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
1687
<li><strong>column</strong> &#8211; the target <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> to be matched</li>
 
1688
<li><strong>require_embedded</strong> &#8211; only return corresponding columns for</li>
 
1689
</ul>
 
1690
</td>
 
1691
</tr>
 
1692
</tbody>
 
1693
</table>
 
1694
<p>the given <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, if the given
 
1695
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> is actually present within a sub-element
 
1696
of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.  Normally the column will match if
 
1697
it merely shares a common ancestor with one of the exported
 
1698
columns of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1699
</dd></dl>
 
1700
 
 
1701
<dl class="method">
 
1702
<dt id="sqlalchemy.sql.expression.FromClause.count">
 
1703
<tt class="descname">count</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.count" title="Permalink to this definition">¶</a></dt>
 
1704
<dd><p>return a SELECT COUNT generated against this
 
1705
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1706
</dd></dl>
 
1707
 
 
1708
<dl class="attribute">
 
1709
<dt id="sqlalchemy.sql.expression.FromClause.description">
 
1710
<tt class="descname">description</tt><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.description" title="Permalink to this definition">¶</a></dt>
 
1711
<dd><p>a brief description of this FromClause.</p>
 
1712
<p>Used primarily for error message formatting.</p>
 
1713
</dd></dl>
 
1714
 
 
1715
<dl class="attribute">
 
1716
<dt id="sqlalchemy.sql.expression.FromClause.foreign_keys">
 
1717
<tt class="descname">foreign_keys</tt><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.foreign_keys" title="Permalink to this definition">¶</a></dt>
 
1718
<dd><p>Return the collection of ForeignKey objects which this
 
1719
FromClause references.</p>
 
1720
</dd></dl>
 
1721
 
 
1722
<dl class="method">
 
1723
<dt id="sqlalchemy.sql.expression.FromClause.is_derived_from">
 
1724
<tt class="descname">is_derived_from</tt><big>(</big><em>fromclause</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.is_derived_from" title="Permalink to this definition">¶</a></dt>
 
1725
<dd><p>Return True if this FromClause is &#8216;derived&#8217; from the given
 
1726
FromClause.</p>
 
1727
<p>An example would be an Alias of a Table is derived from that Table.</p>
 
1728
</dd></dl>
 
1729
 
 
1730
<dl class="method">
 
1731
<dt id="sqlalchemy.sql.expression.FromClause.join">
 
1732
<tt class="descname">join</tt><big>(</big><em>right</em>, <em>onclause=None</em>, <em>isouter=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.join" title="Permalink to this definition">¶</a></dt>
 
1733
<dd><p>return a join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
1734
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1735
</dd></dl>
 
1736
 
 
1737
<dl class="method">
 
1738
<dt id="sqlalchemy.sql.expression.FromClause.outerjoin">
 
1739
<tt class="descname">outerjoin</tt><big>(</big><em>right</em>, <em>onclause=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.outerjoin" title="Permalink to this definition">¶</a></dt>
 
1740
<dd><p>return an outer join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
1741
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1742
</dd></dl>
 
1743
 
 
1744
<dl class="attribute">
 
1745
<dt id="sqlalchemy.sql.expression.FromClause.primary_key">
 
1746
<tt class="descname">primary_key</tt><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.primary_key" title="Permalink to this definition">¶</a></dt>
 
1747
<dd><p>Return the collection of Column objects which comprise the
 
1748
primary key of this FromClause.</p>
 
1749
</dd></dl>
 
1750
 
 
1751
<dl class="method">
 
1752
<dt id="sqlalchemy.sql.expression.FromClause.replace_selectable">
 
1753
<tt class="descname">replace_selectable</tt><big>(</big><em>old</em>, <em>alias</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.replace_selectable" title="Permalink to this definition">¶</a></dt>
 
1754
<dd><p>replace all occurrences of FromClause &#8216;old&#8217; with the given Alias
 
1755
object, returning a copy of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1756
</dd></dl>
 
1757
 
 
1758
<dl class="method">
 
1759
<dt id="sqlalchemy.sql.expression.FromClause.select">
 
1760
<tt class="descname">select</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.FromClause.select" title="Permalink to this definition">¶</a></dt>
 
1761
<dd><p>return a SELECT of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1762
<div class="admonition seealso">
 
1763
<p class="first admonition-title">See also</p>
 
1764
<p class="last"><a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> - general purpose
 
1765
method which allows for arbitrary column lists.</p>
 
1766
</div>
 
1767
</dd></dl>
 
1768
 
 
1769
</dd></dl>
 
1770
 
 
1771
<dl class="class">
 
1772
<dt id="sqlalchemy.sql.expression.Join">
 
1773
<em class="property">class </em><tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">Join</tt><big>(</big><em>left</em>, <em>right</em>, <em>onclause=None</em>, <em>isouter=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join" title="Permalink to this definition">¶</a></dt>
 
1774
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.FromClause</span></tt></a></p>
 
1775
<p>represent a <tt class="docutils literal"><span class="pre">JOIN</span></tt> construct between two <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>
 
1776
elements.</p>
 
1777
<p>The public constructor function for <a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a> is the module-level
 
1778
<a class="reference internal" href="#sqlalchemy.sql.expression.join" title="sqlalchemy.sql.expression.join"><tt class="xref py py-func docutils literal"><span class="pre">join()</span></tt></a> function, as well as the <a class="reference internal" href="#sqlalchemy.sql.expression.join" title="sqlalchemy.sql.expression.join"><tt class="xref py py-func docutils literal"><span class="pre">join()</span></tt></a> method available
 
1779
off all <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> subclasses.</p>
 
1780
<dl class="method">
 
1781
<dt id="sqlalchemy.sql.expression.Join.__init__">
 
1782
<tt class="descname">__init__</tt><big>(</big><em>left</em>, <em>right</em>, <em>onclause=None</em>, <em>isouter=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.__init__" title="Permalink to this definition">¶</a></dt>
 
1783
<dd><p>Construct a new <a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>.</p>
 
1784
<p>The usual entrypoint here is the <a class="reference internal" href="#sqlalchemy.sql.expression.join" title="sqlalchemy.sql.expression.join"><tt class="xref py py-func docutils literal"><span class="pre">join()</span></tt></a>
 
1785
function or the <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.join" title="sqlalchemy.sql.expression.FromClause.join"><tt class="xref py py-meth docutils literal"><span class="pre">FromClause.join()</span></tt></a> method of any
 
1786
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> object.</p>
 
1787
</dd></dl>
 
1788
 
 
1789
<dl class="method">
 
1790
<dt id="sqlalchemy.sql.expression.Join.alias">
 
1791
<tt class="descname">alias</tt><big>(</big><em>name=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.alias" title="Permalink to this definition">¶</a></dt>
 
1792
<dd><p>return an alias of this <a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>.</p>
 
1793
<p>Used against a <a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a> object,
 
1794
<a class="reference internal" href="#sqlalchemy.sql.expression.Join.alias" title="sqlalchemy.sql.expression.Join.alias"><tt class="xref py py-meth docutils literal"><span class="pre">alias()</span></tt></a> calls the <a class="reference internal" href="#sqlalchemy.sql.expression.Join.select" title="sqlalchemy.sql.expression.Join.select"><tt class="xref py py-meth docutils literal"><span class="pre">select()</span></tt></a>
 
1795
method first so that a subquery against a
 
1796
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> construct is generated.
 
1797
the <tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt> construct also has the
 
1798
<tt class="docutils literal"><span class="pre">correlate</span></tt> flag set to <tt class="docutils literal"><span class="pre">False</span></tt> and will not
 
1799
auto-correlate inside an enclosing <tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt>
 
1800
construct.</p>
 
1801
<p>The equivalent long-hand form, given a <a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a> object
 
1802
<tt class="docutils literal"><span class="pre">j</span></tt>, is:</p>
 
1803
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">select</span><span class="p">,</span> <span class="n">alias</span>
 
1804
<span class="n">j</span> <span class="o">=</span> <span class="n">alias</span><span class="p">(</span>
 
1805
    <span class="n">select</span><span class="p">([</span><span class="n">j</span><span class="o">.</span><span class="n">left</span><span class="p">,</span> <span class="n">j</span><span class="o">.</span><span class="n">right</span><span class="p">])</span><span class="o">.</span>\
 
1806
        <span class="n">select_from</span><span class="p">(</span><span class="n">j</span><span class="p">)</span><span class="o">.</span>\
 
1807
        <span class="n">with_labels</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span><span class="o">.</span>\
 
1808
        <span class="n">correlate</span><span class="p">(</span><span class="bp">False</span><span class="p">),</span>
 
1809
    <span class="n">name</span><span class="o">=</span><span class="n">name</span>
 
1810
<span class="p">)</span></pre></div>
 
1811
</div>
 
1812
<p>See <a class="reference internal" href="#sqlalchemy.sql.expression.alias" title="sqlalchemy.sql.expression.alias"><tt class="xref py py-func docutils literal"><span class="pre">alias()</span></tt></a> for further details on
 
1813
aliases.</p>
 
1814
</dd></dl>
 
1815
 
 
1816
<dl class="attribute">
 
1817
<dt id="sqlalchemy.sql.expression.Join.c">
 
1818
<tt class="descname">c</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Join.c" title="Permalink to this definition">¶</a></dt>
 
1819
<dd><div class="inherited-member container">
 
1820
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.c" title="sqlalchemy.sql.expression.FromClause.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1821
<p>An alias for the <a class="reference internal" href="#sqlalchemy.sql.expression.Join.columns" title="sqlalchemy.sql.expression.Join.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> attribute.</p>
 
1822
</dd></dl>
 
1823
 
 
1824
<dl class="attribute">
 
1825
<dt id="sqlalchemy.sql.expression.Join.columns">
 
1826
<tt class="descname">columns</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Join.columns" title="Permalink to this definition">¶</a></dt>
 
1827
<dd><div class="inherited-member container">
 
1828
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.columns" title="sqlalchemy.sql.expression.FromClause.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1829
<p>A named-based collection of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> objects
 
1830
maintained by this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1831
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.Join.columns" title="sqlalchemy.sql.expression.Join.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a>, or <a class="reference internal" href="#sqlalchemy.sql.expression.Join.c" title="sqlalchemy.sql.expression.Join.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> collection, is the gateway
 
1832
to the construction of SQL expressions using table-bound or
 
1833
other selectable-bound columns:</p>
 
1834
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">mytable</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">somecolumn</span> <span class="o">==</span> <span class="mi">5</span><span class="p">)</span></pre></div>
 
1835
</div>
 
1836
</dd></dl>
 
1837
 
 
1838
<dl class="method">
 
1839
<dt id="sqlalchemy.sql.expression.Join.compare">
 
1840
<tt class="descname">compare</tt><big>(</big><em>other</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.compare" title="Permalink to this definition">¶</a></dt>
 
1841
<dd><div class="inherited-member container">
 
1842
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compare" title="sqlalchemy.sql.expression.ClauseElement.compare"><tt class="xref py py-meth docutils literal"><span class="pre">compare()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
1843
<p>Compare this ClauseElement to the given ClauseElement.</p>
 
1844
<p>Subclasses should override the default behavior, which is a
 
1845
straight identity comparison.</p>
 
1846
<p>**kw are arguments consumed by subclass compare() methods and
 
1847
may be used to modify the criteria for comparison.
 
1848
(see <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>)</p>
 
1849
</dd></dl>
 
1850
 
 
1851
<dl class="method">
 
1852
<dt id="sqlalchemy.sql.expression.Join.compile">
 
1853
<tt class="descname">compile</tt><big>(</big><em>bind=None</em>, <em>dialect=None</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.compile" title="Permalink to this definition">¶</a></dt>
 
1854
<dd><div class="inherited-member container">
 
1855
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compile" title="sqlalchemy.sql.expression.ClauseElement.compile"><tt class="xref py py-meth docutils literal"><span class="pre">compile()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
1856
<p>Compile this SQL expression.</p>
 
1857
<p>The return value is a <a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object.
 
1858
Calling <tt class="docutils literal"><span class="pre">str()</span></tt> or <tt class="docutils literal"><span class="pre">unicode()</span></tt> on the returned value will yield a
 
1859
string representation of the result. The
 
1860
<a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object also can return a
 
1861
dictionary of bind parameter names and values
 
1862
using the <tt class="docutils literal"><span class="pre">params</span></tt> accessor.</p>
 
1863
<table class="docutils field-list" frame="void" rules="none">
 
1864
<col class="field-name" />
 
1865
<col class="field-body" />
 
1866
<tbody valign="top">
 
1867
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
1868
<li><strong>bind</strong> &#8211; An <tt class="docutils literal"><span class="pre">Engine</span></tt> or <tt class="docutils literal"><span class="pre">Connection</span></tt> from which a
 
1869
<tt class="docutils literal"><span class="pre">Compiled</span></tt> will be acquired. This argument takes precedence over
 
1870
this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if any.</li>
 
1871
<li><strong>column_keys</strong> &#8211; Used for INSERT and UPDATE statements, a list of
 
1872
column names which should be present in the VALUES clause of the
 
1873
compiled statement. If <tt class="docutils literal"><span class="pre">None</span></tt>, all columns from the target table
 
1874
object are rendered.</li>
 
1875
<li><strong>dialect</strong> &#8211; A <tt class="docutils literal"><span class="pre">Dialect</span></tt> instance from which a <tt class="docutils literal"><span class="pre">Compiled</span></tt>
 
1876
will be acquired. This argument takes precedence over the <cite>bind</cite>
 
1877
argument as well as this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if
 
1878
any.</li>
 
1879
<li><strong>inline</strong> &#8211; Used for INSERT statements, for a dialect which does
 
1880
not support inline retrieval of newly generated primary key
 
1881
columns, will force the expression used to create the new primary
 
1882
key value to be rendered inline within the INSERT statement&#8217;s
 
1883
VALUES clause. This typically refers to Sequence execution but may
 
1884
also refer to any server-side default generation function
 
1885
associated with a primary key <cite>Column</cite>.</li>
 
1886
</ul>
 
1887
</td>
 
1888
</tr>
 
1889
</tbody>
 
1890
</table>
 
1891
</dd></dl>
 
1892
 
 
1893
<dl class="method">
 
1894
<dt id="sqlalchemy.sql.expression.Join.correspond_on_equivalents">
 
1895
<tt class="descname">correspond_on_equivalents</tt><big>(</big><em>column</em>, <em>equivalents</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.correspond_on_equivalents" title="Permalink to this definition">¶</a></dt>
 
1896
<dd><div class="inherited-member container">
 
1897
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.correspond_on_equivalents" title="sqlalchemy.sql.expression.FromClause.correspond_on_equivalents"><tt class="xref py py-meth docutils literal"><span class="pre">correspond_on_equivalents()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1898
<p>Return corresponding_column for the given column, or if None
 
1899
search for a match in the given dictionary.</p>
 
1900
</dd></dl>
 
1901
 
 
1902
<dl class="method">
 
1903
<dt id="sqlalchemy.sql.expression.Join.corresponding_column">
 
1904
<tt class="descname">corresponding_column</tt><big>(</big><em>column</em>, <em>require_embedded=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.corresponding_column" title="Permalink to this definition">¶</a></dt>
 
1905
<dd><div class="inherited-member container">
 
1906
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.corresponding_column" title="sqlalchemy.sql.expression.FromClause.corresponding_column"><tt class="xref py py-meth docutils literal"><span class="pre">corresponding_column()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1907
<p>Given a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, return the exported
 
1908
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> object from this <a class="reference internal" href="#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a>
 
1909
which corresponds to that original
 
1910
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> via a common ancestor
 
1911
column.</p>
 
1912
<table class="docutils field-list" frame="void" rules="none">
 
1913
<col class="field-name" />
 
1914
<col class="field-body" />
 
1915
<tbody valign="top">
 
1916
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
1917
<li><strong>column</strong> &#8211; the target <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> to be matched</li>
 
1918
<li><strong>require_embedded</strong> &#8211; only return corresponding columns for</li>
 
1919
</ul>
 
1920
</td>
 
1921
</tr>
 
1922
</tbody>
 
1923
</table>
 
1924
<p>the given <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, if the given
 
1925
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> is actually present within a sub-element
 
1926
of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.  Normally the column will match if
 
1927
it merely shares a common ancestor with one of the exported
 
1928
columns of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1929
</dd></dl>
 
1930
 
 
1931
<dl class="method">
 
1932
<dt id="sqlalchemy.sql.expression.Join.count">
 
1933
<tt class="descname">count</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.count" title="Permalink to this definition">¶</a></dt>
 
1934
<dd><div class="inherited-member container">
 
1935
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.count" title="sqlalchemy.sql.expression.FromClause.count"><tt class="xref py py-meth docutils literal"><span class="pre">count()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1936
<p>return a SELECT COUNT generated against this
 
1937
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1938
</dd></dl>
 
1939
 
 
1940
<dl class="attribute">
 
1941
<dt id="sqlalchemy.sql.expression.Join.foreign_keys">
 
1942
<tt class="descname">foreign_keys</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Join.foreign_keys" title="Permalink to this definition">¶</a></dt>
 
1943
<dd><div class="inherited-member container">
 
1944
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.foreign_keys" title="sqlalchemy.sql.expression.FromClause.foreign_keys"><tt class="xref py py-attr docutils literal"><span class="pre">foreign_keys</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1945
<p>Return the collection of ForeignKey objects which this
 
1946
FromClause references.</p>
 
1947
</dd></dl>
 
1948
 
 
1949
<dl class="method">
 
1950
<dt id="sqlalchemy.sql.expression.Join.join">
 
1951
<tt class="descname">join</tt><big>(</big><em>right</em>, <em>onclause=None</em>, <em>isouter=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.join" title="Permalink to this definition">¶</a></dt>
 
1952
<dd><div class="inherited-member container">
 
1953
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.join" title="sqlalchemy.sql.expression.FromClause.join"><tt class="xref py py-meth docutils literal"><span class="pre">join()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1954
<p>return a join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
1955
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1956
</dd></dl>
 
1957
 
 
1958
<dl class="method">
 
1959
<dt id="sqlalchemy.sql.expression.Join.outerjoin">
 
1960
<tt class="descname">outerjoin</tt><big>(</big><em>right</em>, <em>onclause=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.outerjoin" title="Permalink to this definition">¶</a></dt>
 
1961
<dd><div class="inherited-member container">
 
1962
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.outerjoin" title="sqlalchemy.sql.expression.FromClause.outerjoin"><tt class="xref py py-meth docutils literal"><span class="pre">outerjoin()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1963
<p>return an outer join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
1964
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1965
</dd></dl>
 
1966
 
 
1967
<dl class="method">
 
1968
<dt id="sqlalchemy.sql.expression.Join.params">
 
1969
<tt class="descname">params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.params" title="Permalink to this definition">¶</a></dt>
 
1970
<dd><div class="inherited-member container">
 
1971
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.params" title="sqlalchemy.sql.expression.ClauseElement.params"><tt class="xref py py-meth docutils literal"><span class="pre">params()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
1972
<p>Return a copy with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a> elements replaced.</p>
 
1973
<p>Returns a copy of this ClauseElement with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a>
 
1974
elements replaced with values taken from the given dictionary:</p>
 
1975
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">clause</span> <span class="o">=</span> <span class="n">column</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">bindparam</span><span class="p">(</span><span class="s">&#39;foo&#39;</span><span class="p">)</span>
 
1976
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">clause</span><span class="o">.</span><span class="n">compile</span><span class="p">()</span><span class="o">.</span><span class="n">params</span>
 
1977
<span class="go">{&#39;foo&#39;:None}</span>
 
1978
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">clause</span><span class="o">.</span><span class="n">params</span><span class="p">({</span><span class="s">&#39;foo&#39;</span><span class="p">:</span><span class="mi">7</span><span class="p">})</span><span class="o">.</span><span class="n">compile</span><span class="p">()</span><span class="o">.</span><span class="n">params</span>
 
1979
<span class="go">{&#39;foo&#39;:7}</span></pre></div>
 
1980
</div>
 
1981
</dd></dl>
 
1982
 
 
1983
<dl class="attribute">
 
1984
<dt id="sqlalchemy.sql.expression.Join.primary_key">
 
1985
<tt class="descname">primary_key</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Join.primary_key" title="Permalink to this definition">¶</a></dt>
 
1986
<dd><div class="inherited-member container">
 
1987
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.primary_key" title="sqlalchemy.sql.expression.FromClause.primary_key"><tt class="xref py py-attr docutils literal"><span class="pre">primary_key</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1988
<p>Return the collection of Column objects which comprise the
 
1989
primary key of this FromClause.</p>
 
1990
</dd></dl>
 
1991
 
 
1992
<dl class="method">
 
1993
<dt id="sqlalchemy.sql.expression.Join.replace_selectable">
 
1994
<tt class="descname">replace_selectable</tt><big>(</big><em>old</em>, <em>alias</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.replace_selectable" title="Permalink to this definition">¶</a></dt>
 
1995
<dd><div class="inherited-member container">
 
1996
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.replace_selectable" title="sqlalchemy.sql.expression.FromClause.replace_selectable"><tt class="xref py py-meth docutils literal"><span class="pre">replace_selectable()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
1997
<p>replace all occurrences of FromClause &#8216;old&#8217; with the given Alias
 
1998
object, returning a copy of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
1999
</dd></dl>
 
2000
 
 
2001
<dl class="method">
 
2002
<dt id="sqlalchemy.sql.expression.Join.select">
 
2003
<tt class="descname">select</tt><big>(</big><em>whereclause=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.select" title="Permalink to this definition">¶</a></dt>
 
2004
<dd><p>Create a <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> from this <a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a>.</p>
 
2005
<p>The equivalent long-hand form, given a <a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a> object
 
2006
<tt class="docutils literal"><span class="pre">j</span></tt>, is:</p>
 
2007
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">select</span>
 
2008
<span class="n">j</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">j</span><span class="o">.</span><span class="n">left</span><span class="p">,</span> <span class="n">j</span><span class="o">.</span><span class="n">right</span><span class="p">],</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span><span class="o">.</span>\
 
2009
            <span class="n">where</span><span class="p">(</span><span class="n">whereclause</span><span class="p">)</span><span class="o">.</span>\
 
2010
            <span class="n">select_from</span><span class="p">(</span><span class="n">j</span><span class="p">)</span></pre></div>
 
2011
</div>
 
2012
<table class="docutils field-list" frame="void" rules="none">
 
2013
<col class="field-name" />
 
2014
<col class="field-body" />
 
2015
<tbody valign="top">
 
2016
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
2017
<li><strong>whereclause</strong> &#8211; the WHERE criterion that will be sent to
 
2018
the <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> function</li>
 
2019
<li><strong>**kwargs</strong> &#8211; all other kwargs are sent to the
 
2020
underlying <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> function.</li>
 
2021
</ul>
 
2022
</td>
 
2023
</tr>
 
2024
</tbody>
 
2025
</table>
 
2026
</dd></dl>
 
2027
 
 
2028
<dl class="method">
 
2029
<dt id="sqlalchemy.sql.expression.Join.unique_params">
 
2030
<tt class="descname">unique_params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Join.unique_params" title="Permalink to this definition">¶</a></dt>
 
2031
<dd><div class="inherited-member container">
 
2032
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.unique_params" title="sqlalchemy.sql.expression.ClauseElement.unique_params"><tt class="xref py py-meth docutils literal"><span class="pre">unique_params()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
2033
<p>Return a copy with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a> elements replaced.</p>
 
2034
<p>Same functionality as <tt class="docutils literal"><span class="pre">params()</span></tt>, except adds <cite>unique=True</cite>
 
2035
to affected bind parameters so that multiple statements can be
 
2036
used.</p>
 
2037
</dd></dl>
 
2038
 
 
2039
</dd></dl>
 
2040
 
 
2041
<dl class="class">
 
2042
<dt id="sqlalchemy.sql.expression.Select">
 
2043
<em class="property">class </em><tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">Select</tt><big>(</big><em>columns</em>, <em>whereclause=None</em>, <em>from_obj=None</em>, <em>distinct=False</em>, <em>having=None</em>, <em>correlate=True</em>, <em>prefixes=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select" title="Permalink to this definition">¶</a></dt>
 
2044
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.HasPrefixes</span></tt>, <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.SelectBase</span></tt></a></p>
 
2045
<p>Represents a <tt class="docutils literal"><span class="pre">SELECT</span></tt> statement.</p>
 
2046
<div class="admonition seealso">
 
2047
<p class="first admonition-title">See also</p>
 
2048
<p><a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> - the function which creates
 
2049
a <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object.</p>
 
2050
<p class="last"><a class="reference internal" href="tutorial.html#coretutorial-selecting"><em>Selecting</em></a> - Core Tutorial description
 
2051
of <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.</p>
 
2052
</div>
 
2053
<dl class="method">
 
2054
<dt id="sqlalchemy.sql.expression.Select.__init__">
 
2055
<tt class="descname">__init__</tt><big>(</big><em>columns</em>, <em>whereclause=None</em>, <em>from_obj=None</em>, <em>distinct=False</em>, <em>having=None</em>, <em>correlate=True</em>, <em>prefixes=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.__init__" title="Permalink to this definition">¶</a></dt>
 
2056
<dd><p>Construct a Select object.</p>
 
2057
<p>The public constructor for Select is the
 
2058
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> function; see that function for
 
2059
argument descriptions.</p>
 
2060
<p>Additional generative and mutator methods are available on the
 
2061
<a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a> superclass.</p>
 
2062
</dd></dl>
 
2063
 
 
2064
<dl class="method">
 
2065
<dt id="sqlalchemy.sql.expression.Select.alias">
 
2066
<tt class="descname">alias</tt><big>(</big><em>name=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.alias" title="Permalink to this definition">¶</a></dt>
 
2067
<dd><div class="inherited-member container">
 
2068
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.alias" title="sqlalchemy.sql.expression.FromClause.alias"><tt class="xref py py-meth docutils literal"><span class="pre">alias()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2069
<p>return an alias of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
2070
<p>This is shorthand for calling:</p>
 
2071
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">alias</span>
 
2072
<span class="n">a</span> <span class="o">=</span> <span class="n">alias</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></pre></div>
 
2073
</div>
 
2074
<p>See <a class="reference internal" href="#sqlalchemy.sql.expression.alias" title="sqlalchemy.sql.expression.alias"><tt class="xref py py-func docutils literal"><span class="pre">alias()</span></tt></a> for details.</p>
 
2075
</dd></dl>
 
2076
 
 
2077
<dl class="method">
 
2078
<dt id="sqlalchemy.sql.expression.Select.append_column">
 
2079
<tt class="descname">append_column</tt><big>(</big><em>column</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.append_column" title="Permalink to this definition">¶</a></dt>
 
2080
<dd><p>append the given column expression to the columns clause of this
 
2081
select() construct.</p>
 
2082
<p>This is an <strong>in-place</strong> mutation method; the
 
2083
<a class="reference internal" href="#sqlalchemy.sql.expression.Select.column" title="sqlalchemy.sql.expression.Select.column"><tt class="xref py py-meth docutils literal"><span class="pre">column()</span></tt></a> method is preferred, as it provides standard
 
2084
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
2085
</dd></dl>
 
2086
 
 
2087
<dl class="method">
 
2088
<dt id="sqlalchemy.sql.expression.Select.append_correlation">
 
2089
<tt class="descname">append_correlation</tt><big>(</big><em>fromclause</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.append_correlation" title="Permalink to this definition">¶</a></dt>
 
2090
<dd><p>append the given correlation expression to this select()
 
2091
construct.</p>
 
2092
<p>This is an <strong>in-place</strong> mutation method; the
 
2093
<a class="reference internal" href="#sqlalchemy.sql.expression.Select.correlate" title="sqlalchemy.sql.expression.Select.correlate"><tt class="xref py py-meth docutils literal"><span class="pre">correlate()</span></tt></a> method is preferred, as it provides standard
 
2094
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
2095
</dd></dl>
 
2096
 
 
2097
<dl class="method">
 
2098
<dt id="sqlalchemy.sql.expression.Select.append_from">
 
2099
<tt class="descname">append_from</tt><big>(</big><em>fromclause</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.append_from" title="Permalink to this definition">¶</a></dt>
 
2100
<dd><p>append the given FromClause expression to this select() construct&#8217;s
 
2101
FROM clause.</p>
 
2102
<p>This is an <strong>in-place</strong> mutation method; the
 
2103
<a class="reference internal" href="#sqlalchemy.sql.expression.Select.select_from" title="sqlalchemy.sql.expression.Select.select_from"><tt class="xref py py-meth docutils literal"><span class="pre">select_from()</span></tt></a> method is preferred, as it provides standard
 
2104
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
2105
</dd></dl>
 
2106
 
 
2107
<dl class="method">
 
2108
<dt id="sqlalchemy.sql.expression.Select.append_group_by">
 
2109
<tt class="descname">append_group_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.append_group_by" title="Permalink to this definition">¶</a></dt>
 
2110
<dd><div class="inherited-member container">
 
2111
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.append_group_by" title="sqlalchemy.sql.expression.SelectBase.append_group_by"><tt class="xref py py-meth docutils literal"><span class="pre">append_group_by()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
2112
<p>Append the given GROUP BY criterion applied to this selectable.</p>
 
2113
<p>The criterion will be appended to any pre-existing GROUP BY criterion.</p>
 
2114
<p>This is an <strong>in-place</strong> mutation method; the
 
2115
<a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.group_by" title="sqlalchemy.sql.expression.SelectBase.group_by"><tt class="xref py py-meth docutils literal"><span class="pre">group_by()</span></tt></a> method is preferred, as it provides standard
 
2116
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
2117
</dd></dl>
 
2118
 
 
2119
<dl class="method">
 
2120
<dt id="sqlalchemy.sql.expression.Select.append_having">
 
2121
<tt class="descname">append_having</tt><big>(</big><em>having</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.append_having" title="Permalink to this definition">¶</a></dt>
 
2122
<dd><p>append the given expression to this select() construct&#8217;s HAVING
 
2123
criterion.</p>
 
2124
<p>The expression will be joined to existing HAVING criterion via AND.</p>
 
2125
<p>This is an <strong>in-place</strong> mutation method; the
 
2126
<a class="reference internal" href="#sqlalchemy.sql.expression.Select.having" title="sqlalchemy.sql.expression.Select.having"><tt class="xref py py-meth docutils literal"><span class="pre">having()</span></tt></a> method is preferred, as it provides standard
 
2127
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
2128
</dd></dl>
 
2129
 
 
2130
<dl class="method">
 
2131
<dt id="sqlalchemy.sql.expression.Select.append_order_by">
 
2132
<tt class="descname">append_order_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.append_order_by" title="Permalink to this definition">¶</a></dt>
 
2133
<dd><div class="inherited-member container">
 
2134
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.append_order_by" title="sqlalchemy.sql.expression.SelectBase.append_order_by"><tt class="xref py py-meth docutils literal"><span class="pre">append_order_by()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
2135
<p>Append the given ORDER BY criterion applied to this selectable.</p>
 
2136
<p>The criterion will be appended to any pre-existing ORDER BY criterion.</p>
 
2137
<p>This is an <strong>in-place</strong> mutation method; the
 
2138
<a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.order_by" title="sqlalchemy.sql.expression.SelectBase.order_by"><tt class="xref py py-meth docutils literal"><span class="pre">order_by()</span></tt></a> method is preferred, as it provides standard
 
2139
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
2140
</dd></dl>
 
2141
 
 
2142
<dl class="method">
 
2143
<dt id="sqlalchemy.sql.expression.Select.append_prefix">
 
2144
<tt class="descname">append_prefix</tt><big>(</big><em>clause</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.append_prefix" title="Permalink to this definition">¶</a></dt>
 
2145
<dd><p>append the given columns clause prefix expression to this select()
 
2146
construct.</p>
 
2147
<p>This is an <strong>in-place</strong> mutation method; the
 
2148
<a class="reference internal" href="#sqlalchemy.sql.expression.Select.prefix_with" title="sqlalchemy.sql.expression.Select.prefix_with"><tt class="xref py py-meth docutils literal"><span class="pre">prefix_with()</span></tt></a> method is preferred, as it provides standard
 
2149
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
2150
</dd></dl>
 
2151
 
 
2152
<dl class="method">
 
2153
<dt id="sqlalchemy.sql.expression.Select.append_whereclause">
 
2154
<tt class="descname">append_whereclause</tt><big>(</big><em>whereclause</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.append_whereclause" title="Permalink to this definition">¶</a></dt>
 
2155
<dd><p>append the given expression to this select() construct&#8217;s WHERE
 
2156
criterion.</p>
 
2157
<p>The expression will be joined to existing WHERE criterion via AND.</p>
 
2158
<p>This is an <strong>in-place</strong> mutation method; the
 
2159
<a class="reference internal" href="#sqlalchemy.sql.expression.Select.where" title="sqlalchemy.sql.expression.Select.where"><tt class="xref py py-meth docutils literal"><span class="pre">where()</span></tt></a> method is preferred, as it provides standard
 
2160
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
2161
</dd></dl>
 
2162
 
 
2163
<dl class="method">
 
2164
<dt id="sqlalchemy.sql.expression.Select.apply_labels">
 
2165
<tt class="descname">apply_labels</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.apply_labels" title="Permalink to this definition">¶</a></dt>
 
2166
<dd><div class="inherited-member container">
 
2167
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.apply_labels" title="sqlalchemy.sql.expression.SelectBase.apply_labels"><tt class="xref py py-meth docutils literal"><span class="pre">apply_labels()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
2168
<p>return a new selectable with the &#8216;use_labels&#8217; flag set to True.</p>
 
2169
<p>This will result in column expressions being generated using labels
 
2170
against their table name, such as &#8220;SELECT somecolumn AS
 
2171
tablename_somecolumn&#8221;. This allows selectables which contain multiple
 
2172
FROM clauses to produce a unique set of column names regardless of
 
2173
name conflicts among the individual FROM clauses.</p>
 
2174
</dd></dl>
 
2175
 
 
2176
<dl class="method">
 
2177
<dt id="sqlalchemy.sql.expression.Select.as_scalar">
 
2178
<tt class="descname">as_scalar</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.as_scalar" title="Permalink to this definition">¶</a></dt>
 
2179
<dd><div class="inherited-member container">
 
2180
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.as_scalar" title="sqlalchemy.sql.expression.SelectBase.as_scalar"><tt class="xref py py-meth docutils literal"><span class="pre">as_scalar()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
2181
<p>return a &#8216;scalar&#8217; representation of this selectable, which can be
 
2182
used as a column expression.</p>
 
2183
<p>Typically, a select statement which has only one column in its columns
 
2184
clause is eligible to be used as a scalar expression.</p>
 
2185
<p>The returned object is an instance of
 
2186
<tt class="xref py py-class docutils literal"><span class="pre">ScalarSelect</span></tt>.</p>
 
2187
</dd></dl>
 
2188
 
 
2189
<dl class="method">
 
2190
<dt id="sqlalchemy.sql.expression.Select.autocommit">
 
2191
<tt class="descname">autocommit</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.autocommit" title="Permalink to this definition">¶</a></dt>
 
2192
<dd><div class="inherited-member container">
 
2193
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.autocommit" title="sqlalchemy.sql.expression.SelectBase.autocommit"><tt class="xref py py-meth docutils literal"><span class="pre">autocommit()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
2194
<p>return a new selectable with the &#8216;autocommit&#8217; flag set to</p>
 
2195
<div class="deprecated">
 
2196
<p><span>Deprecated since version 0.6: </span><tt class="xref py py-func docutils literal"><span class="pre">autocommit()</span></tt> is deprecated. Use <tt class="xref py py-func docutils literal"><span class="pre">Executable.execution_options()</span></tt> with the &#8216;autocommit&#8217; flag.</p>
 
2197
</div>
 
2198
<p>True.</p>
 
2199
</dd></dl>
 
2200
 
 
2201
<dl class="attribute">
 
2202
<dt id="sqlalchemy.sql.expression.Select.c">
 
2203
<tt class="descname">c</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Select.c" title="Permalink to this definition">¶</a></dt>
 
2204
<dd><div class="inherited-member container">
 
2205
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.c" title="sqlalchemy.sql.expression.FromClause.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2206
<p>An alias for the <a class="reference internal" href="#sqlalchemy.sql.expression.Select.columns" title="sqlalchemy.sql.expression.Select.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> attribute.</p>
 
2207
</dd></dl>
 
2208
 
 
2209
<dl class="method">
 
2210
<dt id="sqlalchemy.sql.expression.Select.column">
 
2211
<tt class="descname">column</tt><big>(</big><em>column</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.column" title="Permalink to this definition">¶</a></dt>
 
2212
<dd><p>return a new select() construct with the given column expression
 
2213
added to its columns clause.</p>
 
2214
</dd></dl>
 
2215
 
 
2216
<dl class="attribute">
 
2217
<dt id="sqlalchemy.sql.expression.Select.columns">
 
2218
<tt class="descname">columns</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Select.columns" title="Permalink to this definition">¶</a></dt>
 
2219
<dd><div class="inherited-member container">
 
2220
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.columns" title="sqlalchemy.sql.expression.FromClause.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2221
<p>A named-based collection of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> objects
 
2222
maintained by this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
2223
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.Select.columns" title="sqlalchemy.sql.expression.Select.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a>, or <a class="reference internal" href="#sqlalchemy.sql.expression.Select.c" title="sqlalchemy.sql.expression.Select.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> collection, is the gateway
 
2224
to the construction of SQL expressions using table-bound or
 
2225
other selectable-bound columns:</p>
 
2226
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">mytable</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">somecolumn</span> <span class="o">==</span> <span class="mi">5</span><span class="p">)</span></pre></div>
 
2227
</div>
 
2228
</dd></dl>
 
2229
 
 
2230
<dl class="method">
 
2231
<dt id="sqlalchemy.sql.expression.Select.compare">
 
2232
<tt class="descname">compare</tt><big>(</big><em>other</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.compare" title="Permalink to this definition">¶</a></dt>
 
2233
<dd><div class="inherited-member container">
 
2234
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compare" title="sqlalchemy.sql.expression.ClauseElement.compare"><tt class="xref py py-meth docutils literal"><span class="pre">compare()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
2235
<p>Compare this ClauseElement to the given ClauseElement.</p>
 
2236
<p>Subclasses should override the default behavior, which is a
 
2237
straight identity comparison.</p>
 
2238
<p>**kw are arguments consumed by subclass compare() methods and
 
2239
may be used to modify the criteria for comparison.
 
2240
(see <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>)</p>
 
2241
</dd></dl>
 
2242
 
 
2243
<dl class="method">
 
2244
<dt id="sqlalchemy.sql.expression.Select.compile">
 
2245
<tt class="descname">compile</tt><big>(</big><em>bind=None</em>, <em>dialect=None</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.compile" title="Permalink to this definition">¶</a></dt>
 
2246
<dd><div class="inherited-member container">
 
2247
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compile" title="sqlalchemy.sql.expression.ClauseElement.compile"><tt class="xref py py-meth docutils literal"><span class="pre">compile()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
2248
<p>Compile this SQL expression.</p>
 
2249
<p>The return value is a <a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object.
 
2250
Calling <tt class="docutils literal"><span class="pre">str()</span></tt> or <tt class="docutils literal"><span class="pre">unicode()</span></tt> on the returned value will yield a
 
2251
string representation of the result. The
 
2252
<a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object also can return a
 
2253
dictionary of bind parameter names and values
 
2254
using the <tt class="docutils literal"><span class="pre">params</span></tt> accessor.</p>
 
2255
<table class="docutils field-list" frame="void" rules="none">
 
2256
<col class="field-name" />
 
2257
<col class="field-body" />
 
2258
<tbody valign="top">
 
2259
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
2260
<li><strong>bind</strong> &#8211; An <tt class="docutils literal"><span class="pre">Engine</span></tt> or <tt class="docutils literal"><span class="pre">Connection</span></tt> from which a
 
2261
<tt class="docutils literal"><span class="pre">Compiled</span></tt> will be acquired. This argument takes precedence over
 
2262
this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if any.</li>
 
2263
<li><strong>column_keys</strong> &#8211; Used for INSERT and UPDATE statements, a list of
 
2264
column names which should be present in the VALUES clause of the
 
2265
compiled statement. If <tt class="docutils literal"><span class="pre">None</span></tt>, all columns from the target table
 
2266
object are rendered.</li>
 
2267
<li><strong>dialect</strong> &#8211; A <tt class="docutils literal"><span class="pre">Dialect</span></tt> instance from which a <tt class="docutils literal"><span class="pre">Compiled</span></tt>
 
2268
will be acquired. This argument takes precedence over the <cite>bind</cite>
 
2269
argument as well as this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if
 
2270
any.</li>
 
2271
<li><strong>inline</strong> &#8211; Used for INSERT statements, for a dialect which does
 
2272
not support inline retrieval of newly generated primary key
 
2273
columns, will force the expression used to create the new primary
 
2274
key value to be rendered inline within the INSERT statement&#8217;s
 
2275
VALUES clause. This typically refers to Sequence execution but may
 
2276
also refer to any server-side default generation function
 
2277
associated with a primary key <cite>Column</cite>.</li>
 
2278
</ul>
 
2279
</td>
 
2280
</tr>
 
2281
</tbody>
 
2282
</table>
 
2283
</dd></dl>
 
2284
 
 
2285
<dl class="method">
 
2286
<dt id="sqlalchemy.sql.expression.Select.correlate">
 
2287
<tt class="descname">correlate</tt><big>(</big><em>*fromclauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.correlate" title="Permalink to this definition">¶</a></dt>
 
2288
<dd><p>return a new <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> which will correlate the given FROM
 
2289
clauses to that of an enclosing <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>.</p>
 
2290
<p>Calling this method turns off the <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object&#8217;s
 
2291
default behavior of &#8220;auto-correlation&#8221;.  Normally, FROM elements
 
2292
which appear in a <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> that encloses this one via
 
2293
its <a class="reference internal" href="../glossary.html#term-where-clause"><em class="xref std std-term">WHERE clause</em></a>, ORDER BY, HAVING or
 
2294
<a class="reference internal" href="../glossary.html#term-columns-clause"><em class="xref std std-term">columns clause</em></a> will be omitted from this <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>
 
2295
object&#8217;s <a class="reference internal" href="../glossary.html#term-from-clause"><em class="xref std std-term">FROM clause</em></a>.
 
2296
Setting an explicit correlation collection using the
 
2297
<a class="reference internal" href="#sqlalchemy.sql.expression.Select.correlate" title="sqlalchemy.sql.expression.Select.correlate"><tt class="xref py py-meth docutils literal"><span class="pre">Select.correlate()</span></tt></a> method provides a fixed list of FROM objects
 
2298
that can potentially take place in this process.</p>
 
2299
<p>When <a class="reference internal" href="#sqlalchemy.sql.expression.Select.correlate" title="sqlalchemy.sql.expression.Select.correlate"><tt class="xref py py-meth docutils literal"><span class="pre">Select.correlate()</span></tt></a> is used to apply specific FROM clauses
 
2300
for correlation, the FROM elements become candidates for
 
2301
correlation regardless of how deeply nested this <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>
 
2302
object is, relative to an enclosing <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> which refers to
 
2303
the same FROM object.  This is in contrast to the behavior of
 
2304
&#8220;auto-correlation&#8221; which only correlates to an immediate enclosing
 
2305
<a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>.   Multi-level correlation ensures that the link
 
2306
between enclosed and enclosing <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> is always via
 
2307
at least one WHERE/ORDER BY/HAVING/columns clause in order for
 
2308
correlation to take place.</p>
 
2309
<p>If <tt class="docutils literal"><span class="pre">None</span></tt> is passed, the <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object will correlate
 
2310
none of its FROM entries, and all will render unconditionally
 
2311
in the local FROM clause.</p>
 
2312
<table class="docutils field-list" frame="void" rules="none">
 
2313
<col class="field-name" />
 
2314
<col class="field-body" />
 
2315
<tbody valign="top">
 
2316
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>*fromclauses</strong> &#8211; <p>a list of one or more <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>
 
2317
constructs, or other compatible constructs (i.e. ORM-mapped
 
2318
classes) to become part of the correlate collection.</p>
 
2319
<div class="versionchanged">
 
2320
<p><span>Changed in version 0.8.0: </span>ORM-mapped classes are accepted by
 
2321
<a class="reference internal" href="#sqlalchemy.sql.expression.Select.correlate" title="sqlalchemy.sql.expression.Select.correlate"><tt class="xref py py-meth docutils literal"><span class="pre">Select.correlate()</span></tt></a>.</p>
 
2322
</div>
 
2323
</td>
 
2324
</tr>
 
2325
</tbody>
 
2326
</table>
 
2327
<div class="versionchanged">
 
2328
<p><span>Changed in version 0.8.0: </span>The <a class="reference internal" href="#sqlalchemy.sql.expression.Select.correlate" title="sqlalchemy.sql.expression.Select.correlate"><tt class="xref py py-meth docutils literal"><span class="pre">Select.correlate()</span></tt></a> method no
 
2329
longer unconditionally removes entries from the FROM clause; instead,
 
2330
the candidate FROM entries must also be matched by a FROM entry
 
2331
located in an enclosing <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>, which ultimately encloses
 
2332
this one as present in the WHERE clause, ORDER BY clause, HAVING
 
2333
clause, or columns clause of an enclosing <tt class="xref py py-meth docutils literal"><span class="pre">Select()</span></tt>.</p>
 
2334
</div>
 
2335
<div class="versionchanged">
 
2336
<p><span>Changed in version 0.8.2: </span>explicit correlation takes place
 
2337
via any level of nesting of <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> objects; in previous
 
2338
0.8 versions, correlation would only occur relative to the immediate
 
2339
enclosing <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> construct.</p>
 
2340
</div>
 
2341
<div class="admonition seealso">
 
2342
<p class="first admonition-title">See also</p>
 
2343
<p><a class="reference internal" href="#sqlalchemy.sql.expression.Select.correlate_except" title="sqlalchemy.sql.expression.Select.correlate_except"><tt class="xref py py-meth docutils literal"><span class="pre">Select.correlate_except()</span></tt></a></p>
 
2344
<p class="last"><a class="reference internal" href="tutorial.html#correlated-subqueries"><em>Correlated Subqueries</em></a></p>
 
2345
</div>
 
2346
</dd></dl>
 
2347
 
 
2348
<dl class="method">
 
2349
<dt id="sqlalchemy.sql.expression.Select.correlate_except">
 
2350
<tt class="descname">correlate_except</tt><big>(</big><em>*fromclauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.correlate_except" title="Permalink to this definition">¶</a></dt>
 
2351
<dd><p>return a new <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> which will omit the given FROM
 
2352
clauses from the auto-correlation process.</p>
 
2353
<p>Calling <a class="reference internal" href="#sqlalchemy.sql.expression.Select.correlate_except" title="sqlalchemy.sql.expression.Select.correlate_except"><tt class="xref py py-meth docutils literal"><span class="pre">Select.correlate_except()</span></tt></a> turns off the
 
2354
<a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object&#8217;s default behavior of
 
2355
&#8220;auto-correlation&#8221; for the given FROM elements.  An element
 
2356
specified here will unconditionally appear in the FROM list, while
 
2357
all other FROM elements remain subject to normal auto-correlation
 
2358
behaviors.</p>
 
2359
<div class="versionchanged">
 
2360
<p><span>Changed in version 0.8.2: </span>The <a class="reference internal" href="#sqlalchemy.sql.expression.Select.correlate_except" title="sqlalchemy.sql.expression.Select.correlate_except"><tt class="xref py py-meth docutils literal"><span class="pre">Select.correlate_except()</span></tt></a>
 
2361
method was improved to fully prevent FROM clauses specified here
 
2362
from being omitted from the immediate FROM clause of this
 
2363
<a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>.</p>
 
2364
</div>
 
2365
<p>If <tt class="docutils literal"><span class="pre">None</span></tt> is passed, the <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object will correlate
 
2366
all of its FROM entries.</p>
 
2367
<div class="versionchanged">
 
2368
<p><span>Changed in version 0.8.2: </span>calling <tt class="docutils literal"><span class="pre">correlate_except(None)</span></tt> will
 
2369
correctly auto-correlate all FROM clauses.</p>
 
2370
</div>
 
2371
<table class="docutils field-list" frame="void" rules="none">
 
2372
<col class="field-name" />
 
2373
<col class="field-body" />
 
2374
<tbody valign="top">
 
2375
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>*fromclauses</strong> &#8211; a list of one or more <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>
 
2376
constructs, or other compatible constructs (i.e. ORM-mapped
 
2377
classes) to become part of the correlate-exception collection.</td>
 
2378
</tr>
 
2379
</tbody>
 
2380
</table>
 
2381
<div class="admonition seealso">
 
2382
<p class="first admonition-title">See also</p>
 
2383
<p><a class="reference internal" href="#sqlalchemy.sql.expression.Select.correlate" title="sqlalchemy.sql.expression.Select.correlate"><tt class="xref py py-meth docutils literal"><span class="pre">Select.correlate()</span></tt></a></p>
 
2384
<p class="last"><a class="reference internal" href="tutorial.html#correlated-subqueries"><em>Correlated Subqueries</em></a></p>
 
2385
</div>
 
2386
</dd></dl>
 
2387
 
 
2388
<dl class="method">
 
2389
<dt id="sqlalchemy.sql.expression.Select.correspond_on_equivalents">
 
2390
<tt class="descname">correspond_on_equivalents</tt><big>(</big><em>column</em>, <em>equivalents</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.correspond_on_equivalents" title="Permalink to this definition">¶</a></dt>
 
2391
<dd><div class="inherited-member container">
 
2392
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.correspond_on_equivalents" title="sqlalchemy.sql.expression.FromClause.correspond_on_equivalents"><tt class="xref py py-meth docutils literal"><span class="pre">correspond_on_equivalents()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2393
<p>Return corresponding_column for the given column, or if None
 
2394
search for a match in the given dictionary.</p>
 
2395
</dd></dl>
 
2396
 
 
2397
<dl class="method">
 
2398
<dt id="sqlalchemy.sql.expression.Select.corresponding_column">
 
2399
<tt class="descname">corresponding_column</tt><big>(</big><em>column</em>, <em>require_embedded=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.corresponding_column" title="Permalink to this definition">¶</a></dt>
 
2400
<dd><div class="inherited-member container">
 
2401
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.corresponding_column" title="sqlalchemy.sql.expression.FromClause.corresponding_column"><tt class="xref py py-meth docutils literal"><span class="pre">corresponding_column()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2402
<p>Given a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, return the exported
 
2403
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> object from this <a class="reference internal" href="#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a>
 
2404
which corresponds to that original
 
2405
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> via a common ancestor
 
2406
column.</p>
 
2407
<table class="docutils field-list" frame="void" rules="none">
 
2408
<col class="field-name" />
 
2409
<col class="field-body" />
 
2410
<tbody valign="top">
 
2411
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
2412
<li><strong>column</strong> &#8211; the target <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> to be matched</li>
 
2413
<li><strong>require_embedded</strong> &#8211; only return corresponding columns for</li>
 
2414
</ul>
 
2415
</td>
 
2416
</tr>
 
2417
</tbody>
 
2418
</table>
 
2419
<p>the given <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, if the given
 
2420
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> is actually present within a sub-element
 
2421
of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.  Normally the column will match if
 
2422
it merely shares a common ancestor with one of the exported
 
2423
columns of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
2424
</dd></dl>
 
2425
 
 
2426
<dl class="method">
 
2427
<dt id="sqlalchemy.sql.expression.Select.count">
 
2428
<tt class="descname">count</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.count" title="Permalink to this definition">¶</a></dt>
 
2429
<dd><div class="inherited-member container">
 
2430
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.count" title="sqlalchemy.sql.expression.FromClause.count"><tt class="xref py py-meth docutils literal"><span class="pre">count()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2431
<p>return a SELECT COUNT generated against this
 
2432
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
2433
</dd></dl>
 
2434
 
 
2435
<dl class="method">
 
2436
<dt id="sqlalchemy.sql.expression.Select.cte">
 
2437
<tt class="descname">cte</tt><big>(</big><em>name=None</em>, <em>recursive=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.cte" title="Permalink to this definition">¶</a></dt>
 
2438
<dd><div class="inherited-member container">
 
2439
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.cte" title="sqlalchemy.sql.expression.SelectBase.cte"><tt class="xref py py-meth docutils literal"><span class="pre">cte()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
2440
<p>Return a new <a class="reference internal" href="#sqlalchemy.sql.expression.CTE" title="sqlalchemy.sql.expression.CTE"><tt class="xref py py-class docutils literal"><span class="pre">CTE</span></tt></a>, or Common Table Expression instance.</p>
 
2441
<p>Common table expressions are a SQL standard whereby SELECT
 
2442
statements can draw upon secondary statements specified along
 
2443
with the primary statement, using a clause called &#8220;WITH&#8221;.
 
2444
Special semantics regarding UNION can also be employed to
 
2445
allow &#8220;recursive&#8221; queries, where a SELECT statement can draw
 
2446
upon the set of rows that have previously been selected.</p>
 
2447
<p>SQLAlchemy detects <a class="reference internal" href="#sqlalchemy.sql.expression.CTE" title="sqlalchemy.sql.expression.CTE"><tt class="xref py py-class docutils literal"><span class="pre">CTE</span></tt></a> objects, which are treated
 
2448
similarly to <a class="reference internal" href="#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a> objects, as special elements
 
2449
to be delivered to the FROM clause of the statement as well
 
2450
as to a WITH clause at the top of the statement.</p>
 
2451
<div class="versionadded">
 
2452
<p><span>New in version 0.7.6.</span></p>
 
2453
</div>
 
2454
<table class="docutils field-list" frame="void" rules="none">
 
2455
<col class="field-name" />
 
2456
<col class="field-body" />
 
2457
<tbody valign="top">
 
2458
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
2459
<li><strong>name</strong> &#8211; name given to the common table expression.  Like
 
2460
<tt class="xref py py-meth docutils literal"><span class="pre">_FromClause.alias()</span></tt>, the name can be left as <tt class="docutils literal"><span class="pre">None</span></tt>
 
2461
in which case an anonymous symbol will be used at query
 
2462
compile time.</li>
 
2463
<li><strong>recursive</strong> &#8211; if <tt class="docutils literal"><span class="pre">True</span></tt>, will render <tt class="docutils literal"><span class="pre">WITH</span> <span class="pre">RECURSIVE</span></tt>.
 
2464
A recursive common table expression is intended to be used in
 
2465
conjunction with UNION ALL in order to derive rows
 
2466
from those already selected.</li>
 
2467
</ul>
 
2468
</td>
 
2469
</tr>
 
2470
</tbody>
 
2471
</table>
 
2472
<p>The following examples illustrate two examples from
 
2473
Postgresql&#8217;s documentation at
 
2474
<a class="reference external" href="http://www.postgresql.org/docs/8.4/static/queries-with.html">http://www.postgresql.org/docs/8.4/static/queries-with.html</a>.</p>
 
2475
<p>Example 1, non recursive:</p>
 
2476
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Table</span><span class="p">,</span> <span class="n">Column</span><span class="p">,</span> <span class="n">String</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">MetaData</span><span class="p">,</span> \
 
2477
    <span class="n">select</span><span class="p">,</span> <span class="n">func</span>
 
2478
 
 
2479
<span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
 
2480
 
 
2481
<span class="n">orders</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">&#39;orders&#39;</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
 
2482
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;region&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
2483
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;amount&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
 
2484
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;product&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
2485
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;quantity&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">)</span>
 
2486
<span class="p">)</span>
 
2487
 
 
2488
<span class="n">regional_sales</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
2489
                    <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">,</span>
 
2490
                    <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">amount</span><span class="p">)</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s">&#39;total_sales&#39;</span><span class="p">)</span>
 
2491
                <span class="p">])</span><span class="o">.</span><span class="n">group_by</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">)</span><span class="o">.</span><span class="n">cte</span><span class="p">(</span><span class="s">&quot;regional_sales&quot;</span><span class="p">)</span>
 
2492
 
 
2493
 
 
2494
<span class="n">top_regions</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">regional_sales</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">])</span><span class="o">.</span>\
 
2495
        <span class="n">where</span><span class="p">(</span>
 
2496
            <span class="n">regional_sales</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">total_sales</span> <span class="o">&gt;</span>
 
2497
            <span class="n">select</span><span class="p">([</span>
 
2498
                <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">regional_sales</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">total_sales</span><span class="p">)</span><span class="o">/</span><span class="mi">10</span>
 
2499
            <span class="p">])</span>
 
2500
        <span class="p">)</span><span class="o">.</span><span class="n">cte</span><span class="p">(</span><span class="s">&quot;top_regions&quot;</span><span class="p">)</span>
 
2501
 
 
2502
<span class="n">statement</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
2503
            <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">,</span>
 
2504
            <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">product</span><span class="p">,</span>
 
2505
            <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span><span class="p">)</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s">&quot;product_units&quot;</span><span class="p">),</span>
 
2506
            <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">amount</span><span class="p">)</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s">&quot;product_sales&quot;</span><span class="p">)</span>
 
2507
    <span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="o">.</span><span class="n">in_</span><span class="p">(</span>
 
2508
        <span class="n">select</span><span class="p">([</span><span class="n">top_regions</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">])</span>
 
2509
    <span class="p">))</span><span class="o">.</span><span class="n">group_by</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">,</span> <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">product</span><span class="p">)</span>
 
2510
 
 
2511
<span class="n">result</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">statement</span><span class="p">)</span><span class="o">.</span><span class="n">fetchall</span><span class="p">()</span></pre></div>
 
2512
</div>
 
2513
<p>Example 2, WITH RECURSIVE:</p>
 
2514
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Table</span><span class="p">,</span> <span class="n">Column</span><span class="p">,</span> <span class="n">String</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">MetaData</span><span class="p">,</span> \
 
2515
    <span class="n">select</span><span class="p">,</span> <span class="n">func</span>
 
2516
 
 
2517
<span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
 
2518
 
 
2519
<span class="n">parts</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">&#39;parts&#39;</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
 
2520
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;part&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
2521
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;sub_part&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
2522
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;quantity&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
 
2523
<span class="p">)</span>
 
2524
 
 
2525
<span class="n">included_parts</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
2526
                    <span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">,</span>
 
2527
                    <span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="p">,</span>
 
2528
                    <span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span><span class="p">])</span><span class="o">.</span>\
 
2529
                    <span class="n">where</span><span class="p">(</span><span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="o">==</span><span class="s">&#39;our part&#39;</span><span class="p">)</span><span class="o">.</span>\
 
2530
                    <span class="n">cte</span><span class="p">(</span><span class="n">recursive</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
 
2531
 
 
2532
 
 
2533
<span class="n">incl_alias</span> <span class="o">=</span> <span class="n">included_parts</span><span class="o">.</span><span class="n">alias</span><span class="p">()</span>
 
2534
<span class="n">parts_alias</span> <span class="o">=</span> <span class="n">parts</span><span class="o">.</span><span class="n">alias</span><span class="p">()</span>
 
2535
<span class="n">included_parts</span> <span class="o">=</span> <span class="n">included_parts</span><span class="o">.</span><span class="n">union_all</span><span class="p">(</span>
 
2536
    <span class="n">select</span><span class="p">([</span>
 
2537
        <span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="p">,</span>
 
2538
        <span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">,</span>
 
2539
        <span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span>
 
2540
    <span class="p">])</span><span class="o">.</span>
 
2541
        <span class="n">where</span><span class="p">(</span><span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="o">==</span><span class="n">incl_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">)</span>
 
2542
<span class="p">)</span>
 
2543
 
 
2544
<span class="n">statement</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
2545
            <span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">,</span>
 
2546
            <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span><span class="p">)</span><span class="o">.</span>
 
2547
              <span class="n">label</span><span class="p">(</span><span class="s">&#39;total_quantity&#39;</span><span class="p">)</span>
 
2548
        <span class="p">])</span><span class="o">.</span>                    <span class="n">select_from</span><span class="p">(</span><span class="n">included_parts</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">parts</span><span class="p">,</span>
 
2549
                    <span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="o">==</span><span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="p">))</span><span class="o">.</span>\
 
2550
        <span class="n">group_by</span><span class="p">(</span><span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">)</span>
 
2551
 
 
2552
<span class="n">result</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">statement</span><span class="p">)</span><span class="o">.</span><span class="n">fetchall</span><span class="p">()</span></pre></div>
 
2553
</div>
 
2554
<div class="admonition seealso">
 
2555
<p class="first admonition-title">See also</p>
 
2556
<p class="last"><a class="reference internal" href="../orm/query.html#sqlalchemy.orm.query.Query.cte" title="sqlalchemy.orm.query.Query.cte"><tt class="xref py py-meth docutils literal"><span class="pre">orm.query.Query.cte()</span></tt></a> - ORM version of <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.cte" title="sqlalchemy.sql.expression.SelectBase.cte"><tt class="xref py py-meth docutils literal"><span class="pre">SelectBase.cte()</span></tt></a>.</p>
 
2557
</div>
 
2558
</dd></dl>
 
2559
 
 
2560
<dl class="attribute">
 
2561
<dt id="sqlalchemy.sql.expression.Select.description">
 
2562
<tt class="descname">description</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Select.description" title="Permalink to this definition">¶</a></dt>
 
2563
<dd><div class="inherited-member container">
 
2564
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.description" title="sqlalchemy.sql.expression.FromClause.description"><tt class="xref py py-attr docutils literal"><span class="pre">description</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2565
<p>a brief description of this FromClause.</p>
 
2566
<p>Used primarily for error message formatting.</p>
 
2567
</dd></dl>
 
2568
 
 
2569
<dl class="method">
 
2570
<dt id="sqlalchemy.sql.expression.Select.distinct">
 
2571
<tt class="descname">distinct</tt><big>(</big><em>*expr</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.distinct" title="Permalink to this definition">¶</a></dt>
 
2572
<dd><p>Return a new select() construct which will apply DISTINCT to its
 
2573
columns clause.</p>
 
2574
<table class="docutils field-list" frame="void" rules="none">
 
2575
<col class="field-name" />
 
2576
<col class="field-body" />
 
2577
<tbody valign="top">
 
2578
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>*expr</strong> &#8211; optional column expressions.  When present,
 
2579
the Postgresql dialect will render a <tt class="docutils literal"><span class="pre">DISTINCT</span> <span class="pre">ON</span> <span class="pre">(&lt;expressions&gt;&gt;)</span></tt>
 
2580
construct.</td>
 
2581
</tr>
 
2582
</tbody>
 
2583
</table>
 
2584
</dd></dl>
 
2585
 
 
2586
<dl class="method">
 
2587
<dt id="sqlalchemy.sql.expression.Select.except_">
 
2588
<tt class="descname">except_</tt><big>(</big><em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.except_" title="Permalink to this definition">¶</a></dt>
 
2589
<dd><p>return a SQL EXCEPT of this select() construct against the given
 
2590
selectable.</p>
 
2591
</dd></dl>
 
2592
 
 
2593
<dl class="method">
 
2594
<dt id="sqlalchemy.sql.expression.Select.except_all">
 
2595
<tt class="descname">except_all</tt><big>(</big><em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.except_all" title="Permalink to this definition">¶</a></dt>
 
2596
<dd><p>return a SQL EXCEPT ALL of this select() construct against the
 
2597
given selectable.</p>
 
2598
</dd></dl>
 
2599
 
 
2600
<dl class="method">
 
2601
<dt id="sqlalchemy.sql.expression.Select.execute">
 
2602
<tt class="descname">execute</tt><big>(</big><em>*multiparams</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.execute" title="Permalink to this definition">¶</a></dt>
 
2603
<dd><div class="inherited-member container">
 
2604
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable.execute" title="sqlalchemy.sql.expression.Executable.execute"><tt class="xref py py-meth docutils literal"><span class="pre">execute()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a></div>
 
2605
<p>Compile and execute this <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a>.</p>
 
2606
</dd></dl>
 
2607
 
 
2608
<dl class="method">
 
2609
<dt id="sqlalchemy.sql.expression.Select.execution_options">
 
2610
<tt class="descname">execution_options</tt><big>(</big><em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.execution_options" title="Permalink to this definition">¶</a></dt>
 
2611
<dd><div class="inherited-member container">
 
2612
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable.execution_options" title="sqlalchemy.sql.expression.Executable.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">execution_options()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a></div>
 
2613
<p>Set non-SQL options for the statement which take effect during
 
2614
execution.</p>
 
2615
<p>Execution options can be set on a per-statement or
 
2616
per <a class="reference internal" href="connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> basis.   Additionally, the
 
2617
<a class="reference internal" href="connections.html#sqlalchemy.engine.Engine" title="sqlalchemy.engine.Engine"><tt class="xref py py-class docutils literal"><span class="pre">Engine</span></tt></a> and ORM <a class="reference internal" href="../orm/query.html#sqlalchemy.orm.query.Query" title="sqlalchemy.orm.query.Query"><tt class="xref py py-class docutils literal"><span class="pre">Query</span></tt></a> objects provide
 
2618
access to execution options which they in turn configure upon
 
2619
connections.</p>
 
2620
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.Select.execution_options" title="sqlalchemy.sql.expression.Select.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">execution_options()</span></tt></a> method is generative.  A new
 
2621
instance of this statement is returned that contains the options:</p>
 
2622
<div class="highlight-python"><div class="highlight"><pre><span class="n">statement</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">y</span><span class="p">])</span>
 
2623
<span class="n">statement</span> <span class="o">=</span> <span class="n">statement</span><span class="o">.</span><span class="n">execution_options</span><span class="p">(</span><span class="n">autocommit</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span></pre></div>
 
2624
</div>
 
2625
<p>Note that only a subset of possible execution options can be applied
 
2626
to a statement - these include &#8220;autocommit&#8221; and &#8220;stream_results&#8221;,
 
2627
but not &#8220;isolation_level&#8221; or &#8220;compiled_cache&#8221;.
 
2628
See <a class="reference internal" href="connections.html#sqlalchemy.engine.Connection.execution_options" title="sqlalchemy.engine.Connection.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">Connection.execution_options()</span></tt></a> for a full list of
 
2629
possible options.</p>
 
2630
<div class="admonition seealso">
 
2631
<p class="first admonition-title">See also</p>
 
2632
<p><a class="reference internal" href="connections.html#sqlalchemy.engine.Connection.execution_options" title="sqlalchemy.engine.Connection.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">Connection.execution_options()</span></tt></a></p>
 
2633
<p class="last"><a class="reference internal" href="../orm/query.html#sqlalchemy.orm.query.Query.execution_options" title="sqlalchemy.orm.query.Query.execution_options"><tt class="xref py py-meth docutils literal"><span class="pre">Query.execution_options()</span></tt></a></p>
 
2634
</div>
 
2635
</dd></dl>
 
2636
 
 
2637
<dl class="attribute">
 
2638
<dt id="sqlalchemy.sql.expression.Select.foreign_keys">
 
2639
<tt class="descname">foreign_keys</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Select.foreign_keys" title="Permalink to this definition">¶</a></dt>
 
2640
<dd><div class="inherited-member container">
 
2641
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.foreign_keys" title="sqlalchemy.sql.expression.FromClause.foreign_keys"><tt class="xref py py-attr docutils literal"><span class="pre">foreign_keys</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2642
<p>Return the collection of ForeignKey objects which this
 
2643
FromClause references.</p>
 
2644
</dd></dl>
 
2645
 
 
2646
<dl class="attribute">
 
2647
<dt id="sqlalchemy.sql.expression.Select.froms">
 
2648
<tt class="descname">froms</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Select.froms" title="Permalink to this definition">¶</a></dt>
 
2649
<dd><p>Return the displayed list of FromClause elements.</p>
 
2650
</dd></dl>
 
2651
 
 
2652
<dl class="method">
 
2653
<dt id="sqlalchemy.sql.expression.Select.get_children">
 
2654
<tt class="descname">get_children</tt><big>(</big><em>column_collections=True</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.get_children" title="Permalink to this definition">¶</a></dt>
 
2655
<dd><p>return child elements as per the ClauseElement specification.</p>
 
2656
</dd></dl>
 
2657
 
 
2658
<dl class="method">
 
2659
<dt id="sqlalchemy.sql.expression.Select.group_by">
 
2660
<tt class="descname">group_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.group_by" title="Permalink to this definition">¶</a></dt>
 
2661
<dd><div class="inherited-member container">
 
2662
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.group_by" title="sqlalchemy.sql.expression.SelectBase.group_by"><tt class="xref py py-meth docutils literal"><span class="pre">group_by()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
2663
<p>return a new selectable with the given list of GROUP BY
 
2664
criterion applied.</p>
 
2665
<p>The criterion will be appended to any pre-existing GROUP BY
 
2666
criterion.</p>
 
2667
</dd></dl>
 
2668
 
 
2669
<dl class="method">
 
2670
<dt id="sqlalchemy.sql.expression.Select.having">
 
2671
<tt class="descname">having</tt><big>(</big><em>having</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.having" title="Permalink to this definition">¶</a></dt>
 
2672
<dd><p>return a new select() construct with the given expression added to
 
2673
its HAVING clause, joined to the existing clause via AND, if any.</p>
 
2674
</dd></dl>
 
2675
 
 
2676
<dl class="attribute">
 
2677
<dt id="sqlalchemy.sql.expression.Select.inner_columns">
 
2678
<tt class="descname">inner_columns</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Select.inner_columns" title="Permalink to this definition">¶</a></dt>
 
2679
<dd><p>an iterator of all ColumnElement expressions which would
 
2680
be rendered into the columns clause of the resulting SELECT statement.</p>
 
2681
</dd></dl>
 
2682
 
 
2683
<dl class="method">
 
2684
<dt id="sqlalchemy.sql.expression.Select.intersect">
 
2685
<tt class="descname">intersect</tt><big>(</big><em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.intersect" title="Permalink to this definition">¶</a></dt>
 
2686
<dd><p>return a SQL INTERSECT of this select() construct against the given
 
2687
selectable.</p>
 
2688
</dd></dl>
 
2689
 
 
2690
<dl class="method">
 
2691
<dt id="sqlalchemy.sql.expression.Select.intersect_all">
 
2692
<tt class="descname">intersect_all</tt><big>(</big><em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.intersect_all" title="Permalink to this definition">¶</a></dt>
 
2693
<dd><p>return a SQL INTERSECT ALL of this select() construct against the
 
2694
given selectable.</p>
 
2695
</dd></dl>
 
2696
 
 
2697
<dl class="method">
 
2698
<dt id="sqlalchemy.sql.expression.Select.join">
 
2699
<tt class="descname">join</tt><big>(</big><em>right</em>, <em>onclause=None</em>, <em>isouter=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.join" title="Permalink to this definition">¶</a></dt>
 
2700
<dd><div class="inherited-member container">
 
2701
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.join" title="sqlalchemy.sql.expression.FromClause.join"><tt class="xref py py-meth docutils literal"><span class="pre">join()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2702
<p>return a join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
2703
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
2704
</dd></dl>
 
2705
 
 
2706
<dl class="method">
 
2707
<dt id="sqlalchemy.sql.expression.Select.label">
 
2708
<tt class="descname">label</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.label" title="Permalink to this definition">¶</a></dt>
 
2709
<dd><div class="inherited-member container">
 
2710
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.label" title="sqlalchemy.sql.expression.SelectBase.label"><tt class="xref py py-meth docutils literal"><span class="pre">label()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
2711
<p>return a &#8216;scalar&#8217; representation of this selectable, embedded as a
 
2712
subquery with a label.</p>
 
2713
<div class="admonition seealso">
 
2714
<p class="first admonition-title">See also</p>
 
2715
<p class="last"><a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.as_scalar" title="sqlalchemy.sql.expression.SelectBase.as_scalar"><tt class="xref py py-meth docutils literal"><span class="pre">as_scalar()</span></tt></a>.</p>
 
2716
</div>
 
2717
</dd></dl>
 
2718
 
 
2719
<dl class="method">
 
2720
<dt id="sqlalchemy.sql.expression.Select.limit">
 
2721
<tt class="descname">limit</tt><big>(</big><em>limit</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.limit" title="Permalink to this definition">¶</a></dt>
 
2722
<dd><div class="inherited-member container">
 
2723
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.limit" title="sqlalchemy.sql.expression.SelectBase.limit"><tt class="xref py py-meth docutils literal"><span class="pre">limit()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
2724
<p>return a new selectable with the given LIMIT criterion
 
2725
applied.</p>
 
2726
</dd></dl>
 
2727
 
 
2728
<dl class="attribute">
 
2729
<dt id="sqlalchemy.sql.expression.Select.locate_all_froms">
 
2730
<tt class="descname">locate_all_froms</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Select.locate_all_froms" title="Permalink to this definition">¶</a></dt>
 
2731
<dd><p>return a Set of all FromClause elements referenced by this Select.</p>
 
2732
<p>This set is a superset of that returned by the <tt class="docutils literal"><span class="pre">froms</span></tt> property,
 
2733
which is specifically for those FromClause elements that would
 
2734
actually be rendered.</p>
 
2735
</dd></dl>
 
2736
 
 
2737
<dl class="method">
 
2738
<dt id="sqlalchemy.sql.expression.Select.offset">
 
2739
<tt class="descname">offset</tt><big>(</big><em>offset</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.offset" title="Permalink to this definition">¶</a></dt>
 
2740
<dd><div class="inherited-member container">
 
2741
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.offset" title="sqlalchemy.sql.expression.SelectBase.offset"><tt class="xref py py-meth docutils literal"><span class="pre">offset()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
2742
<p>return a new selectable with the given OFFSET criterion
 
2743
applied.</p>
 
2744
</dd></dl>
 
2745
 
 
2746
<dl class="method">
 
2747
<dt id="sqlalchemy.sql.expression.Select.order_by">
 
2748
<tt class="descname">order_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.order_by" title="Permalink to this definition">¶</a></dt>
 
2749
<dd><div class="inherited-member container">
 
2750
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.order_by" title="sqlalchemy.sql.expression.SelectBase.order_by"><tt class="xref py py-meth docutils literal"><span class="pre">order_by()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase" title="sqlalchemy.sql.expression.SelectBase"><tt class="xref py py-class docutils literal"><span class="pre">SelectBase</span></tt></a></div>
 
2751
<p>return a new selectable with the given list of ORDER BY
 
2752
criterion applied.</p>
 
2753
<p>The criterion will be appended to any pre-existing ORDER BY
 
2754
criterion.</p>
 
2755
</dd></dl>
 
2756
 
 
2757
<dl class="method">
 
2758
<dt id="sqlalchemy.sql.expression.Select.outerjoin">
 
2759
<tt class="descname">outerjoin</tt><big>(</big><em>right</em>, <em>onclause=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.outerjoin" title="Permalink to this definition">¶</a></dt>
 
2760
<dd><div class="inherited-member container">
 
2761
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.outerjoin" title="sqlalchemy.sql.expression.FromClause.outerjoin"><tt class="xref py py-meth docutils literal"><span class="pre">outerjoin()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2762
<p>return an outer join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
2763
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
2764
</dd></dl>
 
2765
 
 
2766
<dl class="method">
 
2767
<dt id="sqlalchemy.sql.expression.Select.params">
 
2768
<tt class="descname">params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.params" title="Permalink to this definition">¶</a></dt>
 
2769
<dd><div class="inherited-member container">
 
2770
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.params" title="sqlalchemy.sql.expression.ClauseElement.params"><tt class="xref py py-meth docutils literal"><span class="pre">params()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
2771
<p>Return a copy with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a> elements replaced.</p>
 
2772
<p>Returns a copy of this ClauseElement with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a>
 
2773
elements replaced with values taken from the given dictionary:</p>
 
2774
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">clause</span> <span class="o">=</span> <span class="n">column</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">bindparam</span><span class="p">(</span><span class="s">&#39;foo&#39;</span><span class="p">)</span>
 
2775
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">clause</span><span class="o">.</span><span class="n">compile</span><span class="p">()</span><span class="o">.</span><span class="n">params</span>
 
2776
<span class="go">{&#39;foo&#39;:None}</span>
 
2777
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">clause</span><span class="o">.</span><span class="n">params</span><span class="p">({</span><span class="s">&#39;foo&#39;</span><span class="p">:</span><span class="mi">7</span><span class="p">})</span><span class="o">.</span><span class="n">compile</span><span class="p">()</span><span class="o">.</span><span class="n">params</span>
 
2778
<span class="go">{&#39;foo&#39;:7}</span></pre></div>
 
2779
</div>
 
2780
</dd></dl>
 
2781
 
 
2782
<dl class="method">
 
2783
<dt id="sqlalchemy.sql.expression.Select.prefix_with">
 
2784
<tt class="descname">prefix_with</tt><big>(</big><em>*expr</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.prefix_with" title="Permalink to this definition">¶</a></dt>
 
2785
<dd><div class="inherited-member container">
 
2786
<em>inherited from the</em> <tt class="xref py py-meth docutils literal"><span class="pre">prefix_with()</span></tt> <em>method of</em> <tt class="xref py py-class docutils literal"><span class="pre">HasPrefixes</span></tt></div>
 
2787
<p>Add one or more expressions following the statement keyword, i.e.
 
2788
SELECT, INSERT, UPDATE, or DELETE. Generative.</p>
 
2789
<p>This is used to support backend-specific prefix keywords such as those
 
2790
provided by MySQL.</p>
 
2791
<p>E.g.:</p>
 
2792
<div class="highlight-python"><div class="highlight"><pre><span class="n">stmt</span> <span class="o">=</span> <span class="n">table</span><span class="o">.</span><span class="n">insert</span><span class="p">()</span><span class="o">.</span><span class="n">prefix_with</span><span class="p">(</span><span class="s">&quot;LOW_PRIORITY&quot;</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="s">&quot;mysql&quot;</span><span class="p">)</span></pre></div>
 
2793
</div>
 
2794
<p>Multiple prefixes can be specified by multiple calls
 
2795
to <a class="reference internal" href="#sqlalchemy.sql.expression.Select.prefix_with" title="sqlalchemy.sql.expression.Select.prefix_with"><tt class="xref py py-meth docutils literal"><span class="pre">prefix_with()</span></tt></a>.</p>
 
2796
<table class="docutils field-list" frame="void" rules="none">
 
2797
<col class="field-name" />
 
2798
<col class="field-body" />
 
2799
<tbody valign="top">
 
2800
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
2801
<li><strong>*expr</strong> &#8211; textual or <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> construct which
 
2802
will be rendered following the INSERT, UPDATE, or DELETE
 
2803
keyword.</li>
 
2804
<li><strong>**kw</strong> &#8211; A single keyword &#8216;dialect&#8217; is accepted.  This is an
 
2805
optional string dialect name which will
 
2806
limit rendering of this prefix to only that dialect.</li>
 
2807
</ul>
 
2808
</td>
 
2809
</tr>
 
2810
</tbody>
 
2811
</table>
 
2812
</dd></dl>
 
2813
 
 
2814
<dl class="attribute">
 
2815
<dt id="sqlalchemy.sql.expression.Select.primary_key">
 
2816
<tt class="descname">primary_key</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Select.primary_key" title="Permalink to this definition">¶</a></dt>
 
2817
<dd><div class="inherited-member container">
 
2818
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.primary_key" title="sqlalchemy.sql.expression.FromClause.primary_key"><tt class="xref py py-attr docutils literal"><span class="pre">primary_key</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2819
<p>Return the collection of Column objects which comprise the
 
2820
primary key of this FromClause.</p>
 
2821
</dd></dl>
 
2822
 
 
2823
<dl class="method">
 
2824
<dt id="sqlalchemy.sql.expression.Select.reduce_columns">
 
2825
<tt class="descname">reduce_columns</tt><big>(</big><em>only_synonyms=True</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.reduce_columns" title="Permalink to this definition">¶</a></dt>
 
2826
<dd><p>Return a new :func`.select` construct with redundantly
 
2827
named, equivalently-valued columns removed from the columns clause.</p>
 
2828
<p>&#8220;Redundant&#8221; here means two columns where one refers to the
 
2829
other either based on foreign key, or via a simple equality
 
2830
comparison in the WHERE clause of the statement.   The primary purpose
 
2831
of this method is to automatically construct a select statement
 
2832
with all uniquely-named columns, without the need to use
 
2833
table-qualified labels as <a class="reference internal" href="#sqlalchemy.sql.expression.Select.apply_labels" title="sqlalchemy.sql.expression.Select.apply_labels"><tt class="xref py py-meth docutils literal"><span class="pre">apply_labels()</span></tt></a> does.</p>
 
2834
<p>When columns are omitted based on foreign key, the referred-to
 
2835
column is the one that&#8217;s kept.  When columns are omitted based on
 
2836
WHERE eqivalence, the first column in the columns clause is the
 
2837
one that&#8217;s kept.</p>
 
2838
<table class="docutils field-list" frame="void" rules="none">
 
2839
<col class="field-name" />
 
2840
<col class="field-body" />
 
2841
<tbody valign="top">
 
2842
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>only_synonyms</strong> &#8211; when True, limit the removal of columns
 
2843
to those which have the same name as the equivalent.   Otherwise,
 
2844
all columns that are equivalent to another are removed.</td>
 
2845
</tr>
 
2846
</tbody>
 
2847
</table>
 
2848
<div class="versionadded">
 
2849
<p><span>New in version 0.8.</span></p>
 
2850
</div>
 
2851
</dd></dl>
 
2852
 
 
2853
<dl class="method">
 
2854
<dt id="sqlalchemy.sql.expression.Select.replace_selectable">
 
2855
<tt class="descname">replace_selectable</tt><big>(</big><em>old</em>, <em>alias</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.replace_selectable" title="Permalink to this definition">¶</a></dt>
 
2856
<dd><div class="inherited-member container">
 
2857
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.replace_selectable" title="sqlalchemy.sql.expression.FromClause.replace_selectable"><tt class="xref py py-meth docutils literal"><span class="pre">replace_selectable()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2858
<p>replace all occurrences of FromClause &#8216;old&#8217; with the given Alias
 
2859
object, returning a copy of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
2860
</dd></dl>
 
2861
 
 
2862
<dl class="method">
 
2863
<dt id="sqlalchemy.sql.expression.Select.scalar">
 
2864
<tt class="descname">scalar</tt><big>(</big><em>*multiparams</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.scalar" title="Permalink to this definition">¶</a></dt>
 
2865
<dd><div class="inherited-member container">
 
2866
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable.scalar" title="sqlalchemy.sql.expression.Executable.scalar"><tt class="xref py py-meth docutils literal"><span class="pre">scalar()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a></div>
 
2867
<p>Compile and execute this <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a>, returning the
 
2868
result&#8217;s scalar representation.</p>
 
2869
</dd></dl>
 
2870
 
 
2871
<dl class="method">
 
2872
<dt id="sqlalchemy.sql.expression.Select.select">
 
2873
<tt class="descname">select</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.select" title="Permalink to this definition">¶</a></dt>
 
2874
<dd><div class="inherited-member container">
 
2875
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.select" title="sqlalchemy.sql.expression.FromClause.select"><tt class="xref py py-meth docutils literal"><span class="pre">select()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
2876
<p>return a SELECT of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
2877
<div class="admonition seealso">
 
2878
<p class="first admonition-title">See also</p>
 
2879
<p class="last"><a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> - general purpose
 
2880
method which allows for arbitrary column lists.</p>
 
2881
</div>
 
2882
</dd></dl>
 
2883
 
 
2884
<dl class="method">
 
2885
<dt id="sqlalchemy.sql.expression.Select.select_from">
 
2886
<tt class="descname">select_from</tt><big>(</big><em>fromclause</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.select_from" title="Permalink to this definition">¶</a></dt>
 
2887
<dd><p>return a new <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> construct with the
 
2888
given FROM expression
 
2889
merged into its list of FROM objects.</p>
 
2890
<p>E.g.:</p>
 
2891
<div class="highlight-python"><div class="highlight"><pre><span class="n">table1</span> <span class="o">=</span> <span class="n">table</span><span class="p">(</span><span class="s">&#39;t1&#39;</span><span class="p">,</span> <span class="n">column</span><span class="p">(</span><span class="s">&#39;a&#39;</span><span class="p">))</span>
 
2892
<span class="n">table2</span> <span class="o">=</span> <span class="n">table</span><span class="p">(</span><span class="s">&#39;t2&#39;</span><span class="p">,</span> <span class="n">column</span><span class="p">(</span><span class="s">&#39;b&#39;</span><span class="p">))</span>
 
2893
<span class="n">s</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">a</span><span class="p">])</span><span class="o">.</span>\
 
2894
    <span class="n">select_from</span><span class="p">(</span>
 
2895
        <span class="n">table1</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">table2</span><span class="p">,</span> <span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">a</span><span class="o">==</span><span class="n">table2</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>
 
2896
    <span class="p">)</span></pre></div>
 
2897
</div>
 
2898
<p>The &#8220;from&#8221; list is a unique set on the identity of each element,
 
2899
so adding an already present <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> or other selectable
 
2900
will have no effect.   Passing a <a class="reference internal" href="#sqlalchemy.sql.expression.Join" title="sqlalchemy.sql.expression.Join"><tt class="xref py py-class docutils literal"><span class="pre">Join</span></tt></a> that refers
 
2901
to an already present <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> or other selectable will have
 
2902
the effect of concealing the presence of that selectable as
 
2903
an individual element in the rendered FROM list, instead
 
2904
rendering it into a JOIN clause.</p>
 
2905
<p>While the typical purpose of <a class="reference internal" href="#sqlalchemy.sql.expression.Select.select_from" title="sqlalchemy.sql.expression.Select.select_from"><tt class="xref py py-meth docutils literal"><span class="pre">Select.select_from()</span></tt></a> is to
 
2906
replace the default, derived FROM clause with a join, it can
 
2907
also be called with individual table elements, multiple times
 
2908
if desired, in the case that the FROM clause cannot be fully
 
2909
derived from the columns clause:</p>
 
2910
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">func</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s">&#39;*&#39;</span><span class="p">)])</span><span class="o">.</span><span class="n">select_from</span><span class="p">(</span><span class="n">table1</span><span class="p">)</span></pre></div>
 
2911
</div>
 
2912
</dd></dl>
 
2913
 
 
2914
<dl class="method">
 
2915
<dt id="sqlalchemy.sql.expression.Select.self_group">
 
2916
<tt class="descname">self_group</tt><big>(</big><em>against=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.self_group" title="Permalink to this definition">¶</a></dt>
 
2917
<dd><p>return a &#8216;grouping&#8217; construct as per the ClauseElement
 
2918
specification.</p>
 
2919
<p>This produces an element that can be embedded in an expression. Note
 
2920
that this method is called automatically as needed when constructing
 
2921
expressions and should not require explicit use.</p>
 
2922
</dd></dl>
 
2923
 
 
2924
<dl class="method">
 
2925
<dt id="sqlalchemy.sql.expression.Select.union">
 
2926
<tt class="descname">union</tt><big>(</big><em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.union" title="Permalink to this definition">¶</a></dt>
 
2927
<dd><p>return a SQL UNION of this select() construct against the given
 
2928
selectable.</p>
 
2929
</dd></dl>
 
2930
 
 
2931
<dl class="method">
 
2932
<dt id="sqlalchemy.sql.expression.Select.union_all">
 
2933
<tt class="descname">union_all</tt><big>(</big><em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.union_all" title="Permalink to this definition">¶</a></dt>
 
2934
<dd><p>return a SQL UNION ALL of this select() construct against the given
 
2935
selectable.</p>
 
2936
</dd></dl>
 
2937
 
 
2938
<dl class="method">
 
2939
<dt id="sqlalchemy.sql.expression.Select.unique_params">
 
2940
<tt class="descname">unique_params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.unique_params" title="Permalink to this definition">¶</a></dt>
 
2941
<dd><div class="inherited-member container">
 
2942
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.unique_params" title="sqlalchemy.sql.expression.ClauseElement.unique_params"><tt class="xref py py-meth docutils literal"><span class="pre">unique_params()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
2943
<p>Return a copy with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.bindparam" title="sqlalchemy.sql.expression.bindparam"><tt class="xref py py-func docutils literal"><span class="pre">bindparam()</span></tt></a> elements replaced.</p>
 
2944
<p>Same functionality as <tt class="docutils literal"><span class="pre">params()</span></tt>, except adds <cite>unique=True</cite>
 
2945
to affected bind parameters so that multiple statements can be
 
2946
used.</p>
 
2947
</dd></dl>
 
2948
 
 
2949
<dl class="method">
 
2950
<dt id="sqlalchemy.sql.expression.Select.where">
 
2951
<tt class="descname">where</tt><big>(</big><em>whereclause</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.where" title="Permalink to this definition">¶</a></dt>
 
2952
<dd><p>return a new select() construct with the given expression added to
 
2953
its WHERE clause, joined to the existing clause via AND, if any.</p>
 
2954
</dd></dl>
 
2955
 
 
2956
<dl class="method">
 
2957
<dt id="sqlalchemy.sql.expression.Select.with_hint">
 
2958
<tt class="descname">with_hint</tt><big>(</big><em>selectable</em>, <em>text</em>, <em>dialect_name='*'</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.with_hint" title="Permalink to this definition">¶</a></dt>
 
2959
<dd><p>Add an indexing hint for the given selectable to this
 
2960
<a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>.</p>
 
2961
<p>The text of the hint is rendered in the appropriate
 
2962
location for the database backend in use, relative
 
2963
to the given <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> or <a class="reference internal" href="#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a> passed as the
 
2964
<tt class="docutils literal"><span class="pre">selectable</span></tt> argument. The dialect implementation
 
2965
typically uses Python string substitution syntax
 
2966
with the token <tt class="docutils literal"><span class="pre">%(name)s</span></tt> to render the name of
 
2967
the table or alias. E.g. when using Oracle, the
 
2968
following:</p>
 
2969
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">mytable</span><span class="p">])</span><span class="o">.</span>\
 
2970
    <span class="n">with_hint</span><span class="p">(</span><span class="n">mytable</span><span class="p">,</span> <span class="s">&quot;+ index(</span><span class="si">%(name)s</span><span class="s"> ix_mytable)&quot;</span><span class="p">)</span></pre></div>
 
2971
</div>
 
2972
<p>Would render SQL as:</p>
 
2973
<div class="highlight-python"><pre>select /*+ index(mytable ix_mytable) */ ... from mytable</pre>
 
2974
</div>
 
2975
<p>The <tt class="docutils literal"><span class="pre">dialect_name</span></tt> option will limit the rendering of a particular
 
2976
hint to a particular backend. Such as, to add hints for both Oracle
 
2977
and Sybase simultaneously:</p>
 
2978
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">mytable</span><span class="p">])</span><span class="o">.</span>\
 
2979
    <span class="n">with_hint</span><span class="p">(</span><span class="n">mytable</span><span class="p">,</span> <span class="s">&quot;+ index(</span><span class="si">%(name)s</span><span class="s"> ix_mytable)&quot;</span><span class="p">,</span> <span class="s">&#39;oracle&#39;</span><span class="p">)</span><span class="o">.</span>\
 
2980
    <span class="n">with_hint</span><span class="p">(</span><span class="n">mytable</span><span class="p">,</span> <span class="s">&quot;WITH INDEX ix_mytable&quot;</span><span class="p">,</span> <span class="s">&#39;sybase&#39;</span><span class="p">)</span></pre></div>
 
2981
</div>
 
2982
</dd></dl>
 
2983
 
 
2984
<dl class="method">
 
2985
<dt id="sqlalchemy.sql.expression.Select.with_only_columns">
 
2986
<tt class="descname">with_only_columns</tt><big>(</big><em>columns</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.Select.with_only_columns" title="Permalink to this definition">¶</a></dt>
 
2987
<dd><p>Return a new <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> construct with its columns
 
2988
clause replaced with the given columns.</p>
 
2989
<div class="versionchanged">
 
2990
<p><span>Changed in version 0.7.3: </span>Due to a bug fix, this method has a slight
 
2991
behavioral change as of version 0.7.3.
 
2992
Prior to version 0.7.3, the FROM clause of
 
2993
a <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> was calculated upfront and as new columns
 
2994
were added; in 0.7.3 and later it&#8217;s calculated
 
2995
at compile time, fixing an issue regarding late binding
 
2996
of columns to parent tables.  This changes the behavior of
 
2997
<a class="reference internal" href="#sqlalchemy.sql.expression.Select.with_only_columns" title="sqlalchemy.sql.expression.Select.with_only_columns"><tt class="xref py py-meth docutils literal"><span class="pre">Select.with_only_columns()</span></tt></a> in that FROM clauses no
 
2998
longer represented in the new list are dropped,
 
2999
but this behavior is more consistent in
 
3000
that the FROM clauses are consistently derived from the
 
3001
current columns clause.  The original intent of this method
 
3002
is to allow trimming of the existing columns list to be fewer
 
3003
columns than originally present; the use case of replacing
 
3004
the columns list with an entirely different one hadn&#8217;t
 
3005
been anticipated until 0.7.3 was released; the usage
 
3006
guidelines below illustrate how this should be done.</p>
 
3007
</div>
 
3008
<p>This method is exactly equivalent to as if the original
 
3009
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> had been called with the given columns
 
3010
clause.   I.e. a statement:</p>
 
3011
<div class="highlight-python"><div class="highlight"><pre><span class="n">s</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">b</span><span class="p">])</span>
 
3012
<span class="n">s</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">with_only_columns</span><span class="p">([</span><span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">b</span><span class="p">])</span></pre></div>
 
3013
</div>
 
3014
<p>should be exactly equivalent to:</p>
 
3015
<div class="highlight-python"><div class="highlight"><pre><span class="n">s</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">b</span><span class="p">])</span></pre></div>
 
3016
</div>
 
3017
<p>This means that FROM clauses which are only derived
 
3018
from the column list will be discarded if the new column
 
3019
list no longer contains that FROM:</p>
 
3020
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">table1</span> <span class="o">=</span> <span class="n">table</span><span class="p">(</span><span class="s">&#39;t1&#39;</span><span class="p">,</span> <span class="n">column</span><span class="p">(</span><span class="s">&#39;a&#39;</span><span class="p">),</span> <span class="n">column</span><span class="p">(</span><span class="s">&#39;b&#39;</span><span class="p">))</span>
 
3021
<span class="gp">&gt;&gt;&gt; </span><span class="n">table2</span> <span class="o">=</span> <span class="n">table</span><span class="p">(</span><span class="s">&#39;t2&#39;</span><span class="p">,</span> <span class="n">column</span><span class="p">(</span><span class="s">&#39;a&#39;</span><span class="p">),</span> <span class="n">column</span><span class="p">(</span><span class="s">&#39;b&#39;</span><span class="p">))</span>
 
3022
<span class="gp">&gt;&gt;&gt; </span><span class="n">s1</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="n">table2</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">b</span><span class="p">])</span>
 
3023
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">s1</span>
 
3024
<span class="go">SELECT t1.a, t2.b FROM t1, t2</span>
 
3025
<span class="gp">&gt;&gt;&gt; </span><span class="n">s2</span> <span class="o">=</span> <span class="n">s1</span><span class="o">.</span><span class="n">with_only_columns</span><span class="p">([</span><span class="n">table2</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">b</span><span class="p">])</span>
 
3026
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">s2</span>
 
3027
<span class="go">SELECT t2.b FROM t1</span></pre></div>
 
3028
</div>
 
3029
<p>The preferred way to maintain a specific FROM clause
 
3030
in the construct, assuming it won&#8217;t be represented anywhere
 
3031
else (i.e. not in the WHERE clause, etc.) is to set it using
 
3032
<a class="reference internal" href="#sqlalchemy.sql.expression.Select.select_from" title="sqlalchemy.sql.expression.Select.select_from"><tt class="xref py py-meth docutils literal"><span class="pre">Select.select_from()</span></tt></a>:</p>
 
3033
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">s1</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="n">table2</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">b</span><span class="p">])</span><span class="o">.</span>\
 
3034
<span class="gp">... </span>        <span class="n">select_from</span><span class="p">(</span><span class="n">table1</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">table2</span><span class="p">,</span>
 
3035
<span class="gp">... </span>                <span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">a</span><span class="o">==</span><span class="n">table2</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">a</span><span class="p">))</span>
 
3036
<span class="gp">&gt;&gt;&gt; </span><span class="n">s2</span> <span class="o">=</span> <span class="n">s1</span><span class="o">.</span><span class="n">with_only_columns</span><span class="p">([</span><span class="n">table2</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">b</span><span class="p">])</span>
 
3037
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">s2</span>
 
3038
<span class="go">SELECT t2.b FROM t1 JOIN t2 ON t1.a=t2.a</span></pre></div>
 
3039
</div>
 
3040
<p>Care should also be taken to use the correct
 
3041
set of column objects passed to <a class="reference internal" href="#sqlalchemy.sql.expression.Select.with_only_columns" title="sqlalchemy.sql.expression.Select.with_only_columns"><tt class="xref py py-meth docutils literal"><span class="pre">Select.with_only_columns()</span></tt></a>.
 
3042
Since the method is essentially equivalent to calling the
 
3043
<a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> construct in the first place with the given
 
3044
columns, the columns passed to <a class="reference internal" href="#sqlalchemy.sql.expression.Select.with_only_columns" title="sqlalchemy.sql.expression.Select.with_only_columns"><tt class="xref py py-meth docutils literal"><span class="pre">Select.with_only_columns()</span></tt></a>
 
3045
should usually be a subset of those which were passed
 
3046
to the <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> construct, not those which are available
 
3047
from the <tt class="docutils literal"><span class="pre">.c</span></tt> collection of that <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.  That
 
3048
is:</p>
 
3049
<div class="highlight-python"><div class="highlight"><pre><span class="n">s</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">b</span><span class="p">])</span><span class="o">.</span><span class="n">select_from</span><span class="p">(</span><span class="n">table1</span><span class="p">)</span>
 
3050
<span class="n">s</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">with_only_columns</span><span class="p">([</span><span class="n">table1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">b</span><span class="p">])</span></pre></div>
 
3051
</div>
 
3052
<p>and <strong>not</strong>:</p>
 
3053
<div class="highlight-python"><div class="highlight"><pre><span class="c"># usually incorrect</span>
 
3054
<span class="n">s</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">with_only_columns</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">b</span><span class="p">])</span></pre></div>
 
3055
</div>
 
3056
<p>The latter would produce the SQL:</p>
 
3057
<div class="highlight-python"><pre>SELECT b
 
3058
FROM (SELECT t1.a AS a, t1.b AS b
 
3059
FROM t1), t1</pre>
 
3060
</div>
 
3061
<p>Since the <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> construct is essentially being
 
3062
asked to select both from <tt class="docutils literal"><span class="pre">table1</span></tt> as well as itself.</p>
 
3063
</dd></dl>
 
3064
 
 
3065
</dd></dl>
 
3066
 
 
3067
<dl class="class">
 
3068
<dt id="sqlalchemy.sql.expression.Selectable">
 
3069
<em class="property">class </em><tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">Selectable</tt><a class="headerlink" href="#sqlalchemy.sql.expression.Selectable" title="Permalink to this definition">¶</a></dt>
 
3070
<dd><p>Bases: <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.ClauseElement</span></tt></a></p>
 
3071
<p>mark a class as being selectable</p>
 
3072
</dd></dl>
 
3073
 
 
3074
<dl class="class">
 
3075
<dt id="sqlalchemy.sql.expression.SelectBase">
 
3076
<em class="property">class </em><tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">SelectBase</tt><big>(</big><em>use_labels=False</em>, <em>for_update=False</em>, <em>limit=None</em>, <em>offset=None</em>, <em>order_by=None</em>, <em>group_by=None</em>, <em>bind=None</em>, <em>autocommit=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase" title="Permalink to this definition">¶</a></dt>
 
3077
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.Executable</span></tt></a>, <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.FromClause</span></tt></a></p>
 
3078
<p>Base class for <a class="reference internal" href="#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> and <a class="reference internal" href="#sqlalchemy.sql.expression.CompoundSelect" title="sqlalchemy.sql.expression.CompoundSelect"><tt class="xref py py-class docutils literal"><span class="pre">CompoundSelect</span></tt></a>.</p>
 
3079
<dl class="method">
 
3080
<dt id="sqlalchemy.sql.expression.SelectBase.append_group_by">
 
3081
<tt class="descname">append_group_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase.append_group_by" title="Permalink to this definition">¶</a></dt>
 
3082
<dd><p>Append the given GROUP BY criterion applied to this selectable.</p>
 
3083
<p>The criterion will be appended to any pre-existing GROUP BY criterion.</p>
 
3084
<p>This is an <strong>in-place</strong> mutation method; the
 
3085
<a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.group_by" title="sqlalchemy.sql.expression.SelectBase.group_by"><tt class="xref py py-meth docutils literal"><span class="pre">group_by()</span></tt></a> method is preferred, as it provides standard
 
3086
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
3087
</dd></dl>
 
3088
 
 
3089
<dl class="method">
 
3090
<dt id="sqlalchemy.sql.expression.SelectBase.append_order_by">
 
3091
<tt class="descname">append_order_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase.append_order_by" title="Permalink to this definition">¶</a></dt>
 
3092
<dd><p>Append the given ORDER BY criterion applied to this selectable.</p>
 
3093
<p>The criterion will be appended to any pre-existing ORDER BY criterion.</p>
 
3094
<p>This is an <strong>in-place</strong> mutation method; the
 
3095
<a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.order_by" title="sqlalchemy.sql.expression.SelectBase.order_by"><tt class="xref py py-meth docutils literal"><span class="pre">order_by()</span></tt></a> method is preferred, as it provides standard
 
3096
<a class="reference internal" href="../glossary.html#term-method-chaining"><em class="xref std std-term">method chaining</em></a>.</p>
 
3097
</dd></dl>
 
3098
 
 
3099
<dl class="method">
 
3100
<dt id="sqlalchemy.sql.expression.SelectBase.apply_labels">
 
3101
<tt class="descname">apply_labels</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase.apply_labels" title="Permalink to this definition">¶</a></dt>
 
3102
<dd><p>return a new selectable with the &#8216;use_labels&#8217; flag set to True.</p>
 
3103
<p>This will result in column expressions being generated using labels
 
3104
against their table name, such as &#8220;SELECT somecolumn AS
 
3105
tablename_somecolumn&#8221;. This allows selectables which contain multiple
 
3106
FROM clauses to produce a unique set of column names regardless of
 
3107
name conflicts among the individual FROM clauses.</p>
 
3108
</dd></dl>
 
3109
 
 
3110
<dl class="method">
 
3111
<dt id="sqlalchemy.sql.expression.SelectBase.as_scalar">
 
3112
<tt class="descname">as_scalar</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase.as_scalar" title="Permalink to this definition">¶</a></dt>
 
3113
<dd><p>return a &#8216;scalar&#8217; representation of this selectable, which can be
 
3114
used as a column expression.</p>
 
3115
<p>Typically, a select statement which has only one column in its columns
 
3116
clause is eligible to be used as a scalar expression.</p>
 
3117
<p>The returned object is an instance of
 
3118
<tt class="xref py py-class docutils literal"><span class="pre">ScalarSelect</span></tt>.</p>
 
3119
</dd></dl>
 
3120
 
 
3121
<dl class="method">
 
3122
<dt id="sqlalchemy.sql.expression.SelectBase.autocommit">
 
3123
<tt class="descname">autocommit</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase.autocommit" title="Permalink to this definition">¶</a></dt>
 
3124
<dd><p>return a new selectable with the &#8216;autocommit&#8217; flag set to</p>
 
3125
<div class="deprecated">
 
3126
<p><span>Deprecated since version 0.6: </span><tt class="xref py py-func docutils literal"><span class="pre">autocommit()</span></tt> is deprecated. Use <tt class="xref py py-func docutils literal"><span class="pre">Executable.execution_options()</span></tt> with the &#8216;autocommit&#8217; flag.</p>
 
3127
</div>
 
3128
<p>True.</p>
 
3129
</dd></dl>
 
3130
 
 
3131
<dl class="method">
 
3132
<dt id="sqlalchemy.sql.expression.SelectBase.cte">
 
3133
<tt class="descname">cte</tt><big>(</big><em>name=None</em>, <em>recursive=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase.cte" title="Permalink to this definition">¶</a></dt>
 
3134
<dd><p>Return a new <a class="reference internal" href="#sqlalchemy.sql.expression.CTE" title="sqlalchemy.sql.expression.CTE"><tt class="xref py py-class docutils literal"><span class="pre">CTE</span></tt></a>, or Common Table Expression instance.</p>
 
3135
<p>Common table expressions are a SQL standard whereby SELECT
 
3136
statements can draw upon secondary statements specified along
 
3137
with the primary statement, using a clause called &#8220;WITH&#8221;.
 
3138
Special semantics regarding UNION can also be employed to
 
3139
allow &#8220;recursive&#8221; queries, where a SELECT statement can draw
 
3140
upon the set of rows that have previously been selected.</p>
 
3141
<p>SQLAlchemy detects <a class="reference internal" href="#sqlalchemy.sql.expression.CTE" title="sqlalchemy.sql.expression.CTE"><tt class="xref py py-class docutils literal"><span class="pre">CTE</span></tt></a> objects, which are treated
 
3142
similarly to <a class="reference internal" href="#sqlalchemy.sql.expression.Alias" title="sqlalchemy.sql.expression.Alias"><tt class="xref py py-class docutils literal"><span class="pre">Alias</span></tt></a> objects, as special elements
 
3143
to be delivered to the FROM clause of the statement as well
 
3144
as to a WITH clause at the top of the statement.</p>
 
3145
<div class="versionadded">
 
3146
<p><span>New in version 0.7.6.</span></p>
 
3147
</div>
 
3148
<table class="docutils field-list" frame="void" rules="none">
 
3149
<col class="field-name" />
 
3150
<col class="field-body" />
 
3151
<tbody valign="top">
 
3152
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
3153
<li><strong>name</strong> &#8211; name given to the common table expression.  Like
 
3154
<tt class="xref py py-meth docutils literal"><span class="pre">_FromClause.alias()</span></tt>, the name can be left as <tt class="docutils literal"><span class="pre">None</span></tt>
 
3155
in which case an anonymous symbol will be used at query
 
3156
compile time.</li>
 
3157
<li><strong>recursive</strong> &#8211; if <tt class="docutils literal"><span class="pre">True</span></tt>, will render <tt class="docutils literal"><span class="pre">WITH</span> <span class="pre">RECURSIVE</span></tt>.
 
3158
A recursive common table expression is intended to be used in
 
3159
conjunction with UNION ALL in order to derive rows
 
3160
from those already selected.</li>
 
3161
</ul>
 
3162
</td>
 
3163
</tr>
 
3164
</tbody>
 
3165
</table>
 
3166
<p>The following examples illustrate two examples from
 
3167
Postgresql&#8217;s documentation at
 
3168
<a class="reference external" href="http://www.postgresql.org/docs/8.4/static/queries-with.html">http://www.postgresql.org/docs/8.4/static/queries-with.html</a>.</p>
 
3169
<p>Example 1, non recursive:</p>
 
3170
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Table</span><span class="p">,</span> <span class="n">Column</span><span class="p">,</span> <span class="n">String</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">MetaData</span><span class="p">,</span> \
 
3171
    <span class="n">select</span><span class="p">,</span> <span class="n">func</span>
 
3172
 
 
3173
<span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
 
3174
 
 
3175
<span class="n">orders</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">&#39;orders&#39;</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
 
3176
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;region&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
3177
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;amount&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
 
3178
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;product&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
3179
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;quantity&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">)</span>
 
3180
<span class="p">)</span>
 
3181
 
 
3182
<span class="n">regional_sales</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
3183
                    <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">,</span>
 
3184
                    <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">amount</span><span class="p">)</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s">&#39;total_sales&#39;</span><span class="p">)</span>
 
3185
                <span class="p">])</span><span class="o">.</span><span class="n">group_by</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">)</span><span class="o">.</span><span class="n">cte</span><span class="p">(</span><span class="s">&quot;regional_sales&quot;</span><span class="p">)</span>
 
3186
 
 
3187
 
 
3188
<span class="n">top_regions</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">regional_sales</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">])</span><span class="o">.</span>\
 
3189
        <span class="n">where</span><span class="p">(</span>
 
3190
            <span class="n">regional_sales</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">total_sales</span> <span class="o">&gt;</span>
 
3191
            <span class="n">select</span><span class="p">([</span>
 
3192
                <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">regional_sales</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">total_sales</span><span class="p">)</span><span class="o">/</span><span class="mi">10</span>
 
3193
            <span class="p">])</span>
 
3194
        <span class="p">)</span><span class="o">.</span><span class="n">cte</span><span class="p">(</span><span class="s">&quot;top_regions&quot;</span><span class="p">)</span>
 
3195
 
 
3196
<span class="n">statement</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
3197
            <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">,</span>
 
3198
            <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">product</span><span class="p">,</span>
 
3199
            <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span><span class="p">)</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s">&quot;product_units&quot;</span><span class="p">),</span>
 
3200
            <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">amount</span><span class="p">)</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s">&quot;product_sales&quot;</span><span class="p">)</span>
 
3201
    <span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="o">.</span><span class="n">in_</span><span class="p">(</span>
 
3202
        <span class="n">select</span><span class="p">([</span><span class="n">top_regions</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">])</span>
 
3203
    <span class="p">))</span><span class="o">.</span><span class="n">group_by</span><span class="p">(</span><span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">region</span><span class="p">,</span> <span class="n">orders</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">product</span><span class="p">)</span>
 
3204
 
 
3205
<span class="n">result</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">statement</span><span class="p">)</span><span class="o">.</span><span class="n">fetchall</span><span class="p">()</span></pre></div>
 
3206
</div>
 
3207
<p>Example 2, WITH RECURSIVE:</p>
 
3208
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">Table</span><span class="p">,</span> <span class="n">Column</span><span class="p">,</span> <span class="n">String</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">MetaData</span><span class="p">,</span> \
 
3209
    <span class="n">select</span><span class="p">,</span> <span class="n">func</span>
 
3210
 
 
3211
<span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
 
3212
 
 
3213
<span class="n">parts</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">&#39;parts&#39;</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
 
3214
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;part&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
3215
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;sub_part&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
 
3216
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;quantity&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
 
3217
<span class="p">)</span>
 
3218
 
 
3219
<span class="n">included_parts</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
3220
                    <span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">,</span>
 
3221
                    <span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="p">,</span>
 
3222
                    <span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span><span class="p">])</span><span class="o">.</span>\
 
3223
                    <span class="n">where</span><span class="p">(</span><span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="o">==</span><span class="s">&#39;our part&#39;</span><span class="p">)</span><span class="o">.</span>\
 
3224
                    <span class="n">cte</span><span class="p">(</span><span class="n">recursive</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
 
3225
 
 
3226
 
 
3227
<span class="n">incl_alias</span> <span class="o">=</span> <span class="n">included_parts</span><span class="o">.</span><span class="n">alias</span><span class="p">()</span>
 
3228
<span class="n">parts_alias</span> <span class="o">=</span> <span class="n">parts</span><span class="o">.</span><span class="n">alias</span><span class="p">()</span>
 
3229
<span class="n">included_parts</span> <span class="o">=</span> <span class="n">included_parts</span><span class="o">.</span><span class="n">union_all</span><span class="p">(</span>
 
3230
    <span class="n">select</span><span class="p">([</span>
 
3231
        <span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="p">,</span>
 
3232
        <span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">,</span>
 
3233
        <span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span>
 
3234
    <span class="p">])</span><span class="o">.</span>
 
3235
        <span class="n">where</span><span class="p">(</span><span class="n">parts_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="o">==</span><span class="n">incl_alias</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">)</span>
 
3236
<span class="p">)</span>
 
3237
 
 
3238
<span class="n">statement</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span>
 
3239
            <span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">,</span>
 
3240
            <span class="n">func</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">quantity</span><span class="p">)</span><span class="o">.</span>
 
3241
              <span class="n">label</span><span class="p">(</span><span class="s">&#39;total_quantity&#39;</span><span class="p">)</span>
 
3242
        <span class="p">])</span><span class="o">.</span>                    <span class="n">select_from</span><span class="p">(</span><span class="n">included_parts</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">parts</span><span class="p">,</span>
 
3243
                    <span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="o">==</span><span class="n">parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">part</span><span class="p">))</span><span class="o">.</span>\
 
3244
        <span class="n">group_by</span><span class="p">(</span><span class="n">included_parts</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">sub_part</span><span class="p">)</span>
 
3245
 
 
3246
<span class="n">result</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">statement</span><span class="p">)</span><span class="o">.</span><span class="n">fetchall</span><span class="p">()</span></pre></div>
 
3247
</div>
 
3248
<div class="admonition seealso">
 
3249
<p class="first admonition-title">See also</p>
 
3250
<p class="last"><a class="reference internal" href="../orm/query.html#sqlalchemy.orm.query.Query.cte" title="sqlalchemy.orm.query.Query.cte"><tt class="xref py py-meth docutils literal"><span class="pre">orm.query.Query.cte()</span></tt></a> - ORM version of <a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.cte" title="sqlalchemy.sql.expression.SelectBase.cte"><tt class="xref py py-meth docutils literal"><span class="pre">SelectBase.cte()</span></tt></a>.</p>
 
3251
</div>
 
3252
</dd></dl>
 
3253
 
 
3254
<dl class="method">
 
3255
<dt id="sqlalchemy.sql.expression.SelectBase.group_by">
 
3256
<tt class="descname">group_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase.group_by" title="Permalink to this definition">¶</a></dt>
 
3257
<dd><p>return a new selectable with the given list of GROUP BY
 
3258
criterion applied.</p>
 
3259
<p>The criterion will be appended to any pre-existing GROUP BY
 
3260
criterion.</p>
 
3261
</dd></dl>
 
3262
 
 
3263
<dl class="method">
 
3264
<dt id="sqlalchemy.sql.expression.SelectBase.label">
 
3265
<tt class="descname">label</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase.label" title="Permalink to this definition">¶</a></dt>
 
3266
<dd><p>return a &#8216;scalar&#8217; representation of this selectable, embedded as a
 
3267
subquery with a label.</p>
 
3268
<div class="admonition seealso">
 
3269
<p class="first admonition-title">See also</p>
 
3270
<p class="last"><a class="reference internal" href="#sqlalchemy.sql.expression.SelectBase.as_scalar" title="sqlalchemy.sql.expression.SelectBase.as_scalar"><tt class="xref py py-meth docutils literal"><span class="pre">as_scalar()</span></tt></a>.</p>
 
3271
</div>
 
3272
</dd></dl>
 
3273
 
 
3274
<dl class="method">
 
3275
<dt id="sqlalchemy.sql.expression.SelectBase.limit">
 
3276
<tt class="descname">limit</tt><big>(</big><em>limit</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase.limit" title="Permalink to this definition">¶</a></dt>
 
3277
<dd><p>return a new selectable with the given LIMIT criterion
 
3278
applied.</p>
 
3279
</dd></dl>
 
3280
 
 
3281
<dl class="method">
 
3282
<dt id="sqlalchemy.sql.expression.SelectBase.offset">
 
3283
<tt class="descname">offset</tt><big>(</big><em>offset</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase.offset" title="Permalink to this definition">¶</a></dt>
 
3284
<dd><p>return a new selectable with the given OFFSET criterion
 
3285
applied.</p>
 
3286
</dd></dl>
 
3287
 
 
3288
<dl class="method">
 
3289
<dt id="sqlalchemy.sql.expression.SelectBase.order_by">
 
3290
<tt class="descname">order_by</tt><big>(</big><em>*clauses</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.SelectBase.order_by" title="Permalink to this definition">¶</a></dt>
 
3291
<dd><p>return a new selectable with the given list of ORDER BY
 
3292
criterion applied.</p>
 
3293
<p>The criterion will be appended to any pre-existing ORDER BY
 
3294
criterion.</p>
 
3295
</dd></dl>
 
3296
 
 
3297
</dd></dl>
 
3298
 
 
3299
<dl class="class">
 
3300
<dt id="sqlalchemy.sql.expression.TableClause">
 
3301
<em class="property">class </em><tt class="descclassname">sqlalchemy.sql.expression.</tt><tt class="descname">TableClause</tt><big>(</big><em>name</em>, <em>*columns</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause" title="Permalink to this definition">¶</a></dt>
 
3302
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.Immutable</span></tt>, <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.FromClause</span></tt></a></p>
 
3303
<p>Represents a minimal &#8220;table&#8221; construct.</p>
 
3304
<p>The constructor for <a class="reference internal" href="#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a> is the
 
3305
<a class="reference internal" href="#sqlalchemy.sql.expression.table" title="sqlalchemy.sql.expression.table"><tt class="xref py py-func docutils literal"><span class="pre">table()</span></tt></a> function.   This produces
 
3306
a lightweight table object that has only a name and a
 
3307
collection of columns, which are typically produced
 
3308
by the <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.column" title="sqlalchemy.sql.expression.column"><tt class="xref py py-func docutils literal"><span class="pre">column()</span></tt></a> function:</p>
 
3309
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="kn">import</span> <span class="n">table</span><span class="p">,</span> <span class="n">column</span>
 
3310
 
 
3311
<span class="n">user</span> <span class="o">=</span> <span class="n">table</span><span class="p">(</span><span class="s">&quot;user&quot;</span><span class="p">,</span>
 
3312
        <span class="n">column</span><span class="p">(</span><span class="s">&quot;id&quot;</span><span class="p">),</span>
 
3313
        <span class="n">column</span><span class="p">(</span><span class="s">&quot;name&quot;</span><span class="p">),</span>
 
3314
        <span class="n">column</span><span class="p">(</span><span class="s">&quot;description&quot;</span><span class="p">),</span>
 
3315
<span class="p">)</span></pre></div>
 
3316
</div>
 
3317
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a> construct serves as the base for
 
3318
the more commonly used <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object, providing
 
3319
the usual set of <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> services including
 
3320
the <tt class="docutils literal"><span class="pre">.c.</span></tt> collection and statement generation methods.</p>
 
3321
<p>It does <strong>not</strong> provide all the additional schema-level services
 
3322
of <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, including constraints, references to other
 
3323
tables, or support for <a class="reference internal" href="metadata.html#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a>-level services.  It&#8217;s useful
 
3324
on its own as an ad-hoc construct used to generate quick SQL
 
3325
statements when a more fully fledged <a class="reference internal" href="metadata.html#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
 
3326
is not on hand.</p>
 
3327
<dl class="method">
 
3328
<dt id="sqlalchemy.sql.expression.TableClause.alias">
 
3329
<tt class="descname">alias</tt><big>(</big><em>name=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.alias" title="Permalink to this definition">¶</a></dt>
 
3330
<dd><div class="inherited-member container">
 
3331
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.alias" title="sqlalchemy.sql.expression.FromClause.alias"><tt class="xref py py-meth docutils literal"><span class="pre">alias()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3332
<p>return an alias of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
3333
<p>This is shorthand for calling:</p>
 
3334
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">alias</span>
 
3335
<span class="n">a</span> <span class="o">=</span> <span class="n">alias</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></pre></div>
 
3336
</div>
 
3337
<p>See <a class="reference internal" href="#sqlalchemy.sql.expression.alias" title="sqlalchemy.sql.expression.alias"><tt class="xref py py-func docutils literal"><span class="pre">alias()</span></tt></a> for details.</p>
 
3338
</dd></dl>
 
3339
 
 
3340
<dl class="attribute">
 
3341
<dt id="sqlalchemy.sql.expression.TableClause.c">
 
3342
<tt class="descname">c</tt><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.c" title="Permalink to this definition">¶</a></dt>
 
3343
<dd><div class="inherited-member container">
 
3344
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.c" title="sqlalchemy.sql.expression.FromClause.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3345
<p>An alias for the <a class="reference internal" href="#sqlalchemy.sql.expression.TableClause.columns" title="sqlalchemy.sql.expression.TableClause.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> attribute.</p>
 
3346
</dd></dl>
 
3347
 
 
3348
<dl class="attribute">
 
3349
<dt id="sqlalchemy.sql.expression.TableClause.columns">
 
3350
<tt class="descname">columns</tt><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.columns" title="Permalink to this definition">¶</a></dt>
 
3351
<dd><div class="inherited-member container">
 
3352
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.columns" title="sqlalchemy.sql.expression.FromClause.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3353
<p>A named-based collection of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> objects
 
3354
maintained by this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
3355
<p>The <a class="reference internal" href="#sqlalchemy.sql.expression.TableClause.columns" title="sqlalchemy.sql.expression.TableClause.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a>, or <a class="reference internal" href="#sqlalchemy.sql.expression.TableClause.c" title="sqlalchemy.sql.expression.TableClause.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> collection, is the gateway
 
3356
to the construction of SQL expressions using table-bound or
 
3357
other selectable-bound columns:</p>
 
3358
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">mytable</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">mytable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">somecolumn</span> <span class="o">==</span> <span class="mi">5</span><span class="p">)</span></pre></div>
 
3359
</div>
 
3360
</dd></dl>
 
3361
 
 
3362
<dl class="method">
 
3363
<dt id="sqlalchemy.sql.expression.TableClause.compare">
 
3364
<tt class="descname">compare</tt><big>(</big><em>other</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.compare" title="Permalink to this definition">¶</a></dt>
 
3365
<dd><div class="inherited-member container">
 
3366
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compare" title="sqlalchemy.sql.expression.ClauseElement.compare"><tt class="xref py py-meth docutils literal"><span class="pre">compare()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
3367
<p>Compare this ClauseElement to the given ClauseElement.</p>
 
3368
<p>Subclasses should override the default behavior, which is a
 
3369
straight identity comparison.</p>
 
3370
<p>**kw are arguments consumed by subclass compare() methods and
 
3371
may be used to modify the criteria for comparison.
 
3372
(see <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>)</p>
 
3373
</dd></dl>
 
3374
 
 
3375
<dl class="method">
 
3376
<dt id="sqlalchemy.sql.expression.TableClause.compile">
 
3377
<tt class="descname">compile</tt><big>(</big><em>bind=None</em>, <em>dialect=None</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.compile" title="Permalink to this definition">¶</a></dt>
 
3378
<dd><div class="inherited-member container">
 
3379
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.compile" title="sqlalchemy.sql.expression.ClauseElement.compile"><tt class="xref py py-meth docutils literal"><span class="pre">compile()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
3380
<p>Compile this SQL expression.</p>
 
3381
<p>The return value is a <a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object.
 
3382
Calling <tt class="docutils literal"><span class="pre">str()</span></tt> or <tt class="docutils literal"><span class="pre">unicode()</span></tt> on the returned value will yield a
 
3383
string representation of the result. The
 
3384
<a class="reference internal" href="internals.html#sqlalchemy.engine.interfaces.Compiled" title="sqlalchemy.engine.interfaces.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a> object also can return a
 
3385
dictionary of bind parameter names and values
 
3386
using the <tt class="docutils literal"><span class="pre">params</span></tt> accessor.</p>
 
3387
<table class="docutils field-list" frame="void" rules="none">
 
3388
<col class="field-name" />
 
3389
<col class="field-body" />
 
3390
<tbody valign="top">
 
3391
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
3392
<li><strong>bind</strong> &#8211; An <tt class="docutils literal"><span class="pre">Engine</span></tt> or <tt class="docutils literal"><span class="pre">Connection</span></tt> from which a
 
3393
<tt class="docutils literal"><span class="pre">Compiled</span></tt> will be acquired. This argument takes precedence over
 
3394
this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if any.</li>
 
3395
<li><strong>column_keys</strong> &#8211; Used for INSERT and UPDATE statements, a list of
 
3396
column names which should be present in the VALUES clause of the
 
3397
compiled statement. If <tt class="docutils literal"><span class="pre">None</span></tt>, all columns from the target table
 
3398
object are rendered.</li>
 
3399
<li><strong>dialect</strong> &#8211; A <tt class="docutils literal"><span class="pre">Dialect</span></tt> instance from which a <tt class="docutils literal"><span class="pre">Compiled</span></tt>
 
3400
will be acquired. This argument takes precedence over the <cite>bind</cite>
 
3401
argument as well as this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>&#8216;s bound engine, if
 
3402
any.</li>
 
3403
<li><strong>inline</strong> &#8211; Used for INSERT statements, for a dialect which does
 
3404
not support inline retrieval of newly generated primary key
 
3405
columns, will force the expression used to create the new primary
 
3406
key value to be rendered inline within the INSERT statement&#8217;s
 
3407
VALUES clause. This typically refers to Sequence execution but may
 
3408
also refer to any server-side default generation function
 
3409
associated with a primary key <cite>Column</cite>.</li>
 
3410
</ul>
 
3411
</td>
 
3412
</tr>
 
3413
</tbody>
 
3414
</table>
 
3415
</dd></dl>
 
3416
 
 
3417
<dl class="method">
 
3418
<dt id="sqlalchemy.sql.expression.TableClause.correspond_on_equivalents">
 
3419
<tt class="descname">correspond_on_equivalents</tt><big>(</big><em>column</em>, <em>equivalents</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.correspond_on_equivalents" title="Permalink to this definition">¶</a></dt>
 
3420
<dd><div class="inherited-member container">
 
3421
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.correspond_on_equivalents" title="sqlalchemy.sql.expression.FromClause.correspond_on_equivalents"><tt class="xref py py-meth docutils literal"><span class="pre">correspond_on_equivalents()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3422
<p>Return corresponding_column for the given column, or if None
 
3423
search for a match in the given dictionary.</p>
 
3424
</dd></dl>
 
3425
 
 
3426
<dl class="method">
 
3427
<dt id="sqlalchemy.sql.expression.TableClause.corresponding_column">
 
3428
<tt class="descname">corresponding_column</tt><big>(</big><em>column</em>, <em>require_embedded=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.corresponding_column" title="Permalink to this definition">¶</a></dt>
 
3429
<dd><div class="inherited-member container">
 
3430
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.corresponding_column" title="sqlalchemy.sql.expression.FromClause.corresponding_column"><tt class="xref py py-meth docutils literal"><span class="pre">corresponding_column()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3431
<p>Given a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, return the exported
 
3432
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> object from this <a class="reference internal" href="#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a>
 
3433
which corresponds to that original
 
3434
<a class="reference internal" href="metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> via a common ancestor
 
3435
column.</p>
 
3436
<table class="docutils field-list" frame="void" rules="none">
 
3437
<col class="field-name" />
 
3438
<col class="field-body" />
 
3439
<tbody valign="top">
 
3440
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
3441
<li><strong>column</strong> &#8211; the target <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> to be matched</li>
 
3442
<li><strong>require_embedded</strong> &#8211; only return corresponding columns for</li>
 
3443
</ul>
 
3444
</td>
 
3445
</tr>
 
3446
</tbody>
 
3447
</table>
 
3448
<p>the given <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a>, if the given
 
3449
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> is actually present within a sub-element
 
3450
of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.  Normally the column will match if
 
3451
it merely shares a common ancestor with one of the exported
 
3452
columns of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
3453
</dd></dl>
 
3454
 
 
3455
<dl class="method">
 
3456
<dt id="sqlalchemy.sql.expression.TableClause.count">
 
3457
<tt class="descname">count</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.count" title="Permalink to this definition">¶</a></dt>
 
3458
<dd><p>return a SELECT COUNT generated against this
 
3459
<a class="reference internal" href="#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a>.</p>
 
3460
</dd></dl>
 
3461
 
 
3462
<dl class="method">
 
3463
<dt id="sqlalchemy.sql.expression.TableClause.delete">
 
3464
<tt class="descname">delete</tt><big>(</big><em>whereclause=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.delete" title="Permalink to this definition">¶</a></dt>
 
3465
<dd><p>Generate a <a class="reference internal" href="dml.html#sqlalchemy.sql.expression.delete" title="sqlalchemy.sql.expression.delete"><tt class="xref py py-func docutils literal"><span class="pre">delete()</span></tt></a> construct against this
 
3466
<a class="reference internal" href="#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a>.</p>
 
3467
<p>E.g.:</p>
 
3468
<div class="highlight-python"><div class="highlight"><pre><span class="n">table</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">id</span><span class="o">==</span><span class="mi">7</span><span class="p">)</span></pre></div>
 
3469
</div>
 
3470
<p>See <a class="reference internal" href="dml.html#sqlalchemy.sql.expression.delete" title="sqlalchemy.sql.expression.delete"><tt class="xref py py-func docutils literal"><span class="pre">delete()</span></tt></a> for argument and usage information.</p>
 
3471
</dd></dl>
 
3472
 
 
3473
<dl class="attribute">
 
3474
<dt id="sqlalchemy.sql.expression.TableClause.foreign_keys">
 
3475
<tt class="descname">foreign_keys</tt><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.foreign_keys" title="Permalink to this definition">¶</a></dt>
 
3476
<dd><div class="inherited-member container">
 
3477
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.foreign_keys" title="sqlalchemy.sql.expression.FromClause.foreign_keys"><tt class="xref py py-attr docutils literal"><span class="pre">foreign_keys</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3478
<p>Return the collection of ForeignKey objects which this
 
3479
FromClause references.</p>
 
3480
</dd></dl>
 
3481
 
 
3482
<dl class="attribute">
 
3483
<dt id="sqlalchemy.sql.expression.TableClause.implicit_returning">
 
3484
<tt class="descname">implicit_returning</tt><em class="property"> = False</em><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.implicit_returning" title="Permalink to this definition">¶</a></dt>
 
3485
<dd><p><a class="reference internal" href="#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a> doesn&#8217;t support having a primary key or column
 
3486
-level defaults, so implicit returning doesn&#8217;t apply.</p>
 
3487
</dd></dl>
 
3488
 
 
3489
<dl class="method">
 
3490
<dt id="sqlalchemy.sql.expression.TableClause.insert">
 
3491
<tt class="descname">insert</tt><big>(</big><em>values=None</em>, <em>inline=False</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.insert" title="Permalink to this definition">¶</a></dt>
 
3492
<dd><p>Generate an <a class="reference internal" href="dml.html#sqlalchemy.sql.expression.insert" title="sqlalchemy.sql.expression.insert"><tt class="xref py py-func docutils literal"><span class="pre">insert()</span></tt></a> construct against this
 
3493
<a class="reference internal" href="#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a>.</p>
 
3494
<p>E.g.:</p>
 
3495
<div class="highlight-python"><div class="highlight"><pre><span class="n">table</span><span class="o">.</span><span class="n">insert</span><span class="p">()</span><span class="o">.</span><span class="n">values</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&#39;foo&#39;</span><span class="p">)</span></pre></div>
 
3496
</div>
 
3497
<p>See <a class="reference internal" href="dml.html#sqlalchemy.sql.expression.insert" title="sqlalchemy.sql.expression.insert"><tt class="xref py py-func docutils literal"><span class="pre">insert()</span></tt></a> for argument and usage information.</p>
 
3498
</dd></dl>
 
3499
 
 
3500
<dl class="method">
 
3501
<dt id="sqlalchemy.sql.expression.TableClause.is_derived_from">
 
3502
<tt class="descname">is_derived_from</tt><big>(</big><em>fromclause</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.is_derived_from" title="Permalink to this definition">¶</a></dt>
 
3503
<dd><div class="inherited-member container">
 
3504
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.is_derived_from" title="sqlalchemy.sql.expression.FromClause.is_derived_from"><tt class="xref py py-meth docutils literal"><span class="pre">is_derived_from()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3505
<p>Return True if this FromClause is &#8216;derived&#8217; from the given
 
3506
FromClause.</p>
 
3507
<p>An example would be an Alias of a Table is derived from that Table.</p>
 
3508
</dd></dl>
 
3509
 
 
3510
<dl class="method">
 
3511
<dt id="sqlalchemy.sql.expression.TableClause.join">
 
3512
<tt class="descname">join</tt><big>(</big><em>right</em>, <em>onclause=None</em>, <em>isouter=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.join" title="Permalink to this definition">¶</a></dt>
 
3513
<dd><div class="inherited-member container">
 
3514
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.join" title="sqlalchemy.sql.expression.FromClause.join"><tt class="xref py py-meth docutils literal"><span class="pre">join()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3515
<p>return a join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
3516
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
3517
</dd></dl>
 
3518
 
 
3519
<dl class="method">
 
3520
<dt id="sqlalchemy.sql.expression.TableClause.outerjoin">
 
3521
<tt class="descname">outerjoin</tt><big>(</big><em>right</em>, <em>onclause=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.outerjoin" title="Permalink to this definition">¶</a></dt>
 
3522
<dd><div class="inherited-member container">
 
3523
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.outerjoin" title="sqlalchemy.sql.expression.FromClause.outerjoin"><tt class="xref py py-meth docutils literal"><span class="pre">outerjoin()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3524
<p>return an outer join of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a> against another
 
3525
<a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
3526
</dd></dl>
 
3527
 
 
3528
<dl class="attribute">
 
3529
<dt id="sqlalchemy.sql.expression.TableClause.primary_key">
 
3530
<tt class="descname">primary_key</tt><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.primary_key" title="Permalink to this definition">¶</a></dt>
 
3531
<dd><div class="inherited-member container">
 
3532
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.primary_key" title="sqlalchemy.sql.expression.FromClause.primary_key"><tt class="xref py py-attr docutils literal"><span class="pre">primary_key</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3533
<p>Return the collection of Column objects which comprise the
 
3534
primary key of this FromClause.</p>
 
3535
</dd></dl>
 
3536
 
 
3537
<dl class="method">
 
3538
<dt id="sqlalchemy.sql.expression.TableClause.replace_selectable">
 
3539
<tt class="descname">replace_selectable</tt><big>(</big><em>old</em>, <em>alias</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.replace_selectable" title="Permalink to this definition">¶</a></dt>
 
3540
<dd><div class="inherited-member container">
 
3541
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.replace_selectable" title="sqlalchemy.sql.expression.FromClause.replace_selectable"><tt class="xref py py-meth docutils literal"><span class="pre">replace_selectable()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3542
<p>replace all occurrences of FromClause &#8216;old&#8217; with the given Alias
 
3543
object, returning a copy of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
3544
</dd></dl>
 
3545
 
 
3546
<dl class="method">
 
3547
<dt id="sqlalchemy.sql.expression.TableClause.select">
 
3548
<tt class="descname">select</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.select" title="Permalink to this definition">¶</a></dt>
 
3549
<dd><div class="inherited-member container">
 
3550
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause.select" title="sqlalchemy.sql.expression.FromClause.select"><tt class="xref py py-meth docutils literal"><span class="pre">select()</span></tt></a> <em>method of</em> <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a></div>
 
3551
<p>return a SELECT of this <a class="reference internal" href="#sqlalchemy.sql.expression.FromClause" title="sqlalchemy.sql.expression.FromClause"><tt class="xref py py-class docutils literal"><span class="pre">FromClause</span></tt></a>.</p>
 
3552
<div class="admonition seealso">
 
3553
<p class="first admonition-title">See also</p>
 
3554
<p class="last"><a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> - general purpose
 
3555
method which allows for arbitrary column lists.</p>
 
3556
</div>
 
3557
</dd></dl>
 
3558
 
 
3559
<dl class="method">
 
3560
<dt id="sqlalchemy.sql.expression.TableClause.self_group">
 
3561
<tt class="descname">self_group</tt><big>(</big><em>against=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.self_group" title="Permalink to this definition">¶</a></dt>
 
3562
<dd><div class="inherited-member container">
 
3563
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement.self_group" title="sqlalchemy.sql.expression.ClauseElement.self_group"><tt class="xref py py-meth docutils literal"><span class="pre">self_group()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a></div>
 
3564
<p>Apply a &#8216;grouping&#8217; to this <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>.</p>
 
3565
<p>This method is overridden by subclasses to return a
 
3566
&#8220;grouping&#8221; construct, i.e. parenthesis.   In particular
 
3567
it&#8217;s used by &#8220;binary&#8221; expressions to provide a grouping
 
3568
around themselves when placed into a larger expression,
 
3569
as well as by <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a> constructs when placed into
 
3570
the FROM clause of another <a class="reference internal" href="#sqlalchemy.sql.expression.select" title="sqlalchemy.sql.expression.select"><tt class="xref py py-func docutils literal"><span class="pre">select()</span></tt></a>.  (Note that
 
3571
subqueries should be normally created using the
 
3572
<tt class="xref py py-func docutils literal"><span class="pre">Select.alias()</span></tt> method, as many platforms require
 
3573
nested SELECT statements to be named).</p>
 
3574
<p>As expressions are composed together, the application of
 
3575
<a class="reference internal" href="#sqlalchemy.sql.expression.TableClause.self_group" title="sqlalchemy.sql.expression.TableClause.self_group"><tt class="xref py py-meth docutils literal"><span class="pre">self_group()</span></tt></a> is automatic - end-user code should never
 
3576
need to use this method directly.  Note that SQLAlchemy&#8217;s
 
3577
clause constructs take operator precedence into account -
 
3578
so parenthesis might not be needed, for example, in
 
3579
an expression like <tt class="docutils literal"><span class="pre">x</span> <span class="pre">OR</span> <span class="pre">(y</span> <span class="pre">AND</span> <span class="pre">z)</span></tt> - AND takes precedence
 
3580
over OR.</p>
 
3581
<p>The base <a class="reference internal" href="#sqlalchemy.sql.expression.TableClause.self_group" title="sqlalchemy.sql.expression.TableClause.self_group"><tt class="xref py py-meth docutils literal"><span class="pre">self_group()</span></tt></a> method of <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>
 
3582
just returns self.</p>
 
3583
</dd></dl>
 
3584
 
 
3585
<dl class="method">
 
3586
<dt id="sqlalchemy.sql.expression.TableClause.update">
 
3587
<tt class="descname">update</tt><big>(</big><em>whereclause=None</em>, <em>values=None</em>, <em>inline=False</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.sql.expression.TableClause.update" title="Permalink to this definition">¶</a></dt>
 
3588
<dd><p>Generate an <a class="reference internal" href="dml.html#sqlalchemy.sql.expression.update" title="sqlalchemy.sql.expression.update"><tt class="xref py py-func docutils literal"><span class="pre">update()</span></tt></a> construct against this
 
3589
<a class="reference internal" href="#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a>.</p>
 
3590
<p>E.g.:</p>
 
3591
<div class="highlight-python"><div class="highlight"><pre><span class="n">table</span><span class="o">.</span><span class="n">update</span><span class="p">()</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">id</span><span class="o">==</span><span class="mi">7</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&#39;foo&#39;</span><span class="p">)</span></pre></div>
 
3592
</div>
 
3593
<p>See <a class="reference internal" href="dml.html#sqlalchemy.sql.expression.update" title="sqlalchemy.sql.expression.update"><tt class="xref py py-func docutils literal"><span class="pre">update()</span></tt></a> for argument and usage information.</p>
 
3594
</dd></dl>
 
3595
 
 
3596
</dd></dl>
 
3597
 
 
3598
</div>
 
3599
 
 
3600
    </div>
 
3601
 
 
3602
</div>
 
3603
 
 
3604
<div id="docs-bottom-navigation" class="docs-navigation-links">
 
3605
        Previous:
 
3606
        <a href="sqlelement.html" title="previous chapter">Column Elements and Expressions</a>
 
3607
        Next:
 
3608
        <a href="dml.html" title="next chapter">Insert, Updates, Deletes</a>
 
3609
 
 
3610
    <div id="docs-copyright">
 
3611
        &copy; <a href="../copyright.html">Copyright</a> 2007-2013, the SQLAlchemy authors and contributors.
 
3612
        Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2b1.
 
3613
    </div>
 
3614
</div>
 
3615
 
 
3616
</div>
 
3617
 
 
3618
        
 
3619
    </body>
 
3620
</html>
 
3621
 
 
3622