/
DatabaseMethods.html
1138 lines (1088 loc) · 107 KB
/
DatabaseMethods.html
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<title>Sequel::Postgres::DatabaseMethods</title>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
<link href='../../../css/style.css' media='screen' rel='stylesheet' type='text/css'>
<script type='text/javascript'>
//<![CDATA[
function popupCode(url) {
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
}
function toggleCode(id) {
var code = document.getElementById(id)
code.style.display = code.style.display != 'block' ? 'block' : 'none'
return true
}
// Make codeblocks hidden by default
document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
//]]>
</script>
</head>
<body class='page'>
<div class='class' id='wrapper'>
<div class='header'>
<h1 class='name'>
<span class='type'>module</span>
Sequel::Postgres::DatabaseMethods
</h1>
<ol class='paths'>
<li>
<a target="docwin" href="../../../files/lib/sequel/adapters/shared/postgres_rb.html">lib/sequel/adapters/shared/postgres.rb</a>
</li>
</ol>
</div>
<div id='content'>
<div id='text'>
<div id='description'>
<p>Methods shared by <a href="Database.html">Database</a> instances that
connect to PostgreSQL.</p>
</div>
<div id='method-list'>
<h2>Methods</h2>
<h3>Public Instance</h3>
<ol>
<li><a target="docwin" href="#method-i-add_named_conversion_proc">add_named_conversion_proc</a></li>
<li><a target="docwin" href="#method-i-commit_prepared_transaction">commit_prepared_transaction</a></li>
<li><a target="docwin" href="#attribute-i-conversion_procs">conversion_procs</a></li>
<li><a target="docwin" href="#method-i-create_function">create_function</a></li>
<li><a target="docwin" href="#method-i-create_language">create_language</a></li>
<li><a target="docwin" href="#method-i-create_schema">create_schema</a></li>
<li><a target="docwin" href="#method-i-create_trigger">create_trigger</a></li>
<li><a target="docwin" href="#method-i-database_type">database_type</a></li>
<li><a target="docwin" href="#method-i-do">do</a></li>
<li><a target="docwin" href="#method-i-drop_function">drop_function</a></li>
<li><a target="docwin" href="#method-i-drop_language">drop_language</a></li>
<li><a target="docwin" href="#method-i-drop_schema">drop_schema</a></li>
<li><a target="docwin" href="#method-i-drop_trigger">drop_trigger</a></li>
<li><a target="docwin" href="#method-i-foreign_key_list">foreign_key_list</a></li>
<li><a target="docwin" href="#method-i-indexes">indexes</a></li>
<li><a target="docwin" href="#method-i-locks">locks</a></li>
<li><a target="docwin" href="#method-i-notify">notify</a></li>
<li><a target="docwin" href="#method-i-primary_key">primary_key</a></li>
<li><a target="docwin" href="#method-i-primary_key_sequence">primary_key_sequence</a></li>
<li><a target="docwin" href="#method-i-refresh_view">refresh_view</a></li>
<li><a target="docwin" href="#method-i-reset_conversion_procs">reset_conversion_procs</a></li>
<li><a target="docwin" href="#method-i-reset_primary_key_sequence">reset_primary_key_sequence</a></li>
<li><a target="docwin" href="#method-i-rollback_prepared_transaction">rollback_prepared_transaction</a></li>
<li><a target="docwin" href="#method-i-serial_primary_key_options">serial_primary_key_options</a></li>
<li><a target="docwin" href="#method-i-server_version">server_version</a></li>
<li><a target="docwin" href="#method-i-supports_create_table_if_not_exists-3F">supports_create_table_if_not_exists?</a></li>
<li><a target="docwin" href="#method-i-supports_deferrable_constraints-3F">supports_deferrable_constraints?</a></li>
<li><a target="docwin" href="#method-i-supports_deferrable_foreign_key_constraints-3F">supports_deferrable_foreign_key_constraints?</a></li>
<li><a target="docwin" href="#method-i-supports_drop_table_if_exists-3F">supports_drop_table_if_exists?</a></li>
<li><a target="docwin" href="#method-i-supports_partial_indexes-3F">supports_partial_indexes?</a></li>
<li><a target="docwin" href="#method-i-supports_prepared_transactions-3F">supports_prepared_transactions?</a></li>
<li><a target="docwin" href="#method-i-supports_savepoints-3F">supports_savepoints?</a></li>
<li><a target="docwin" href="#method-i-supports_transaction_isolation_levels-3F">supports_transaction_isolation_levels?</a></li>
<li><a target="docwin" href="#method-i-supports_transactional_ddl-3F">supports_transactional_ddl?</a></li>
<li><a target="docwin" href="#method-i-supports_trigger_conditions-3F">supports_trigger_conditions?</a></li>
<li><a target="docwin" href="#method-i-tables">tables</a></li>
<li><a target="docwin" href="#method-i-type_supported-3F">type_supported?</a></li>
<li><a target="docwin" href="#method-i-values">values</a></li>
<li><a target="docwin" href="#method-i-views">views</a></li>
</ol>
</div>
<div id='context'>
</div>
<div id='section'>
<div id='constants-list'>
<h2>Constants</h2>
<div class='name-list'>
<table summary='Constants'>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>DATABASE_ERROR_REGEXPS</td>
<td>=</td>
<td class='context-item-value'>
[
# Add this check first, since otherwise it's possible for users to control
# which exception class is generated.
[/invalid input syntax/, DatabaseError],
[/duplicate key value violates unique constraint/, UniqueConstraintViolation],
[/violates foreign key constraint/, ForeignKeyConstraintViolation],
[/violates check constraint/, CheckConstraintViolation],
[/violates not-null constraint/, NotNullConstraintViolation],
[/conflicting key value violates exclusion constraint/, ExclusionConstraintViolation],
[/could not serialize access/, SerializationFailure],
].freeze
</td>
<td> </td>
<td class='context-item-desc'></td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>DEADLOCK_SQL_STATE</td>
<td>=</td>
<td class='context-item-value'>'40P01'.freeze</td>
<td> </td>
<td class='context-item-desc'></td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>EXCLUSION_CONSTRAINT_SQL_STATE</td>
<td>=</td>
<td class='context-item-value'>'23P01'.freeze</td>
<td> </td>
<td class='context-item-desc'></td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>FOREIGN_KEY_LIST_ON_DELETE_MAP</td>
<td>=</td>
<td class='context-item-value'>{'a'.freeze=>:no_action, 'r'.freeze=>:restrict, 'c'.freeze=>:cascade, 'n'.freeze=>:set_null, 'd'.freeze=>:set_default}.freeze</td>
<td> </td>
<td class='context-item-desc'></td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>ON_COMMIT</td>
<td>=</td>
<td class='context-item-value'>
{
:drop => 'DROP', :delete_rows => 'DELETE ROWS', :preserve_rows => 'PRESERVE ROWS',
}.freeze
</td>
<td> </td>
<td class='context-item-desc'></td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>POSTGRES_DEFAULT_RE</td>
<td>=</td>
<td class='context-item-value'>/\A(?:B?('.*')::[^']+|\((-?\d+(?:\.\d+)?)\))\z/</td>
<td> </td>
<td class='context-item-desc'></td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>PREPARED_ARG_PLACEHOLDER</td>
<td>=</td>
<td class='context-item-value'>LiteralString.new('$').freeze</td>
<td> </td>
<td class='context-item-desc'></td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>RE_CURRVAL_ERROR</td>
<td>=</td>
<td class='context-item-value'>/currval of sequence "(.*)" is not yet defined in this session|relation "(.*)" does not exist/.freeze</td>
<td> </td>
<td class='context-item-desc'></td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>SELECT_CUSTOM_SEQUENCE_SQL</td>
<td>=</td>
<td class='context-item-value'>
(<<-end_sql
SELECT name.nspname AS "schema",
CASE
WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN
substr(split_part(def.adsrc, '''', 2),
strpos(split_part(def.adsrc, '''', 2), '.')+1)
ELSE split_part(def.adsrc, '''', 2)
END AS "sequence"
FROM pg_class t
JOIN pg_namespace name ON (t.relnamespace = name.oid)
JOIN pg_attribute attr ON (t.oid = attrelid)
JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum)
JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1])
WHERE cons.contype = 'p'
AND def.adsrc ~* 'nextval'
end_sql
).strip.gsub(/\s+/, ' ').freeze
</td>
<td> </td>
<td class='context-item-desc'>
<p><a href="../SQL.html">SQL</a> fragment for custom sequences (ones not
created by serial primary key), Returning the schema and literal form of
the sequence name, by parsing the column defaults table.</p>
</td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>SELECT_PK_SQL</td>
<td>=</td>
<td class='context-item-value'>
(<<-end_sql
SELECT pg_attribute.attname AS pk
FROM pg_class, pg_attribute, pg_index, pg_namespace
WHERE pg_class.oid = pg_attribute.attrelid
AND pg_class.relnamespace = pg_namespace.oid
AND pg_class.oid = pg_index.indrelid
AND pg_index.indkey[0] = pg_attribute.attnum
AND pg_index.indisprimary = 't'
end_sql
).strip.gsub(/\s+/, ' ').freeze
</td>
<td> </td>
<td class='context-item-desc'>
<p><a href="../SQL.html">SQL</a> fragment for determining primary key column
for the given table. Only returns the first primary key if the table has a
composite primary key.</p>
</td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>SELECT_SERIAL_SEQUENCE_SQL</td>
<td>=</td>
<td class='context-item-value'>
(<<-end_sql
SELECT name.nspname AS "schema", seq.relname AS "sequence"
FROM pg_class seq, pg_attribute attr, pg_depend dep,
pg_namespace name, pg_constraint cons, pg_class t
WHERE seq.oid = dep.objid
AND seq.relnamespace = name.oid
AND seq.relkind = 'S'
AND attr.attrelid = dep.refobjid
AND attr.attnum = dep.refobjsubid
AND attr.attrelid = cons.conrelid
AND attr.attnum = cons.conkey[1]
AND attr.attrelid = t.oid
AND cons.contype = 'p'
end_sql
).strip.gsub(/\s+/, ' ').freeze
</td>
<td> </td>
<td class='context-item-desc'>
<p><a href="../SQL.html">SQL</a> fragment for getting sequence associated with
table's primary key, assuming it was a serial primary key column.</p>
</td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>UNLOGGED</td>
<td>=</td>
<td class='context-item-value'>'UNLOGGED '.freeze</td>
<td> </td>
<td class='context-item-desc'></td>
</tr>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>VALID_CLIENT_MIN_MESSAGES</td>
<td>=</td>
<td class='context-item-value'>%w'DEBUG5 DEBUG4 DEBUG3 DEBUG2 DEBUG1 LOG NOTICE WARNING ERROR FATAL PANIC'.freeze</td>
<td> </td>
<td class='context-item-desc'></td>
</tr>
</table>
</div>
</div>
<div id='attribute-list'>
<h2 class='section-bar'>Attributes</h2>
<div class='name-list'>
<table>
<tr class='top-aligned-row context-row'>
<td class='context-item-name'>
<a name='attribute-i-conversion_procs'>conversion_procs</a>
</td>
<td class='context-item-value'>[R]</td>
<td class='context-item-desc'>
<p>A hash of conversion procs, keyed by type integer (oid) and having callable
values for the conversion proc for that type.</p>
</td>
</tr>
</table>
</div>
</div>
<div id='methods'>
<h2>Public Instance methods</h2>
<div class='method public-instance' id='method-method-i-add_named_conversion_proc'>
<a name='method-i-add_named_conversion_proc'></a>
<div class='synopsis'>
<span class='name'>add_named_conversion_proc</span>
<span class='arguments'>(name, &block)</span>
</div>
<div class='description'>
<p>Add a conversion proc for a named type. This should be used for types
without fixed OIDs, which includes all types that are not included in a
default PostgreSQL installation. If a block is given, it is used as the
conversion proc, otherwise the conversion proc is looked up in the
PG_NAMED_TYPES hash.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-add_named_conversion_proc-source'); return false">
[show source]
</a>
<pre id='method-i-add_named_conversion_proc-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 162</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">add_named_conversion_proc</span>(<span class="ruby-identifier">name</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
 <span class="ruby-identifier">add_named_conversion_procs</span>(<span class="ruby-identifier">conversion_procs</span>, <span class="ruby-identifier">name</span>=<span class="ruby-operator">></span>(<span class="ruby-identifier">block</span> <span class="ruby-operator">||</span> <span class="ruby-constant">PG_NAMED_TYPES</span>[<span class="ruby-identifier">name</span>]))
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-commit_prepared_transaction'>
<a name='method-i-commit_prepared_transaction'></a>
<div class='synopsis'>
<span class='name'>commit_prepared_transaction</span>
<span class='arguments'>(transaction_id, opts=OPTS)</span>
</div>
<div class='description'>
<p>Commit an existing prepared transaction with the given transaction
identifier string.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-commit_prepared_transaction-source'); return false">
[show source]
</a>
<pre id='method-i-commit_prepared_transaction-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 168</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">commit_prepared_transaction</span>(<span class="ruby-identifier">transaction_id</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-identifier">run</span>(<span class="ruby-node">"COMMIT PREPARED #{literal(transaction_id)}"</span>, <span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-create_function'>
<a name='method-i-create_function'></a>
<div class='synopsis'>
<span class='name'>create_function</span>
<span class='arguments'>(name, definition, opts=OPTS)</span>
</div>
<div class='description'>
<p>Creates the function in the database. Arguments:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>name </td><td>
<p>name of the function to create</p>
</td></tr><tr><td class='label'>definition </td><td>
<p>string definition of the function, or object file for a dynamically loaded
C function.</p>
</td></tr><tr><td class='label'>opts </td><td>
<p>options hash:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>:args </td><td>
<p>function arguments, can be either a symbol or string specifying a type or
an array of 1-3 elements:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>1 </td><td>
<p>argument data type</p>
</td></tr><tr><td class='label'>2 </td><td>
<p>argument name</p>
</td></tr><tr><td class='label'>3 </td><td>
<p>argument mode (e.g. in, out, inout)</p>
</td></tr></tbody></table>
</td></tr><tr><td class='label'>:behavior </td><td>
<p>Should be IMMUTABLE, STABLE, or VOLATILE. PostgreSQL assumes VOLATILE by
default.</p>
</td></tr><tr><td class='label'>:cost </td><td>
<p>The estimated cost of the function, used by the query planner.</p>
</td></tr><tr><td class='label'>:language </td><td>
<p>The language the function uses. <a href="../SQL.html">SQL</a> is the
default.</p>
</td></tr><tr><td class='label'>:link_symbol </td><td>
<p>For a dynamically loaded see function, the function's link symbol if
different from the definition argument.</p>
</td></tr><tr><td class='label'>:returns </td><td>
<p>The data type returned by the function. If you are using OUT or INOUT
argument modes, this is ignored. Otherwise, if this is not specified, void
is used by default to specify the function is not supposed to return a
value.</p>
</td></tr><tr><td class='label'>:rows </td><td>
<p>The estimated number of rows the function will return. Only use if the
function returns SETOF something.</p>
</td></tr><tr><td class='label'>:security_definer </td><td>
<p>Makes the privileges of the function the same as the privileges of the user
who defined the function instead of the privileges of the user who runs the
function. There are security implications when doing this, see the
PostgreSQL documentation.</p>
</td></tr><tr><td class='label'>:set </td><td>
<p>Configuration variables to set while the function is being run, can be a
hash or an array of two pairs. search_path is often used here if
:security_definer is used.</p>
</td></tr><tr><td class='label'>:strict </td><td>
<p>Makes the function return NULL when any argument is NULL.</p>
</td></tr></tbody></table>
</td></tr></tbody></table>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-create_function-source'); return false">
[show source]
</a>
<pre id='method-i-create_function-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 192</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">create_function</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">definition</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-keyword">self</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">create_function_sql</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">definition</span>, <span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-create_language'>
<a name='method-i-create_language'></a>
<div class='synopsis'>
<span class='name'>create_language</span>
<span class='arguments'>(name, opts=OPTS)</span>
</div>
<div class='description'>
<p>Create the procedural language in the database. Arguments:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>name </td><td>
<p>Name of the procedural language (e.g. plpgsql)</p>
</td></tr><tr><td class='label'>opts </td><td>
<p>options hash:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>:handler </td><td>
<p>The name of a previously registered function used as a call handler for
this language.</p>
</td></tr><tr><td class='label'>:replace </td><td>
<p>Replace the installed language if it already exists (on PostgreSQL 9.0+).</p>
</td></tr><tr><td class='label'>:trusted </td><td>
<p>Marks the language being created as trusted, allowing unprivileged users to
create functions using this language.</p>
</td></tr><tr><td class='label'>:validator </td><td>
<p>The name of previously registered function used as a validator of functions
defined in this language.</p>
</td></tr></tbody></table>
</td></tr></tbody></table>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-create_language-source'); return false">
[show source]
</a>
<pre id='method-i-create_language-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 203</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">create_language</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-keyword">self</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">create_language_sql</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-create_schema'>
<a name='method-i-create_schema'></a>
<div class='synopsis'>
<span class='name'>create_schema</span>
<span class='arguments'>(name, opts=OPTS)</span>
</div>
<div class='description'>
<p>Create a schema in the database. Arguments:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>name </td><td>
<p>Name of the schema (e.g. admin)</p>
</td></tr><tr><td class='label'>opts </td><td>
<p>options hash:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>:if_not_exists </td><td>
<p>Don't raise an error if the schema already exists (PostgreSQL 9.3+)</p>
</td></tr><tr><td class='label'>:owner </td><td>
<p>The owner to set for the schema (defaults to current user if not specified)</p>
</td></tr></tbody></table>
</td></tr></tbody></table>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-create_schema-source'); return false">
[show source]
</a>
<pre id='method-i-create_schema-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 212</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">create_schema</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-keyword">self</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">create_schema_sql</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-create_trigger'>
<a name='method-i-create_trigger'></a>
<div class='synopsis'>
<span class='name'>create_trigger</span>
<span class='arguments'>(table, name, function, opts=OPTS)</span>
</div>
<div class='description'>
<p>Create a trigger in the database. Arguments:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>table </td><td>
<p>the table on which this trigger operates</p>
</td></tr><tr><td class='label'>name </td><td>
<p>the name of this trigger</p>
</td></tr><tr><td class='label'>function </td><td>
<p>the function to call for this trigger, which should return type trigger.</p>
</td></tr><tr><td class='label'>opts </td><td>
<p>options hash:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>:after </td><td>
<p>Calls the trigger after execution instead of before.</p>
</td></tr><tr><td class='label'>:args </td><td>
<p>An argument or array of arguments to pass to the function.</p>
</td></tr><tr><td class='label'>:each_row </td><td>
<p>Calls the trigger for each row instead of for each statement.</p>
</td></tr><tr><td class='label'>:events </td><td>
<p>Can be :insert, :update, :delete, or an array of any of those. Calls the
trigger whenever that type of statement is used. By default, the trigger
is called for insert, update, or delete.</p>
</td></tr><tr><td class='label'>:when </td><td>
<p>A filter to use for the trigger</p>
</td></tr></tbody></table>
</td></tr></tbody></table>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-create_trigger-source'); return false">
[show source]
</a>
<pre id='method-i-create_trigger-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 227</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">create_trigger</span>(<span class="ruby-identifier">table</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">function</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-keyword">self</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">create_trigger_sql</span>(<span class="ruby-identifier">table</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">function</span>, <span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-database_type'>
<a name='method-i-database_type'></a>
<div class='synopsis'>
<span class='name'>database_type</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p>PostgreSQL uses the :postgres database type.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-database_type-source'); return false">
[show source]
</a>
<pre id='method-i-database_type-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 232</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">database_type</span>
 <span class="ruby-value">:postgres</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-do'>
<a name='method-i-do'></a>
<div class='synopsis'>
<span class='name'>do</span>
<span class='arguments'>(code, opts=OPTS)</span>
</div>
<div class='description'>
<p>Use PostgreSQL's DO syntax to execute an anonymous code block. The
code should be the literal code string to use in the underlying procedural
language. Options:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>:language </td><td>
<p>The procedural language the code is written in. The PostgreSQL default is
plpgsql. Can be specified as a string or a symbol.</p>
</td></tr></tbody></table>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-do-source'); return false">
[show source]
</a>
<pre id='method-i-do-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 241</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">do</span>(<span class="ruby-identifier">code</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-identifier">language</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:language</span>]
 <span class="ruby-identifier">run</span> <span class="ruby-node">"DO #{"LANGUAGE #{literal(language.to_s)} " if language}#{literal(code)}"</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-drop_function'>
<a name='method-i-drop_function'></a>
<div class='synopsis'>
<span class='name'>drop_function</span>
<span class='arguments'>(name, opts=OPTS)</span>
</div>
<div class='description'>
<p>Drops the function from the database. Arguments:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>name </td><td>
<p>name of the function to drop</p>
</td></tr><tr><td class='label'>opts </td><td>
<p>options hash:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>:args </td><td>
<p>The arguments for the function. See create_function_sql.</p>
</td></tr><tr><td class='label'>:cascade </td><td>
<p>Drop other objects depending on this function.</p>
</td></tr><tr><td class='label'>:if_exists </td><td>
<p>Don't raise an error if the function doesn't exist.</p>
</td></tr></tbody></table>
</td></tr></tbody></table>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-drop_function-source'); return false">
[show source]
</a>
<pre id='method-i-drop_function-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 252</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">drop_function</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-keyword">self</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">drop_function_sql</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-drop_language'>
<a name='method-i-drop_language'></a>
<div class='synopsis'>
<span class='name'>drop_language</span>
<span class='arguments'>(name, opts=OPTS)</span>
</div>
<div class='description'>
<p>Drops a procedural language from the database. Arguments:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>name </td><td>
<p>name of the procedural language to drop</p>
</td></tr><tr><td class='label'>opts </td><td>
<p>options hash:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>:cascade </td><td>
<p>Drop other objects depending on this function.</p>
</td></tr><tr><td class='label'>:if_exists </td><td>
<p>Don't raise an error if the function doesn't exist.</p>
</td></tr></tbody></table>
</td></tr></tbody></table>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-drop_language-source'); return false">
[show source]
</a>
<pre id='method-i-drop_language-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 261</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">drop_language</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-keyword">self</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">drop_language_sql</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-drop_schema'>
<a name='method-i-drop_schema'></a>
<div class='synopsis'>
<span class='name'>drop_schema</span>
<span class='arguments'>(name, opts=OPTS)</span>
</div>
<div class='description'>
<p>Drops a schema from the database. Arguments:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>name </td><td>
<p>name of the schema to drop</p>
</td></tr><tr><td class='label'>opts </td><td>
<p>options hash:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>:cascade </td><td>
<p>Drop all objects in this schema.</p>
</td></tr><tr><td class='label'>:if_exists </td><td>
<p>Don't raise an error if the schema doesn't exist.</p>
</td></tr></tbody></table>
</td></tr></tbody></table>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-drop_schema-source'); return false">
[show source]
</a>
<pre id='method-i-drop_schema-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 270</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">drop_schema</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-keyword">self</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">drop_schema_sql</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-drop_trigger'>
<a name='method-i-drop_trigger'></a>
<div class='synopsis'>
<span class='name'>drop_trigger</span>
<span class='arguments'>(table, name, opts=OPTS)</span>
</div>
<div class='description'>
<p>Drops a trigger from the database. Arguments:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>table </td><td>
<p>table from which to drop the trigger</p>
</td></tr><tr><td class='label'>name </td><td>
<p>name of the trigger to drop</p>
</td></tr><tr><td class='label'>opts </td><td>
<p>options hash:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>:cascade </td><td>
<p>Drop other objects depending on this function.</p>
</td></tr><tr><td class='label'>:if_exists </td><td>
<p>Don't raise an error if the function doesn't exist.</p>
</td></tr></tbody></table>
</td></tr></tbody></table>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-drop_trigger-source'); return false">
[show source]
</a>
<pre id='method-i-drop_trigger-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 280</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">drop_trigger</span>(<span class="ruby-identifier">table</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-keyword">self</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">drop_trigger_sql</span>(<span class="ruby-identifier">table</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-foreign_key_list'>
<a name='method-i-foreign_key_list'></a>
<div class='synopsis'>
<span class='name'>foreign_key_list</span>
<span class='arguments'>(table, opts=OPTS)</span>
</div>
<div class='description'>
<p>Return full foreign key information using the pg system tables, including
:name, :on_delete, :on_update, and :deferrable entries in the hashes.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-foreign_key_list-source'); return false">
[show source]
</a>
<pre id='method-i-foreign_key_list-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 286</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">foreign_key_list</span>(<span class="ruby-identifier">table</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-identifier">m</span> = <span class="ruby-identifier">output_identifier_meth</span>
 <span class="ruby-identifier">schema</span>, <span class="ruby-identifier">_</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-value">:schema</span>, <span class="ruby-identifier">schema_and_table</span>(<span class="ruby-identifier">table</span>))
 <span class="ruby-identifier">range</span> = <span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-value">32</span>

 <span class="ruby-identifier">base_ds</span> = <span class="ruby-identifier">metadata_dataset</span>.
 <span class="ruby-identifier">from</span>(<span class="ruby-value">:pg_constraint___co</span>).
 <span class="ruby-identifier">join</span>(<span class="ruby-value">:pg_class___cl</span>, <span class="ruby-value">:oid=</span><span class="ruby-operator">></span><span class="ruby-value">:conrelid</span>).
 <span class="ruby-identifier">where</span>(<span class="ruby-value">:cl__relkind=</span><span class="ruby-operator">></span><span class="ruby-string">'r'</span>, <span class="ruby-value">:co__contype=</span><span class="ruby-operator">></span><span class="ruby-string">'f'</span>, <span class="ruby-value">:cl__oid=</span><span class="ruby-operator">></span><span class="ruby-identifier">regclass_oid</span>(<span class="ruby-identifier">table</span>))

 <span class="ruby-comment"># We split the parsing into two separate queries, which are merged manually later.</span>
 <span class="ruby-comment"># This is because PostgreSQL stores both the referencing and referenced columns in</span>
 <span class="ruby-comment"># arrays, and I don't know a simple way to not create a cross product, as PostgreSQL</span>
 <span class="ruby-comment"># doesn't appear to have a function that takes an array and element and gives you</span>
 <span class="ruby-comment"># the index of that element in the array.</span>

 <span class="ruby-identifier">ds</span> = <span class="ruby-identifier">base_ds</span>.
 <span class="ruby-identifier">join</span>(<span class="ruby-value">:pg_attribute___att</span>, <span class="ruby-value">:attrelid=</span><span class="ruby-operator">></span><span class="ruby-value">:oid</span>, <span class="ruby-value">:attnum=</span><span class="ruby-operator">></span><span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">Function</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:ANY</span>, <span class="ruby-value">:co__conkey</span>)).
 <span class="ruby-identifier">order</span>(<span class="ruby-value">:co__conname</span>, <span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">CaseExpression</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">range</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> [<span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">Subscript</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:co__conkey</span>, [<span class="ruby-identifier">x</span>]), <span class="ruby-identifier">x</span>]}, <span class="ruby-value">32</span>, <span class="ruby-value">:att__attnum</span>)).
 <span class="ruby-identifier">select</span>(<span class="ruby-value">:co__conname___name</span>, <span class="ruby-value">:att__attname___column</span>, <span class="ruby-value">:co__confupdtype___on_update</span>, <span class="ruby-value">:co__confdeltype___on_delete</span>,
 <span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">BooleanExpression</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:AND</span>, <span class="ruby-value">:co__condeferrable</span>, <span class="ruby-value">:co__condeferred</span>).<span class="ruby-identifier">as</span>(<span class="ruby-value">:deferrable</span>))

 <span class="ruby-identifier">ref_ds</span> = <span class="ruby-identifier">base_ds</span>.
 <span class="ruby-identifier">join</span>(<span class="ruby-value">:pg_class___cl2</span>, <span class="ruby-value">:oid=</span><span class="ruby-operator">></span><span class="ruby-value">:co__confrelid</span>).
 <span class="ruby-identifier">join</span>(<span class="ruby-value">:pg_attribute___att2</span>, <span class="ruby-value">:attrelid=</span><span class="ruby-operator">></span><span class="ruby-value">:oid</span>, <span class="ruby-value">:attnum=</span><span class="ruby-operator">></span><span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">Function</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:ANY</span>, <span class="ruby-value">:co__confkey</span>)).
 <span class="ruby-identifier">order</span>(<span class="ruby-value">:co__conname</span>, <span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">CaseExpression</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">range</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> [<span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">Subscript</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:co__conkey</span>, [<span class="ruby-identifier">x</span>]), <span class="ruby-identifier">x</span>]}, <span class="ruby-value">32</span>, <span class="ruby-value">:att2__attnum</span>)).
 <span class="ruby-identifier">select</span>(<span class="ruby-value">:co__conname___name</span>, <span class="ruby-value">:cl2__relname___table</span>, <span class="ruby-value">:att2__attname___refcolumn</span>)

 <span class="ruby-comment"># If a schema is given, we only search in that schema, and the returned :table</span>
 <span class="ruby-comment"># entry is schema qualified as well.</span>
 <span class="ruby-keyword">if</span> <span class="ruby-identifier">schema</span>
 <span class="ruby-identifier">ref_ds</span> = <span class="ruby-identifier">ref_ds</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value">:pg_namespace___nsp2</span>, <span class="ruby-value">:oid=</span><span class="ruby-operator">></span><span class="ruby-value">:cl2__relnamespace</span>).
 <span class="ruby-identifier">select_more</span>(<span class="ruby-value">:nsp2__nspname___schema</span>)
 <span class="ruby-keyword">end</span>

 <span class="ruby-identifier">h</span> = {}
 <span class="ruby-identifier">fklod_map</span> = <span class="ruby-constant">FOREIGN_KEY_LIST_ON_DELETE_MAP</span> 
 <span class="ruby-identifier">ds</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
 <span class="ruby-keyword">if</span> <span class="ruby-identifier">r</span> = <span class="ruby-identifier">h</span>[<span class="ruby-identifier">row</span>[<span class="ruby-value">:name</span>]]
 <span class="ruby-identifier">r</span>[<span class="ruby-value">:columns</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">row</span>[<span class="ruby-value">:column</span>])
 <span class="ruby-keyword">else</span>
 <span class="ruby-identifier">h</span>[<span class="ruby-identifier">row</span>[<span class="ruby-value">:name</span>]] = {<span class="ruby-value">:name=</span><span class="ruby-operator">></span><span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">row</span>[<span class="ruby-value">:name</span>]), <span class="ruby-value">:columns=</span><span class="ruby-operator">></span>[<span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">row</span>[<span class="ruby-value">:column</span>])], <span class="ruby-value">:on_update=</span><span class="ruby-operator">></span><span class="ruby-identifier">fklod_map</span>[<span class="ruby-identifier">row</span>[<span class="ruby-value">:on_update</span>]], <span class="ruby-value">:on_delete=</span><span class="ruby-operator">></span><span class="ruby-identifier">fklod_map</span>[<span class="ruby-identifier">row</span>[<span class="ruby-value">:on_delete</span>]], <span class="ruby-value">:deferrable=</span><span class="ruby-operator">></span><span class="ruby-identifier">row</span>[<span class="ruby-value">:deferrable</span>]}
 <span class="ruby-keyword">end</span>
 <span class="ruby-keyword">end</span>
 <span class="ruby-identifier">ref_ds</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
 <span class="ruby-identifier">r</span> = <span class="ruby-identifier">h</span>[<span class="ruby-identifier">row</span>[<span class="ruby-value">:name</span>]]
 <span class="ruby-identifier">r</span>[<span class="ruby-value">:table</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">schema</span> <span class="ruby-operator">?</span> <span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">QualifiedIdentifier</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">row</span>[<span class="ruby-value">:schema</span>]), <span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">row</span>[<span class="ruby-value">:table</span>])) <span class="ruby-operator">:</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">row</span>[<span class="ruby-value">:table</span>])
 <span class="ruby-identifier">r</span>[<span class="ruby-value">:key</span>] <span class="ruby-operator">||=</span> []
 <span class="ruby-identifier">r</span>[<span class="ruby-value">:key</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">row</span>[<span class="ruby-value">:refcolumn</span>])
 <span class="ruby-keyword">end</span>
 <span class="ruby-identifier">h</span>.<span class="ruby-identifier">values</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-indexes'>
<a name='method-i-indexes'></a>
<div class='synopsis'>
<span class='name'>indexes</span>
<span class='arguments'>(table, opts=OPTS)</span>
</div>
<div class='description'>
<p>Use the pg_* system tables to determine indexes on a table</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-indexes-source'); return false">
[show source]
</a>
<pre id='method-i-indexes-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 340</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">indexes</span>(<span class="ruby-identifier">table</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-identifier">m</span> = <span class="ruby-identifier">output_identifier_meth</span>
 <span class="ruby-identifier">range</span> = <span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-value">32</span>
 <span class="ruby-identifier">attnums</span> = <span class="ruby-identifier">server_version</span> <span class="ruby-operator">>=</span> <span class="ruby-value">80100</span> <span class="ruby-operator">?</span> <span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">Function</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:ANY</span>, <span class="ruby-value">:ind__indkey</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">range</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">Subscript</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:ind__indkey</span>, [<span class="ruby-identifier">x</span>])}
 <span class="ruby-identifier">ds</span> = <span class="ruby-identifier">metadata_dataset</span>.
 <span class="ruby-identifier">from</span>(<span class="ruby-value">:pg_class___tab</span>).
 <span class="ruby-identifier">join</span>(<span class="ruby-value">:pg_index___ind</span>, <span class="ruby-value">:indrelid=</span><span class="ruby-operator">></span><span class="ruby-value">:oid</span>).
 <span class="ruby-identifier">join</span>(<span class="ruby-value">:pg_class___indc</span>, <span class="ruby-value">:oid=</span><span class="ruby-operator">></span><span class="ruby-value">:indexrelid</span>).
 <span class="ruby-identifier">join</span>(<span class="ruby-value">:pg_attribute___att</span>, <span class="ruby-value">:attrelid=</span><span class="ruby-operator">></span><span class="ruby-value">:tab__oid</span>, <span class="ruby-value">:attnum=</span><span class="ruby-operator">></span><span class="ruby-identifier">attnums</span>).
 <span class="ruby-identifier">left_join</span>(<span class="ruby-value">:pg_constraint___con</span>, <span class="ruby-value">:conname=</span><span class="ruby-operator">></span><span class="ruby-value">:indc__relname</span>).
 <span class="ruby-identifier">filter</span>(<span class="ruby-value">:indc__relkind=</span><span class="ruby-operator">></span><span class="ruby-string">'i'</span>, <span class="ruby-value">:ind__indisprimary=</span><span class="ruby-operator">></span><span class="ruby-keyword">false</span>, <span class="ruby-value">:indexprs=</span><span class="ruby-operator">></span><span class="ruby-keyword">nil</span>, <span class="ruby-value">:indpred=</span><span class="ruby-operator">></span><span class="ruby-keyword">nil</span>, <span class="ruby-value">:indisvalid=</span><span class="ruby-operator">></span><span class="ruby-keyword">true</span>, <span class="ruby-value">:tab__oid=</span><span class="ruby-operator">></span><span class="ruby-identifier">regclass_oid</span>(<span class="ruby-identifier">table</span>, <span class="ruby-identifier">opts</span>)).
 <span class="ruby-identifier">order</span>(<span class="ruby-value">:indc__relname</span>, <span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">CaseExpression</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">range</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> [<span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">Subscript</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:ind__indkey</span>, [<span class="ruby-identifier">x</span>]), <span class="ruby-identifier">x</span>]}, <span class="ruby-value">32</span>, <span class="ruby-value">:att__attnum</span>)).
 <span class="ruby-identifier">select</span>(<span class="ruby-value">:indc__relname___name</span>, <span class="ruby-value">:ind__indisunique___unique</span>, <span class="ruby-value">:att__attname___column</span>, <span class="ruby-value">:con__condeferrable___deferrable</span>)

 <span class="ruby-identifier">ds</span>.<span class="ruby-identifier">filter!</span>(<span class="ruby-value">:indisready=</span><span class="ruby-operator">></span><span class="ruby-keyword">true</span>, <span class="ruby-value">:indcheckxmin=</span><span class="ruby-operator">></span><span class="ruby-keyword">false</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">server_version</span> <span class="ruby-operator">>=</span> <span class="ruby-value">80300</span>

 <span class="ruby-identifier">indexes</span> = {}
 <span class="ruby-identifier">ds</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
 <span class="ruby-identifier">i</span> = <span class="ruby-identifier">indexes</span>[<span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">r</span>[<span class="ruby-value">:name</span>])] <span class="ruby-operator">||=</span> {<span class="ruby-value">:columns=</span><span class="ruby-operator">></span>[], <span class="ruby-value">:unique=</span><span class="ruby-operator">></span><span class="ruby-identifier">r</span>[<span class="ruby-value">:unique</span>], <span class="ruby-value">:deferrable=</span><span class="ruby-operator">></span><span class="ruby-identifier">r</span>[<span class="ruby-value">:deferrable</span>]}
 <span class="ruby-identifier">i</span>[<span class="ruby-value">:columns</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">r</span>[<span class="ruby-value">:column</span>])
 <span class="ruby-keyword">end</span>
 <span class="ruby-identifier">indexes</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-locks'>
<a name='method-i-locks'></a>
<div class='synopsis'>
<span class='name'>locks</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p><a href="Dataset.html">Dataset</a> containing all current database locks</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-locks-source'); return false">
[show source]
</a>
<pre id='method-i-locks-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 365</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">locks</span>
 <span class="ruby-identifier">dataset</span>.<span class="ruby-identifier">from</span>(<span class="ruby-value">:pg_class</span>).<span class="ruby-identifier">join</span>(<span class="ruby-value">:pg_locks</span>, <span class="ruby-value">:relation=</span><span class="ruby-operator">></span><span class="ruby-value">:relfilenode</span>).<span class="ruby-identifier">select</span>(<span class="ruby-value">:pg_class__relname</span>, <span class="ruby-constant">Sequel</span><span class="ruby-operator">::</span><span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">ColumnAll</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:pg_locks</span>))
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-notify'>
<a name='method-i-notify'></a>
<div class='synopsis'>
<span class='name'>notify</span>
<span class='arguments'>(channel, opts=OPTS)</span>
</div>
<div class='description'>
<p>Notifies the given channel. See the PostgreSQL NOTIFY documentation.
Options:</p>
<table class="rdoc-list note-list"><tbody><tr><td class='label'>:payload </td><td>
<p>The payload string to use for the NOTIFY statement. Only supported in
PostgreSQL 9.0+.</p>
</td></tr><tr><td class='label'>:server </td><td>
<p>The server to which to send the NOTIFY statement, if the sharding support
is being used.</p>
</td></tr></tbody></table>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-notify-source'); return false">
[show source]
</a>
<pre id='method-i-notify-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 375</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">notify</span>(<span class="ruby-identifier">channel</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-identifier">sql</span> = <span class="ruby-string">"NOTIFY "</span>
 <span class="ruby-identifier">dataset</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:identifier_append</span>, <span class="ruby-identifier">sql</span>, <span class="ruby-identifier">channel</span>)
 <span class="ruby-keyword">if</span> <span class="ruby-identifier">payload</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:payload</span>]
 <span class="ruby-identifier">sql</span> <span class="ruby-operator"><<</span> <span class="ruby-string">", "</span>
 <span class="ruby-identifier">dataset</span>.<span class="ruby-identifier">literal_append</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-identifier">payload</span>.<span class="ruby-identifier">to_s</span>)
 <span class="ruby-keyword">end</span>
 <span class="ruby-identifier">execute_ddl</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-primary_key'>
<a name='method-i-primary_key'></a>
<div class='synopsis'>
<span class='name'>primary_key</span>
<span class='arguments'>(table, opts=OPTS)</span>
</div>
<div class='description'>
<p>Return primary key for the given table.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-primary_key-source'); return false">
[show source]
</a>
<pre id='method-i-primary_key-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 386</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">primary_key</span>(<span class="ruby-identifier">table</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-identifier">quoted_table</span> = <span class="ruby-identifier">quote_schema_table</span>(<span class="ruby-identifier">table</span>)
 <span class="ruby-constant">Sequel</span>.<span class="ruby-identifier">synchronize</span>{<span class="ruby-keyword">return</span> <span class="ruby-ivar">@primary_keys</span>[<span class="ruby-identifier">quoted_table</span>] <span class="ruby-keyword">if</span> <span class="ruby-ivar">@primary_keys</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">quoted_table</span>)}
 <span class="ruby-identifier">sql</span> = <span class="ruby-node">"#{SELECT_PK_SQL} AND pg_class.oid = #{literal(regclass_oid(table, opts))}"</span>
 <span class="ruby-identifier">value</span> = <span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">sql</span>).<span class="ruby-identifier">single_value</span>
 <span class="ruby-constant">Sequel</span>.<span class="ruby-identifier">synchronize</span>{<span class="ruby-ivar">@primary_keys</span>[<span class="ruby-identifier">quoted_table</span>] = <span class="ruby-identifier">value</span>}
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-primary_key_sequence'>
<a name='method-i-primary_key_sequence'></a>
<div class='synopsis'>
<span class='name'>primary_key_sequence</span>
<span class='arguments'>(table, opts=OPTS)</span>
</div>
<div class='description'>
<p>Return the sequence providing the default for the primary key for the given
table.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-primary_key_sequence-source'); return false">
[show source]
</a>
<pre id='method-i-primary_key_sequence-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 395</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">primary_key_sequence</span>(<span class="ruby-identifier">table</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-identifier">quoted_table</span> = <span class="ruby-identifier">quote_schema_table</span>(<span class="ruby-identifier">table</span>)
 <span class="ruby-constant">Sequel</span>.<span class="ruby-identifier">synchronize</span>{<span class="ruby-keyword">return</span> <span class="ruby-ivar">@primary_key_sequences</span>[<span class="ruby-identifier">quoted_table</span>] <span class="ruby-keyword">if</span> <span class="ruby-ivar">@primary_key_sequences</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">quoted_table</span>)}
 <span class="ruby-identifier">sql</span> = <span class="ruby-node">"#{SELECT_SERIAL_SEQUENCE_SQL} AND t.oid = #{literal(regclass_oid(table, opts))}"</span>
 <span class="ruby-keyword">if</span> <span class="ruby-identifier">pks</span> = <span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">sql</span>).<span class="ruby-identifier">single_record</span>
 <span class="ruby-identifier">value</span> = <span class="ruby-identifier">literal</span>(<span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">QualifiedIdentifier</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">pks</span>[<span class="ruby-value">:schema</span>], <span class="ruby-identifier">pks</span>[<span class="ruby-value">:sequence</span>]))
 <span class="ruby-constant">Sequel</span>.<span class="ruby-identifier">synchronize</span>{<span class="ruby-ivar">@primary_key_sequences</span>[<span class="ruby-identifier">quoted_table</span>] = <span class="ruby-identifier">value</span>}
 <span class="ruby-keyword">else</span>
 <span class="ruby-identifier">sql</span> = <span class="ruby-node">"#{SELECT_CUSTOM_SEQUENCE_SQL} AND t.oid = #{literal(regclass_oid(table, opts))}"</span>
 <span class="ruby-keyword">if</span> <span class="ruby-identifier">pks</span> = <span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">sql</span>).<span class="ruby-identifier">single_record</span>
 <span class="ruby-identifier">value</span> = <span class="ruby-identifier">literal</span>(<span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">QualifiedIdentifier</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">pks</span>[<span class="ruby-value">:schema</span>], <span class="ruby-constant">LiteralString</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">pks</span>[<span class="ruby-value">:sequence</span>])))
 <span class="ruby-constant">Sequel</span>.<span class="ruby-identifier">synchronize</span>{<span class="ruby-ivar">@primary_key_sequences</span>[<span class="ruby-identifier">quoted_table</span>] = <span class="ruby-identifier">value</span>}
 <span class="ruby-keyword">end</span>
 <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-refresh_view'>
<a name='method-i-refresh_view'></a>
<div class='synopsis'>
<span class='name'>refresh_view</span>
<span class='arguments'>(name, opts=OPTS)</span>
</div>
<div class='description'>
<p>Refresh the materialized view with the given name.</p>
<pre class="ruby"><span class="ruby-constant">DB</span>.<span class="ruby-identifier">refresh_view</span>(:<span class="ruby-identifier">items_view</span>)
<span class="ruby-comment"># REFRESH MATERIALIZED VIEW items_view</span>
<span class="ruby-constant">DB</span>.<span class="ruby-identifier">refresh_view</span>(:<span class="ruby-identifier">items_view</span>, :<span class="ruby-identifier">concurrently=</span><span class="ruby-operator">></span><span class="ruby-keyword">true</span>)
<span class="ruby-comment"># REFRESH MATERIALIZED VIEW CONCURRENTLY items_view</span></pre>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-refresh_view-source'); return false">
[show source]
</a>
<pre id='method-i-refresh_view-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 417</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">refresh_view</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-identifier">run</span> <span class="ruby-node">"REFRESH MATERIALIZED VIEW#{' CONCURRENTLY' if opts[:concurrently]} #{quote_schema_table(name)}"</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-reset_conversion_procs'>
<a name='method-i-reset_conversion_procs'></a>
<div class='synopsis'>
<span class='name'>reset_conversion_procs</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p>Reset the database's conversion procs, requires a server query if there
any named types.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-reset_conversion_procs-source'); return false">
[show source]
</a>
<pre id='method-i-reset_conversion_procs-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 423</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">reset_conversion_procs</span>
 <span class="ruby-ivar">@conversion_procs</span> = <span class="ruby-identifier">get_conversion_procs</span>
 <span class="ruby-identifier">conversion_procs_updated</span>
 <span class="ruby-ivar">@conversion_procs</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-reset_primary_key_sequence'>
<a name='method-i-reset_primary_key_sequence'></a>
<div class='synopsis'>
<span class='name'>reset_primary_key_sequence</span>
<span class='arguments'>(table)</span>
</div>
<div class='description'>
<p>Reset the primary key sequence for the given table, basing it on the
maximum current value of the table's primary key.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-reset_primary_key_sequence-source'); return false">
[show source]
</a>
<pre id='method-i-reset_primary_key_sequence-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 431</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">reset_primary_key_sequence</span>(<span class="ruby-identifier">table</span>)
 <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">seq</span> = <span class="ruby-identifier">primary_key_sequence</span>(<span class="ruby-identifier">table</span>)
 <span class="ruby-identifier">pk</span> = <span class="ruby-constant">SQL</span><span class="ruby-operator">::</span><span class="ruby-constant">Identifier</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">primary_key</span>(<span class="ruby-identifier">table</span>))
 <span class="ruby-identifier">db</span> = <span class="ruby-keyword">self</span>
 <span class="ruby-identifier">seq_ds</span> = <span class="ruby-identifier">db</span>.<span class="ruby-identifier">from</span>(<span class="ruby-constant">LiteralString</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">seq</span>))
 <span class="ruby-identifier">s</span>, <span class="ruby-identifier">t</span> = <span class="ruby-identifier">schema_and_table</span>(<span class="ruby-identifier">table</span>)
 <span class="ruby-identifier">table</span> = <span class="ruby-constant">Sequel</span>.<span class="ruby-identifier">qualify</span>(<span class="ruby-identifier">s</span>, <span class="ruby-identifier">t</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">s</span>
 <span class="ruby-identifier">get</span>{<span class="ruby-identifier">setval</span>(<span class="ruby-identifier">seq</span>, <span class="ruby-identifier">db</span>[<span class="ruby-identifier">table</span>].<span class="ruby-identifier">select</span>{<span class="ruby-identifier">coalesce</span>(<span class="ruby-identifier">max</span>(<span class="ruby-identifier">pk</span>)<span class="ruby-operator">+</span><span class="ruby-identifier">seq_ds</span>.<span class="ruby-identifier">select</span>{<span class="ruby-value">:increment_by</span>}, <span class="ruby-identifier">seq_ds</span>.<span class="ruby-identifier">select</span>(<span class="ruby-value">:min_value</span>))}, <span class="ruby-keyword">false</span>)}
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-rollback_prepared_transaction'>
<a name='method-i-rollback_prepared_transaction'></a>
<div class='synopsis'>
<span class='name'>rollback_prepared_transaction</span>
<span class='arguments'>(transaction_id, opts=OPTS)</span>
</div>
<div class='description'>
<p>Rollback an existing prepared transaction with the given transaction
identifier string.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-rollback_prepared_transaction-source'); return false">
[show source]
</a>
<pre id='method-i-rollback_prepared_transaction-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 443</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">rollback_prepared_transaction</span>(<span class="ruby-identifier">transaction_id</span>, <span class="ruby-identifier">opts</span>=<span class="ruby-constant">OPTS</span>)
 <span class="ruby-identifier">run</span>(<span class="ruby-node">"ROLLBACK PREPARED #{literal(transaction_id)}"</span>, <span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-serial_primary_key_options'>
<a name='method-i-serial_primary_key_options'></a>
<div class='synopsis'>
<span class='name'>serial_primary_key_options</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p>PostgreSQL uses SERIAL psuedo-type instead of AUTOINCREMENT for managing
incrementing primary keys.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-serial_primary_key_options-source'); return false">
[show source]
</a>
<pre id='method-i-serial_primary_key_options-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 449</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">serial_primary_key_options</span>
 {<span class="ruby-value">:primary_key</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span>, <span class="ruby-value">:serial</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span>, <span class="ruby-value">:type=</span><span class="ruby-operator">></span><span class="ruby-constant">Integer</span>}
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-server_version'>
<a name='method-i-server_version'></a>
<div class='synopsis'>
<span class='name'>server_version</span>
<span class='arguments'>(server=nil)</span>
</div>
<div class='description'>
<p>The version of the PostgreSQL server, used for determining capability.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-server_version-source'); return false">
[show source]
</a>
<pre id='method-i-server_version-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 454</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">server_version</span>(<span class="ruby-identifier">server</span>=<span class="ruby-keyword">nil</span>)
 <span class="ruby-keyword">return</span> <span class="ruby-ivar">@server_version</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@server_version</span>
 <span class="ruby-ivar">@server_version</span> = <span class="ruby-identifier">synchronize</span>(<span class="ruby-identifier">server</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">conn</span><span class="ruby-operator">|</span>
 (<span class="ruby-identifier">conn</span>.<span class="ruby-identifier">server_version</span> <span class="ruby-keyword">rescue</span> <span class="ruby-keyword">nil</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">conn</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:server_version</span>)
 <span class="ruby-keyword">end</span>
 <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@server_version</span>
 <span class="ruby-ivar">@server_version</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">m</span> = <span class="ruby-regexp">/PostgreSQL (\d+)\.(\d+)(?:(?:rc\d+)|\.(\d+))?/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">fetch</span>(<span class="ruby-string">'SELECT version()'</span>).<span class="ruby-identifier">single_value</span>)
 (<span class="ruby-identifier">m</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span> <span class="ruby-operator">*</span> <span class="ruby-value">10000</span>) <span class="ruby-operator">+</span> (<span class="ruby-identifier">m</span>[<span class="ruby-value">2</span>].<span class="ruby-identifier">to_i</span> <span class="ruby-operator">*</span> <span class="ruby-value">100</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">m</span>[<span class="ruby-value">3</span>].<span class="ruby-identifier">to_i</span>
 <span class="ruby-keyword">else</span>
 <span class="ruby-value">0</span>
 <span class="ruby-keyword">end</span>
 <span class="ruby-keyword">end</span>
 <span class="ruby-identifier">warn</span> <span class="ruby-string">'Sequel no longer supports PostgreSQL <8.2, some things may not work'</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@server_version</span> <span class="ruby-operator"><</span> <span class="ruby-value">80200</span>
 <span class="ruby-ivar">@server_version</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-supports_create_table_if_not_exists-3F'>
<a name='method-i-supports_create_table_if_not_exists-3F'></a>
<div class='synopsis'>
<span class='name'>supports_create_table_if_not_exists?</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p>PostgreSQL supports CREATE TABLE IF NOT EXISTS on 9.1+</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-supports_create_table_if_not_exists-3F-source'); return false">
[show source]
</a>
<pre id='method-i-supports_create_table_if_not_exists-3F-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 471</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">supports_create_table_if_not_exists?</span>
 <span class="ruby-identifier">server_version</span> <span class="ruby-operator">>=</span> <span class="ruby-value">90100</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-supports_deferrable_constraints-3F'>
<a name='method-i-supports_deferrable_constraints-3F'></a>
<div class='synopsis'>
<span class='name'>supports_deferrable_constraints?</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p>PostgreSQL 9.0+ supports some types of deferrable constraints beyond
foreign key constraints.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-supports_deferrable_constraints-3F-source'); return false">
[show source]
</a>
<pre id='method-i-supports_deferrable_constraints-3F-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 476</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">supports_deferrable_constraints?</span>
 <span class="ruby-identifier">server_version</span> <span class="ruby-operator">>=</span> <span class="ruby-value">90000</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-supports_deferrable_foreign_key_constraints-3F'>
<a name='method-i-supports_deferrable_foreign_key_constraints-3F'></a>
<div class='synopsis'>
<span class='name'>supports_deferrable_foreign_key_constraints?</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p>PostgreSQL supports deferrable foreign key constraints.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-supports_deferrable_foreign_key_constraints-3F-source'); return false">
[show source]
</a>
<pre id='method-i-supports_deferrable_foreign_key_constraints-3F-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 481</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">supports_deferrable_foreign_key_constraints?</span>
 <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-supports_drop_table_if_exists-3F'>
<a name='method-i-supports_drop_table_if_exists-3F'></a>
<div class='synopsis'>
<span class='name'>supports_drop_table_if_exists?</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p>PostgreSQL supports DROP TABLE IF EXISTS</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-supports_drop_table_if_exists-3F-source'); return false">
[show source]
</a>
<pre id='method-i-supports_drop_table_if_exists-3F-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 486</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">supports_drop_table_if_exists?</span>
 <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-supports_partial_indexes-3F'>
<a name='method-i-supports_partial_indexes-3F'></a>
<div class='synopsis'>
<span class='name'>supports_partial_indexes?</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p>PostgreSQL supports partial indexes.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-supports_partial_indexes-3F-source'); return false">
[show source]
</a>
<pre id='method-i-supports_partial_indexes-3F-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 491</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">supports_partial_indexes?</span>
 <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-supports_prepared_transactions-3F'>
<a name='method-i-supports_prepared_transactions-3F'></a>
<div class='synopsis'>
<span class='name'>supports_prepared_transactions?</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p>PostgreSQL supports prepared transactions (two-phase commit) if
max_prepared_transactions is greater than 0.</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-supports_prepared_transactions-3F-source'); return false">
[show source]
</a>
<pre id='method-i-supports_prepared_transactions-3F-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 502</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">supports_prepared_transactions?</span>
 <span class="ruby-keyword">return</span> <span class="ruby-ivar">@supports_prepared_transactions</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-ivar">@supports_prepared_transactions</span>)
 <span class="ruby-ivar">@supports_prepared_transactions</span> = <span class="ruby-keyword">self</span>[<span class="ruby-string">'SHOW max_prepared_transactions'</span>].<span class="ruby-identifier">get</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-supports_savepoints-3F'>
<a name='method-i-supports_savepoints-3F'></a>
<div class='synopsis'>
<span class='name'>supports_savepoints?</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p>PostgreSQL supports savepoints</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-supports_savepoints-3F-source'); return false">
[show source]
</a>
<pre id='method-i-supports_savepoints-3F-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 508</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">supports_savepoints?</span>
 <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class='method public-instance' id='method-method-i-supports_transaction_isolation_levels-3F'>
<a name='method-i-supports_transaction_isolation_levels-3F'></a>
<div class='synopsis'>
<span class='name'>supports_transaction_isolation_levels?</span>
<span class='arguments'>()</span>
</div>
<div class='description'>
<p>PostgreSQL supports transaction isolation levels</p>
</div>
<div class='source'>
<a class='source-toggle' href='#' onclick="toggleCode('method-i-supports_transaction_isolation_levels-3F-source'); return false">
[show source]
</a>
<pre id='method-i-supports_transaction_isolation_levels-3F-source'><span class="ruby-comment"># File lib/sequel/adapters/shared/postgres.rb, line 513</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">supports_transaction_isolation_levels?</span>
 <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>