1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml">
6
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
11
Describing Databases with MetaData
13
SQLAlchemy 0.8 Documentation
17
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
18
<link rel="stylesheet" href="../_static/docs.css" type="text/css" />
20
<script type="text/javascript">
21
var DOCUMENTATION_OPTIONS = {
24
COLLAPSE_MODINDEX: false,
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="Schema Definition Language" href="schema.html" />
37
<link rel="next" title="Reflecting Database Objects" href="reflection.html" />
38
<link rel="prev" title="Schema Definition Language" href="schema.html" />
53
<div id="docs-container">
57
<div id="docs-header">
58
<h1>SQLAlchemy 0.8 Documentation</h1>
60
<div id="docs-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" />
69
<div id="docs-version-header">
70
Release: <span class="version-num">0.8.3</span> | Release Date: October 26, 2013
77
<div id="docs-top-navigation">
78
<div id="docs-top-page-control" class="docs-navigation-links">
81
<a href="schema.html" title="previous chapter">Schema Definition Language</a>
84
<a href="reflection.html" title="next chapter">Reflecting Database Objects</a>
88
<a href="../contents.html">Table of Contents</a> |
89
<a href="../genindex.html">Index</a>
90
| <a href="../_sources/core/metadata.txt">view source
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="schema.html" title="Schema Definition Language">Schema Definition Language</a>
100
Describing Databases with MetaData
105
Describing Databases with MetaData
112
<div id="docs-body-container">
114
<div id="docs-sidebar">
115
<h3><a href="../index.html">Table of Contents</a></h3>
117
<li><a class="reference internal" href="#">Describing Databases with MetaData</a><ul>
118
<li><a class="reference internal" href="#accessing-tables-and-columns">Accessing Tables and Columns</a></li>
119
<li><a class="reference internal" href="#creating-and-dropping-database-tables">Creating and Dropping Database Tables</a></li>
120
<li><a class="reference internal" href="#altering-schemas-through-migrations">Altering Schemas through Migrations</a></li>
121
<li><a class="reference internal" href="#specifying-the-schema-name">Specifying the Schema Name</a></li>
122
<li><a class="reference internal" href="#backend-specific-options">Backend-Specific Options</a></li>
123
<li><a class="reference internal" href="#column-table-metadata-api">Column, Table, MetaData API</a></li>
129
<h4>Previous Topic</h4>
131
<a href="schema.html" title="previous chapter">Schema Definition Language</a>
135
<a href="reflection.html" title="next chapter">Reflecting Database Objects</a>
139
<h4>Quick Search</h4>
141
<form class="search" action="../search.html" method="get">
142
<input type="text" name="q" size="18" /> <input type="submit" value="Search" />
143
<input type="hidden" name="check_keywords" value="yes" />
144
<input type="hidden" name="area" value="default" />
150
<div id="docs-body" class="withsidebar" >
152
<div class="section" id="module-sqlalchemy.schema">
153
<span id="describing-databases-with-metadata"></span><span id="metadata-describing"></span><span id="metadata-describing-toplevel"></span><span id="metadata-toplevel"></span><h1>Describing Databases with MetaData<a class="headerlink" href="#module-sqlalchemy.schema" title="Permalink to this headline">¶</a></h1>
154
<p>This section discusses the fundamental <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, <a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
155
and <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> objects.</p>
156
<p>A collection of metadata entities is stored in an object aptly named
157
<a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a>:</p>
158
<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="o">*</span>
160
<span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span></pre></div>
162
<p><a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> is a container object that keeps together
163
many different features of a database (or multiple databases) being described.</p>
164
<p>To represent a table, use the <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> class. Its two
165
primary arguments are the table name, then the
166
<a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> object which it will be associated with.
167
The remaining positional arguments are mostly
168
<a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects describing each column:</p>
169
<div class="highlight-python"><div class="highlight"><pre><span class="n">user</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'user'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
170
<span class="n">Column</span><span class="p">(</span><span class="s">'user_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span> <span class="o">=</span> <span class="bp">True</span><span class="p">),</span>
171
<span class="n">Column</span><span class="p">(</span><span class="s">'user_name'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">16</span><span class="p">),</span> <span class="n">nullable</span> <span class="o">=</span> <span class="bp">False</span><span class="p">),</span>
172
<span class="n">Column</span><span class="p">(</span><span class="s">'email_address'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">60</span><span class="p">)),</span>
173
<span class="n">Column</span><span class="p">(</span><span class="s">'password'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">20</span><span class="p">),</span> <span class="n">nullable</span> <span class="o">=</span> <span class="bp">False</span><span class="p">)</span>
174
<span class="p">)</span></pre></div>
176
<p>Above, a table called <tt class="docutils literal"><span class="pre">user</span></tt> is described, which contains four columns. The
177
primary key of the table consists of the <tt class="docutils literal"><span class="pre">user_id</span></tt> column. Multiple columns
178
may be assigned the <tt class="docutils literal"><span class="pre">primary_key=True</span></tt> flag which denotes a multi-column
179
primary key, known as a <em>composite</em> primary key.</p>
180
<p>Note also that each column describes its datatype using objects corresponding
181
to genericized types, such as <a class="reference internal" href="types.html#sqlalchemy.types.Integer" title="sqlalchemy.types.Integer"><tt class="xref py py-class docutils literal"><span class="pre">Integer</span></tt></a> and
182
<a class="reference internal" href="types.html#sqlalchemy.types.String" title="sqlalchemy.types.String"><tt class="xref py py-class docutils literal"><span class="pre">String</span></tt></a>. SQLAlchemy features dozens of types of
183
varying levels of specificity as well as the ability to create custom types.
184
Documentation on the type system can be found at <em class="xref std std-ref">types</em>.</p>
185
<div class="section" id="accessing-tables-and-columns">
186
<h2>Accessing Tables and Columns<a class="headerlink" href="#accessing-tables-and-columns" title="Permalink to this headline">¶</a></h2>
187
<p>The <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> object contains all of the schema
188
constructs we’ve associated with it. It supports a few methods of accessing
189
these table objects, such as the <tt class="docutils literal"><span class="pre">sorted_tables</span></tt> accessor which returns a
190
list of each <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object in order of foreign key
191
dependency (that is, each table is preceded by all tables which it
193
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">metadata</span><span class="o">.</span><span class="n">sorted_tables</span><span class="p">:</span>
194
<span class="gp">... </span> <span class="k">print</span> <span class="n">t</span><span class="o">.</span><span class="n">name</span>
195
<span class="go">user</span>
196
<span class="go">user_preference</span>
197
<span class="go">invoice</span>
198
<span class="go">invoice_item</span></pre></div>
200
<p>In most cases, individual <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects have been
201
explicitly declared, and these objects are typically accessed directly as
202
module-level variables in an application. Once a
203
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> has been defined, it has a full set of
204
accessors which allow inspection of its properties. Given the following
205
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> definition:</p>
206
<div class="highlight-python"><div class="highlight"><pre><span class="n">employees</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'employees'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
207
<span class="n">Column</span><span class="p">(</span><span class="s">'employee_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
208
<span class="n">Column</span><span class="p">(</span><span class="s">'employee_name'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">60</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
209
<span class="n">Column</span><span class="p">(</span><span class="s">'employee_dept'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">"departments.department_id"</span><span class="p">))</span>
210
<span class="p">)</span></pre></div>
212
<p>Note the <a class="reference internal" href="constraints.html#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> object used in this table -
213
this construct defines a reference to a remote table, and is fully described
214
in <em class="xref std std-ref">metadata_foreignkeys</em>. Methods of accessing information about this
216
<div class="highlight-python"><div class="highlight"><pre><span class="c"># access the column "EMPLOYEE_ID":</span>
217
<span class="n">employees</span><span class="o">.</span><span class="n">columns</span><span class="o">.</span><span class="n">employee_id</span>
219
<span class="c"># or just</span>
220
<span class="n">employees</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">employee_id</span>
222
<span class="c"># via string</span>
223
<span class="n">employees</span><span class="o">.</span><span class="n">c</span><span class="p">[</span><span class="s">'employee_id'</span><span class="p">]</span>
225
<span class="c"># iterate through all columns</span>
226
<span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">employees</span><span class="o">.</span><span class="n">c</span><span class="p">:</span>
227
<span class="k">print</span> <span class="n">c</span>
229
<span class="c"># get the table's primary key columns</span>
230
<span class="k">for</span> <span class="n">primary_key</span> <span class="ow">in</span> <span class="n">employees</span><span class="o">.</span><span class="n">primary_key</span><span class="p">:</span>
231
<span class="k">print</span> <span class="n">primary_key</span>
233
<span class="c"># get the table's foreign key objects:</span>
234
<span class="k">for</span> <span class="n">fkey</span> <span class="ow">in</span> <span class="n">employees</span><span class="o">.</span><span class="n">foreign_keys</span><span class="p">:</span>
235
<span class="k">print</span> <span class="n">fkey</span>
237
<span class="c"># access the table's MetaData:</span>
238
<span class="n">employees</span><span class="o">.</span><span class="n">metadata</span>
240
<span class="c"># access the table's bound Engine or Connection, if its MetaData is bound:</span>
241
<span class="n">employees</span><span class="o">.</span><span class="n">bind</span>
243
<span class="c"># access a column's name, type, nullable, primary key, foreign key</span>
244
<span class="n">employees</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">employee_id</span><span class="o">.</span><span class="n">name</span>
245
<span class="n">employees</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">employee_id</span><span class="o">.</span><span class="n">type</span>
246
<span class="n">employees</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">employee_id</span><span class="o">.</span><span class="n">nullable</span>
247
<span class="n">employees</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">employee_id</span><span class="o">.</span><span class="n">primary_key</span>
248
<span class="n">employees</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">employee_dept</span><span class="o">.</span><span class="n">foreign_keys</span>
250
<span class="c"># get the "key" of a column, which defaults to its name, but can</span>
251
<span class="c"># be any user-defined string:</span>
252
<span class="n">employees</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">employee_name</span><span class="o">.</span><span class="n">key</span>
254
<span class="c"># access a column's table:</span>
255
<span class="n">employees</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">employee_id</span><span class="o">.</span><span class="n">table</span> <span class="ow">is</span> <span class="n">employees</span>
257
<span class="c"># get the table related by a foreign key</span>
258
<span class="nb">list</span><span class="p">(</span><span class="n">employees</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">employee_dept</span><span class="o">.</span><span class="n">foreign_keys</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">column</span><span class="o">.</span><span class="n">table</span></pre></div>
261
<div class="section" id="creating-and-dropping-database-tables">
262
<h2>Creating and Dropping Database Tables<a class="headerlink" href="#creating-and-dropping-database-tables" title="Permalink to this headline">¶</a></h2>
263
<p>Once you’ve defined some <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects, assuming
264
you’re working with a brand new database one thing you might want to do is
265
issue CREATE statements for those tables and their related constructs (as an
266
aside, it’s also quite possible that you <em>don’t</em> want to do this, if you
267
already have some preferred methodology such as tools included with your
268
database or an existing scripting system - if that’s the case, feel free to
269
skip this section - SQLAlchemy has no requirement that it be used to create
271
<p>The usual way to issue CREATE is to use
272
<a class="reference internal" href="#sqlalchemy.schema.MetaData.create_all" title="sqlalchemy.schema.MetaData.create_all"><tt class="xref py py-func docutils literal"><span class="pre">create_all()</span></tt></a> on the
273
<a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> object. This method will issue queries
274
that first check for the existence of each individual table, and if not found
275
will issue the CREATE statements:</p>
277
<div><div class="highlight-python+sql"><div class="highlight"><pre><span class="n">engine</span> <span class="o">=</span> <span class="n">create_engine</span><span class="p">(</span><span class="s">'sqlite:///:memory:'</span><span class="p">)</span>
279
<span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
281
<span class="n">user</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'user'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
282
<span class="n">Column</span><span class="p">(</span><span class="s">'user_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span> <span class="o">=</span> <span class="bp">True</span><span class="p">),</span>
283
<span class="n">Column</span><span class="p">(</span><span class="s">'user_name'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">16</span><span class="p">),</span> <span class="n">nullable</span> <span class="o">=</span> <span class="bp">False</span><span class="p">),</span>
284
<span class="n">Column</span><span class="p">(</span><span class="s">'email_address'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">60</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="s">'email'</span><span class="p">),</span>
285
<span class="n">Column</span><span class="p">(</span><span class="s">'password'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">20</span><span class="p">),</span> <span class="n">nullable</span> <span class="o">=</span> <span class="bp">False</span><span class="p">)</span>
286
<span class="p">)</span>
288
<span class="n">user_prefs</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'user_prefs'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
289
<span class="n">Column</span><span class="p">(</span><span class="s">'pref_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
290
<span class="n">Column</span><span class="p">(</span><span class="s">'user_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">"user.user_id"</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
291
<span class="n">Column</span><span class="p">(</span><span class="s">'pref_name'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">40</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
292
<span class="n">Column</span><span class="p">(</span><span class="s">'pref_value'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">100</span><span class="p">))</span>
293
<span class="p">)</span>
295
<a href='#' class='sql_link'>sql</a><span class="n">metadata</span><span class="o">.</span><span class="n">create_all</span><span class="p">(</span><span class="n">engine</span><span class="p">)</span>
296
<div class='popup_sql'>PRAGMA table_info(user){}
298
user_id INTEGER NOT NULL PRIMARY KEY,
299
user_name VARCHAR(16) NOT NULL,
300
email_address VARCHAR(60),
301
password VARCHAR(20) NOT NULL
303
PRAGMA table_info(user_prefs){}
304
CREATE TABLE user_prefs(
305
pref_id INTEGER NOT NULL PRIMARY KEY,
306
user_id INTEGER NOT NULL REFERENCES user(user_id),
307
pref_name VARCHAR(40) NOT NULL,
308
pref_value VARCHAR(100)
312
<p><a class="reference internal" href="#sqlalchemy.schema.MetaData.create_all" title="sqlalchemy.schema.MetaData.create_all"><tt class="xref py py-func docutils literal"><span class="pre">create_all()</span></tt></a> creates foreign key constraints
313
between tables usually inline with the table definition itself, and for this
314
reason it also generates the tables in order of their dependency. There are
315
options to change this behavior such that <tt class="docutils literal"><span class="pre">ALTER</span> <span class="pre">TABLE</span></tt> is used instead.</p>
316
<p>Dropping all tables is similarly achieved using the
317
<a class="reference internal" href="#sqlalchemy.schema.MetaData.drop_all" title="sqlalchemy.schema.MetaData.drop_all"><tt class="xref py py-func docutils literal"><span class="pre">drop_all()</span></tt></a> method. This method does the
318
exact opposite of <a class="reference internal" href="#sqlalchemy.schema.MetaData.create_all" title="sqlalchemy.schema.MetaData.create_all"><tt class="xref py py-func docutils literal"><span class="pre">create_all()</span></tt></a> - the
319
presence of each table is checked first, and tables are dropped in reverse
320
order of dependency.</p>
321
<p>Creating and dropping individual tables can be done via the <tt class="docutils literal"><span class="pre">create()</span></tt> and
322
<tt class="docutils literal"><span class="pre">drop()</span></tt> methods of <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>. These methods by
323
default issue the CREATE or DROP regardless of the table being present:</p>
324
<div class="highlight-python+sql"><div class="highlight"><pre><span class="n">engine</span> <span class="o">=</span> <span class="n">create_engine</span><span class="p">(</span><span class="s">'sqlite:///:memory:'</span><span class="p">)</span>
326
<span class="n">meta</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
328
<span class="n">employees</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'employees'</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
329
<span class="n">Column</span><span class="p">(</span><span class="s">'employee_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
330
<span class="n">Column</span><span class="p">(</span><span class="s">'employee_name'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">60</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s">'name'</span><span class="p">),</span>
331
<span class="n">Column</span><span class="p">(</span><span class="s">'employee_dept'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">"departments.department_id"</span><span class="p">))</span>
332
<span class="p">)</span>
333
<a href='#' class='sql_link'>sql</a><span class="n">employees</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">engine</span><span class="p">)</span>
334
<div class='popup_sql'>CREATE TABLE employees(
335
employee_id SERIAL NOT NULL PRIMARY KEY,
336
employee_name VARCHAR(60) NOT NULL,
337
employee_dept INTEGER REFERENCES departments(department_id)
340
<p><tt class="docutils literal"><span class="pre">drop()</span></tt> method:</p>
341
<div class="highlight-python+sql"><div class="highlight"><pre><a href='#' class='sql_link'>sql</a><span class="n">employees</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="n">engine</span><span class="p">)</span>
342
<div class='popup_sql'>DROP TABLE employee</div></pre></div>
344
<p>To enable the “check first for the table existing” logic, add the
345
<tt class="docutils literal"><span class="pre">checkfirst=True</span></tt> argument to <tt class="docutils literal"><span class="pre">create()</span></tt> or <tt class="docutils literal"><span class="pre">drop()</span></tt>:</p>
346
<div class="highlight-python"><div class="highlight"><pre><span class="n">employees</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">engine</span><span class="p">,</span> <span class="n">checkfirst</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
347
<span class="n">employees</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="n">engine</span><span class="p">,</span> <span class="n">checkfirst</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span></pre></div>
350
<div class="section" id="altering-schemas-through-migrations">
351
<span id="schema-migrations"></span><h2>Altering Schemas through Migrations<a class="headerlink" href="#altering-schemas-through-migrations" title="Permalink to this headline">¶</a></h2>
352
<p>While SQLAlchemy directly supports emitting CREATE and DROP statements for schema
353
constructs, the ability to alter those constructs, usually via the ALTER statement
354
as well as other database-specific constructs, is outside of the scope of SQLAlchemy
355
itself. While it’s easy enough to emit ALTER statements and similar by hand,
356
such as by passing a string to <a class="reference internal" href="connections.html#sqlalchemy.engine.Connection.execute" title="sqlalchemy.engine.Connection.execute"><tt class="xref py py-meth docutils literal"><span class="pre">Connection.execute()</span></tt></a> or by using the
357
<a class="reference internal" href="ddl.html#sqlalchemy.schema.DDL" title="sqlalchemy.schema.DDL"><tt class="xref py py-class docutils literal"><span class="pre">DDL</span></tt></a> construct, it’s a common practice to automate the maintenance of
358
database schemas in relation to application code using schema migration tools.</p>
359
<p>There are two major migration tools available for SQLAlchemy:</p>
361
<li><a class="reference external" href="http://alembic.readthedocs.org">Alembic</a> - Written by the author of SQLAlchemy,
362
Alembic features a highly customizable environment and a minimalistic usage pattern,
363
supporting such features as transactional DDL, automatic generation of “candidate”
364
migrations, an “offline” mode which generates SQL scripts, and support for branch
366
<li><a class="reference external" href="http://code.google.com/p/sqlalchemy-migrate/">SQLAlchemy-Migrate</a> - The original
367
migration tool for SQLAlchemy, SQLAlchemy-Migrate is widely used and continues
368
under active development. SQLAlchemy-Migrate includes features such as
369
SQL script generation, ORM class generation, ORM model comparison, and extensive
370
support for SQLite migrations.</li>
373
<div class="section" id="specifying-the-schema-name">
374
<h2>Specifying the Schema Name<a class="headerlink" href="#specifying-the-schema-name" title="Permalink to this headline">¶</a></h2>
375
<p>Some databases support the concept of multiple schemas. A
376
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> can reference this by specifying the
377
<tt class="docutils literal"><span class="pre">schema</span></tt> keyword argument:</p>
378
<div class="highlight-python"><div class="highlight"><pre><span class="n">financial_info</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'financial_info'</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
379
<span class="n">Column</span><span class="p">(</span><span class="s">'id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
380
<span class="n">Column</span><span class="p">(</span><span class="s">'value'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">100</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
381
<span class="n">schema</span><span class="o">=</span><span class="s">'remote_banks'</span>
382
<span class="p">)</span></pre></div>
384
<p>Within the <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> collection, this table will be
385
identified by the combination of <tt class="docutils literal"><span class="pre">financial_info</span></tt> and <tt class="docutils literal"><span class="pre">remote_banks</span></tt>. If
386
another table called <tt class="docutils literal"><span class="pre">financial_info</span></tt> is referenced without the
387
<tt class="docutils literal"><span class="pre">remote_banks</span></tt> schema, it will refer to a different
388
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>. <a class="reference internal" href="constraints.html#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a>
389
objects can specify references to columns in this table using the form
390
<tt class="docutils literal"><span class="pre">remote_banks.financial_info.id</span></tt>.</p>
391
<p>The <tt class="docutils literal"><span class="pre">schema</span></tt> argument should be used for any name qualifiers required,
392
including Oracle’s “owner” attribute and similar. It also can accommodate a
393
dotted name for longer schemes:</p>
394
<div class="highlight-python"><div class="highlight"><pre><span class="n">schema</span><span class="o">=</span><span class="s">"dbo.scott"</span></pre></div>
397
<div class="section" id="backend-specific-options">
398
<h2>Backend-Specific Options<a class="headerlink" href="#backend-specific-options" title="Permalink to this headline">¶</a></h2>
399
<p><a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> supports database-specific options. For
400
example, MySQL has different table backend types, including “MyISAM” and
401
“InnoDB”. This can be expressed with <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> using
402
<tt class="docutils literal"><span class="pre">mysql_engine</span></tt>:</p>
403
<div class="highlight-python"><div class="highlight"><pre><span class="n">addresses</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'engine_email_addresses'</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
404
<span class="n">Column</span><span class="p">(</span><span class="s">'address_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span> <span class="o">=</span> <span class="bp">True</span><span class="p">),</span>
405
<span class="n">Column</span><span class="p">(</span><span class="s">'remote_user_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">user_id</span><span class="p">)),</span>
406
<span class="n">Column</span><span class="p">(</span><span class="s">'email_address'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">20</span><span class="p">)),</span>
407
<span class="n">mysql_engine</span><span class="o">=</span><span class="s">'InnoDB'</span>
408
<span class="p">)</span></pre></div>
410
<p>Other backends may support table-level options as well - these would be
411
described in the individual documentation sections for each dialect.</p>
413
<div class="section" id="column-table-metadata-api">
414
<h2>Column, Table, MetaData API<a class="headerlink" href="#column-table-metadata-api" title="Permalink to this headline">¶</a></h2>
416
<dt id="sqlalchemy.schema.Column">
417
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">Column</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column" title="Permalink to this definition">¶</a></dt>
418
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.SchemaItem</span></tt></a>, <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnClause" title="sqlalchemy.sql.expression.ColumnClause"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.ColumnClause</span></tt></a></p>
419
<p>Represents a column in a database table.</p>
421
<dt id="sqlalchemy.schema.Column.__eq__">
422
<tt class="descname">__eq__</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.__eq__" title="Permalink to this definition">¶</a></dt>
423
<dd><div class="inherited-member container">
424
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.__eq__" title="sqlalchemy.sql.operators.ColumnOperators.__eq__"><tt class="xref py py-meth docutils literal"><span class="pre">__eq__()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
425
<p>Implement the <tt class="docutils literal"><span class="pre">==</span></tt> operator.</p>
426
<p>In a column context, produces the clause <tt class="docutils literal"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">b</span></tt>.
427
If the target is <tt class="docutils literal"><span class="pre">None</span></tt>, produces <tt class="docutils literal"><span class="pre">a</span> <span class="pre">IS</span> <span class="pre">NULL</span></tt>.</p>
431
<dt id="sqlalchemy.schema.Column.__init__">
432
<tt class="descname">__init__</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.__init__" title="Permalink to this definition">¶</a></dt>
433
<dd><p>Construct a new <tt class="docutils literal"><span class="pre">Column</span></tt> object.</p>
434
<table class="docutils field-list" frame="void" rules="none">
435
<col class="field-name" />
436
<col class="field-body" />
438
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
439
<li><strong>name</strong> – <p>The name of this column as represented in the database.
440
This argument may be the first positional argument, or specified
442
<p>Names which contain no upper case characters
443
will be treated as case insensitive names, and will not be quoted
444
unless they are a reserved word. Names with any number of upper
445
case characters will be quoted and sent exactly. Note that this
446
behavior applies even for databases which standardize upper
447
case names as case insensitive such as Oracle.</p>
448
<p>The name field may be omitted at construction time and applied
449
later, at any time before the Column is associated with a
450
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>. This is to support convenient
451
usage within the <a class="reference internal" href="../orm/extensions/declarative.html#module-sqlalchemy.ext.declarative" title="sqlalchemy.ext.declarative"><tt class="xref py py-mod docutils literal"><span class="pre">declarative</span></tt></a> extension.</p>
453
<li><strong>type_</strong> – <p>The column’s type, indicated using an instance which
454
subclasses <a class="reference internal" href="types.html#sqlalchemy.types.TypeEngine" title="sqlalchemy.types.TypeEngine"><tt class="xref py py-class docutils literal"><span class="pre">TypeEngine</span></tt></a>. If no arguments
455
are required for the type, the class of the type can be sent
457
<div class="highlight-python"><div class="highlight"><pre><span class="c"># use a type with arguments</span>
458
<span class="n">Column</span><span class="p">(</span><span class="s">'data'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">))</span>
460
<span class="c"># use no arguments</span>
461
<span class="n">Column</span><span class="p">(</span><span class="s">'level'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">)</span></pre></div>
463
<p>The <tt class="docutils literal"><span class="pre">type</span></tt> argument may be the second positional argument
464
or specified by keyword.</p>
465
<p>There is partial support for automatic detection of the
466
type based on that of a <a class="reference internal" href="constraints.html#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> associated
467
with this column, if the type is specified as <tt class="docutils literal"><span class="pre">None</span></tt>.
468
However, this feature is not fully implemented and
469
may not function in all cases.</p>
471
<li><strong>*args</strong> – Additional positional arguments include various
472
<a class="reference internal" href="#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a> derived constructs which will be applied
473
as options to the column. These include instances of
474
<a class="reference internal" href="constraints.html#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">Constraint</span></tt></a>, <a class="reference internal" href="constraints.html#sqlalchemy.schema.ForeignKey" title="sqlalchemy.schema.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a>, <a class="reference internal" href="defaults.html#sqlalchemy.schema.ColumnDefault" title="sqlalchemy.schema.ColumnDefault"><tt class="xref py py-class docutils literal"><span class="pre">ColumnDefault</span></tt></a>,
475
and <a class="reference internal" href="defaults.html#sqlalchemy.schema.Sequence" title="sqlalchemy.schema.Sequence"><tt class="xref py py-class docutils literal"><span class="pre">Sequence</span></tt></a>. In some cases an equivalent keyword
476
argument is available such as <tt class="docutils literal"><span class="pre">server_default</span></tt>, <tt class="docutils literal"><span class="pre">default</span></tt>
477
and <tt class="docutils literal"><span class="pre">unique</span></tt>.</li>
478
<li><strong>autoincrement</strong> – <p>This flag may be set to <tt class="docutils literal"><span class="pre">False</span></tt> to
479
indicate an integer primary key column that should not be
480
considered to be the “autoincrement” column, that is
481
the integer primary key column which generates values
482
implicitly upon INSERT and whose value is usually returned
483
via the DBAPI cursor.lastrowid attribute. It defaults
484
to <tt class="docutils literal"><span class="pre">True</span></tt> to satisfy the common use case of a table
485
with a single integer primary key column. If the table
486
has a composite primary key consisting of more than one
487
integer column, set this flag to True only on the
488
column that should be considered “autoincrement”.</p>
489
<p>The setting <em>only</em> has an effect for columns which are:</p>
491
<li>Integer derived (i.e. INT, SMALLINT, BIGINT).</li>
492
<li>Part of the primary key</li>
493
<li>Are not referenced by any foreign keys, unless
494
the value is specified as <tt class="docutils literal"><span class="pre">'ignore_fk'</span></tt><div class="versionadded">
495
<p><span>New in version 0.7.4.</span></p>
498
<li>have no server side or client side defaults (with the exception
499
of Postgresql SERIAL).</li>
501
<p>The setting has these two effects on columns that meet the
504
<li>DDL issued for the column will include database-specific
505
keywords intended to signify this column as an
506
“autoincrement” column, such as AUTO INCREMENT on MySQL,
507
SERIAL on Postgresql, and IDENTITY on MS-SQL. It does
508
<em>not</em> issue AUTOINCREMENT for SQLite since this is a
509
special SQLite flag that is not required for autoincrementing
510
behavior. See the SQLite dialect documentation for
511
information on SQLite’s AUTOINCREMENT.</li>
512
<li>The column will be considered to be available as
513
cursor.lastrowid or equivalent, for those dialects which
514
“post fetch” newly inserted identifiers after a row has
515
been inserted (SQLite, MySQL, MS-SQL). It does not have
516
any effect in this regard for databases that use sequences
517
to generate primary key identifiers (i.e. Firebird, Postgresql,
520
<div class="versionchanged">
521
<p><span>Changed in version 0.7.4: </span><tt class="docutils literal"><span class="pre">autoincrement</span></tt> accepts a special value <tt class="docutils literal"><span class="pre">'ignore_fk'</span></tt>
522
to indicate that autoincrementing status regardless of foreign
523
key references. This applies to certain composite foreign key
524
setups, such as the one demonstrated in the ORM documentation
525
at <a class="reference internal" href="../orm/relationships.html#post-update"><em>Rows that point to themselves / Mutually Dependent Rows</em></a>.</p>
528
<li><strong>default</strong> – <p>A scalar, Python callable, or
529
<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> expression representing the
530
<em>default value</em> for this column, which will be invoked upon insert
531
if this column is otherwise not specified in the VALUES clause of
532
the insert. This is a shortcut to using <a class="reference internal" href="defaults.html#sqlalchemy.schema.ColumnDefault" title="sqlalchemy.schema.ColumnDefault"><tt class="xref py py-class docutils literal"><span class="pre">ColumnDefault</span></tt></a> as
533
a positional argument; see that class for full detail on the
534
structure of the argument.</p>
535
<p>Contrast this argument to <tt class="docutils literal"><span class="pre">server_default</span></tt> which creates a
536
default generator on the database side.</p>
538
<li><strong>doc</strong> – optional String that can be used by the ORM or similar
539
to document attributes. This attribute does not render SQL
540
comments (a future attribute ‘comment’ will achieve that).</li>
541
<li><strong>key</strong> – An optional string identifier which will identify this
542
<tt class="docutils literal"><span class="pre">Column</span></tt> object on the <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>. When a key is provided,
543
this is the only identifier referencing the <tt class="docutils literal"><span class="pre">Column</span></tt> within the
544
application, including ORM attribute mapping; the <tt class="docutils literal"><span class="pre">name</span></tt> field
545
is used only when rendering SQL.</li>
546
<li><strong>index</strong> – When <tt class="docutils literal"><span class="pre">True</span></tt>, indicates that the column is indexed.
547
This is a shortcut for using a <a class="reference internal" href="constraints.html#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> construct on the
548
table. To specify indexes with explicit names or indexes that
549
contain multiple columns, use the <a class="reference internal" href="constraints.html#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> construct
551
<li><strong>info</strong> – Optional data dictionary which will be populated into the
552
<a class="reference internal" href="#sqlalchemy.schema.SchemaItem.info" title="sqlalchemy.schema.SchemaItem.info"><tt class="xref py py-attr docutils literal"><span class="pre">SchemaItem.info</span></tt></a> attribute of this object.</li>
553
<li><strong>nullable</strong> – If set to the default of <tt class="docutils literal"><span class="pre">True</span></tt>, indicates the
554
column will be rendered as allowing NULL, else it’s rendered as
555
NOT NULL. This parameter is only used when issuing CREATE TABLE
557
<li><strong>onupdate</strong> – A scalar, Python callable, or
558
<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> representing a
559
default value to be applied to the column within UPDATE
560
statements, which wil be invoked upon update if this column is not
561
present in the SET clause of the update. This is a shortcut to
562
using <a class="reference internal" href="defaults.html#sqlalchemy.schema.ColumnDefault" title="sqlalchemy.schema.ColumnDefault"><tt class="xref py py-class docutils literal"><span class="pre">ColumnDefault</span></tt></a> as a positional argument with
563
<tt class="docutils literal"><span class="pre">for_update=True</span></tt>.</li>
564
<li><strong>primary_key</strong> – If <tt class="docutils literal"><span class="pre">True</span></tt>, marks this column as a primary key
565
column. Multiple columns can have this flag set to specify
566
composite primary keys. As an alternative, the primary key of a
567
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> can be specified via an explicit
568
<a class="reference internal" href="constraints.html#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a> object.</li>
569
<li><strong>server_default</strong> – <p>A <a class="reference internal" href="defaults.html#sqlalchemy.schema.FetchedValue" title="sqlalchemy.schema.FetchedValue"><tt class="xref py py-class docutils literal"><span class="pre">FetchedValue</span></tt></a> instance, str, Unicode
570
or <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> construct representing
571
the DDL DEFAULT value for the column.</p>
572
<p>String types will be emitted as-is, surrounded by single quotes:</p>
573
<div class="highlight-python"><pre>Column('x', Text, server_default="val")
575
x TEXT DEFAULT 'val'</pre>
577
<p>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> expression will be
578
rendered as-is, without quotes:</p>
579
<div class="highlight-python"><pre>Column('y', DateTime, server_default=text('NOW()'))0
581
y DATETIME DEFAULT NOW()</pre>
583
<p>Strings and text() will be converted into a <a class="reference internal" href="defaults.html#sqlalchemy.schema.DefaultClause" title="sqlalchemy.schema.DefaultClause"><tt class="xref py py-class docutils literal"><span class="pre">DefaultClause</span></tt></a>
584
object upon initialization.</p>
585
<p>Use <a class="reference internal" href="defaults.html#sqlalchemy.schema.FetchedValue" title="sqlalchemy.schema.FetchedValue"><tt class="xref py py-class docutils literal"><span class="pre">FetchedValue</span></tt></a> to indicate that an already-existing
586
column will generate a default value on the database side which
587
will be available to SQLAlchemy for post-fetch after inserts. This
588
construct does not specify any DDL and the implementation is left
589
to the database, such as via a trigger.</p>
591
<li><strong>server_onupdate</strong> – A <a class="reference internal" href="defaults.html#sqlalchemy.schema.FetchedValue" title="sqlalchemy.schema.FetchedValue"><tt class="xref py py-class docutils literal"><span class="pre">FetchedValue</span></tt></a> instance
592
representing a database-side default generation function. This
593
indicates to SQLAlchemy that a newly generated value will be
594
available after updates. This construct does not specify any DDL
595
and the implementation is left to the database, such as via a
597
<li><strong>quote</strong> – Force quoting of this column’s name on or off,
598
corresponding to <tt class="docutils literal"><span class="pre">True</span></tt> or <tt class="docutils literal"><span class="pre">False</span></tt>. When left at its default
599
of <tt class="docutils literal"><span class="pre">None</span></tt>, the column identifier will be quoted according to
600
whether the name is case sensitive (identifiers with at least one
601
upper case character are treated as case sensitive), or if it’s a
602
reserved word. This flag is only needed to force quoting of a
603
reserved word which is not known by the SQLAlchemy dialect.</li>
604
<li><strong>unique</strong> – When <tt class="docutils literal"><span class="pre">True</span></tt>, indicates that this column contains a
605
unique constraint, or if <tt class="docutils literal"><span class="pre">index</span></tt> is <tt class="docutils literal"><span class="pre">True</span></tt> as well, indicates
606
that the <a class="reference internal" href="constraints.html#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> should be created with the unique flag.
607
To specify multiple columns in the constraint/index or to specify
608
an explicit name, use the <a class="reference internal" href="constraints.html#sqlalchemy.schema.UniqueConstraint" title="sqlalchemy.schema.UniqueConstraint"><tt class="xref py py-class docutils literal"><span class="pre">UniqueConstraint</span></tt></a> or
609
<a class="reference internal" href="constraints.html#sqlalchemy.schema.Index" title="sqlalchemy.schema.Index"><tt class="xref py py-class docutils literal"><span class="pre">Index</span></tt></a> constructs explicitly.</li>
610
<li><strong>system</strong> – <p>When <tt class="docutils literal"><span class="pre">True</span></tt>, indicates this is a “system” column,
611
that is a column which is automatically made available by the
612
database, and should not be included in the columns list for a
613
<tt class="docutils literal"><span class="pre">CREATE</span> <span class="pre">TABLE</span></tt> statement.</p>
614
<p>For more elaborate scenarios where columns should be conditionally
615
rendered differently on different backends, consider custom
616
compilation rules for <a class="reference internal" href="ddl.html#sqlalchemy.schema.CreateColumn" title="sqlalchemy.schema.CreateColumn"><tt class="xref py py-class docutils literal"><span class="pre">CreateColumn</span></tt></a>.</p>
617
<dl class="docutils">
618
<dt>..versionadded:: 0.8.3 Added the <tt class="docutils literal"><span class="pre">system=True</span></tt> parameter to</dt>
619
<dd><a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</dd>
630
<dt id="sqlalchemy.schema.Column.__le__">
631
<tt class="descname">__le__</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.__le__" title="Permalink to this definition">¶</a></dt>
632
<dd><div class="inherited-member container">
633
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.__le__" title="sqlalchemy.sql.operators.ColumnOperators.__le__"><tt class="xref py py-meth docutils literal"><span class="pre">__le__()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
634
<p>Implement the <tt class="docutils literal"><span class="pre"><=</span></tt> operator.</p>
635
<p>In a column context, produces the clause <tt class="docutils literal"><span class="pre">a</span> <span class="pre"><=</span> <span class="pre">b</span></tt>.</p>
639
<dt id="sqlalchemy.schema.Column.__lt__">
640
<tt class="descname">__lt__</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.__lt__" title="Permalink to this definition">¶</a></dt>
641
<dd><div class="inherited-member container">
642
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.__lt__" title="sqlalchemy.sql.operators.ColumnOperators.__lt__"><tt class="xref py py-meth docutils literal"><span class="pre">__lt__()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
643
<p>Implement the <tt class="docutils literal"><span class="pre"><</span></tt> operator.</p>
644
<p>In a column context, produces the clause <tt class="docutils literal"><span class="pre">a</span> <span class="pre"><</span> <span class="pre">b</span></tt>.</p>
648
<dt id="sqlalchemy.schema.Column.__ne__">
649
<tt class="descname">__ne__</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.__ne__" title="Permalink to this definition">¶</a></dt>
650
<dd><div class="inherited-member container">
651
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.__ne__" title="sqlalchemy.sql.operators.ColumnOperators.__ne__"><tt class="xref py py-meth docutils literal"><span class="pre">__ne__()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
652
<p>Implement the <tt class="docutils literal"><span class="pre">!=</span></tt> operator.</p>
653
<p>In a column context, produces the clause <tt class="docutils literal"><span class="pre">a</span> <span class="pre">!=</span> <span class="pre">b</span></tt>.
654
If the target is <tt class="docutils literal"><span class="pre">None</span></tt>, produces <tt class="docutils literal"><span class="pre">a</span> <span class="pre">IS</span> <span class="pre">NOT</span> <span class="pre">NULL</span></tt>.</p>
657
<dl class="attribute">
658
<dt id="sqlalchemy.schema.Column.anon_label">
659
<tt class="descname">anon_label</tt><a class="headerlink" href="#sqlalchemy.schema.Column.anon_label" title="Permalink to this definition">¶</a></dt>
660
<dd><div class="inherited-member container">
661
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement.anon_label" title="sqlalchemy.sql.expression.ColumnElement.anon_label"><tt class="xref py py-attr docutils literal"><span class="pre">anon_label</span></tt></a> <em>attribute of</em> <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></div>
662
<p>provides a constant ‘anonymous label’ for this ColumnElement.</p>
663
<p>This is a label() expression which will be named at compile time.
664
The same label() is returned each time anon_label is called so
665
that expressions can reference anon_label multiple times, producing
666
the same label name at compile time.</p>
667
<p>the compiler uses this function automatically at compile time
668
for expressions that are known to be ‘unnamed’ like binary
669
expressions and function calls.</p>
673
<dt id="sqlalchemy.schema.Column.append_foreign_key">
674
<tt class="descname">append_foreign_key</tt><big>(</big><em>fk</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.append_foreign_key" title="Permalink to this definition">¶</a></dt>
678
<dt id="sqlalchemy.schema.Column.asc">
679
<tt class="descname">asc</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.asc" title="Permalink to this definition">¶</a></dt>
680
<dd><div class="inherited-member container">
681
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.asc" title="sqlalchemy.sql.operators.ColumnOperators.asc"><tt class="xref py py-meth docutils literal"><span class="pre">asc()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
682
<p>Produce a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.asc" title="sqlalchemy.sql.expression.asc"><tt class="xref py py-func docutils literal"><span class="pre">asc()</span></tt></a> clause against the
686
<dl class="attribute">
687
<dt id="sqlalchemy.schema.Column.base_columns">
688
<tt class="descname">base_columns</tt><a class="headerlink" href="#sqlalchemy.schema.Column.base_columns" title="Permalink to this definition">¶</a></dt>
689
<dd><div class="inherited-member container">
690
<em>inherited from the</em> <tt class="xref py py-attr docutils literal"><span class="pre">base_columns</span></tt> <em>attribute of</em> <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></div>
694
<dt id="sqlalchemy.schema.Column.between">
695
<tt class="descname">between</tt><big>(</big><em>cleft</em>, <em>cright</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.between" title="Permalink to this definition">¶</a></dt>
696
<dd><div class="inherited-member container">
697
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.between" title="sqlalchemy.sql.operators.ColumnOperators.between"><tt class="xref py py-meth docutils literal"><span class="pre">between()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
698
<p>Produce a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.between" title="sqlalchemy.sql.expression.between"><tt class="xref py py-func docutils literal"><span class="pre">between()</span></tt></a> clause against
699
the parent object, given the lower and upper range.</p>
702
<dl class="attribute">
703
<dt id="sqlalchemy.schema.Column.bind">
704
<tt class="descname">bind</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.schema.Column.bind" title="Permalink to this definition">¶</a></dt>
708
<dt id="sqlalchemy.schema.Column.collate">
709
<tt class="descname">collate</tt><big>(</big><em>collation</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.collate" title="Permalink to this definition">¶</a></dt>
710
<dd><div class="inherited-member container">
711
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.collate" title="sqlalchemy.sql.operators.ColumnOperators.collate"><tt class="xref py py-meth docutils literal"><span class="pre">collate()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
712
<p>Produce a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.collate" title="sqlalchemy.sql.expression.collate"><tt class="xref py py-func docutils literal"><span class="pre">collate()</span></tt></a> clause against
713
the parent object, given the collation string.</p>
716
<dl class="attribute">
717
<dt id="sqlalchemy.schema.Column.comparator">
718
<tt class="descname">comparator</tt><a class="headerlink" href="#sqlalchemy.schema.Column.comparator" title="Permalink to this definition">¶</a></dt>
719
<dd><div class="inherited-member container">
720
<em>inherited from the</em> <tt class="xref py py-attr docutils literal"><span class="pre">comparator</span></tt> <em>attribute of</em> <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></div>
724
<dt id="sqlalchemy.schema.Column.compare">
725
<tt class="descname">compare</tt><big>(</big><em>other</em>, <em>use_proxies=False</em>, <em>equivalents=None</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.compare" title="Permalink to this definition">¶</a></dt>
726
<dd><div class="inherited-member container">
727
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement.compare" title="sqlalchemy.sql.expression.ColumnElement.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.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a></div>
728
<p>Compare this ColumnElement to another.</p>
729
<p>Special arguments understood:</p>
730
<table class="docutils field-list" frame="void" rules="none">
731
<col class="field-name" />
732
<col class="field-body" />
734
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
735
<li><strong>use_proxies</strong> – when True, consider two columns that
736
share a common base column as equivalent (i.e. shares_lineage())</li>
737
<li><strong>equivalents</strong> – a dictionary of columns as keys mapped to sets
738
of columns. If the given “other” column is present in this
739
dictionary, if any of the columns in the corresponding set() pass the
740
comparison test, the result is True. This is used to expand the
741
comparison to other columns that may be known to be equivalent to
742
this one via foreign key or other criterion.</li>
751
<dt id="sqlalchemy.schema.Column.compile">
752
<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.schema.Column.compile" title="Permalink to this definition">¶</a></dt>
753
<dd><div class="inherited-member container">
754
<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>
755
<p>Compile this SQL expression.</p>
756
<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.
757
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
758
string representation of the result. The
759
<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
760
dictionary of bind parameter names and values
761
using the <tt class="docutils literal"><span class="pre">params</span></tt> accessor.</p>
762
<table class="docutils field-list" frame="void" rules="none">
763
<col class="field-name" />
764
<col class="field-body" />
766
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
767
<li><strong>bind</strong> – 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
768
<tt class="docutils literal"><span class="pre">Compiled</span></tt> will be acquired. This argument takes precedence over
769
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>‘s bound engine, if any.</li>
770
<li><strong>column_keys</strong> – Used for INSERT and UPDATE statements, a list of
771
column names which should be present in the VALUES clause of the
772
compiled statement. If <tt class="docutils literal"><span class="pre">None</span></tt>, all columns from the target table
773
object are rendered.</li>
774
<li><strong>dialect</strong> – 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>
775
will be acquired. This argument takes precedence over the <cite>bind</cite>
776
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>‘s bound engine, if
778
<li><strong>inline</strong> – Used for INSERT statements, for a dialect which does
779
not support inline retrieval of newly generated primary key
780
columns, will force the expression used to create the new primary
781
key value to be rendered inline within the INSERT statement’s
782
VALUES clause. This typically refers to Sequence execution but may
783
also refer to any server-side default generation function
784
associated with a primary key <cite>Column</cite>.</li>
793
<dt id="sqlalchemy.schema.Column.concat">
794
<tt class="descname">concat</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.concat" title="Permalink to this definition">¶</a></dt>
795
<dd><div class="inherited-member container">
796
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.concat" title="sqlalchemy.sql.operators.ColumnOperators.concat"><tt class="xref py py-meth docutils literal"><span class="pre">concat()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
797
<p>Implement the ‘concat’ operator.</p>
798
<p>In a column context, produces the clause <tt class="docutils literal"><span class="pre">a</span> <span class="pre">||</span> <span class="pre">b</span></tt>,
799
or uses the <tt class="docutils literal"><span class="pre">concat()</span></tt> operator on MySQL.</p>
803
<dt id="sqlalchemy.schema.Column.contains">
804
<tt class="descname">contains</tt><big>(</big><em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.contains" title="Permalink to this definition">¶</a></dt>
805
<dd><div class="inherited-member container">
806
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.contains" title="sqlalchemy.sql.operators.ColumnOperators.contains"><tt class="xref py py-meth docutils literal"><span class="pre">contains()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
807
<p>Implement the ‘contains’ operator.</p>
808
<p>In a column context, produces the clause <tt class="docutils literal"><span class="pre">LIKE</span> <span class="pre">'%<other>%'</span></tt></p>
812
<dt id="sqlalchemy.schema.Column.copy">
813
<tt class="descname">copy</tt><big>(</big><em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.copy" title="Permalink to this definition">¶</a></dt>
814
<dd><p>Create a copy of this <tt class="docutils literal"><span class="pre">Column</span></tt>, unitialized.</p>
815
<p>This is used in <tt class="docutils literal"><span class="pre">Table.tometadata</span></tt>.</p>
818
<dl class="attribute">
819
<dt id="sqlalchemy.schema.Column.default">
820
<tt class="descname">default</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.schema.Column.default" title="Permalink to this definition">¶</a></dt>
824
<dt id="sqlalchemy.schema.Column.desc">
825
<tt class="descname">desc</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.desc" title="Permalink to this definition">¶</a></dt>
826
<dd><div class="inherited-member container">
827
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.desc" title="sqlalchemy.sql.operators.ColumnOperators.desc"><tt class="xref py py-meth docutils literal"><span class="pre">desc()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
828
<p>Produce a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.desc" title="sqlalchemy.sql.expression.desc"><tt class="xref py py-func docutils literal"><span class="pre">desc()</span></tt></a> clause against the
832
<dl class="attribute">
833
<dt id="sqlalchemy.schema.Column.description">
834
<tt class="descname">description</tt><a class="headerlink" href="#sqlalchemy.schema.Column.description" title="Permalink to this definition">¶</a></dt>
835
<dd><div class="inherited-member container">
836
<em>inherited from the</em> <tt class="xref py py-attr docutils literal"><span class="pre">description</span></tt> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnClause" title="sqlalchemy.sql.expression.ColumnClause"><tt class="xref py py-class docutils literal"><span class="pre">ColumnClause</span></tt></a></div>
839
<dl class="attribute">
840
<dt id="sqlalchemy.schema.Column.dispatch">
841
<tt class="descname">dispatch</tt><a class="headerlink" href="#sqlalchemy.schema.Column.dispatch" title="Permalink to this definition">¶</a></dt>
842
<dd><p>alias of <tt class="xref py py-class docutils literal"><span class="pre">DDLEventsDispatch</span></tt></p>
846
<dt id="sqlalchemy.schema.Column.distinct">
847
<tt class="descname">distinct</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.distinct" title="Permalink to this definition">¶</a></dt>
848
<dd><div class="inherited-member container">
849
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.distinct" title="sqlalchemy.sql.operators.ColumnOperators.distinct"><tt class="xref py py-meth docutils literal"><span class="pre">distinct()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
850
<p>Produce a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.distinct" title="sqlalchemy.sql.expression.distinct"><tt class="xref py py-func docutils literal"><span class="pre">distinct()</span></tt></a> clause against the
855
<dt id="sqlalchemy.schema.Column.endswith">
856
<tt class="descname">endswith</tt><big>(</big><em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.endswith" title="Permalink to this definition">¶</a></dt>
857
<dd><div class="inherited-member container">
858
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.endswith" title="sqlalchemy.sql.operators.ColumnOperators.endswith"><tt class="xref py py-meth docutils literal"><span class="pre">endswith()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
859
<p>Implement the ‘endswith’ operator.</p>
860
<p>In a column context, produces the clause <tt class="docutils literal"><span class="pre">LIKE</span> <span class="pre">'%<other>'</span></tt></p>
863
<dl class="attribute">
864
<dt id="sqlalchemy.schema.Column.expression">
865
<tt class="descname">expression</tt><a class="headerlink" href="#sqlalchemy.schema.Column.expression" title="Permalink to this definition">¶</a></dt>
866
<dd><div class="inherited-member container">
867
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement.expression" title="sqlalchemy.sql.expression.ColumnElement.expression"><tt class="xref py py-attr docutils literal"><span class="pre">expression</span></tt></a> <em>attribute of</em> <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></div>
868
<p>Return a column expression.</p>
869
<p>Part of the inspection interface; returns self.</p>
872
<dl class="attribute">
873
<dt id="sqlalchemy.schema.Column.foreign_keys">
874
<tt class="descname">foreign_keys</tt><em class="property"> = []</em><a class="headerlink" href="#sqlalchemy.schema.Column.foreign_keys" title="Permalink to this definition">¶</a></dt>
878
<dt id="sqlalchemy.schema.Column.get_children">
879
<tt class="descname">get_children</tt><big>(</big><em>schema_visitor=False</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.get_children" title="Permalink to this definition">¶</a></dt>
883
<dt id="sqlalchemy.schema.Column.ilike">
884
<tt class="descname">ilike</tt><big>(</big><em>other</em>, <em>escape=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.ilike" title="Permalink to this definition">¶</a></dt>
885
<dd><div class="inherited-member container">
886
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.ilike" title="sqlalchemy.sql.operators.ColumnOperators.ilike"><tt class="xref py py-meth docutils literal"><span class="pre">ilike()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
887
<p>Implement the <tt class="docutils literal"><span class="pre">ilike</span></tt> operator.</p>
888
<p>In a column context, produces the clause <tt class="docutils literal"><span class="pre">a</span> <span class="pre">ILIKE</span> <span class="pre">other</span></tt>.</p>
890
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">sometable</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">sometable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">column</span><span class="o">.</span><span class="n">ilike</span><span class="p">(</span><span class="s">"</span><span class="si">%f</span><span class="s">oobar%"</span><span class="p">))</span></pre></div>
892
<table class="docutils field-list" frame="void" rules="none">
893
<col class="field-name" />
894
<col class="field-body" />
896
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
897
<li><strong>other</strong> – expression to be compared</li>
898
<li><strong>escape</strong> – <p>optional escape character, renders the <tt class="docutils literal"><span class="pre">ESCAPE</span></tt>
900
<div class="highlight-python"><div class="highlight"><pre><span class="n">somecolumn</span><span class="o">.</span><span class="n">ilike</span><span class="p">(</span><span class="s">"foo/%bar"</span><span class="p">,</span> <span class="n">escape</span><span class="o">=</span><span class="s">"/"</span><span class="p">)</span></pre></div>
908
<div class="admonition seealso">
909
<p class="first admonition-title">See also</p>
910
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.like" title="sqlalchemy.sql.operators.ColumnOperators.like"><tt class="xref py py-meth docutils literal"><span class="pre">ColumnOperators.like()</span></tt></a></p>
915
<dt id="sqlalchemy.schema.Column.in_">
916
<tt class="descname">in_</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.in_" title="Permalink to this definition">¶</a></dt>
917
<dd><div class="inherited-member container">
918
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.in_" title="sqlalchemy.sql.operators.ColumnOperators.in_"><tt class="xref py py-meth docutils literal"><span class="pre">in_()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
919
<p>Implement the <tt class="docutils literal"><span class="pre">in</span></tt> operator.</p>
920
<p>In a column context, produces the clause <tt class="docutils literal"><span class="pre">a</span> <span class="pre">IN</span> <span class="pre">other</span></tt>.
921
“other” may be a tuple/list of column expressions,
922
or a <a class="reference internal" href="selectable.html#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.</p>
925
<dl class="attribute">
926
<dt id="sqlalchemy.schema.Column.info">
927
<tt class="descname">info</tt><a class="headerlink" href="#sqlalchemy.schema.Column.info" title="Permalink to this definition">¶</a></dt>
928
<dd><div class="inherited-member container">
929
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.schema.SchemaItem.info" title="sqlalchemy.schema.SchemaItem.info"><tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
930
<p>Info dictionary associated with the object, allowing user-defined
931
data to be associated with this <a class="reference internal" href="#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a>.</p>
932
<p>The dictionary is automatically generated when first accessed.
933
It can also be specified in the constructor of some objects,
934
such as <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> and <a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</p>
938
<dt id="sqlalchemy.schema.Column.is_">
939
<tt class="descname">is_</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.is_" title="Permalink to this definition">¶</a></dt>
940
<dd><div class="inherited-member container">
941
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.is_" title="sqlalchemy.sql.operators.ColumnOperators.is_"><tt class="xref py py-meth docutils literal"><span class="pre">is_()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
942
<p>Implement the <tt class="docutils literal"><span class="pre">IS</span></tt> operator.</p>
943
<p>Normally, <tt class="docutils literal"><span class="pre">IS</span></tt> is generated automatically when comparing to a
944
value of <tt class="docutils literal"><span class="pre">None</span></tt>, which resolves to <tt class="docutils literal"><span class="pre">NULL</span></tt>. However, explicit
945
usage of <tt class="docutils literal"><span class="pre">IS</span></tt> may be desirable if comparing to boolean values
946
on certain platforms.</p>
947
<div class="versionadded">
948
<p><span>New in version 0.7.9.</span></p>
950
<div class="admonition seealso">
951
<p class="first admonition-title">See also</p>
952
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.isnot" title="sqlalchemy.sql.operators.ColumnOperators.isnot"><tt class="xref py py-meth docutils literal"><span class="pre">ColumnOperators.isnot()</span></tt></a></p>
956
<dl class="attribute">
957
<dt id="sqlalchemy.schema.Column.is_clause_element">
958
<tt class="descname">is_clause_element</tt><em class="property"> = True</em><a class="headerlink" href="#sqlalchemy.schema.Column.is_clause_element" title="Permalink to this definition">¶</a></dt>
961
<dl class="attribute">
962
<dt id="sqlalchemy.schema.Column.is_selectable">
963
<tt class="descname">is_selectable</tt><em class="property"> = False</em><a class="headerlink" href="#sqlalchemy.schema.Column.is_selectable" title="Permalink to this definition">¶</a></dt>
967
<dt id="sqlalchemy.schema.Column.isnot">
968
<tt class="descname">isnot</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.isnot" title="Permalink to this definition">¶</a></dt>
969
<dd><div class="inherited-member container">
970
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.isnot" title="sqlalchemy.sql.operators.ColumnOperators.isnot"><tt class="xref py py-meth docutils literal"><span class="pre">isnot()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
971
<p>Implement the <tt class="docutils literal"><span class="pre">IS</span> <span class="pre">NOT</span></tt> operator.</p>
972
<p>Normally, <tt class="docutils literal"><span class="pre">IS</span> <span class="pre">NOT</span></tt> is generated automatically when comparing to a
973
value of <tt class="docutils literal"><span class="pre">None</span></tt>, which resolves to <tt class="docutils literal"><span class="pre">NULL</span></tt>. However, explicit
974
usage of <tt class="docutils literal"><span class="pre">IS</span> <span class="pre">NOT</span></tt> may be desirable if comparing to boolean values
975
on certain platforms.</p>
976
<div class="versionadded">
977
<p><span>New in version 0.7.9.</span></p>
979
<div class="admonition seealso">
980
<p class="first admonition-title">See also</p>
981
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.is_" title="sqlalchemy.sql.operators.ColumnOperators.is_"><tt class="xref py py-meth docutils literal"><span class="pre">ColumnOperators.is_()</span></tt></a></p>
986
<dt id="sqlalchemy.schema.Column.label">
987
<tt class="descname">label</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.label" title="Permalink to this definition">¶</a></dt>
988
<dd><div class="inherited-member container">
989
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement.label" title="sqlalchemy.sql.expression.ColumnElement.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="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></div>
990
<p>Produce a column label, i.e. <tt class="docutils literal"><span class="pre"><columnname></span> <span class="pre">AS</span> <span class="pre"><name></span></tt>.</p>
991
<p>This is a shortcut to the <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.label" title="sqlalchemy.sql.expression.label"><tt class="xref py py-func docutils literal"><span class="pre">label()</span></tt></a> function.</p>
992
<p>if ‘name’ is None, an anonymous label name will be generated.</p>
996
<dt id="sqlalchemy.schema.Column.like">
997
<tt class="descname">like</tt><big>(</big><em>other</em>, <em>escape=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.like" title="Permalink to this definition">¶</a></dt>
998
<dd><div class="inherited-member container">
999
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.like" title="sqlalchemy.sql.operators.ColumnOperators.like"><tt class="xref py py-meth docutils literal"><span class="pre">like()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
1000
<p>Implement the <tt class="docutils literal"><span class="pre">like</span></tt> operator.</p>
1001
<p>In a column context, produces the clause <tt class="docutils literal"><span class="pre">a</span> <span class="pre">LIKE</span> <span class="pre">other</span></tt>.</p>
1003
<div class="highlight-python"><div class="highlight"><pre><span class="n">select</span><span class="p">([</span><span class="n">sometable</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">sometable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">column</span><span class="o">.</span><span class="n">like</span><span class="p">(</span><span class="s">"</span><span class="si">%f</span><span class="s">oobar%"</span><span class="p">))</span></pre></div>
1005
<table class="docutils field-list" frame="void" rules="none">
1006
<col class="field-name" />
1007
<col class="field-body" />
1008
<tbody valign="top">
1009
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1010
<li><strong>other</strong> – expression to be compared</li>
1011
<li><strong>escape</strong> – <p>optional escape character, renders the <tt class="docutils literal"><span class="pre">ESCAPE</span></tt>
1013
<div class="highlight-python"><div class="highlight"><pre><span class="n">somecolumn</span><span class="o">.</span><span class="n">like</span><span class="p">(</span><span class="s">"foo/%bar"</span><span class="p">,</span> <span class="n">escape</span><span class="o">=</span><span class="s">"/"</span><span class="p">)</span></pre></div>
1021
<div class="admonition seealso">
1022
<p class="first admonition-title">See also</p>
1023
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.ilike" title="sqlalchemy.sql.operators.ColumnOperators.ilike"><tt class="xref py py-meth docutils literal"><span class="pre">ColumnOperators.ilike()</span></tt></a></p>
1028
<dt id="sqlalchemy.schema.Column.match">
1029
<tt class="descname">match</tt><big>(</big><em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.match" title="Permalink to this definition">¶</a></dt>
1030
<dd><div class="inherited-member container">
1031
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.match" title="sqlalchemy.sql.operators.ColumnOperators.match"><tt class="xref py py-meth docutils literal"><span class="pre">match()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
1032
<p>Implements the ‘match’ operator.</p>
1033
<p>In a column context, this produces a MATCH clause, i.e.
1034
<tt class="docutils literal"><span class="pre">MATCH</span> <span class="pre">'<other>'</span></tt>. The allowed contents of <tt class="docutils literal"><span class="pre">other</span></tt>
1035
are database backend specific.</p>
1039
<dt id="sqlalchemy.schema.Column.notilike">
1040
<tt class="descname">notilike</tt><big>(</big><em>other</em>, <em>escape=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.notilike" title="Permalink to this definition">¶</a></dt>
1041
<dd><div class="inherited-member container">
1042
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.notilike" title="sqlalchemy.sql.operators.ColumnOperators.notilike"><tt class="xref py py-meth docutils literal"><span class="pre">notilike()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
1043
<p>implement the <tt class="docutils literal"><span class="pre">NOT</span> <span class="pre">ILIKE</span></tt> operator.</p>
1044
<p>This is equivalent to using negation with
1045
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.ilike" title="sqlalchemy.sql.operators.ColumnOperators.ilike"><tt class="xref py py-meth docutils literal"><span class="pre">ColumnOperators.ilike()</span></tt></a>, i.e. <tt class="docutils literal"><span class="pre">~x.ilike(y)</span></tt>.</p>
1046
<div class="versionadded">
1047
<p><span>New in version 0.8.</span></p>
1049
<div class="admonition seealso">
1050
<p class="first admonition-title">See also</p>
1051
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.ilike" title="sqlalchemy.sql.operators.ColumnOperators.ilike"><tt class="xref py py-meth docutils literal"><span class="pre">ColumnOperators.ilike()</span></tt></a></p>
1056
<dt id="sqlalchemy.schema.Column.notin_">
1057
<tt class="descname">notin_</tt><big>(</big><em>other</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.notin_" title="Permalink to this definition">¶</a></dt>
1058
<dd><div class="inherited-member container">
1059
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.notin_" title="sqlalchemy.sql.operators.ColumnOperators.notin_"><tt class="xref py py-meth docutils literal"><span class="pre">notin_()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
1060
<p>implement the <tt class="docutils literal"><span class="pre">NOT</span> <span class="pre">IN</span></tt> operator.</p>
1061
<p>This is equivalent to using negation with <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.in_" title="sqlalchemy.sql.operators.ColumnOperators.in_"><tt class="xref py py-meth docutils literal"><span class="pre">ColumnOperators.in_()</span></tt></a>,
1062
i.e. <tt class="docutils literal"><span class="pre">~x.in_(y)</span></tt>.</p>
1063
<div class="versionadded">
1064
<p><span>New in version 0.8.</span></p>
1066
<div class="admonition seealso">
1067
<p class="first admonition-title">See also</p>
1068
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.in_" title="sqlalchemy.sql.operators.ColumnOperators.in_"><tt class="xref py py-meth docutils literal"><span class="pre">ColumnOperators.in_()</span></tt></a></p>
1073
<dt id="sqlalchemy.schema.Column.notlike">
1074
<tt class="descname">notlike</tt><big>(</big><em>other</em>, <em>escape=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.notlike" title="Permalink to this definition">¶</a></dt>
1075
<dd><div class="inherited-member container">
1076
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.notlike" title="sqlalchemy.sql.operators.ColumnOperators.notlike"><tt class="xref py py-meth docutils literal"><span class="pre">notlike()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
1077
<p>implement the <tt class="docutils literal"><span class="pre">NOT</span> <span class="pre">LIKE</span></tt> operator.</p>
1078
<p>This is equivalent to using negation with
1079
<a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.like" title="sqlalchemy.sql.operators.ColumnOperators.like"><tt class="xref py py-meth docutils literal"><span class="pre">ColumnOperators.like()</span></tt></a>, i.e. <tt class="docutils literal"><span class="pre">~x.like(y)</span></tt>.</p>
1080
<div class="versionadded">
1081
<p><span>New in version 0.8.</span></p>
1083
<div class="admonition seealso">
1084
<p class="first admonition-title">See also</p>
1085
<p class="last"><a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.like" title="sqlalchemy.sql.operators.ColumnOperators.like"><tt class="xref py py-meth docutils literal"><span class="pre">ColumnOperators.like()</span></tt></a></p>
1090
<dt id="sqlalchemy.schema.Column.nullsfirst">
1091
<tt class="descname">nullsfirst</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.nullsfirst" title="Permalink to this definition">¶</a></dt>
1092
<dd><div class="inherited-member container">
1093
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.nullsfirst" title="sqlalchemy.sql.operators.ColumnOperators.nullsfirst"><tt class="xref py py-meth docutils literal"><span class="pre">nullsfirst()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
1094
<p>Produce a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.nullsfirst" title="sqlalchemy.sql.expression.nullsfirst"><tt class="xref py py-func docutils literal"><span class="pre">nullsfirst()</span></tt></a> clause against the
1099
<dt id="sqlalchemy.schema.Column.nullslast">
1100
<tt class="descname">nullslast</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.nullslast" title="Permalink to this definition">¶</a></dt>
1101
<dd><div class="inherited-member container">
1102
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.nullslast" title="sqlalchemy.sql.operators.ColumnOperators.nullslast"><tt class="xref py py-meth docutils literal"><span class="pre">nullslast()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
1103
<p>Produce a <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.nullslast" title="sqlalchemy.sql.expression.nullslast"><tt class="xref py py-func docutils literal"><span class="pre">nullslast()</span></tt></a> clause against the
1107
<dl class="attribute">
1108
<dt id="sqlalchemy.schema.Column.onupdate">
1109
<tt class="descname">onupdate</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.schema.Column.onupdate" title="Permalink to this definition">¶</a></dt>
1113
<dt id="sqlalchemy.schema.Column.op">
1114
<tt class="descname">op</tt><big>(</big><em>opstring</em>, <em>precedence=0</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.op" title="Permalink to this definition">¶</a></dt>
1115
<dd><div class="inherited-member container">
1116
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.Operators.op" title="sqlalchemy.sql.operators.Operators.op"><tt class="xref py py-meth docutils literal"><span class="pre">op()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.Operators" title="sqlalchemy.sql.operators.Operators"><tt class="xref py py-class docutils literal"><span class="pre">Operators</span></tt></a></div>
1117
<p>produce a generic operator function.</p>
1119
<div class="highlight-python"><div class="highlight"><pre><span class="n">somecolumn</span><span class="o">.</span><span class="n">op</span><span class="p">(</span><span class="s">"*"</span><span class="p">)(</span><span class="mi">5</span><span class="p">)</span></pre></div>
1122
<div class="highlight-python"><div class="highlight"><pre><span class="n">somecolumn</span> <span class="o">*</span> <span class="mi">5</span></pre></div>
1124
<p>This function can also be used to make bitwise operators explicit. For
1126
<div class="highlight-python"><div class="highlight"><pre><span class="n">somecolumn</span><span class="o">.</span><span class="n">op</span><span class="p">(</span><span class="s">'&'</span><span class="p">)(</span><span class="mh">0xff</span><span class="p">)</span></pre></div>
1128
<p>is a bitwise AND of the value in <tt class="docutils literal"><span class="pre">somecolumn</span></tt>.</p>
1129
<table class="docutils field-list" frame="void" rules="none">
1130
<col class="field-name" />
1131
<col class="field-body" />
1132
<tbody valign="top">
1133
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1134
<li><strong>operator</strong> – a string which will be output as the infix operator
1135
between this element and the expression passed to the
1136
generated function.</li>
1137
<li><strong>precedence</strong> – <p>precedence to apply to the operator, when
1138
parenthesizing expressions. A lower number will cause the expression
1139
to be parenthesized when applied against another operator with
1140
higher precedence. The default value of <tt class="docutils literal"><span class="pre">0</span></tt> is lower than all
1141
operators except for the comma (<tt class="docutils literal"><span class="pre">,</span></tt>) and <tt class="docutils literal"><span class="pre">AS</span></tt> operators.
1142
A value of 100 will be higher or equal to all operators, and -100
1143
will be lower than or equal to all operators.</p>
1144
<div class="versionadded">
1145
<p><span>New in version 0.8: </span>- added the ‘precedence’ argument.</p>
1153
<div class="admonition seealso">
1154
<p class="first admonition-title">See also</p>
1155
<p class="last"><a class="reference internal" href="types.html#types-operators"><em>Redefining and Creating New Operators</em></a></p>
1160
<dt id="sqlalchemy.schema.Column.operate">
1161
<tt class="descname">operate</tt><big>(</big><em>op</em>, <em>*other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.operate" title="Permalink to this definition">¶</a></dt>
1162
<dd><div class="inherited-member container">
1163
<em>inherited from the</em> <tt class="xref py py-meth docutils literal"><span class="pre">operate()</span></tt> <em>method of</em> <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></div>
1167
<dt id="sqlalchemy.schema.Column.params">
1168
<tt class="descname">params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.params" title="Permalink to this definition">¶</a></dt>
1169
<dd><div class="inherited-member container">
1170
<em>inherited from the</em> <tt class="xref py py-meth docutils literal"><span class="pre">params()</span></tt> <em>method of</em> <tt class="xref py py-class docutils literal"><span class="pre">Immutable</span></tt></div>
1173
<dl class="attribute">
1174
<dt id="sqlalchemy.schema.Column.primary_key">
1175
<tt class="descname">primary_key</tt><em class="property"> = False</em><a class="headerlink" href="#sqlalchemy.schema.Column.primary_key" title="Permalink to this definition">¶</a></dt>
1178
<dl class="attribute">
1179
<dt id="sqlalchemy.schema.Column.proxy_set">
1180
<tt class="descname">proxy_set</tt><a class="headerlink" href="#sqlalchemy.schema.Column.proxy_set" title="Permalink to this definition">¶</a></dt>
1181
<dd><div class="inherited-member container">
1182
<em>inherited from the</em> <tt class="xref py py-attr docutils literal"><span class="pre">proxy_set</span></tt> <em>attribute of</em> <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></div>
1185
<dl class="attribute">
1186
<dt id="sqlalchemy.schema.Column.quote">
1187
<tt class="descname">quote</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.schema.Column.quote" title="Permalink to this definition">¶</a></dt>
1191
<dt id="sqlalchemy.schema.Column.references">
1192
<tt class="descname">references</tt><big>(</big><em>column</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.references" title="Permalink to this definition">¶</a></dt>
1193
<dd><p>Return True if this Column references the given column via foreign
1198
<dt id="sqlalchemy.schema.Column.reverse_operate">
1199
<tt class="descname">reverse_operate</tt><big>(</big><em>op</em>, <em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.reverse_operate" title="Permalink to this definition">¶</a></dt>
1200
<dd><div class="inherited-member container">
1201
<em>inherited from the</em> <tt class="xref py py-meth docutils literal"><span class="pre">reverse_operate()</span></tt> <em>method of</em> <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></div>
1205
<dt id="sqlalchemy.schema.Column.self_group">
1206
<tt class="descname">self_group</tt><big>(</big><em>against=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.self_group" title="Permalink to this definition">¶</a></dt>
1207
<dd><div class="inherited-member container">
1208
<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>
1209
<p>Apply a ‘grouping’ 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>
1210
<p>This method is overridden by subclasses to return a
1211
“grouping” construct, i.e. parenthesis. In particular
1212
it’s used by “binary” expressions to provide a grouping
1213
around themselves when placed into a larger expression,
1214
as well as by <a class="reference internal" href="selectable.html#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
1215
the FROM clause of another <a class="reference internal" href="selectable.html#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
1216
subqueries should be normally created using the
1217
<tt class="xref py py-func docutils literal"><span class="pre">Select.alias()</span></tt> method, as many platforms require
1218
nested SELECT statements to be named).</p>
1219
<p>As expressions are composed together, the application of
1220
<a class="reference internal" href="#sqlalchemy.schema.Column.self_group" title="sqlalchemy.schema.Column.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
1221
need to use this method directly. Note that SQLAlchemy’s
1222
clause constructs take operator precedence into account -
1223
so parenthesis might not be needed, for example, in
1224
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
1226
<p>The base <a class="reference internal" href="#sqlalchemy.schema.Column.self_group" title="sqlalchemy.schema.Column.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>
1227
just returns self.</p>
1230
<dl class="attribute">
1231
<dt id="sqlalchemy.schema.Column.server_default">
1232
<tt class="descname">server_default</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.schema.Column.server_default" title="Permalink to this definition">¶</a></dt>
1235
<dl class="attribute">
1236
<dt id="sqlalchemy.schema.Column.server_onupdate">
1237
<tt class="descname">server_onupdate</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.schema.Column.server_onupdate" title="Permalink to this definition">¶</a></dt>
1241
<dt id="sqlalchemy.schema.Column.shares_lineage">
1242
<tt class="descname">shares_lineage</tt><big>(</big><em>othercolumn</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.shares_lineage" title="Permalink to this definition">¶</a></dt>
1243
<dd><div class="inherited-member container">
1244
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnElement.shares_lineage" title="sqlalchemy.sql.expression.ColumnElement.shares_lineage"><tt class="xref py py-meth docutils literal"><span class="pre">shares_lineage()</span></tt></a> <em>method of</em> <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></div>
1245
<p>Return True if 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>
1246
has a common ancestor to this <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>
1250
<dt id="sqlalchemy.schema.Column.startswith">
1251
<tt class="descname">startswith</tt><big>(</big><em>other</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.startswith" title="Permalink to this definition">¶</a></dt>
1252
<dd><div class="inherited-member container">
1253
<em>inherited from the</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.startswith" title="sqlalchemy.sql.operators.ColumnOperators.startswith"><tt class="xref py py-meth docutils literal"><span class="pre">startswith()</span></tt></a> <em>method of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.operators.ColumnOperators" title="sqlalchemy.sql.operators.ColumnOperators"><tt class="xref py py-class docutils literal"><span class="pre">ColumnOperators</span></tt></a></div>
1254
<p>Implement the <tt class="docutils literal"><span class="pre">startwith</span></tt> operator.</p>
1255
<p>In a column context, produces the clause <tt class="docutils literal"><span class="pre">LIKE</span> <span class="pre">'<other>%'</span></tt></p>
1258
<dl class="attribute">
1259
<dt id="sqlalchemy.schema.Column.supports_execution">
1260
<tt class="descname">supports_execution</tt><em class="property"> = False</em><a class="headerlink" href="#sqlalchemy.schema.Column.supports_execution" title="Permalink to this definition">¶</a></dt>
1263
<dl class="attribute">
1264
<dt id="sqlalchemy.schema.Column.table">
1265
<tt class="descname">table</tt><a class="headerlink" href="#sqlalchemy.schema.Column.table" title="Permalink to this definition">¶</a></dt>
1266
<dd><div class="inherited-member container">
1267
<em>inherited from the</em> <tt class="xref py py-attr docutils literal"><span class="pre">table</span></tt> <em>attribute of</em> <a class="reference internal" href="sqlelement.html#sqlalchemy.sql.expression.ColumnClause" title="sqlalchemy.sql.expression.ColumnClause"><tt class="xref py py-class docutils literal"><span class="pre">ColumnClause</span></tt></a></div>
1270
<dl class="attribute">
1271
<dt id="sqlalchemy.schema.Column.timetuple">
1272
<tt class="descname">timetuple</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.schema.Column.timetuple" title="Permalink to this definition">¶</a></dt>
1275
<dl class="attribute">
1276
<dt id="sqlalchemy.schema.Column.type">
1277
<tt class="descname">type</tt><a class="headerlink" href="#sqlalchemy.schema.Column.type" title="Permalink to this definition">¶</a></dt>
1278
<dd><div class="inherited-member container">
1279
<em>inherited from the</em> <tt class="xref py py-attr docutils literal"><span class="pre">type</span></tt> <em>attribute of</em> <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></div>
1283
<dt id="sqlalchemy.schema.Column.unique_params">
1284
<tt class="descname">unique_params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Column.unique_params" title="Permalink to this definition">¶</a></dt>
1285
<dd><div class="inherited-member container">
1286
<em>inherited from the</em> <tt class="xref py py-meth docutils literal"><span class="pre">unique_params()</span></tt> <em>method of</em> <tt class="xref py py-class docutils literal"><span class="pre">Immutable</span></tt></div>
1292
<dt id="sqlalchemy.schema.MetaData">
1293
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">MetaData</tt><big>(</big><em>bind=None</em>, <em>reflect=False</em>, <em>schema=None</em>, <em>quote_schema=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.MetaData" title="Permalink to this definition">¶</a></dt>
1294
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.SchemaItem</span></tt></a></p>
1295
<p>A collection of <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects and their associated schema
1297
<p>Holds a collection of <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects as well as
1298
an optional binding to an <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
1299
<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>. If bound, the <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects
1300
in the collection and their columns may participate in implicit SQL
1302
<p>The <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects themselves are stored in the
1303
<tt class="docutils literal"><span class="pre">metadata.tables</span></tt> dictionary.</p>
1304
<p>The <tt class="docutils literal"><span class="pre">bind</span></tt> property may be assigned to dynamically. A common pattern is
1305
to start unbound and then bind later when an engine is available:</p>
1306
<div class="highlight-python"><div class="highlight"><pre><span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
1307
<span class="c"># define tables</span>
1308
<span class="n">Table</span><span class="p">(</span><span class="s">'mytable'</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span> <span class="o">...</span><span class="p">)</span>
1309
<span class="c"># connect to an engine later, perhaps after loading a URL from a</span>
1310
<span class="c"># configuration file</span>
1311
<span class="n">metadata</span><span class="o">.</span><span class="n">bind</span> <span class="o">=</span> <span class="n">an_engine</span></pre></div>
1313
<p>MetaData is a thread-safe object after tables have been explicitly defined
1314
or loaded via reflection.</p>
1315
<div class="admonition seealso">
1316
<p class="first admonition-title">See also</p>
1317
<p class="last"><a class="reference internal" href="#metadata-describing"><em>Describing Databases with MetaData</em></a> - Introduction to database metadata</p>
1320
<dt id="sqlalchemy.schema.MetaData.__init__">
1321
<tt class="descname">__init__</tt><big>(</big><em>bind=None</em>, <em>reflect=False</em>, <em>schema=None</em>, <em>quote_schema=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.MetaData.__init__" title="Permalink to this definition">¶</a></dt>
1322
<dd><p>Create a new MetaData object.</p>
1323
<table class="docutils field-list" frame="void" rules="none">
1324
<col class="field-name" />
1325
<col class="field-body" />
1326
<tbody valign="top">
1327
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1328
<li><strong>bind</strong> – An Engine or Connection to bind to. May also be a string or URL
1329
instance, these are passed to create_engine() and this MetaData will
1330
be bound to the resulting engine.</li>
1331
<li><strong>reflect</strong> – <p>Optional, automatically load all tables from the bound database.
1332
Defaults to False. <tt class="docutils literal"><span class="pre">bind</span></tt> is required when this option is set.</p>
1333
<div class="deprecated">
1334
<p><span>Deprecated since version 0.8: </span>Please use the <a class="reference internal" href="#sqlalchemy.schema.MetaData.reflect" title="sqlalchemy.schema.MetaData.reflect"><tt class="xref py py-meth docutils literal"><span class="pre">MetaData.reflect()</span></tt></a> method.</p>
1337
<li><strong>schema</strong> – The default schema to use for the <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>,
1338
<a class="reference internal" href="defaults.html#sqlalchemy.schema.Sequence" title="sqlalchemy.schema.Sequence"><tt class="xref py py-class docutils literal"><span class="pre">Sequence</span></tt></a>, and other objects associated with this
1339
<a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a>. Defaults to <tt class="docutils literal"><span class="pre">None</span></tt>.</li>
1340
<li><strong>quote_schema</strong> – Sets the <tt class="docutils literal"><span class="pre">quote_schema</span></tt> flag for those <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>,
1341
<a class="reference internal" href="defaults.html#sqlalchemy.schema.Sequence" title="sqlalchemy.schema.Sequence"><tt class="xref py py-class docutils literal"><span class="pre">Sequence</span></tt></a>, and other objects which make usage of the
1342
local <tt class="docutils literal"><span class="pre">schema</span></tt> name.</li>
1348
<div class="versionadded">
1349
<p><span>New in version 0.7.4: </span><tt class="docutils literal"><span class="pre">schema</span></tt> and <tt class="docutils literal"><span class="pre">quote_schema</span></tt> parameters.</p>
1354
<dt id="sqlalchemy.schema.MetaData.append_ddl_listener">
1355
<tt class="descname">append_ddl_listener</tt><big>(</big><em>event_name</em>, <em>listener</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.MetaData.append_ddl_listener" title="Permalink to this definition">¶</a></dt>
1356
<dd><p>Append a DDL event listener to this <tt class="docutils literal"><span class="pre">MetaData</span></tt>.</p>
1357
<p>Deprecated. See <a class="reference internal" href="events.html#sqlalchemy.events.DDLEvents" title="sqlalchemy.events.DDLEvents"><tt class="xref py py-class docutils literal"><span class="pre">DDLEvents</span></tt></a>.</p>
1360
<dl class="attribute">
1361
<dt id="sqlalchemy.schema.MetaData.bind">
1362
<tt class="descname">bind</tt><a class="headerlink" href="#sqlalchemy.schema.MetaData.bind" title="Permalink to this definition">¶</a></dt>
1363
<dd><p>An <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 which this
1364
<a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> is bound.</p>
1365
<p>Typically, a <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> is assigned to this attribute
1366
so that “implicit execution” may be used, or alternatively
1367
as a means of providing engine binding information to an
1368
ORM <a class="reference internal" href="../orm/session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> object:</p>
1369
<div class="highlight-python"><div class="highlight"><pre><span class="n">engine</span> <span class="o">=</span> <span class="n">create_engine</span><span class="p">(</span><span class="s">"someurl://"</span><span class="p">)</span>
1370
<span class="n">metadata</span><span class="o">.</span><span class="n">bind</span> <span class="o">=</span> <span class="n">engine</span></pre></div>
1372
<div class="admonition seealso">
1373
<p class="first admonition-title">See also</p>
1374
<p class="last"><a class="reference internal" href="connections.html#dbengine-implicit"><em>Connectionless Execution, Implicit Execution</em></a> - background on “bound metadata”</p>
1379
<dt id="sqlalchemy.schema.MetaData.clear">
1380
<tt class="descname">clear</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.schema.MetaData.clear" title="Permalink to this definition">¶</a></dt>
1381
<dd><p>Clear all Table objects from this MetaData.</p>
1385
<dt id="sqlalchemy.schema.MetaData.create_all">
1386
<tt class="descname">create_all</tt><big>(</big><em>bind=None</em>, <em>tables=None</em>, <em>checkfirst=True</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.MetaData.create_all" title="Permalink to this definition">¶</a></dt>
1387
<dd><p>Create all tables stored in this metadata.</p>
1388
<p>Conditional by default, will not attempt to recreate tables already
1389
present in the target database.</p>
1390
<table class="docutils field-list" frame="void" rules="none">
1391
<col class="field-name" />
1392
<col class="field-body" />
1393
<tbody valign="top">
1394
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1395
<li><strong>bind</strong> – A <a class="reference internal" href="connections.html#sqlalchemy.engine.Connectable" title="sqlalchemy.engine.Connectable"><tt class="xref py py-class docutils literal"><span class="pre">Connectable</span></tt></a> used to access the
1396
database; if None, uses the existing bind on this <tt class="docutils literal"><span class="pre">MetaData</span></tt>, if
1398
<li><strong>tables</strong> – Optional list of <tt class="docutils literal"><span class="pre">Table</span></tt> objects, which is a subset of the total
1399
tables in the <tt class="docutils literal"><span class="pre">MetaData</span></tt> (others are ignored).</li>
1400
<li><strong>checkfirst</strong> – Defaults to True, don’t issue CREATEs for tables already present
1401
in the target database.</li>
1410
<dt id="sqlalchemy.schema.MetaData.drop_all">
1411
<tt class="descname">drop_all</tt><big>(</big><em>bind=None</em>, <em>tables=None</em>, <em>checkfirst=True</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.MetaData.drop_all" title="Permalink to this definition">¶</a></dt>
1412
<dd><p>Drop all tables stored in this metadata.</p>
1413
<p>Conditional by default, will not attempt to drop tables not present in
1414
the target database.</p>
1415
<table class="docutils field-list" frame="void" rules="none">
1416
<col class="field-name" />
1417
<col class="field-body" />
1418
<tbody valign="top">
1419
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1420
<li><strong>bind</strong> – A <a class="reference internal" href="connections.html#sqlalchemy.engine.Connectable" title="sqlalchemy.engine.Connectable"><tt class="xref py py-class docutils literal"><span class="pre">Connectable</span></tt></a> used to access the
1421
database; if None, uses the existing bind on this <tt class="docutils literal"><span class="pre">MetaData</span></tt>, if
1423
<li><strong>tables</strong> – Optional list of <tt class="docutils literal"><span class="pre">Table</span></tt> objects, which is a subset of the
1424
total tables in the <tt class="docutils literal"><span class="pre">MetaData</span></tt> (others are ignored).</li>
1425
<li><strong>checkfirst</strong> – Defaults to True, only issue DROPs for tables confirmed to be
1426
present in the target database.</li>
1435
<dt id="sqlalchemy.schema.MetaData.is_bound">
1436
<tt class="descname">is_bound</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.schema.MetaData.is_bound" title="Permalink to this definition">¶</a></dt>
1437
<dd><p>True if this MetaData is bound to an Engine or Connection.</p>
1441
<dt id="sqlalchemy.schema.MetaData.reflect">
1442
<tt class="descname">reflect</tt><big>(</big><em>bind=None</em>, <em>schema=None</em>, <em>views=False</em>, <em>only=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.MetaData.reflect" title="Permalink to this definition">¶</a></dt>
1443
<dd><p>Load all available table definitions from the database.</p>
1444
<p>Automatically creates <tt class="docutils literal"><span class="pre">Table</span></tt> entries in this <tt class="docutils literal"><span class="pre">MetaData</span></tt> for any
1445
table available in the database but not yet present in the
1446
<tt class="docutils literal"><span class="pre">MetaData</span></tt>. May be called multiple times to pick up tables recently
1447
added to the database, however no special action is taken if a table
1448
in this <tt class="docutils literal"><span class="pre">MetaData</span></tt> no longer exists in the database.</p>
1449
<table class="docutils field-list" frame="void" rules="none">
1450
<col class="field-name" />
1451
<col class="field-body" />
1452
<tbody valign="top">
1453
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1454
<li><strong>bind</strong> – A <a class="reference internal" href="connections.html#sqlalchemy.engine.Connectable" title="sqlalchemy.engine.Connectable"><tt class="xref py py-class docutils literal"><span class="pre">Connectable</span></tt></a> used to access the database; if None, uses
1455
the existing bind on this <tt class="docutils literal"><span class="pre">MetaData</span></tt>, if any.</li>
1456
<li><strong>schema</strong> – Optional, query and reflect tables from an alterate schema.
1457
If None, the schema associated with this <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a>
1458
is used, if any.</li>
1459
<li><strong>views</strong> – If True, also reflect views.</li>
1460
<li><strong>only</strong> – <p>Optional. Load only a sub-set of available named tables. May be
1461
specified as a sequence of names or a callable.</p>
1462
<p>If a sequence of names is provided, only those tables will be
1463
reflected. An error is raised if a table is requested but not
1464
available. Named tables already present in this <tt class="docutils literal"><span class="pre">MetaData</span></tt> are
1466
<p>If a callable is provided, it will be used as a boolean predicate to
1467
filter the list of potential table names. The callable is called
1468
with a table name and this <tt class="docutils literal"><span class="pre">MetaData</span></tt> instance as positional
1469
arguments and should return a true value for any table to reflect.</p>
1479
<dt id="sqlalchemy.schema.MetaData.remove">
1480
<tt class="descname">remove</tt><big>(</big><em>table</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.MetaData.remove" title="Permalink to this definition">¶</a></dt>
1481
<dd><p>Remove the given Table object from this MetaData.</p>
1484
<dl class="attribute">
1485
<dt id="sqlalchemy.schema.MetaData.sorted_tables">
1486
<tt class="descname">sorted_tables</tt><a class="headerlink" href="#sqlalchemy.schema.MetaData.sorted_tables" title="Permalink to this definition">¶</a></dt>
1487
<dd><p>Returns a list of <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects sorted in order of
1488
foreign key dependency.</p>
1489
<p>The sorting will place <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> objects that have dependencies
1490
first, before the dependencies themselves, representing the
1491
order in which they can be created. To get the order in which
1492
the tables would be dropped, use the <tt class="docutils literal"><span class="pre">reversed()</span></tt> Python built-in.</p>
1493
<div class="admonition seealso">
1494
<p class="first admonition-title">See also</p>
1495
<p class="last"><tt class="xref py py-meth docutils literal"><span class="pre">Inspector.sorted_tables()</span></tt></p>
1502
<dt id="sqlalchemy.schema.SchemaItem">
1503
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">SchemaItem</tt><a class="headerlink" href="#sqlalchemy.schema.SchemaItem" title="Permalink to this definition">¶</a></dt>
1504
<dd><p>Bases: <a class="reference internal" href="events.html#sqlalchemy.events.SchemaEventTarget" title="sqlalchemy.events.SchemaEventTarget"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.events.SchemaEventTarget</span></tt></a>, <tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.visitors.Visitable</span></tt></p>
1505
<p>Base class for items that define a database schema.</p>
1507
<dt id="sqlalchemy.schema.SchemaItem.get_children">
1508
<tt class="descname">get_children</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.SchemaItem.get_children" title="Permalink to this definition">¶</a></dt>
1509
<dd><p>used to allow SchemaVisitor access</p>
1512
<dl class="attribute">
1513
<dt id="sqlalchemy.schema.SchemaItem.info">
1514
<tt class="descname">info</tt><a class="headerlink" href="#sqlalchemy.schema.SchemaItem.info" title="Permalink to this definition">¶</a></dt>
1515
<dd><p>Info dictionary associated with the object, allowing user-defined
1516
data to be associated with this <a class="reference internal" href="#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a>.</p>
1517
<p>The dictionary is automatically generated when first accessed.
1518
It can also be specified in the constructor of some objects,
1519
such as <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> and <a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</p>
1525
<dt id="sqlalchemy.schema.Table">
1526
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">Table</tt><big>(</big><em>*args</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table" title="Permalink to this definition">¶</a></dt>
1527
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.SchemaItem</span></tt></a>, <a class="reference internal" href="selectable.html#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.sql.expression.TableClause</span></tt></a></p>
1528
<p>Represent a table in a database.</p>
1530
<div class="highlight-python"><div class="highlight"><pre><span class="n">mytable</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">"mytable"</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
1531
<span class="n">Column</span><span class="p">(</span><span class="s">'mytable_id'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
1532
<span class="n">Column</span><span class="p">(</span><span class="s">'value'</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">))</span>
1533
<span class="p">)</span></pre></div>
1535
<p>The <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object constructs a unique instance of itself based
1536
on its name and optional schema name within the given
1537
<a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> object. Calling the <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
1538
constructor with the same name and same <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> argument
1539
a second time will return the <em>same</em> <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object - in this way
1540
the <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> constructor acts as a registry function.</p>
1541
<div class="admonition seealso">
1542
<p class="first admonition-title">See also</p>
1543
<p class="last"><a class="reference internal" href="#metadata-describing"><em>Describing Databases with MetaData</em></a> - Introduction to database metadata</p>
1545
<p>Constructor arguments are as follows:</p>
1546
<table class="docutils field-list" frame="void" rules="none">
1547
<col class="field-name" />
1548
<col class="field-body" />
1549
<tbody valign="top">
1550
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1551
<li><strong>name</strong> – <p>The name of this table as represented in the database.</p>
1552
<p>This property, along with the <em>schema</em>, indicates the <em>singleton
1553
identity</em> of this table in relation to its parent <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a>.
1554
Additional calls to <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> with the same name, metadata,
1555
and schema name will return the same <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object.</p>
1556
<p>Names which contain no upper case characters
1557
will be treated as case insensitive names, and will not be quoted
1558
unless they are a reserved word. Names with any number of upper
1559
case characters will be quoted and sent exactly. Note that this
1560
behavior applies even for databases which standardize upper
1561
case names as case insensitive such as Oracle.</p>
1563
<li><strong>metadata</strong> – a <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> object which will contain this
1564
table. The metadata is used as a point of association of this table
1565
with other tables which are referenced via foreign key. It also
1566
may be used to associate this table with a particular
1567
<a class="reference internal" href="connections.html#sqlalchemy.engine.Connectable" title="sqlalchemy.engine.Connectable"><tt class="xref py py-class docutils literal"><span class="pre">Connectable</span></tt></a>.</li>
1568
<li><strong>*args</strong> – Additional positional arguments are used primarily
1569
to add the list of <a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects contained within this
1570
table. Similar to the style of a CREATE TABLE statement, other
1571
<a class="reference internal" href="#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a> constructs may be added here, including
1572
<a class="reference internal" href="constraints.html#sqlalchemy.schema.PrimaryKeyConstraint" title="sqlalchemy.schema.PrimaryKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt></a>, and <a class="reference internal" href="constraints.html#sqlalchemy.schema.ForeignKeyConstraint" title="sqlalchemy.schema.ForeignKeyConstraint"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt></a>.</li>
1573
<li><strong>autoload</strong> – Defaults to False: the Columns for this table should
1574
be reflected from the database. Usually there will be no Column
1575
objects in the constructor if this property is set.</li>
1576
<li><strong>autoload_replace</strong> – <p>If <tt class="docutils literal"><span class="pre">True</span></tt>, when using <tt class="docutils literal"><span class="pre">autoload=True</span></tt>
1577
and <tt class="docutils literal"><span class="pre">extend_existing=True</span></tt>,
1578
replace <tt class="docutils literal"><span class="pre">Column</span></tt> objects already present in the <tt class="docutils literal"><span class="pre">Table</span></tt> that’s
1579
in the <tt class="docutils literal"><span class="pre">MetaData</span></tt> registry with
1580
what’s reflected. Otherwise, all existing columns will be
1581
excluded from the reflection process. Note that this does
1582
not impact <tt class="docutils literal"><span class="pre">Column</span></tt> objects specified in the same call to <tt class="docutils literal"><span class="pre">Table</span></tt>
1583
which includes <tt class="docutils literal"><span class="pre">autoload</span></tt>, those always take precedence.
1584
Defaults to <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
1585
<div class="versionadded">
1586
<p><span>New in version 0.7.5.</span></p>
1589
<li><strong>autoload_with</strong> – If autoload==True, this is an optional Engine
1590
or Connection instance to be used for the table reflection. If
1591
<tt class="docutils literal"><span class="pre">None</span></tt>, the underlying MetaData’s bound connectable will be used.</li>
1592
<li><strong>extend_existing</strong> – <p>When <tt class="docutils literal"><span class="pre">True</span></tt>, indicates that if this
1593
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> is already present in the given <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a>,
1594
apply further arguments within the constructor to the existing
1595
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>.</p>
1596
<p>If <tt class="docutils literal"><span class="pre">extend_existing</span></tt> or <tt class="docutils literal"><span class="pre">keep_existing</span></tt> are not set, an error is
1597
raised if additional table modifiers are specified when
1598
the given <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> is already present in the <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a>.</p>
1599
<div class="versionchanged">
1600
<p><span>Changed in version 0.7.4: </span><tt class="docutils literal"><span class="pre">extend_existing</span></tt> will work in conjunction
1601
with <tt class="docutils literal"><span class="pre">autoload=True</span></tt> to run a new reflection operation against
1602
the database; new <a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects will be produced
1603
from database metadata to replace those existing with the same
1604
name, and additional <a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects not present
1605
in the <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> will be added.</p>
1607
<p>As is always the case with <tt class="docutils literal"><span class="pre">autoload=True</span></tt>, <a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>
1608
objects can be specified in the same <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> constructor,
1609
which will take precedence. I.e.:</p>
1610
<div class="highlight-python"><div class="highlight"><pre><span class="n">Table</span><span class="p">(</span><span class="s">"mytable"</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
1611
<span class="n">Column</span><span class="p">(</span><span class="s">'y'</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
1612
<span class="n">extend_existing</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
1613
<span class="n">autoload</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
1614
<span class="n">autoload_with</span><span class="o">=</span><span class="n">engine</span>
1615
<span class="p">)</span></pre></div>
1617
<p>The above will overwrite all columns within <tt class="docutils literal"><span class="pre">mytable</span></tt> which
1618
are present in the database, except for <tt class="docutils literal"><span class="pre">y</span></tt> which will be used as is
1619
from the above definition. If the <tt class="docutils literal"><span class="pre">autoload_replace</span></tt> flag
1620
is set to False, no existing columns will be replaced.</p>
1622
<li><strong>implicit_returning</strong> – True by default - indicates that
1623
RETURNING can be used by default to fetch newly inserted primary key
1624
values, for backends which support this. Note that
1625
create_engine() also provides an implicit_returning flag.</li>
1626
<li><strong>include_columns</strong> – A list of strings indicating a subset of
1627
columns to be loaded via the <tt class="docutils literal"><span class="pre">autoload</span></tt> operation; table columns who
1628
aren’t present in this list will not be represented on the resulting
1629
<tt class="docutils literal"><span class="pre">Table</span></tt> object. Defaults to <tt class="docutils literal"><span class="pre">None</span></tt> which indicates all columns
1630
should be reflected.</li>
1631
<li><strong>info</strong> – Optional data dictionary which will be populated into the
1632
<a class="reference internal" href="#sqlalchemy.schema.SchemaItem.info" title="sqlalchemy.schema.SchemaItem.info"><tt class="xref py py-attr docutils literal"><span class="pre">SchemaItem.info</span></tt></a> attribute of this object.</li>
1633
<li><strong>keep_existing</strong> – <p>When <tt class="docutils literal"><span class="pre">True</span></tt>, indicates that if this Table
1634
is already present in the given <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a>, ignore
1635
further arguments within the constructor to the existing
1636
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, and return the <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object as
1637
originally created. This is to allow a function that wishes
1638
to define a new <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> on first call, but on
1639
subsequent calls will return the same <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>,
1640
without any of the declarations (particularly constraints)
1641
being applied a second time. Also see extend_existing.</p>
1642
<p>If extend_existing or keep_existing are not set, an error is
1643
raised if additional table modifiers are specified when
1644
the given <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> is already present in the <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a>.</p>
1646
<li><strong>listeners</strong> – <p>A list of tuples of the form <tt class="docutils literal"><span class="pre">(<eventname>,</span> <span class="pre"><fn>)</span></tt>
1647
which will be passed to <a class="reference internal" href="event.html#sqlalchemy.event.listen" title="sqlalchemy.event.listen"><tt class="xref py py-func docutils literal"><span class="pre">event.listen()</span></tt></a> upon construction.
1648
This alternate hook to <a class="reference internal" href="event.html#sqlalchemy.event.listen" title="sqlalchemy.event.listen"><tt class="xref py py-func docutils literal"><span class="pre">event.listen()</span></tt></a> allows the establishment
1649
of a listener function specific to this <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> before
1650
the “autoload” process begins. Particularly useful for
1651
the <a class="reference internal" href="events.html#sqlalchemy.events.DDLEvents.column_reflect" title="sqlalchemy.events.DDLEvents.column_reflect"><tt class="xref py py-meth docutils literal"><span class="pre">DDLEvents.column_reflect()</span></tt></a> event:</p>
1652
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">listen_for_reflect</span><span class="p">(</span><span class="n">table</span><span class="p">,</span> <span class="n">column_info</span><span class="p">):</span>
1653
<span class="s">"handle the column reflection event"</span>
1654
<span class="c"># ...</span>
1656
<span class="n">t</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span>
1657
<span class="s">'sometable'</span><span class="p">,</span>
1658
<span class="n">autoload</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
1659
<span class="n">listeners</span><span class="o">=</span><span class="p">[</span>
1660
<span class="p">(</span><span class="s">'column_reflect'</span><span class="p">,</span> <span class="n">listen_for_reflect</span><span class="p">)</span>
1661
<span class="p">])</span></pre></div>
1664
<li><strong>mustexist</strong> – When <tt class="docutils literal"><span class="pre">True</span></tt>, indicates that this Table must already
1665
be present in the given <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> collection, else
1666
an exception is raised.</li>
1667
<li><strong>prefixes</strong> – A list of strings to insert after CREATE in the CREATE TABLE
1668
statement. They will be separated by spaces.</li>
1669
<li><strong>quote</strong> – Force quoting of this table’s name on or off, corresponding
1670
to <tt class="docutils literal"><span class="pre">True</span></tt> or <tt class="docutils literal"><span class="pre">False</span></tt>. When left at its default of <tt class="docutils literal"><span class="pre">None</span></tt>,
1671
the column identifier will be quoted according to whether the name is
1672
case sensitive (identifiers with at least one upper case character are
1673
treated as case sensitive), or if it’s a reserved word. This flag
1674
is only needed to force quoting of a reserved word which is not known
1675
by the SQLAlchemy dialect.</li>
1676
<li><strong>quote_schema</strong> – same as ‘quote’ but applies to the schema identifier.</li>
1677
<li><strong>schema</strong> – The <em>schema name</em> for this table, which is required if
1678
the table resides in a schema other than the default selected schema
1679
for the engine’s database connection. Defaults to <tt class="docutils literal"><span class="pre">None</span></tt>.</li>
1680
<li><strong>useexisting</strong> – Deprecated. Use extend_existing.</li>
1687
<dt id="sqlalchemy.schema.Table.__init__">
1688
<tt class="descname">__init__</tt><big>(</big><em>*args</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.__init__" title="Permalink to this definition">¶</a></dt>
1689
<dd><p>Constructor for <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>.</p>
1690
<p>This method is a no-op. See the top-level
1691
documentation for <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
1692
for constructor arguments.</p>
1696
<dt id="sqlalchemy.schema.Table.add_is_dependent_on">
1697
<tt class="descname">add_is_dependent_on</tt><big>(</big><em>table</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.add_is_dependent_on" title="Permalink to this definition">¶</a></dt>
1698
<dd><p>Add a ‘dependency’ for this Table.</p>
1699
<p>This is another Table object which must be created
1700
first before this one can, or dropped after this one.</p>
1701
<p>Usually, dependencies between tables are determined via
1702
ForeignKey objects. However, for other situations that
1703
create dependencies outside of foreign keys (rules, inheriting),
1704
this method can manually establish such a link.</p>
1708
<dt id="sqlalchemy.schema.Table.alias">
1709
<tt class="descname">alias</tt><big>(</big><em>name=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.alias" title="Permalink to this definition">¶</a></dt>
1710
<dd><div class="inherited-member container">
1711
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
1712
<p>return an alias of this <a class="reference internal" href="selectable.html#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>
1713
<p>This is shorthand for calling:</p>
1714
<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>
1715
<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>
1717
<p>See <a class="reference internal" href="selectable.html#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>
1721
<dt id="sqlalchemy.schema.Table.append_column">
1722
<tt class="descname">append_column</tt><big>(</big><em>column</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.append_column" title="Permalink to this definition">¶</a></dt>
1723
<dd><p>Append a <a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> to this <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>.</p>
1724
<p>The “key” of the newly added <a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>, i.e. the
1725
value of its <tt class="docutils literal"><span class="pre">.key</span></tt> attribute, will then be available
1726
in the <tt class="docutils literal"><span class="pre">.c</span></tt> collection of this <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, and the
1727
column definition will be included in any CREATE TABLE, SELECT,
1728
UPDATE, etc. statements generated from this <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>
1730
<p>Note that this does <strong>not</strong> change the definition of the table
1731
as it exists within any underlying database, assuming that
1732
table has already been created in the database. Relational
1733
databases support the addition of columns to existing tables
1734
using the SQL ALTER command, which would need to be
1735
emitted for an already-existing table that doesn’t contain
1736
the newly added column.</p>
1740
<dt id="sqlalchemy.schema.Table.append_constraint">
1741
<tt class="descname">append_constraint</tt><big>(</big><em>constraint</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.append_constraint" title="Permalink to this definition">¶</a></dt>
1742
<dd><p>Append a <a class="reference internal" href="constraints.html#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">Constraint</span></tt></a> to this
1743
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>.</p>
1744
<p>This has the effect of the constraint being included in any
1745
future CREATE TABLE statement, assuming specific DDL creation
1746
events have not been associated with the given
1747
<a class="reference internal" href="constraints.html#sqlalchemy.schema.Constraint" title="sqlalchemy.schema.Constraint"><tt class="xref py py-class docutils literal"><span class="pre">Constraint</span></tt></a> object.</p>
1748
<p>Note that this does <strong>not</strong> produce the constraint within the
1749
relational database automatically, for a table that already exists
1750
in the database. To add a constraint to an
1751
existing relational database table, the SQL ALTER command must
1752
be used. SQLAlchemy also provides the
1753
<a class="reference internal" href="ddl.html#sqlalchemy.schema.AddConstraint" title="sqlalchemy.schema.AddConstraint"><tt class="xref py py-class docutils literal"><span class="pre">AddConstraint</span></tt></a> construct which can produce this SQL when
1754
invoked as an executable clause.</p>
1758
<dt id="sqlalchemy.schema.Table.append_ddl_listener">
1759
<tt class="descname">append_ddl_listener</tt><big>(</big><em>event_name</em>, <em>listener</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.append_ddl_listener" title="Permalink to this definition">¶</a></dt>
1760
<dd><p>Append a DDL event listener to this <tt class="docutils literal"><span class="pre">Table</span></tt>.</p>
1761
<p>Deprecated. See <a class="reference internal" href="events.html#sqlalchemy.events.DDLEvents" title="sqlalchemy.events.DDLEvents"><tt class="xref py py-class docutils literal"><span class="pre">DDLEvents</span></tt></a>.</p>
1764
<dl class="attribute">
1765
<dt id="sqlalchemy.schema.Table.bind">
1766
<tt class="descname">bind</tt><a class="headerlink" href="#sqlalchemy.schema.Table.bind" title="Permalink to this definition">¶</a></dt>
1767
<dd><p>Return the connectable associated with this Table.</p>
1770
<dl class="attribute">
1771
<dt id="sqlalchemy.schema.Table.c">
1772
<tt class="descname">c</tt><a class="headerlink" href="#sqlalchemy.schema.Table.c" title="Permalink to this definition">¶</a></dt>
1773
<dd><div class="inherited-member container">
1774
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
1775
<p>An alias for the <a class="reference internal" href="#sqlalchemy.schema.Table.columns" title="sqlalchemy.schema.Table.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a> attribute.</p>
1778
<dl class="attribute">
1779
<dt id="sqlalchemy.schema.Table.columns">
1780
<tt class="descname">columns</tt><a class="headerlink" href="#sqlalchemy.schema.Table.columns" title="Permalink to this definition">¶</a></dt>
1781
<dd><div class="inherited-member container">
1782
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
1783
<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
1784
maintained by this <a class="reference internal" href="selectable.html#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>
1785
<p>The <a class="reference internal" href="#sqlalchemy.schema.Table.columns" title="sqlalchemy.schema.Table.columns"><tt class="xref py py-attr docutils literal"><span class="pre">columns</span></tt></a>, or <a class="reference internal" href="#sqlalchemy.schema.Table.c" title="sqlalchemy.schema.Table.c"><tt class="xref py py-attr docutils literal"><span class="pre">c</span></tt></a> collection, is the gateway
1786
to the construction of SQL expressions using table-bound or
1787
other selectable-bound columns:</p>
1788
<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>
1793
<dt id="sqlalchemy.schema.Table.compare">
1794
<tt class="descname">compare</tt><big>(</big><em>other</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.compare" title="Permalink to this definition">¶</a></dt>
1795
<dd><div class="inherited-member container">
1796
<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>
1797
<p>Compare this ClauseElement to the given ClauseElement.</p>
1798
<p>Subclasses should override the default behavior, which is a
1799
straight identity comparison.</p>
1800
<p>**kw are arguments consumed by subclass compare() methods and
1801
may be used to modify the criteria for comparison.
1802
(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>
1806
<dt id="sqlalchemy.schema.Table.compile">
1807
<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.schema.Table.compile" title="Permalink to this definition">¶</a></dt>
1808
<dd><div class="inherited-member container">
1809
<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>
1810
<p>Compile this SQL expression.</p>
1811
<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.
1812
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
1813
string representation of the result. The
1814
<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
1815
dictionary of bind parameter names and values
1816
using the <tt class="docutils literal"><span class="pre">params</span></tt> accessor.</p>
1817
<table class="docutils field-list" frame="void" rules="none">
1818
<col class="field-name" />
1819
<col class="field-body" />
1820
<tbody valign="top">
1821
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1822
<li><strong>bind</strong> – 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
1823
<tt class="docutils literal"><span class="pre">Compiled</span></tt> will be acquired. This argument takes precedence over
1824
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>‘s bound engine, if any.</li>
1825
<li><strong>column_keys</strong> – Used for INSERT and UPDATE statements, a list of
1826
column names which should be present in the VALUES clause of the
1827
compiled statement. If <tt class="docutils literal"><span class="pre">None</span></tt>, all columns from the target table
1828
object are rendered.</li>
1829
<li><strong>dialect</strong> – 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>
1830
will be acquired. This argument takes precedence over the <cite>bind</cite>
1831
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>‘s bound engine, if
1833
<li><strong>inline</strong> – Used for INSERT statements, for a dialect which does
1834
not support inline retrieval of newly generated primary key
1835
columns, will force the expression used to create the new primary
1836
key value to be rendered inline within the INSERT statement’s
1837
VALUES clause. This typically refers to Sequence execution but may
1838
also refer to any server-side default generation function
1839
associated with a primary key <cite>Column</cite>.</li>
1848
<dt id="sqlalchemy.schema.Table.correspond_on_equivalents">
1849
<tt class="descname">correspond_on_equivalents</tt><big>(</big><em>column</em>, <em>equivalents</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.correspond_on_equivalents" title="Permalink to this definition">¶</a></dt>
1850
<dd><div class="inherited-member container">
1851
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
1852
<p>Return corresponding_column for the given column, or if None
1853
search for a match in the given dictionary.</p>
1857
<dt id="sqlalchemy.schema.Table.corresponding_column">
1858
<tt class="descname">corresponding_column</tt><big>(</big><em>column</em>, <em>require_embedded=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.corresponding_column" title="Permalink to this definition">¶</a></dt>
1859
<dd><div class="inherited-member container">
1860
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
1861
<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
1862
<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="selectable.html#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a>
1863
which corresponds to that original
1864
<a class="reference internal" href="#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
1866
<table class="docutils field-list" frame="void" rules="none">
1867
<col class="field-name" />
1868
<col class="field-body" />
1869
<tbody valign="top">
1870
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1871
<li><strong>column</strong> – 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>
1872
<li><strong>require_embedded</strong> – only return corresponding columns for</li>
1878
<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
1879
<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
1880
of this <a class="reference internal" href="selectable.html#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
1881
it merely shares a common ancestor with one of the exported
1882
columns of this <a class="reference internal" href="selectable.html#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>
1886
<dt id="sqlalchemy.schema.Table.count">
1887
<tt class="descname">count</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.count" title="Permalink to this definition">¶</a></dt>
1888
<dd><div class="inherited-member container">
1889
<em>inherited from the</em> <a class="reference internal" href="selectable.html#sqlalchemy.sql.expression.TableClause.count" title="sqlalchemy.sql.expression.TableClause.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="selectable.html#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a></div>
1890
<p>return a SELECT COUNT generated against this
1891
<a class="reference internal" href="selectable.html#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>
1895
<dt id="sqlalchemy.schema.Table.create">
1896
<tt class="descname">create</tt><big>(</big><em>bind=None</em>, <em>checkfirst=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.create" title="Permalink to this definition">¶</a></dt>
1897
<dd><p>Issue a <tt class="docutils literal"><span class="pre">CREATE</span></tt> statement for this
1898
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, using the given <a class="reference internal" href="connections.html#sqlalchemy.engine.Connectable" title="sqlalchemy.engine.Connectable"><tt class="xref py py-class docutils literal"><span class="pre">Connectable</span></tt></a>
1899
for connectivity.</p>
1900
<div class="admonition seealso">
1901
<p class="first admonition-title">See also</p>
1902
<p class="last"><a class="reference internal" href="#sqlalchemy.schema.MetaData.create_all" title="sqlalchemy.schema.MetaData.create_all"><tt class="xref py py-meth docutils literal"><span class="pre">MetaData.create_all()</span></tt></a>.</p>
1907
<dt id="sqlalchemy.schema.Table.delete">
1908
<tt class="descname">delete</tt><big>(</big><em>whereclause=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.delete" title="Permalink to this definition">¶</a></dt>
1909
<dd><div class="inherited-member container">
1910
<em>inherited from the</em> <a class="reference internal" href="selectable.html#sqlalchemy.sql.expression.TableClause.delete" title="sqlalchemy.sql.expression.TableClause.delete"><tt class="xref py py-meth docutils literal"><span class="pre">delete()</span></tt></a> <em>method of</em> <a class="reference internal" href="selectable.html#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a></div>
1911
<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
1912
<a class="reference internal" href="selectable.html#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>
1914
<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>
1916
<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>
1919
<dl class="attribute">
1920
<dt id="sqlalchemy.schema.Table.description">
1921
<tt class="descname">description</tt><a class="headerlink" href="#sqlalchemy.schema.Table.description" title="Permalink to this definition">¶</a></dt>
1922
<dd><div class="inherited-member container">
1923
<em>inherited from the</em> <tt class="xref py py-attr docutils literal"><span class="pre">description</span></tt> <em>attribute of</em> <a class="reference internal" href="selectable.html#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a></div>
1926
<dl class="attribute">
1927
<dt id="sqlalchemy.schema.Table.dispatch">
1928
<tt class="descname">dispatch</tt><a class="headerlink" href="#sqlalchemy.schema.Table.dispatch" title="Permalink to this definition">¶</a></dt>
1929
<dd><p>alias of <tt class="xref py py-class docutils literal"><span class="pre">DDLEventsDispatch</span></tt></p>
1933
<dt id="sqlalchemy.schema.Table.drop">
1934
<tt class="descname">drop</tt><big>(</big><em>bind=None</em>, <em>checkfirst=False</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.drop" title="Permalink to this definition">¶</a></dt>
1935
<dd><p>Issue a <tt class="docutils literal"><span class="pre">DROP</span></tt> statement for this
1936
<a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>, using the given <a class="reference internal" href="connections.html#sqlalchemy.engine.Connectable" title="sqlalchemy.engine.Connectable"><tt class="xref py py-class docutils literal"><span class="pre">Connectable</span></tt></a>
1937
for connectivity.</p>
1938
<div class="admonition seealso">
1939
<p class="first admonition-title">See also</p>
1940
<p class="last"><a class="reference internal" href="#sqlalchemy.schema.MetaData.drop_all" title="sqlalchemy.schema.MetaData.drop_all"><tt class="xref py py-meth docutils literal"><span class="pre">MetaData.drop_all()</span></tt></a>.</p>
1945
<dt id="sqlalchemy.schema.Table.exists">
1946
<tt class="descname">exists</tt><big>(</big><em>bind=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.exists" title="Permalink to this definition">¶</a></dt>
1947
<dd><p>Return True if this table exists.</p>
1950
<dl class="attribute">
1951
<dt id="sqlalchemy.schema.Table.foreign_keys">
1952
<tt class="descname">foreign_keys</tt><a class="headerlink" href="#sqlalchemy.schema.Table.foreign_keys" title="Permalink to this definition">¶</a></dt>
1953
<dd><div class="inherited-member container">
1954
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
1955
<p>Return the collection of ForeignKey objects which this
1956
FromClause references.</p>
1960
<dt id="sqlalchemy.schema.Table.get_children">
1961
<tt class="descname">get_children</tt><big>(</big><em>column_collections=True</em>, <em>schema_visitor=False</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.get_children" title="Permalink to this definition">¶</a></dt>
1964
<dl class="attribute">
1965
<dt id="sqlalchemy.schema.Table.implicit_returning">
1966
<tt class="descname">implicit_returning</tt><em class="property"> = False</em><a class="headerlink" href="#sqlalchemy.schema.Table.implicit_returning" title="Permalink to this definition">¶</a></dt>
1969
<dl class="attribute">
1970
<dt id="sqlalchemy.schema.Table.info">
1971
<tt class="descname">info</tt><a class="headerlink" href="#sqlalchemy.schema.Table.info" title="Permalink to this definition">¶</a></dt>
1972
<dd><div class="inherited-member container">
1973
<em>inherited from the</em> <a class="reference internal" href="#sqlalchemy.schema.SchemaItem.info" title="sqlalchemy.schema.SchemaItem.info"><tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt></a> <em>attribute of</em> <a class="reference internal" href="#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a></div>
1974
<p>Info dictionary associated with the object, allowing user-defined
1975
data to be associated with this <a class="reference internal" href="#sqlalchemy.schema.SchemaItem" title="sqlalchemy.schema.SchemaItem"><tt class="xref py py-class docutils literal"><span class="pre">SchemaItem</span></tt></a>.</p>
1976
<p>The dictionary is automatically generated when first accessed.
1977
It can also be specified in the constructor of some objects,
1978
such as <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> and <a class="reference internal" href="#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>.</p>
1982
<dt id="sqlalchemy.schema.Table.insert">
1983
<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.schema.Table.insert" title="Permalink to this definition">¶</a></dt>
1984
<dd><div class="inherited-member container">
1985
<em>inherited from the</em> <a class="reference internal" href="selectable.html#sqlalchemy.sql.expression.TableClause.insert" title="sqlalchemy.sql.expression.TableClause.insert"><tt class="xref py py-meth docutils literal"><span class="pre">insert()</span></tt></a> <em>method of</em> <a class="reference internal" href="selectable.html#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a></div>
1986
<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
1987
<a class="reference internal" href="selectable.html#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>
1989
<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">'foo'</span><span class="p">)</span></pre></div>
1991
<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>
1994
<dl class="attribute">
1995
<dt id="sqlalchemy.schema.Table.is_clause_element">
1996
<tt class="descname">is_clause_element</tt><em class="property"> = True</em><a class="headerlink" href="#sqlalchemy.schema.Table.is_clause_element" title="Permalink to this definition">¶</a></dt>
2000
<dt id="sqlalchemy.schema.Table.is_derived_from">
2001
<tt class="descname">is_derived_from</tt><big>(</big><em>fromclause</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.is_derived_from" title="Permalink to this definition">¶</a></dt>
2002
<dd><div class="inherited-member container">
2003
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
2004
<p>Return True if this FromClause is ‘derived’ from the given
2006
<p>An example would be an Alias of a Table is derived from that Table.</p>
2009
<dl class="attribute">
2010
<dt id="sqlalchemy.schema.Table.is_selectable">
2011
<tt class="descname">is_selectable</tt><em class="property"> = True</em><a class="headerlink" href="#sqlalchemy.schema.Table.is_selectable" title="Permalink to this definition">¶</a></dt>
2015
<dt id="sqlalchemy.schema.Table.join">
2016
<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.schema.Table.join" title="Permalink to this definition">¶</a></dt>
2017
<dd><div class="inherited-member container">
2018
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
2019
<p>return a join of this <a class="reference internal" href="selectable.html#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
2020
<a class="reference internal" href="selectable.html#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>
2023
<dl class="attribute">
2024
<dt id="sqlalchemy.schema.Table.key">
2025
<tt class="descname">key</tt><a class="headerlink" href="#sqlalchemy.schema.Table.key" title="Permalink to this definition">¶</a></dt>
2028
<dl class="attribute">
2029
<dt id="sqlalchemy.schema.Table.named_with_column">
2030
<tt class="descname">named_with_column</tt><em class="property"> = True</em><a class="headerlink" href="#sqlalchemy.schema.Table.named_with_column" title="Permalink to this definition">¶</a></dt>
2034
<dt id="sqlalchemy.schema.Table.outerjoin">
2035
<tt class="descname">outerjoin</tt><big>(</big><em>right</em>, <em>onclause=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.outerjoin" title="Permalink to this definition">¶</a></dt>
2036
<dd><div class="inherited-member container">
2037
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
2038
<p>return an outer join of this <a class="reference internal" href="selectable.html#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
2039
<a class="reference internal" href="selectable.html#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>
2043
<dt id="sqlalchemy.schema.Table.params">
2044
<tt class="descname">params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.params" title="Permalink to this definition">¶</a></dt>
2045
<dd><div class="inherited-member container">
2046
<em>inherited from the</em> <tt class="xref py py-meth docutils literal"><span class="pre">params()</span></tt> <em>method of</em> <tt class="xref py py-class docutils literal"><span class="pre">Immutable</span></tt></div>
2049
<dl class="attribute">
2050
<dt id="sqlalchemy.schema.Table.primary_key">
2051
<tt class="descname">primary_key</tt><a class="headerlink" href="#sqlalchemy.schema.Table.primary_key" title="Permalink to this definition">¶</a></dt>
2052
<dd><div class="inherited-member container">
2053
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
2054
<p>Return the collection of Column objects which comprise the
2055
primary key of this FromClause.</p>
2058
<dl class="attribute">
2059
<dt id="sqlalchemy.schema.Table.quote">
2060
<tt class="descname">quote</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.schema.Table.quote" title="Permalink to this definition">¶</a></dt>
2064
<dt id="sqlalchemy.schema.Table.replace_selectable">
2065
<tt class="descname">replace_selectable</tt><big>(</big><em>old</em>, <em>alias</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.replace_selectable" title="Permalink to this definition">¶</a></dt>
2066
<dd><div class="inherited-member container">
2067
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
2068
<p>replace all occurrences of FromClause ‘old’ with the given Alias
2069
object, returning a copy of this <a class="reference internal" href="selectable.html#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>
2072
<dl class="attribute">
2073
<dt id="sqlalchemy.schema.Table.schema">
2074
<tt class="descname">schema</tt><em class="property"> = None</em><a class="headerlink" href="#sqlalchemy.schema.Table.schema" title="Permalink to this definition">¶</a></dt>
2078
<dt id="sqlalchemy.schema.Table.select">
2079
<tt class="descname">select</tt><big>(</big><em>whereclause=None</em>, <em>**params</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.select" title="Permalink to this definition">¶</a></dt>
2080
<dd><div class="inherited-member container">
2081
<em>inherited from the</em> <a class="reference internal" href="selectable.html#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="selectable.html#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>
2082
<p>return a SELECT of this <a class="reference internal" href="selectable.html#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>
2083
<div class="admonition seealso">
2084
<p class="first admonition-title">See also</p>
2085
<p class="last"><a class="reference internal" href="selectable.html#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
2086
method which allows for arbitrary column lists.</p>
2090
<dl class="attribute">
2091
<dt id="sqlalchemy.schema.Table.selectable">
2092
<tt class="descname">selectable</tt><a class="headerlink" href="#sqlalchemy.schema.Table.selectable" title="Permalink to this definition">¶</a></dt>
2093
<dd><div class="inherited-member container">
2094
<em>inherited from the</em> <tt class="xref py py-attr docutils literal"><span class="pre">selectable</span></tt> <em>attribute of</em> <a class="reference internal" href="selectable.html#sqlalchemy.sql.expression.Selectable" title="sqlalchemy.sql.expression.Selectable"><tt class="xref py py-class docutils literal"><span class="pre">Selectable</span></tt></a></div>
2098
<dt id="sqlalchemy.schema.Table.self_group">
2099
<tt class="descname">self_group</tt><big>(</big><em>against=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.self_group" title="Permalink to this definition">¶</a></dt>
2100
<dd><div class="inherited-member container">
2101
<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>
2102
<p>Apply a ‘grouping’ 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>
2103
<p>This method is overridden by subclasses to return a
2104
“grouping” construct, i.e. parenthesis. In particular
2105
it’s used by “binary” expressions to provide a grouping
2106
around themselves when placed into a larger expression,
2107
as well as by <a class="reference internal" href="selectable.html#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
2108
the FROM clause of another <a class="reference internal" href="selectable.html#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
2109
subqueries should be normally created using the
2110
<tt class="xref py py-func docutils literal"><span class="pre">Select.alias()</span></tt> method, as many platforms require
2111
nested SELECT statements to be named).</p>
2112
<p>As expressions are composed together, the application of
2113
<a class="reference internal" href="#sqlalchemy.schema.Table.self_group" title="sqlalchemy.schema.Table.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
2114
need to use this method directly. Note that SQLAlchemy’s
2115
clause constructs take operator precedence into account -
2116
so parenthesis might not be needed, for example, in
2117
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
2119
<p>The base <a class="reference internal" href="#sqlalchemy.schema.Table.self_group" title="sqlalchemy.schema.Table.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>
2120
just returns self.</p>
2123
<dl class="attribute">
2124
<dt id="sqlalchemy.schema.Table.supports_execution">
2125
<tt class="descname">supports_execution</tt><em class="property"> = False</em><a class="headerlink" href="#sqlalchemy.schema.Table.supports_execution" title="Permalink to this definition">¶</a></dt>
2129
<dt id="sqlalchemy.schema.Table.tometadata">
2130
<tt class="descname">tometadata</tt><big>(</big><em>metadata</em>, <em>schema=<symbol 'retain_schema></em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.tometadata" title="Permalink to this definition">¶</a></dt>
2131
<dd><p>Return a copy of this <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> associated with a different
2132
<a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a>.</p>
2134
<div class="highlight-python"><div class="highlight"><pre><span class="n">some_engine</span> <span class="o">=</span> <span class="n">create_engine</span><span class="p">(</span><span class="s">"sqlite:///some.db"</span><span class="p">)</span>
2136
<span class="c"># create two metadata</span>
2137
<span class="n">meta1</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
2138
<span class="n">meta2</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
2140
<span class="c"># load 'users' from the sqlite engine</span>
2141
<span class="n">users_table</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'users'</span><span class="p">,</span> <span class="n">meta1</span><span class="p">,</span> <span class="n">autoload</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
2142
<span class="n">autoload_with</span><span class="o">=</span><span class="n">some_engine</span><span class="p">)</span>
2144
<span class="c"># create the same Table object for the plain metadata</span>
2145
<span class="n">users_table_2</span> <span class="o">=</span> <span class="n">users_table</span><span class="o">.</span><span class="n">tometadata</span><span class="p">(</span><span class="n">meta2</span><span class="p">)</span></pre></div>
2147
<table class="docutils field-list" frame="void" rules="none">
2148
<col class="field-name" />
2149
<col class="field-body" />
2150
<tbody valign="top">
2151
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
2152
<li><strong>metadata</strong> – Target <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">MetaData</span></tt></a> object.</li>
2153
<li><strong>schema</strong> – Optional string name of a target schema, or
2154
<tt class="docutils literal"><span class="pre">None</span></tt> for no schema. The <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a> object will be
2155
given this schema name upon copy. Defaults to the special
2156
symbol <tt class="xref py py-attr docutils literal"><span class="pre">RETAIN_SCHEMA</span></tt> which indicates no change should be
2157
made to the schema name of the resulting <a class="reference internal" href="#sqlalchemy.schema.Table" title="sqlalchemy.schema.Table"><tt class="xref py py-class docutils literal"><span class="pre">Table</span></tt></a>.</li>
2166
<dt id="sqlalchemy.schema.Table.unique_params">
2167
<tt class="descname">unique_params</tt><big>(</big><em>*optionaldict</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.schema.Table.unique_params" title="Permalink to this definition">¶</a></dt>
2168
<dd><div class="inherited-member container">
2169
<em>inherited from the</em> <tt class="xref py py-meth docutils literal"><span class="pre">unique_params()</span></tt> <em>method of</em> <tt class="xref py py-class docutils literal"><span class="pre">Immutable</span></tt></div>
2173
<dt id="sqlalchemy.schema.Table.update">
2174
<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.schema.Table.update" title="Permalink to this definition">¶</a></dt>
2175
<dd><div class="inherited-member container">
2176
<em>inherited from the</em> <a class="reference internal" href="selectable.html#sqlalchemy.sql.expression.TableClause.update" title="sqlalchemy.sql.expression.TableClause.update"><tt class="xref py py-meth docutils literal"><span class="pre">update()</span></tt></a> <em>method of</em> <a class="reference internal" href="selectable.html#sqlalchemy.sql.expression.TableClause" title="sqlalchemy.sql.expression.TableClause"><tt class="xref py py-class docutils literal"><span class="pre">TableClause</span></tt></a></div>
2177
<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
2178
<a class="reference internal" href="selectable.html#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>
2180
<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">'foo'</span><span class="p">)</span></pre></div>
2182
<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>
2188
<dt id="sqlalchemy.schema.ThreadLocalMetaData">
2189
<em class="property">class </em><tt class="descclassname">sqlalchemy.schema.</tt><tt class="descname">ThreadLocalMetaData</tt><a class="headerlink" href="#sqlalchemy.schema.ThreadLocalMetaData" title="Permalink to this definition">¶</a></dt>
2190
<dd><p>Bases: <a class="reference internal" href="#sqlalchemy.schema.MetaData" title="sqlalchemy.schema.MetaData"><tt class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.MetaData</span></tt></a></p>
2191
<p>A MetaData variant that presents a different <tt class="docutils literal"><span class="pre">bind</span></tt> in every thread.</p>
2192
<p>Makes the <tt class="docutils literal"><span class="pre">bind</span></tt> property of the MetaData a thread-local value, allowing
2193
this collection of tables to be bound to different <tt class="docutils literal"><span class="pre">Engine</span></tt>
2194
implementations or connections in each thread.</p>
2195
<p>The ThreadLocalMetaData starts off bound to None in each thread. Binds
2196
must be made explicitly by assigning to the <tt class="docutils literal"><span class="pre">bind</span></tt> property or using
2197
<tt class="docutils literal"><span class="pre">connect()</span></tt>. You can also re-bind dynamically multiple times per
2198
thread, just like a regular <tt class="docutils literal"><span class="pre">MetaData</span></tt>.</p>
2200
<dt id="sqlalchemy.schema.ThreadLocalMetaData.__init__">
2201
<tt class="descname">__init__</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ThreadLocalMetaData.__init__" title="Permalink to this definition">¶</a></dt>
2202
<dd><p>Construct a ThreadLocalMetaData.</p>
2205
<dl class="attribute">
2206
<dt id="sqlalchemy.schema.ThreadLocalMetaData.bind">
2207
<tt class="descname">bind</tt><a class="headerlink" href="#sqlalchemy.schema.ThreadLocalMetaData.bind" title="Permalink to this definition">¶</a></dt>
2208
<dd><p>The bound Engine or Connection for this thread.</p>
2209
<p>This property may be assigned an Engine or Connection, or assigned a
2210
string or URL to automatically create a basic Engine for this bind
2211
with <tt class="docutils literal"><span class="pre">create_engine()</span></tt>.</p>
2215
<dt id="sqlalchemy.schema.ThreadLocalMetaData.dispose">
2216
<tt class="descname">dispose</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ThreadLocalMetaData.dispose" title="Permalink to this definition">¶</a></dt>
2217
<dd><p>Dispose all bound engines, in all thread contexts.</p>
2221
<dt id="sqlalchemy.schema.ThreadLocalMetaData.is_bound">
2222
<tt class="descname">is_bound</tt><big>(</big><big>)</big><a class="headerlink" href="#sqlalchemy.schema.ThreadLocalMetaData.is_bound" title="Permalink to this definition">¶</a></dt>
2223
<dd><p>True if there is a bind for this thread.</p>
2235
<div id="docs-bottom-navigation" class="docs-navigation-links">
2237
<a href="schema.html" title="previous chapter">Schema Definition Language</a>
2239
<a href="reflection.html" title="next chapter">Reflecting Database Objects</a>
2241
<div id="docs-copyright">
2242
© <a href="../copyright.html">Copyright</a> 2007-2013, the SQLAlchemy authors and contributors.
2243
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2b1.