forked from python-postgres/be
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgres_types.html
More file actions
510 lines (499 loc) · 31.7 KB
/
Copy pathpostgres_types.html
File metadata and controls
510 lines (499 loc) · 31.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Postgres.types Module — pg-python v1.0.0 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '1.0.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="pg-python v1.0.0 documentation" href="index.html" />
<link rel="prev" title="Postgres Module" href="postgres.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="postgres.html" title="Postgres Module"
accesskey="P">previous</a> |</li>
<li><a href="index.html">pg-python v1.0.0 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="postgres-types-module">
<h1>Postgres.types Module<a class="headerlink" href="#postgres-types-module" title="Permalink to this headline">¶</a></h1>
<p><tt class="docutils literal"><span class="pre">Postgres.types</span></tt> is a psuedo-module used to facilite import statements so
that data types in the <tt class="docutils literal"><span class="pre">pg_catalog</span></tt> schema can be easily referenced from
Python code:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Postgres.types</span> <span class="kn">import</span> <span class="n">bytea</span><span class="p">,</span> <span class="n">circle</span>
</pre></div>
</div>
<p>This chapter discusses some of the interfaces provided on those data types.</p>
<div class="section" id="postgres-types-date">
<span id="pg-types-date"></span><h2>Postgres.types.date<a class="headerlink" href="#postgres-types-date" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference external" href="postgres.html#pg-type"><em>Postgres.Type</em></a> for the <tt class="docutils literal"><span class="pre">pg_catalog.date</span></tt> data type:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Postgres.types</span> <span class="kn">import</span> <span class="n">date</span>
<span class="n">d</span> <span class="o">=</span> <span class="n">date</span><span class="p">(</span><span class="s">'2000-01-01'</span><span class="p">)</span>
<span class="k">assert</span> <span class="n">d</span><span class="o">.</span><span class="n">year</span> <span class="o">==</span> <span class="mi">2000</span>
<span class="k">assert</span> <span class="n">d</span><span class="o">.</span><span class="n">month</span> <span class="o">==</span> <span class="mi">1</span>
<span class="k">assert</span> <span class="n">d</span><span class="o">.</span><span class="n">day</span> <span class="o">==</span> <span class="mi">1</span>
</pre></div>
</div>
<p><strong>Properties:</strong></p>
<blockquote>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">date.millennium</span></tt></dt>
<dd>The ‘millennium’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">date.century</span></tt></dt>
<dd>The ‘century’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">date.decade</span></tt></dt>
<dd>The ‘decade’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">date.year</span></tt></dt>
<dd>The ‘year’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">date.quarter</span></tt></dt>
<dd>The ‘quarter’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">date.week</span></tt></dt>
<dd>The ‘week’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">date.month</span></tt></dt>
<dd>The ‘month’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">date.day</span></tt></dt>
<dd>The ‘day’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">date.dayofyear</span></tt></dt>
<dd>The ‘doy’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">date.dayofweek</span></tt></dt>
<dd>The ‘dow’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">date.epoch</span></tt></dt>
<dd>The ‘epoch’ part as a Python float.</dd>
</dl>
</blockquote>
</div>
<div class="section" id="postgres-types-interval">
<h2>Postgres.types.interval<a class="headerlink" href="#postgres-types-interval" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference external" href="postgres.html#pg-type"><em>Postgres.Type</em></a> for the <tt class="docutils literal"><span class="pre">pg_catalog.interval</span></tt> data type:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Postgres.types</span> <span class="kn">import</span> <span class="n">interval</span>
<span class="n">i</span> <span class="o">=</span> <span class="n">interval</span><span class="p">(</span><span class="s">'10 years 1 months 2 days 3 hours 4 minutes 5 seconds'</span><span class="p">)</span>
<span class="k">assert</span> <span class="n">i</span><span class="o">.</span><span class="n">year</span> <span class="o">==</span> <span class="mi">10</span>
<span class="k">assert</span> <span class="n">i</span><span class="o">.</span><span class="n">month</span> <span class="o">==</span> <span class="mi">1</span>
<span class="k">assert</span> <span class="n">i</span><span class="o">.</span><span class="n">day</span> <span class="o">==</span> <span class="mi">2</span>
<span class="k">assert</span> <span class="n">i</span><span class="o">.</span><span class="n">hour</span> <span class="o">==</span> <span class="mi">3</span>
<span class="k">assert</span> <span class="n">i</span><span class="o">.</span><span class="n">minute</span> <span class="o">==</span> <span class="mi">4</span>
<span class="k">assert</span> <span class="n">i</span><span class="o">.</span><span class="n">second</span> <span class="o">==</span> <span class="mi">5</span>
</pre></div>
</div>
<p><strong>Properties:</strong></p>
<blockquote>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">millennium</span></tt></dt>
<dd>The ‘millennium’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">century</span></tt></dt>
<dd>The ‘century’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">decade</span></tt></dt>
<dd>The ‘decade’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">year</span></tt></dt>
<dd>The ‘year’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">quarter</span></tt></dt>
<dd>The ‘quarter’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">week</span></tt></dt>
<dd>The ‘week’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">month</span></tt></dt>
<dd>The ‘month’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">day</span></tt></dt>
<dd>The ‘day’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">hour</span></tt></dt>
<dd>The ‘hour’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">minute</span></tt></dt>
<dd>The ‘minute’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">second</span></tt></dt>
<dd>The ‘second’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">millisecond</span></tt></dt>
<dd>The ‘millisecond’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">microsecond</span></tt></dt>
<dd>The ‘microsecond’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timezone</span></tt></dt>
<dd>The ‘timezone’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">epoch</span></tt></dt>
<dd>The ‘epoch’ part as a Python float.</dd>
</dl>
</blockquote>
</div>
<div class="section" id="postgres-types-record">
<span id="pg-types-record"></span><h2>Postgres.types.record<a class="headerlink" href="#postgres-types-record" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference external" href="postgres.html#pg-type"><em>Postgres.Type</em></a> instance for the <tt class="docutils literal"><span class="pre">pg_catalog.record</span></tt> data type.
This type is used as the abstract base type for all composite types.</p>
<p>Subclasses of this type are used to represent table types. These types are
used by <a class="reference external" href="programming.html#programming-trf"><em>Trigger Returning Functions</em></a> in order to represent the data given
to the row-level entry points.</p>
<p><strong>Constructors:</strong></p>
<blockquote>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">record(sequence)</span></tt></dt>
<dd>Create an instance of the record using the given sequence. The length
of the sequence <em>must</em> be equal to the number of attributes in the record.</dd>
<dt><tt class="docutils literal"><span class="pre">record(dictionary)</span></tt></dt>
<dd>Create an instance of the record using the given dictionary. The keys of
the dictionary must map to an attribute name. Any unspecified attributes
will be initialized to <tt class="docutils literal"><span class="pre">NULL</span></tt>.</dd>
<dt><tt class="docutils literal"><span class="pre">record(str)</span></tt></dt>
<dd>Create an instance of the record using a string. This string is given to
the record’s type input function.</dd>
</dl>
</blockquote>
<p>Only subclasses <tt class="docutils literal"><span class="pre">Postgres.types.record</span></tt> can be <em>directly</em> instantiated.</p>
<p><strong>Properties:</strong></p>
<blockquote>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">record.column_types</span></tt></dt>
<dd><p class="first">A tuple of <a class="reference external" href="postgres.html#pg-type"><em>Postgres.Type</em></a> instances. The index of
each item corresponds to the column type.</p>
<p class="last">This property is available on record subclasses <em>and</em> instances thereof.</p>
</dd>
<dt><tt class="docutils literal"><span class="pre">record.column_names</span></tt></dt>
<dd><p class="first">A tuple of strings naming the columns of the composite.</p>
<p class="last">This property is available on record subclasses <em>and</em> instances thereof.</p>
</dd>
<dt><tt class="docutils literal"><span class="pre">record.pg_column_types</span></tt></dt>
<dd><p class="first">A tuple of type Oid’s specifying the column types.</p>
<p class="last">This property is available on record subclasses <em>and</em> instances thereof.</p>
</dd>
<dt><tt class="docutils literal"><span class="pre">record.descriptor</span></tt></dt>
<dd><p class="first">A <cite>Postgres.TupleDesc</cite> object describing the composite.</p>
<p class="last">This property is available on record subclasses <em>and</em> instances thereof.</p>
</dd>
</dl>
</blockquote>
<p><strong>Methods:</strong></p>
<blockquote>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">record.replace(*args,</span> <span class="pre">**kw)</span></tt></dt>
<dd><p class="first">Replace the attributes of the record instance using the arguments. A
new instance will be returned.</p>
<p>If positional arguments are given, the index of each argument will correspond
with the attribute that will be replaced using the argument.</p>
<p>If keyword arguments are given, each keyword corresponds to the
attribute that will be replaced using the attribute’s name:</p>
<div class="last highlight-python"><pre>BEGIN;
CREATE TYPE py_test_ctyp AS (i int, t text, f float);
CREATE FUNCTION modify_fields(py_test_ctyp)
RETURNS py_test_ctyp
LANGUAGE python AS
$python$
def main(x):
return x.replace(None, 'text', f = 1.423)
$python$;
SELECT modify_fields(ROW(100, 'not-this-text', NULL)::py_test_ctyp);
-- modify_fields
-----------------
-- (,text,1.423)
ABORT;</pre>
</div>
</dd>
<dt><tt class="docutils literal"><span class="pre">record.transform(*args,</span> <span class="pre">**kw)</span></tt></dt>
<dd><p class="first">Transform the attributes of the record instance using the callable arguments. A
new instance will be returned. Similar to replace, but arguments must be
callables that can take a single parameter.</p>
<p>If positional arguments are given, the index of each argument will correspond
with the attribute that will be transformed using the callable argument.
If the argument is <tt class="xref docutils literal"><span class="pre">None</span></tt>, the attribute will not be
changed.</p>
<p>If keyword arguments are given, each keyword corresponds to the
attribute that will be transformed using the callable:</p>
<div class="last highlight-python"><pre>BEGIN;
CREATE TYPE py_test_ctyp2 AS (i int, t text, f float);
CREATE FUNCTION transform_fields(py_test_ctyp2)
RETURNS py_test_ctyp2
LANGUAGE python AS
$python$
def main(x):
return x.transform(None, lambda x: x + ' ! appended text', f = lambda x: x / 2.0)
$python$;
SELECT transform_fields(ROW(200, 'text', 27)::py_test_ctyp2);
-- transform_fields
-------------------------------------
-- (200,"text ! appended text",13.5)
ABORT;</pre>
</div>
</dd>
<dt><tt class="docutils literal"><span class="pre">record.keys()</span></tt></dt>
<dd>Returns the <tt class="docutils literal"><span class="pre">column_names</span></tt> tuple.</dd>
<dt><tt class="docutils literal"><span class="pre">record.values()</span></tt></dt>
<dd>Returns the record object.</dd>
<dt><tt class="docutils literal"><span class="pre">record.items()</span></tt></dt>
<dd><p class="first">Returns iterator producing tuples whose first item is the attribute
name, and whose second item the associated value.</p>
<p class="last">The iterator produces the pairs using the index order of the
attributes.</p>
</dd>
<dt><tt class="docutils literal"><span class="pre">record.__getitem__(idx_or_slice),</span> <span class="pre">record[idx_or_slice]</span></tt></dt>
<dd><p class="first">Return the attributes in the record associated with index or slice. If a
slice is requested, a Python tuple of <cite>Postgres.Object</cite> instances will be returned.</p>
<p class="last">Attributes can be referenced by name or index as records are both a
sequence and a mapping.</p>
</dd>
<dt><tt class="docutils literal"><span class="pre">record.__len__(),</span> <span class="pre">len(record)</span></tt></dt>
<dd>Return the number of attributes in the record.</dd>
</dl>
</blockquote>
</div>
<div class="section" id="postgres-types-time">
<h2>Postgres.types.time<a class="headerlink" href="#postgres-types-time" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference external" href="postgres.html#pg-type"><em>Postgres.Type</em></a> for the <tt class="docutils literal"><span class="pre">pg_catalog.time</span></tt> data type:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Postgres.types</span> <span class="kn">import</span> <span class="n">time</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">time</span><span class="p">(</span><span class="s">'12:00:00'</span><span class="p">)</span>
<span class="k">assert</span> <span class="n">t</span><span class="o">.</span><span class="n">hour</span> <span class="o">==</span> <span class="mi">12</span>
<span class="k">assert</span> <span class="n">t</span><span class="o">.</span><span class="n">minute</span> <span class="o">==</span> <span class="mi">0</span>
<span class="k">assert</span> <span class="n">t</span><span class="o">.</span><span class="n">second</span> <span class="o">==</span> <span class="mi">0</span>
</pre></div>
</div>
<dl class="docutils">
<dt>Properties:</dt>
<dd><dl class="first last docutils">
<dt><tt class="docutils literal"><span class="pre">time.hour</span></tt></dt>
<dd>The ‘hour’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">time.minute</span></tt></dt>
<dd>The ‘minute’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">time.second</span></tt></dt>
<dd>The ‘second’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">time.millisecond</span></tt></dt>
<dd>The ‘millisecond’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">time.microsecond</span></tt></dt>
<dd>The ‘microsecond’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">time.epoch</span></tt></dt>
<dd>The ‘epoch’ part as a Python float.</dd>
</dl>
</dd>
</dl>
</div>
<div class="section" id="postgres-types-timestamp">
<h2>Postgres.types.timestamp<a class="headerlink" href="#postgres-types-timestamp" title="Permalink to this headline">¶</a></h2>
<p>The <cite>Postgres.Type</cite> for the <tt class="docutils literal"><span class="pre">pg_catalog.timestamp</span></tt> data type:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Postgres.types</span> <span class="kn">import</span> <span class="n">timestamp</span>
<span class="n">ts</span> <span class="o">=</span> <span class="n">timestamp</span><span class="p">(</span><span class="s">'2000-01-01 12:00:00'</span><span class="p">)</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">year</span> <span class="o">==</span> <span class="mi">2000</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">month</span> <span class="o">==</span> <span class="mi">1</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">day</span> <span class="o">==</span> <span class="mi">1</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">hour</span> <span class="o">==</span> <span class="mi">12</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">minute</span> <span class="o">==</span> <span class="mi">0</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">second</span> <span class="o">==</span> <span class="mi">0</span>
</pre></div>
</div>
<p><strong>Properties:</strong></p>
<blockquote>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">millennium</span></tt></dt>
<dd>The ‘millennium’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">century</span></tt></dt>
<dd>The ‘century’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">decade</span></tt></dt>
<dd>The ‘decade’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">year</span></tt></dt>
<dd>The ‘year’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">quarter</span></tt></dt>
<dd>The ‘quarter’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">week</span></tt></dt>
<dd>The ‘week’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">month</span></tt></dt>
<dd>The ‘month’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">day</span></tt></dt>
<dd>The ‘day’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">dayofyear</span></tt></dt>
<dd>The ‘doy’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">dayofweek</span></tt></dt>
<dd>The ‘dow’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">hour</span></tt></dt>
<dd>The ‘hour’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">minute</span></tt></dt>
<dd>The ‘minute’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">second</span></tt></dt>
<dd>The ‘second’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">millisecond</span></tt></dt>
<dd>The ‘millisecond’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">microsecond</span></tt></dt>
<dd>The ‘microsecond’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">epoch</span></tt></dt>
<dd>The ‘epoch’ part as a Python float.</dd>
</dl>
</blockquote>
</div>
<div class="section" id="postgres-types-timetz">
<h2>Postgres.types.timetz<a class="headerlink" href="#postgres-types-timetz" title="Permalink to this headline">¶</a></h2>
<p>The <cite>Postgres.Type</cite> for the <tt class="docutils literal"><span class="pre">pg_catalog.timetz</span></tt> data type:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Postgres.types</span> <span class="kn">import</span> <span class="n">timetz</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">time</span><span class="p">(</span><span class="s">'12:00:00+00'</span><span class="p">)</span>
<span class="k">assert</span> <span class="n">t</span><span class="o">.</span><span class="n">hour</span> <span class="o">==</span> <span class="mi">12</span>
<span class="k">assert</span> <span class="n">t</span><span class="o">.</span><span class="n">minute</span> <span class="o">==</span> <span class="mi">0</span>
<span class="k">assert</span> <span class="n">t</span><span class="o">.</span><span class="n">second</span> <span class="o">==</span> <span class="mi">0</span>
<span class="k">assert</span> <span class="n">t</span><span class="o">.</span><span class="n">timezone</span> <span class="o">==</span> <span class="mi">0</span>
</pre></div>
</div>
<p><strong>Properties:</strong></p>
<blockquote>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">hour</span></tt></dt>
<dd>The ‘hour’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">minute</span></tt></dt>
<dd>The ‘minute’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">second</span></tt></dt>
<dd>The ‘second’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">millisecond</span></tt></dt>
<dd>The ‘millisecond’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">microsecond</span></tt></dt>
<dd>The ‘microsecond’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">epoch</span></tt></dt>
<dd>The ‘epoch’ part as a Python float.</dd>
<dt><tt class="docutils literal"><span class="pre">timezone</span></tt></dt>
<dd>The ‘timezone’ part as a Python int.</dd>
</dl>
</blockquote>
</div>
<div class="section" id="postgres-types-timestamptz">
<span id="pg-types-timestamptz"></span><h2>Postgres.types.timestamptz<a class="headerlink" href="#postgres-types-timestamptz" title="Permalink to this headline">¶</a></h2>
<p>The <cite>Postgres.Type</cite> for the <tt class="docutils literal"><span class="pre">pg_catalog.timestamptz</span></tt> data type:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Postgres.types</span> <span class="kn">import</span> <span class="n">timestamptz</span>
<span class="n">ts</span> <span class="o">=</span> <span class="n">timestamptz</span><span class="p">(</span><span class="s">'2000-01-01 12:00:00'</span><span class="p">)</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">year</span> <span class="o">==</span> <span class="mi">2000</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">month</span> <span class="o">==</span> <span class="mi">1</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">day</span> <span class="o">==</span> <span class="mi">1</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">hour</span> <span class="o">==</span> <span class="mi">12</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">minute</span> <span class="o">==</span> <span class="mi">0</span>
<span class="k">assert</span> <span class="n">ts</span><span class="o">.</span><span class="n">second</span> <span class="o">==</span> <span class="mi">0</span>
</pre></div>
</div>
<p><strong>Properties</strong>:</p>
<blockquote>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">timestamptz.millennium</span></tt></dt>
<dd>The ‘millennium’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.century</span></tt></dt>
<dd>The ‘century’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.decade</span></tt></dt>
<dd>The ‘decade’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.year</span></tt></dt>
<dd>The ‘year’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.quarter</span></tt></dt>
<dd>The ‘quarter’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.week</span></tt></dt>
<dd>The ‘week’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.month</span></tt></dt>
<dd>The ‘month’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.day</span></tt></dt>
<dd>The ‘day’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.dayofyear</span></tt></dt>
<dd>The ‘doy’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.dayofweek</span></tt></dt>
<dd>The ‘dow’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.hour</span></tt></dt>
<dd>The ‘hour’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.minute</span></tt></dt>
<dd>The ‘minute’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.second</span></tt></dt>
<dd>The ‘second’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.millisecond</span></tt></dt>
<dd>The ‘millisecond’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.microsecond</span></tt></dt>
<dd>The ‘microsecond’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.timezone</span></tt></dt>
<dd>The ‘timezone’ part as a Python int.</dd>
<dt><tt class="docutils literal"><span class="pre">timestamptz.epoch</span></tt></dt>
<dd>The ‘epoch’ part as a Python float.</dd>
</dl>
</blockquote>
</div>
<div class="section" id="postgres-types-xid">
<h2>Postgres.types.xid<a class="headerlink" href="#postgres-types-xid" title="Permalink to this headline">¶</a></h2>
<p>The <cite>Postgres.Type</cite> for the <tt class="docutils literal"><span class="pre">pg_catalog.xid</span></tt> data type:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Postgres.types</span> <span class="kn">import</span> <span class="n">xid</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">xid</span><span class="o">.</span><span class="n">current</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Constructors</strong>:</p>
<blockquote>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">xid.current()</span></tt></dt>
<dd>Create a new instance using the current transaction
identifier(<tt class="docutils literal"><span class="pre">GetCurrentTransactionId</span></tt>).</dd>
<dt><tt class="docutils literal"><span class="pre">xid.current_sub()</span></tt></dt>
<dd>Create a new instance using the current subtransaction
identifier(<tt class="docutils literal"><span class="pre">GetCurrentSubTransactionId</span></tt>).</dd>
</dl>
</blockquote>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference external" href="">Postgres.types Module</a><ul>
<li><a class="reference external" href="#postgres-types-date">Postgres.types.date</a></li>
<li><a class="reference external" href="#postgres-types-interval">Postgres.types.interval</a></li>
<li><a class="reference external" href="#postgres-types-record">Postgres.types.record</a></li>
<li><a class="reference external" href="#postgres-types-time">Postgres.types.time</a></li>
<li><a class="reference external" href="#postgres-types-timestamp">Postgres.types.timestamp</a></li>
<li><a class="reference external" href="#postgres-types-timetz">Postgres.types.timetz</a></li>
<li><a class="reference external" href="#postgres-types-timestamptz">Postgres.types.timestamptz</a></li>
<li><a class="reference external" href="#postgres-types-xid">Postgres.types.xid</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="postgres.html"
title="previous chapter">Postgres Module</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/postgres_types.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="postgres.html" title="Postgres Module"
>previous</a> |</li>
<li><a href="index.html">pg-python v1.0.0 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2010, James William Pye <x@jwp.name>.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
</div>
</body>
</html>