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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
U
¸ý°d–¢ãf@sddZddlmZddlmZddlmZddlZddlm    Z    ddlm
Z
ddlm Z dd    lm Z d
d l mZd
d l mZd
d l mZd
dl mZd
dl mZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlm Z d
dlm!Z!d
dl"m#Z#d
dl"m$Z$d
dl"m%Z%d
dl"m&Z&d
dl"m'Z'd
dl"m(Z(d
dl"m)Z)d
d l"m*Z*d
d!l"m+Z+d
d"l"m,Z,d
d#l"m-Z-d
d$l"m.Z.d
d%l"m/Z/d
d&l"m0Z0d
d'l"m1Z1d
d(l"m2Z2d
d)l"m3Z3d
d*l"m4Z4d
d+l"m5Z5d
d,l"m6Z6d
d-l"m7Z7d
d.l"m8Z8d
d/l"m9Z9d
d0l"m:Z:d
d1l"m;Z;d2d3l m<Z<d2d4l m=Z=d2d5l m>Z>d2d6l m?Z?d2d7l m@Z@d2d8lAmBZBd2d9lAmCZCd2d:lAmDZDd2d;lAmEZEd2d<lAmFZFd2d=lAmGZGd2d>lHmIZId2d?l?mJZJd2d@l?mKZKd2dAl?mLZLd2dBl?mMZMd2dCl?mNZNd2dDl?mOZOd2dEl?mPZPd2d7l?m@ZQd2dFlRmSZSd2dGlTmUZUd2dHl"mVZVd2dIl"mWZWd2dJl"mXZXd2dKl"mYZYd2dLl"mZZZd2dMl"m[Z[d2dNl"m\Z\d2dOl"m]Z]d2dPl"m^Z^d2dQl"m_Z_d2dRl"m`Z`d2dSl"maZad2dTl"mbZbd2dUlcmdZde edVejf¡ZgdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dd€dd‚dƒd„d…d†d‡dˆd‰dŠd‹dŒddŽddd‘d’d“d”d•d–d—d˜d™dšd›dœddždŸd d¡d¢d£d¤d¥d¦d§d¨d©dªd«d¬d­d®d¯d°d±d²d³d´dµd¶d·d¸d¹dºd»d¼hfZhePjiejiePjje+ePjke ePjljmejnePjlejleae6iZoejiejpejlejqejrejsejtejuejvejwejxejyejzej{ej|ej}e\eVe_ebeXePj~ePj~e`e]e[e^e*e(e)eae&e&e,e-e.e/e7eZe:e:e:e9e9eYe9e'eWe+e;d½œ2ZGd¾d¿„d¿eLj€ƒZGdÀdÁ„dÁeLj‚ƒZƒGdÂdÄdÃeLj„ƒZ…GdÄdńdÅeLj†ƒZ‡GdÆdDŽdÇedƒZˆGdÈdɄdÉedƒZ‰GdÊd˄dËeˆƒZŠGdÌd̈́dÍeˆƒZ‹GdÎdτdÏeGjŒƒZGdÐdфdÑeCjŽƒZGdÒdӄdÓeBjƒZ‘GdÔdՄdÕeBjƒZ’GdÖdׄd×eCj“ƒZ”dS)Øa.É
.. dialect:: postgresql
    :name: PostgreSQL
    :full_support: 9.6, 10, 11, 12, 13, 14
    :normal_support: 9.6+
    :best_effort: 9+
 
.. _postgresql_sequences:
 
Sequences/SERIAL/IDENTITY
-------------------------
 
PostgreSQL supports sequences, and SQLAlchemy uses these as the default means
of creating new primary key values for integer-based primary key columns. When
creating tables, SQLAlchemy will issue the ``SERIAL`` datatype for
integer-based primary key columns, which generates a sequence and server side
default corresponding to the column.
 
To specify a specific named sequence to be used for primary key generation,
use the :func:`~sqlalchemy.schema.Sequence` construct::
 
    Table(
        "sometable",
        metadata,
        Column(
            "id", Integer, Sequence("some_id_seq", start=1), primary_key=True
        )
    )
 
When SQLAlchemy issues a single INSERT statement, to fulfill the contract of
having the "last insert identifier" available, a RETURNING clause is added to
the INSERT statement which specifies the primary key columns should be
returned after the statement completes. The RETURNING functionality only takes
place if PostgreSQL 8.2 or later is in use. As a fallback approach, the
sequence, whether specified explicitly or implicitly via ``SERIAL``, is
executed independently beforehand, the returned value to be used in the
subsequent insert. Note that when an
:func:`~sqlalchemy.sql.expression.insert()` construct is executed using
"executemany" semantics, the "last inserted identifier" functionality does not
apply; no RETURNING clause is emitted nor is the sequence pre-executed in this
case.
 
 
PostgreSQL 10 and above IDENTITY columns
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
PostgreSQL 10 and above have a new IDENTITY feature that supersedes the use
of SERIAL. The :class:`_schema.Identity` construct in a
:class:`_schema.Column` can be used to control its behavior::
 
    from sqlalchemy import Table, Column, MetaData, Integer, Computed
 
    metadata = MetaData()
 
    data = Table(
        "data",
        metadata,
        Column(
            'id', Integer, Identity(start=42, cycle=True), primary_key=True
        ),
        Column('data', String)
    )
 
The CREATE TABLE for the above :class:`_schema.Table` object would be:
 
.. sourcecode:: sql
 
    CREATE TABLE data (
        id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 42 CYCLE),
        data VARCHAR,
        PRIMARY KEY (id)
    )
 
.. versionchanged::  1.4   Added :class:`_schema.Identity` construct
   in a :class:`_schema.Column` to specify the option of an autoincrementing
   column.
 
.. note::
 
   Previous versions of SQLAlchemy did not have built-in support for rendering
   of IDENTITY, and could use the following compilation hook to replace
   occurrences of SERIAL with IDENTITY::
 
       from sqlalchemy.schema import CreateColumn
       from sqlalchemy.ext.compiler import compiles
 
 
       @compiles(CreateColumn, 'postgresql')
       def use_identity(element, compiler, **kw):
           text = compiler.visit_create_column(element, **kw)
           text = text.replace(
               "SERIAL", "INT GENERATED BY DEFAULT AS IDENTITY"
            )
           return text
 
   Using the above, a table such as::
 
       t = Table(
           't', m,
           Column('id', Integer, primary_key=True),
           Column('data', String)
       )
 
   Will generate on the backing database as::
 
       CREATE TABLE t (
           id INT GENERATED BY DEFAULT AS IDENTITY,
           data VARCHAR,
           PRIMARY KEY (id)
       )
 
.. _postgresql_ss_cursors:
 
Server Side Cursors
-------------------
 
Server-side cursor support is available for the psycopg2, asyncpg
dialects and may also be available in others.
 
Server side cursors are enabled on a per-statement basis by using the
:paramref:`.Connection.execution_options.stream_results` connection execution
option::
 
    with engine.connect() as conn:
        result = conn.execution_options(stream_results=True).execute(text("select * from table"))
 
Note that some kinds of SQL statements may not be supported with
server side cursors; generally, only SQL statements that return rows should be
used with this option.
 
.. deprecated:: 1.4  The dialect-level server_side_cursors flag is deprecated
   and will be removed in a future release.  Please use the
   :paramref:`_engine.Connection.stream_results` execution option for
   unbuffered cursor support.
 
.. seealso::
 
    :ref:`engine_stream_results`
 
.. _postgresql_isolation_level:
 
Transaction Isolation Level
---------------------------
 
Most SQLAlchemy dialects support setting of transaction isolation level
using the :paramref:`_sa.create_engine.isolation_level` parameter
at the :func:`_sa.create_engine` level, and at the :class:`_engine.Connection`
level via the :paramref:`.Connection.execution_options.isolation_level`
parameter.
 
For PostgreSQL dialects, this feature works either by making use of the
DBAPI-specific features, such as psycopg2's isolation level flags which will
embed the isolation level setting inline with the ``"BEGIN"`` statement, or for
DBAPIs with no direct support by emitting ``SET SESSION CHARACTERISTICS AS
TRANSACTION ISOLATION LEVEL <level>`` ahead of the ``"BEGIN"`` statement
emitted by the DBAPI.   For the special AUTOCOMMIT isolation level,
DBAPI-specific techniques are used which is typically an ``.autocommit``
flag on the DBAPI connection object.
 
To set isolation level using :func:`_sa.create_engine`::
 
    engine = create_engine(
        "postgresql+pg8000://scott:tiger@localhost/test",
        isolation_level = "REPEATABLE READ"
    )
 
To set using per-connection execution options::
 
    with engine.connect() as conn:
        conn = conn.execution_options(
            isolation_level="REPEATABLE READ"
        )
        with conn.begin():
            # ... work with transaction
 
There are also more options for isolation level configurations, such as
"sub-engine" objects linked to a main :class:`_engine.Engine` which each apply
different isolation level settings.  See the discussion at
:ref:`dbapi_autocommit` for background.
 
Valid values for ``isolation_level`` on most PostgreSQL dialects include:
 
* ``READ COMMITTED``
* ``READ UNCOMMITTED``
* ``REPEATABLE READ``
* ``SERIALIZABLE``
* ``AUTOCOMMIT``
 
.. seealso::
 
    :ref:`dbapi_autocommit`
 
    :ref:`postgresql_readonly_deferrable`
 
    :ref:`psycopg2_isolation_level`
 
    :ref:`pg8000_isolation_level`
 
.. _postgresql_readonly_deferrable:
 
Setting READ ONLY / DEFERRABLE
------------------------------
 
Most PostgreSQL dialects support setting the "READ ONLY" and "DEFERRABLE"
characteristics of the transaction, which is in addition to the isolation level
setting. These two attributes can be established either in conjunction with or
independently of the isolation level by passing the ``postgresql_readonly`` and
``postgresql_deferrable`` flags with
:meth:`_engine.Connection.execution_options`.  The example below illustrates
passing the ``"SERIALIZABLE"`` isolation level at the same time as setting
"READ ONLY" and "DEFERRABLE"::
 
    with engine.connect() as conn:
        conn = conn.execution_options(
            isolation_level="SERIALIZABLE",
            postgresql_readonly=True,
            postgresql_deferrable=True
        )
        with conn.begin():
            #  ... work with transaction
 
Note that some DBAPIs such as asyncpg only support "readonly" with
SERIALIZABLE isolation.
 
.. versionadded:: 1.4 added support for the ``postgresql_readonly``
   and ``postgresql_deferrable`` execution options.
 
.. _postgresql_reset_on_return:
 
Temporary Table / Resource Reset for Connection Pooling
-------------------------------------------------------
 
The :class:`.QueuePool` connection pool implementation used
by the SQLAlchemy :class:`.Engine` object includes
:ref:`reset on return <pool_reset_on_return>` behavior that will invoke
the DBAPI ``.rollback()`` method when connections are returned to the pool.
While this rollback will clear out the immediate state used by the previous
transaction, it does not cover a wider range of session-level state, including
temporary tables as well as other server state such as prepared statement
handles and statement caches.   The PostgreSQL database includes a variety
of commands which may be used to reset this state, including
``DISCARD``, ``RESET``, ``DEALLOCATE``, and ``UNLISTEN``.
 
 
To install
one or more of these commands as the means of performing reset-on-return,
the :meth:`.PoolEvents.reset` event hook may be used, as demonstrated
in the example below. The implementation
will end transactions in progress as well as discard temporary tables
using the ``CLOSE``, ``RESET`` and ``DISCARD`` commands; see the PostgreSQL
documentation for background on what each of these statements do.
 
The :paramref:`_sa.create_engine.pool_reset_on_return` parameter
is set to ``None`` so that the custom scheme can replace the default behavior
completely.   The custom hook implementation calls ``.rollback()`` in any case,
as it's usually important that the DBAPI's own tracking of commit/rollback
will remain consistent with the state of the transaction::
 
 
    from sqlalchemy import create_engine
    from sqlalchemy import event
 
    postgresql_engine = create_engine(
        "postgresql+pyscopg2://scott:tiger@hostname/dbname",
 
        # disable default reset-on-return scheme
        pool_reset_on_return=None,
    )
 
 
    @event.listens_for(postgresql_engine, "reset")
    def _reset_postgresql(dbapi_connection, connection_record, reset_state):
        if not reset_state.terminate_only:
            dbapi_connection.execute("CLOSE ALL")
            dbapi_connection.execute("RESET ALL")
            dbapi_connection.execute("DISCARD TEMP")
 
        # so that the DBAPI itself knows that the connection has been
        # reset
        dbapi_connection.rollback()
 
.. versionchanged:: 2.0.0b3  Added additional state arguments to
   the :meth:`.PoolEvents.reset` event and additionally ensured the event
   is invoked for all "reset" occurrences, so that it's appropriate
   as a place for custom "reset" handlers.   Previous schemes which
   use the :meth:`.PoolEvents.checkin` handler remain usable as well.
 
.. seealso::
 
    :ref:`pool_reset_on_return` - in the :ref:`pooling_toplevel` documentation
 
.. _postgresql_alternate_search_path:
 
Setting Alternate Search Paths on Connect
------------------------------------------
 
The PostgreSQL ``search_path`` variable refers to the list of schema names
that will be implicitly referred towards when a particular table or other
object is referenced in a SQL statement.  As detailed in the next section
:ref:`postgresql_schema_reflection`, SQLAlchemy is generally organized around
the concept of keeping this variable at its default value of ``public``,
however, in order to have it set to any arbitrary name or names when connections
are used automatically, the "SET SESSION search_path" command may be invoked
for all connections in a pool using the following event handler, as discussed
at :ref:`schema_set_default_connections`::
 
    from sqlalchemy import event
    from sqlalchemy import create_engine
 
    engine = create_engine("postgresql+psycopg2://scott:tiger@host/dbname")
 
    @event.listens_for(engine, "connect", insert=True)
    def set_search_path(dbapi_connection, connection_record):
        existing_autocommit = dbapi_connection.autocommit
        dbapi_connection.autocommit = True
        cursor = dbapi_connection.cursor()
        cursor.execute("SET SESSION search_path='%s'" % schema_name)
        cursor.close()
        dbapi_connection.autocommit = existing_autocommit
 
The reason the recipe is complicated by use of the ``.autocommit`` DBAPI
attribute is so that when the ``SET SESSION search_path`` directive is invoked,
it is invoked outside of the scope of any transaction and therefore will not
be reverted when the DBAPI connection has a rollback.
 
.. seealso::
 
  :ref:`schema_set_default_connections` - in the :ref:`metadata_toplevel` documentation
 
 
 
 
.. _postgresql_schema_reflection:
 
Remote-Schema Table Introspection and PostgreSQL search_path
------------------------------------------------------------
 
.. admonition:: Section Best Practices Summarized
 
    keep the ``search_path`` variable set to its default of ``public``, without
    any other schema names. For other schema names, name these explicitly
    within :class:`_schema.Table` definitions. Alternatively, the
    ``postgresql_ignore_search_path`` option will cause all reflected
    :class:`_schema.Table` objects to have a :attr:`_schema.Table.schema`
    attribute set up.
 
The PostgreSQL dialect can reflect tables from any schema, as outlined in
:ref:`metadata_reflection_schemas`.
 
With regards to tables which these :class:`_schema.Table`
objects refer to via foreign key constraint, a decision must be made as to how
the ``.schema`` is represented in those remote tables, in the case where that
remote schema name is also a member of the current
`PostgreSQL search path
<https://www.postgresql.org/docs/current/static/ddl-schemas.html#DDL-SCHEMAS-PATH>`_.
 
By default, the PostgreSQL dialect mimics the behavior encouraged by
PostgreSQL's own ``pg_get_constraintdef()`` builtin procedure.  This function
returns a sample definition for a particular foreign key constraint,
omitting the referenced schema name from that definition when the name is
also in the PostgreSQL schema search path.  The interaction below
illustrates this behavior::
 
    test=> CREATE TABLE test_schema.referred(id INTEGER PRIMARY KEY);
    CREATE TABLE
    test=> CREATE TABLE referring(
    test(>         id INTEGER PRIMARY KEY,
    test(>         referred_id INTEGER REFERENCES test_schema.referred(id));
    CREATE TABLE
    test=> SET search_path TO public, test_schema;
    test=> SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM
    test-> pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n
    test-> ON n.oid = c.relnamespace
    test-> JOIN pg_catalog.pg_constraint r  ON c.oid = r.conrelid
    test-> WHERE c.relname='referring' AND r.contype = 'f'
    test-> ;
                   pg_get_constraintdef
    ---------------------------------------------------
     FOREIGN KEY (referred_id) REFERENCES referred(id)
    (1 row)
 
Above, we created a table ``referred`` as a member of the remote schema
``test_schema``, however when we added ``test_schema`` to the
PG ``search_path`` and then asked ``pg_get_constraintdef()`` for the
``FOREIGN KEY`` syntax, ``test_schema`` was not included in the output of
the function.
 
On the other hand, if we set the search path back to the typical default
of ``public``::
 
    test=> SET search_path TO public;
    SET
 
The same query against ``pg_get_constraintdef()`` now returns the fully
schema-qualified name for us::
 
    test=> SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM
    test-> pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n
    test-> ON n.oid = c.relnamespace
    test-> JOIN pg_catalog.pg_constraint r  ON c.oid = r.conrelid
    test-> WHERE c.relname='referring' AND r.contype = 'f';
                         pg_get_constraintdef
    ---------------------------------------------------------------
     FOREIGN KEY (referred_id) REFERENCES test_schema.referred(id)
    (1 row)
 
SQLAlchemy will by default use the return value of ``pg_get_constraintdef()``
in order to determine the remote schema name.  That is, if our ``search_path``
were set to include ``test_schema``, and we invoked a table
reflection process as follows::
 
    >>> from sqlalchemy import Table, MetaData, create_engine, text
    >>> engine = create_engine("postgresql+psycopg2://scott:tiger@localhost/test")
    >>> with engine.connect() as conn:
    ...     conn.execute(text("SET search_path TO test_schema, public"))
    ...     metadata_obj = MetaData()
    ...     referring = Table('referring', metadata_obj,
    ...                       autoload_with=conn)
    ...
    <sqlalchemy.engine.result.CursorResult object at 0x101612ed0>
 
The above process would deliver to the :attr:`_schema.MetaData.tables`
collection
``referred`` table named **without** the schema::
 
    >>> metadata_obj.tables['referred'].schema is None
    True
 
To alter the behavior of reflection such that the referred schema is
maintained regardless of the ``search_path`` setting, use the
``postgresql_ignore_search_path`` option, which can be specified as a
dialect-specific argument to both :class:`_schema.Table` as well as
:meth:`_schema.MetaData.reflect`::
 
    >>> with engine.connect() as conn:
    ...     conn.execute(text("SET search_path TO test_schema, public"))
    ...     metadata_obj = MetaData()
    ...     referring = Table('referring', metadata_obj,
    ...                       autoload_with=conn,
    ...                       postgresql_ignore_search_path=True)
    ...
    <sqlalchemy.engine.result.CursorResult object at 0x1016126d0>
 
We will now have ``test_schema.referred`` stored as schema-qualified::
 
    >>> metadata_obj.tables['test_schema.referred'].schema
    'test_schema'
 
.. sidebar:: Best Practices for PostgreSQL Schema reflection
 
    The description of PostgreSQL schema reflection behavior is complex, and
    is the product of many years of dealing with widely varied use cases and
    user preferences. But in fact, there's no need to understand any of it if
    you just stick to the simplest use pattern: leave the ``search_path`` set
    to its default of ``public`` only, never refer to the name ``public`` as
    an explicit schema name otherwise, and refer to all other schema names
    explicitly when building up a :class:`_schema.Table` object.  The options
    described here are only for those users who can't, or prefer not to, stay
    within these guidelines.
 
Note that **in all cases**, the "default" schema is always reflected as
``None``. The "default" schema on PostgreSQL is that which is returned by the
PostgreSQL ``current_schema()`` function.  On a typical PostgreSQL
installation, this is the name ``public``.  So a table that refers to another
which is in the ``public`` (i.e. default) schema will always have the
``.schema`` attribute set to ``None``.
 
.. seealso::
 
    :ref:`reflection_schema_qualified_interaction` - discussion of the issue
    from a backend-agnostic perspective
 
    `The Schema Search Path
    <https://www.postgresql.org/docs/current/static/ddl-schemas.html#DDL-SCHEMAS-PATH>`_
    - on the PostgreSQL website.
 
INSERT/UPDATE...RETURNING
-------------------------
 
The dialect supports PG 8.2's ``INSERT..RETURNING``, ``UPDATE..RETURNING`` and
``DELETE..RETURNING`` syntaxes.   ``INSERT..RETURNING`` is used by default
for single-row INSERT statements in order to fetch newly generated
primary key identifiers.   To specify an explicit ``RETURNING`` clause,
use the :meth:`._UpdateBase.returning` method on a per-statement basis::
 
    # INSERT..RETURNING
    result = table.insert().returning(table.c.col1, table.c.col2).\
        values(name='foo')
    print(result.fetchall())
 
    # UPDATE..RETURNING
    result = table.update().returning(table.c.col1, table.c.col2).\
        where(table.c.name=='foo').values(name='bar')
    print(result.fetchall())
 
    # DELETE..RETURNING
    result = table.delete().returning(table.c.col1, table.c.col2).\
        where(table.c.name=='foo')
    print(result.fetchall())
 
.. _postgresql_insert_on_conflict:
 
INSERT...ON CONFLICT (Upsert)
------------------------------
 
Starting with version 9.5, PostgreSQL allows "upserts" (update or insert) of
rows into a table via the ``ON CONFLICT`` clause of the ``INSERT`` statement. A
candidate row will only be inserted if that row does not violate any unique
constraints.  In the case of a unique constraint violation, a secondary action
can occur which can be either "DO UPDATE", indicating that the data in the
target row should be updated, or "DO NOTHING", which indicates to silently skip
this row.
 
Conflicts are determined using existing unique constraints and indexes.  These
constraints may be identified either using their name as stated in DDL,
or they may be inferred by stating the columns and conditions that comprise
the indexes.
 
SQLAlchemy provides ``ON CONFLICT`` support via the PostgreSQL-specific
:func:`_postgresql.insert()` function, which provides
the generative methods :meth:`_postgresql.Insert.on_conflict_do_update`
and :meth:`~.postgresql.Insert.on_conflict_do_nothing`:
 
.. sourcecode:: pycon+sql
 
    >>> from sqlalchemy.dialects.postgresql import insert
    >>> insert_stmt = insert(my_table).values(
    ...     id='some_existing_id',
    ...     data='inserted value')
    >>> do_nothing_stmt = insert_stmt.on_conflict_do_nothing(
    ...     index_elements=['id']
    ... )
    >>> print(do_nothing_stmt)
    {printsql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s)
    ON CONFLICT (id) DO NOTHING
    {stop}
 
    >>> do_update_stmt = insert_stmt.on_conflict_do_update(
    ...     constraint='pk_my_table',
    ...     set_=dict(data='updated value')
    ... )
    >>> print(do_update_stmt)
    {printsql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s)
    ON CONFLICT ON CONSTRAINT pk_my_table DO UPDATE SET data = %(param_1)s
 
.. seealso::
 
    `INSERT .. ON CONFLICT
    <https://www.postgresql.org/docs/current/static/sql-insert.html#SQL-ON-CONFLICT>`_
    - in the PostgreSQL documentation.
 
Specifying the Target
^^^^^^^^^^^^^^^^^^^^^
 
Both methods supply the "target" of the conflict using either the
named constraint or by column inference:
 
* The :paramref:`_postgresql.Insert.on_conflict_do_update.index_elements` argument
  specifies a sequence containing string column names, :class:`_schema.Column`
  objects, and/or SQL expression elements, which would identify a unique
  index:
 
  .. sourcecode:: pycon+sql
 
    >>> do_update_stmt = insert_stmt.on_conflict_do_update(
    ...     index_elements=['id'],
    ...     set_=dict(data='updated value')
    ... )
    >>> print(do_update_stmt)
    {printsql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s)
    ON CONFLICT (id) DO UPDATE SET data = %(param_1)s
    {stop}
 
    >>> do_update_stmt = insert_stmt.on_conflict_do_update(
    ...     index_elements=[my_table.c.id],
    ...     set_=dict(data='updated value')
    ... )
    >>> print(do_update_stmt)
    {printsql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s)
    ON CONFLICT (id) DO UPDATE SET data = %(param_1)s
 
* When using :paramref:`_postgresql.Insert.on_conflict_do_update.index_elements` to
  infer an index, a partial index can be inferred by also specifying the
  use the :paramref:`_postgresql.Insert.on_conflict_do_update.index_where` parameter:
 
  .. sourcecode:: pycon+sql
 
    >>> stmt = insert(my_table).values(user_email='a@b.com', data='inserted data')
    >>> stmt = stmt.on_conflict_do_update(
    ...     index_elements=[my_table.c.user_email],
    ...     index_where=my_table.c.user_email.like('%@gmail.com'),
    ...     set_=dict(data=stmt.excluded.data)
    ... )
    >>> print(stmt)
    {printsql}INSERT INTO my_table (data, user_email)
    VALUES (%(data)s, %(user_email)s) ON CONFLICT (user_email)
    WHERE user_email LIKE %(user_email_1)s DO UPDATE SET data = excluded.data
 
* The :paramref:`_postgresql.Insert.on_conflict_do_update.constraint` argument is
  used to specify an index directly rather than inferring it.  This can be
  the name of a UNIQUE constraint, a PRIMARY KEY constraint, or an INDEX:
 
  .. sourcecode:: pycon+sql
 
    >>> do_update_stmt = insert_stmt.on_conflict_do_update(
    ...     constraint='my_table_idx_1',
    ...     set_=dict(data='updated value')
    ... )
    >>> print(do_update_stmt)
    {printsql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s)
    ON CONFLICT ON CONSTRAINT my_table_idx_1 DO UPDATE SET data = %(param_1)s
    {stop}
 
    >>> do_update_stmt = insert_stmt.on_conflict_do_update(
    ...     constraint='my_table_pk',
    ...     set_=dict(data='updated value')
    ... )
    >>> print(do_update_stmt)
    {printsql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s)
    ON CONFLICT ON CONSTRAINT my_table_pk DO UPDATE SET data = %(param_1)s
    {stop}
 
* The :paramref:`_postgresql.Insert.on_conflict_do_update.constraint` argument may
  also refer to a SQLAlchemy construct representing a constraint,
  e.g. :class:`.UniqueConstraint`, :class:`.PrimaryKeyConstraint`,
  :class:`.Index`, or :class:`.ExcludeConstraint`.   In this use,
  if the constraint has a name, it is used directly.  Otherwise, if the
  constraint is unnamed, then inference will be used, where the expressions
  and optional WHERE clause of the constraint will be spelled out in the
  construct.  This use is especially convenient
  to refer to the named or unnamed primary key of a :class:`_schema.Table`
  using the
  :attr:`_schema.Table.primary_key` attribute:
 
  .. sourcecode:: pycon+sql
 
    >>> do_update_stmt = insert_stmt.on_conflict_do_update(
    ...     constraint=my_table.primary_key,
    ...     set_=dict(data='updated value')
    ... )
    >>> print(do_update_stmt)
    {printsql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s)
    ON CONFLICT (id) DO UPDATE SET data = %(param_1)s
 
The SET Clause
^^^^^^^^^^^^^^^
 
``ON CONFLICT...DO UPDATE`` is used to perform an update of the already
existing row, using any combination of new values as well as values
from the proposed insertion.   These values are specified using the
:paramref:`_postgresql.Insert.on_conflict_do_update.set_` parameter.  This
parameter accepts a dictionary which consists of direct values
for UPDATE:
 
.. sourcecode:: pycon+sql
 
    >>> stmt = insert(my_table).values(id='some_id', data='inserted value')
    >>> do_update_stmt = stmt.on_conflict_do_update(
    ...     index_elements=['id'],
    ...     set_=dict(data='updated value')
    ... )
    >>> print(do_update_stmt)
    {printsql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s)
    ON CONFLICT (id) DO UPDATE SET data = %(param_1)s
 
.. warning::
 
    The :meth:`_expression.Insert.on_conflict_do_update`
    method does **not** take into
    account Python-side default UPDATE values or generation functions, e.g.
    those specified using :paramref:`_schema.Column.onupdate`.
    These values will not be exercised for an ON CONFLICT style of UPDATE,
    unless they are manually specified in the
    :paramref:`_postgresql.Insert.on_conflict_do_update.set_` dictionary.
 
Updating using the Excluded INSERT Values
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
In order to refer to the proposed insertion row, the special alias
:attr:`~.postgresql.Insert.excluded` is available as an attribute on
the :class:`_postgresql.Insert` object; this object is a
:class:`_expression.ColumnCollection`
which alias contains all columns of the target
table:
 
.. sourcecode:: pycon+sql
 
    >>> stmt = insert(my_table).values(
    ...     id='some_id',
    ...     data='inserted value',
    ...     author='jlh'
    ... )
    >>> do_update_stmt = stmt.on_conflict_do_update(
    ...     index_elements=['id'],
    ...     set_=dict(data='updated value', author=stmt.excluded.author)
    ... )
    >>> print(do_update_stmt)
    {printsql}INSERT INTO my_table (id, data, author)
    VALUES (%(id)s, %(data)s, %(author)s)
    ON CONFLICT (id) DO UPDATE SET data = %(param_1)s, author = excluded.author
 
Additional WHERE Criteria
^^^^^^^^^^^^^^^^^^^^^^^^^
 
The :meth:`_expression.Insert.on_conflict_do_update` method also accepts
a WHERE clause using the :paramref:`_postgresql.Insert.on_conflict_do_update.where`
parameter, which will limit those rows which receive an UPDATE:
 
.. sourcecode:: pycon+sql
 
    >>> stmt = insert(my_table).values(
    ...     id='some_id',
    ...     data='inserted value',
    ...     author='jlh'
    ... )
    >>> on_update_stmt = stmt.on_conflict_do_update(
    ...     index_elements=['id'],
    ...     set_=dict(data='updated value', author=stmt.excluded.author),
    ...     where=(my_table.c.status == 2)
    ... )
    >>> print(on_update_stmt)
    {printsql}INSERT INTO my_table (id, data, author)
    VALUES (%(id)s, %(data)s, %(author)s)
    ON CONFLICT (id) DO UPDATE SET data = %(param_1)s, author = excluded.author
    WHERE my_table.status = %(status_1)s
 
Skipping Rows with DO NOTHING
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
``ON CONFLICT`` may be used to skip inserting a row entirely
if any conflict with a unique or exclusion constraint occurs; below
this is illustrated using the
:meth:`~.postgresql.Insert.on_conflict_do_nothing` method:
 
.. sourcecode:: pycon+sql
 
    >>> stmt = insert(my_table).values(id='some_id', data='inserted value')
    >>> stmt = stmt.on_conflict_do_nothing(index_elements=['id'])
    >>> print(stmt)
    {printsql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s)
    ON CONFLICT (id) DO NOTHING
 
If ``DO NOTHING`` is used without specifying any columns or constraint,
it has the effect of skipping the INSERT for any unique or exclusion
constraint violation which occurs:
 
.. sourcecode:: pycon+sql
 
    >>> stmt = insert(my_table).values(id='some_id', data='inserted value')
    >>> stmt = stmt.on_conflict_do_nothing()
    >>> print(stmt)
    {printsql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s)
    ON CONFLICT DO NOTHING
 
.. _postgresql_match:
 
Full Text Search
----------------
 
PostgreSQL's full text search system is available through the use of the
:data:`.func` namespace, combined with the use of custom operators
via the :meth:`.Operators.bool_op` method.    For simple cases with some
degree of cross-backend compatibility, the :meth:`.Operators.match` operator
may also be used.
 
.. _postgresql_simple_match:
 
Simple plain text matching with ``match()``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
The :meth:`.Operators.match` operator provides for cross-compatible simple
text matching.   For the PostgreSQL backend, it's hardcoded to generate
an expression using the ``@@`` operator in conjunction with the
``plainto_tsquery()`` PostgreSQL function.
 
On the PostgreSQL dialect, an expression like the following::
 
    select(sometable.c.text.match("search string"))
 
would emit to the database::
 
    SELECT text @@ plainto_tsquery('search string') FROM table
 
Above, passing a plain string to :meth:`.Operators.match` will automatically
make use of ``plainto_tsquery()`` to specify the type of tsquery.  This
establishes basic database cross-compatibility for :meth:`.Operators.match`
with other backends.
 
.. versionchanged:: 2.0 The default tsquery generation function used by the
   PostgreSQL dialect with :meth:`.Operators.match` is ``plainto_tsquery()``.
 
   To render exactly what was rendered in 1.4, use the following form::
 
        from sqlalchemy import func
 
        select(
            sometable.c.text.bool_op("@@")(func.to_tsquery("search string"))
        )
 
   Which would emit::
 
        SELECT text @@ to_tsquery('search string') FROM table
 
Using PostgreSQL full text functions and operators directly
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
Text search operations beyond the simple use of :meth:`.Operators.match`
may make use of the :data:`.func` namespace to generate PostgreSQL full-text
functions, in combination with :meth:`.Operators.bool_op` to generate
any boolean operator.
 
For example, the query::
 
    select(
        func.to_tsquery('cat').bool_op("@>")(func.to_tsquery('cat & rat'))
    )
 
would generate:
 
.. sourcecode:: sql
 
    SELECT to_tsquery('cat') @> to_tsquery('cat & rat')
 
 
The :class:`_postgresql.TSVECTOR` type can provide for explicit CAST::
 
    from sqlalchemy.dialects.postgresql import TSVECTOR
    from sqlalchemy import select, cast
    select(cast("some text", TSVECTOR))
 
produces a statement equivalent to::
 
    SELECT CAST('some text' AS TSVECTOR) AS anon_1
 
The ``func`` namespace is augmented by the PostgreSQL dialect to set up
correct argument and return types for most full text search functions.
These functions are used automatically by the :attr:`_sql.func` namespace
assuming the ``sqlalchemy.dialects.postgresql`` package has been imported,
or :func:`_sa.create_engine` has been invoked using a ``postgresql``
dialect.  These functions are documented at:
 
* :class:`_postgresql.to_tsvector`
* :class:`_postgresql.to_tsquery`
* :class:`_postgresql.plainto_tsquery`
* :class:`_postgresql.phraseto_tsquery`
* :class:`_postgresql.websearch_to_tsquery`
* :class:`_postgresql.ts_headline`
 
Specifying the "regconfig" with ``match()`` or custom operators
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
PostgreSQL's ``plainto_tsquery()`` function accepts an optional
"regconfig" argument that is used to instruct PostgreSQL to use a
particular pre-computed GIN or GiST index in order to perform the search.
When using :meth:`.Operators.match`, this additional parameter may be
specified using the ``postgresql_regconfig`` parameter, such as::
 
    select(mytable.c.id).where(
        mytable.c.title.match('somestring', postgresql_regconfig='english')
    )
 
Which would emit::
 
    SELECT mytable.id FROM mytable
    WHERE mytable.title @@ plainto_tsquery('english', 'somestring')
 
When using other PostgreSQL search functions with :data:`.func`, the
"regconfig" parameter may be passed directly as the initial argument::
 
    select(mytable.c.id).where(
        func.to_tsvector("english", mytable.c.title).bool_op("@@")(
            func.to_tsquery("english", "somestring")
        )
    )
 
produces a statement equivalent to::
 
    SELECT mytable.id FROM mytable
    WHERE to_tsvector('english', mytable.title) @@
        to_tsquery('english', 'somestring')
 
It is recommended that you use the ``EXPLAIN ANALYZE...`` tool from
PostgreSQL to ensure that you are generating queries with SQLAlchemy that
take full advantage of any indexes you may have created for full text search.
 
.. seealso::
 
    `Full Text Search <https://www.postgresql.org/docs/current/textsearch-controls.html>`_ - in the PostgreSQL documentation
 
 
FROM ONLY ...
-------------
 
The dialect supports PostgreSQL's ONLY keyword for targeting only a particular
table in an inheritance hierarchy. This can be used to produce the
``SELECT ... FROM ONLY``, ``UPDATE ONLY ...``, and ``DELETE FROM ONLY ...``
syntaxes. It uses SQLAlchemy's hints mechanism::
 
    # SELECT ... FROM ONLY ...
    result = table.select().with_hint(table, 'ONLY', 'postgresql')
    print(result.fetchall())
 
    # UPDATE ONLY ...
    table.update(values=dict(foo='bar')).with_hint('ONLY',
                                                   dialect_name='postgresql')
 
    # DELETE FROM ONLY ...
    table.delete().with_hint('ONLY', dialect_name='postgresql')
 
 
.. _postgresql_indexes:
 
PostgreSQL-Specific Index Options
---------------------------------
 
Several extensions to the :class:`.Index` construct are available, specific
to the PostgreSQL dialect.
 
Covering Indexes
^^^^^^^^^^^^^^^^
 
The ``postgresql_include`` option renders INCLUDE(colname) for the given
string names::
 
    Index("my_index", table.c.x, postgresql_include=['y'])
 
would render the index as ``CREATE INDEX my_index ON table (x) INCLUDE (y)``
 
Note that this feature requires PostgreSQL 11 or later.
 
.. versionadded:: 1.4
 
.. _postgresql_partial_indexes:
 
Partial Indexes
^^^^^^^^^^^^^^^
 
Partial indexes add criterion to the index definition so that the index is
applied to a subset of rows.   These can be specified on :class:`.Index`
using the ``postgresql_where`` keyword argument::
 
  Index('my_index', my_table.c.id, postgresql_where=my_table.c.value > 10)
 
.. _postgresql_operator_classes:
 
Operator Classes
^^^^^^^^^^^^^^^^
 
PostgreSQL allows the specification of an *operator class* for each column of
an index (see
https://www.postgresql.org/docs/current/interactive/indexes-opclass.html).
The :class:`.Index` construct allows these to be specified via the
``postgresql_ops`` keyword argument::
 
    Index(
        'my_index', my_table.c.id, my_table.c.data,
        postgresql_ops={
            'data': 'text_pattern_ops',
            'id': 'int4_ops'
        })
 
Note that the keys in the ``postgresql_ops`` dictionaries are the
"key" name of the :class:`_schema.Column`, i.e. the name used to access it from
the ``.c`` collection of :class:`_schema.Table`, which can be configured to be
different than the actual name of the column as expressed in the database.
 
If ``postgresql_ops`` is to be used against a complex SQL expression such
as a function call, then to apply to the column it must be given a label
that is identified in the dictionary by name, e.g.::
 
    Index(
        'my_index', my_table.c.id,
        func.lower(my_table.c.data).label('data_lower'),
        postgresql_ops={
            'data_lower': 'text_pattern_ops',
            'id': 'int4_ops'
        })
 
Operator classes are also supported by the
:class:`_postgresql.ExcludeConstraint` construct using the
:paramref:`_postgresql.ExcludeConstraint.ops` parameter. See that parameter for
details.
 
.. versionadded:: 1.3.21 added support for operator classes with
   :class:`_postgresql.ExcludeConstraint`.
 
 
Index Types
^^^^^^^^^^^
 
PostgreSQL provides several index types: B-Tree, Hash, GiST, and GIN, as well
as the ability for users to create their own (see
https://www.postgresql.org/docs/current/static/indexes-types.html). These can be
specified on :class:`.Index` using the ``postgresql_using`` keyword argument::
 
    Index('my_index', my_table.c.data, postgresql_using='gin')
 
The value passed to the keyword argument will be simply passed through to the
underlying CREATE INDEX command, so it *must* be a valid index type for your
version of PostgreSQL.
 
.. _postgresql_index_storage:
 
Index Storage Parameters
^^^^^^^^^^^^^^^^^^^^^^^^
 
PostgreSQL allows storage parameters to be set on indexes. The storage
parameters available depend on the index method used by the index. Storage
parameters can be specified on :class:`.Index` using the ``postgresql_with``
keyword argument::
 
    Index('my_index', my_table.c.data, postgresql_with={"fillfactor": 50})
 
PostgreSQL allows to define the tablespace in which to create the index.
The tablespace can be specified on :class:`.Index` using the
``postgresql_tablespace`` keyword argument::
 
    Index('my_index', my_table.c.data, postgresql_tablespace='my_tablespace')
 
Note that the same option is available on :class:`_schema.Table` as well.
 
.. _postgresql_index_concurrently:
 
Indexes with CONCURRENTLY
^^^^^^^^^^^^^^^^^^^^^^^^^
 
The PostgreSQL index option CONCURRENTLY is supported by passing the
flag ``postgresql_concurrently`` to the :class:`.Index` construct::
 
    tbl = Table('testtbl', m, Column('data', Integer))
 
    idx1 = Index('test_idx1', tbl.c.data, postgresql_concurrently=True)
 
The above index construct will render DDL for CREATE INDEX, assuming
PostgreSQL 8.2 or higher is detected or for a connection-less dialect, as::
 
    CREATE INDEX CONCURRENTLY test_idx1 ON testtbl (data)
 
For DROP INDEX, assuming PostgreSQL 9.2 or higher is detected or for
a connection-less dialect, it will emit::
 
    DROP INDEX CONCURRENTLY test_idx1
 
When using CONCURRENTLY, the PostgreSQL database requires that the statement
be invoked outside of a transaction block.   The Python DBAPI enforces that
even for a single statement, a transaction is present, so to use this
construct, the DBAPI's "autocommit" mode must be used::
 
    metadata = MetaData()
    table = Table(
        "foo", metadata,
        Column("id", String))
    index = Index(
        "foo_idx", table.c.id, postgresql_concurrently=True)
 
    with engine.connect() as conn:
        with conn.execution_options(isolation_level='AUTOCOMMIT'):
            table.create(conn)
 
.. seealso::
 
    :ref:`postgresql_isolation_level`
 
.. _postgresql_index_reflection:
 
PostgreSQL Index Reflection
---------------------------
 
The PostgreSQL database creates a UNIQUE INDEX implicitly whenever the
UNIQUE CONSTRAINT construct is used.   When inspecting a table using
:class:`_reflection.Inspector`, the :meth:`_reflection.Inspector.get_indexes`
and the :meth:`_reflection.Inspector.get_unique_constraints`
will report on these
two constructs distinctly; in the case of the index, the key
``duplicates_constraint`` will be present in the index entry if it is
detected as mirroring a constraint.   When performing reflection using
``Table(..., autoload_with=engine)``, the UNIQUE INDEX is **not** returned
in :attr:`_schema.Table.indexes` when it is detected as mirroring a
:class:`.UniqueConstraint` in the :attr:`_schema.Table.constraints` collection
.
 
Special Reflection Options
--------------------------
 
The :class:`_reflection.Inspector`
used for the PostgreSQL backend is an instance
of :class:`.PGInspector`, which offers additional methods::
 
    from sqlalchemy import create_engine, inspect
 
    engine = create_engine("postgresql+psycopg2://localhost/test")
    insp = inspect(engine)  # will be a PGInspector
 
    print(insp.get_enums())
 
.. autoclass:: PGInspector
    :members:
 
.. _postgresql_table_options:
 
PostgreSQL Table Options
------------------------
 
Several options for CREATE TABLE are supported directly by the PostgreSQL
dialect in conjunction with the :class:`_schema.Table` construct:
 
* ``TABLESPACE``::
 
    Table("some_table", metadata, ..., postgresql_tablespace='some_tablespace')
 
  The above option is also available on the :class:`.Index` construct.
 
* ``ON COMMIT``::
 
    Table("some_table", metadata, ..., postgresql_on_commit='PRESERVE ROWS')
 
* ``WITH OIDS``::
 
    Table("some_table", metadata, ..., postgresql_with_oids=True)
 
* ``WITHOUT OIDS``::
 
    Table("some_table", metadata, ..., postgresql_with_oids=False)
 
* ``INHERITS``::
 
    Table("some_table", metadata, ..., postgresql_inherits="some_supertable")
 
    Table("some_table", metadata, ..., postgresql_inherits=("t1", "t2", ...))
 
* ``PARTITION BY``::
 
    Table("some_table", metadata, ...,
          postgresql_partition_by='LIST (part_column)')
 
    .. versionadded:: 1.2.6
 
.. seealso::
 
    `PostgreSQL CREATE TABLE options
    <https://www.postgresql.org/docs/current/static/sql-createtable.html>`_ -
    in the PostgreSQL documentation.
 
.. _postgresql_constraint_options:
 
PostgreSQL Constraint Options
-----------------------------
 
The following option(s) are supported by the PostgreSQL dialect in conjunction
with selected constraint constructs:
 
* ``NOT VALID``:  This option applies towards CHECK and FOREIGN KEY constraints
  when the constraint is being added to an existing table via ALTER TABLE,
  and has the effect that existing rows are not scanned during the ALTER
  operation against the constraint being added.
 
  When using a SQL migration tool such as `Alembic <https://alembic.sqlalchemy.org>`_
  that renders ALTER TABLE constructs, the ``postgresql_not_valid`` argument
  may be specified as an additional keyword argument within the operation
  that creates the constraint, as in the following Alembic example::
 
        def update():
            op.create_foreign_key(
                "fk_user_address",
                "address",
                "user",
                ["user_id"],
                ["id"],
                postgresql_not_valid=True
            )
 
  The keyword is ultimately accepted directly by the
  :class:`_schema.CheckConstraint`, :class:`_schema.ForeignKeyConstraint`
  and :class:`_schema.ForeignKey` constructs; when using a tool like
  Alembic, dialect-specific keyword arguments are passed through to
  these constructs from the migration operation directives::
 
       CheckConstraint("some_field IS NOT NULL", postgresql_not_valid=True)
 
       ForeignKeyConstraint(["some_id"], ["some_table.some_id"], postgresql_not_valid=True)
 
  .. versionadded:: 1.4.32
 
  .. seealso::
 
      `PostgreSQL ALTER TABLE options
      <https://www.postgresql.org/docs/current/static/sql-altertable.html>`_ -
      in the PostgreSQL documentation.
 
.. _postgresql_table_valued_overview:
 
Table values, Table and Column valued functions, Row and Tuple objects
-----------------------------------------------------------------------
 
PostgreSQL makes great use of modern SQL forms such as table-valued functions,
tables and rows as values.   These constructs are commonly used as part
of PostgreSQL's support for complex datatypes such as JSON, ARRAY, and other
datatypes.  SQLAlchemy's SQL expression language has native support for
most table-valued and row-valued forms.
 
.. _postgresql_table_valued:
 
Table-Valued Functions
^^^^^^^^^^^^^^^^^^^^^^^
 
Many PostgreSQL built-in functions are intended to be used in the FROM clause
of a SELECT statement, and are capable of returning table rows or sets of table
rows. A large portion of PostgreSQL's JSON functions for example such as
``json_array_elements()``, ``json_object_keys()``, ``json_each_text()``,
``json_each()``, ``json_to_record()``, ``json_populate_recordset()`` use such
forms. These classes of SQL function calling forms in SQLAlchemy are available
using the :meth:`_functions.FunctionElement.table_valued` method in conjunction
with :class:`_functions.Function` objects generated from the :data:`_sql.func`
namespace.
 
Examples from PostgreSQL's reference documentation follow below:
 
* ``json_each()``:
 
  .. sourcecode:: pycon+sql
 
    >>> from sqlalchemy import select, func
    >>> stmt = select(func.json_each('{"a":"foo", "b":"bar"}').table_valued("key", "value"))
    >>> print(stmt)
    {printsql}SELECT anon_1.key, anon_1.value
    FROM json_each(:json_each_1) AS anon_1
 
* ``json_populate_record()``:
 
  .. sourcecode:: pycon+sql
 
    >>> from sqlalchemy import select, func, literal_column
    >>> stmt = select(
    ...     func.json_populate_record(
    ...         literal_column("null::myrowtype"),
    ...         '{"a":1,"b":2}'
    ...     ).table_valued("a", "b", name="x")
    ... )
    >>> print(stmt)
    {printsql}SELECT x.a, x.b
    FROM json_populate_record(null::myrowtype, :json_populate_record_1) AS x
 
* ``json_to_record()`` - this form uses a PostgreSQL specific form of derived
  columns in the alias, where we may make use of :func:`_sql.column` elements with
  types to produce them.  The :meth:`_functions.FunctionElement.table_valued`
  method produces  a :class:`_sql.TableValuedAlias` construct, and the method
  :meth:`_sql.TableValuedAlias.render_derived` method sets up the derived
  columns specification:
 
  .. sourcecode:: pycon+sql
 
    >>> from sqlalchemy import select, func, column, Integer, Text
    >>> stmt = select(
    ...     func.json_to_record('{"a":1,"b":[1,2,3],"c":"bar"}').table_valued(
    ...         column("a", Integer), column("b", Text), column("d", Text),
    ...     ).render_derived(name="x", with_types=True)
    ... )
    >>> print(stmt)
    {printsql}SELECT x.a, x.b, x.d
    FROM json_to_record(:json_to_record_1) AS x(a INTEGER, b TEXT, d TEXT)
 
* ``WITH ORDINALITY`` - part of the SQL standard, ``WITH ORDINALITY`` adds an
  ordinal counter to the output of a function and is accepted by a limited set
  of PostgreSQL functions including ``unnest()`` and ``generate_series()``. The
  :meth:`_functions.FunctionElement.table_valued` method accepts a keyword
  parameter ``with_ordinality`` for this purpose, which accepts the string name
  that will be applied to the "ordinality" column:
 
  .. sourcecode:: pycon+sql
 
    >>> from sqlalchemy import select, func
    >>> stmt = select(
    ...     func.generate_series(4, 1, -1).
    ...     table_valued("value", with_ordinality="ordinality").
    ...     render_derived()
    ... )
    >>> print(stmt)
    {printsql}SELECT anon_1.value, anon_1.ordinality
    FROM generate_series(:generate_series_1, :generate_series_2, :generate_series_3)
    WITH ORDINALITY AS anon_1(value, ordinality)
 
.. versionadded:: 1.4.0b2
 
.. seealso::
 
    :ref:`tutorial_functions_table_valued` - in the :ref:`unified_tutorial`
 
.. _postgresql_column_valued:
 
Column Valued Functions
^^^^^^^^^^^^^^^^^^^^^^^
 
Similar to the table valued function, a column valued function is present
in the FROM clause, but delivers itself to the columns clause as a single
scalar value.  PostgreSQL functions such as ``json_array_elements()``,
``unnest()`` and ``generate_series()`` may use this form. Column valued functions are available using the
:meth:`_functions.FunctionElement.column_valued` method of :class:`_functions.FunctionElement`:
 
* ``json_array_elements()``:
 
  .. sourcecode:: pycon+sql
 
    >>> from sqlalchemy import select, func
    >>> stmt = select(func.json_array_elements('["one", "two"]').column_valued("x"))
    >>> print(stmt)
    {printsql}SELECT x
    FROM json_array_elements(:json_array_elements_1) AS x
 
* ``unnest()`` - in order to generate a PostgreSQL ARRAY literal, the
  :func:`_postgresql.array` construct may be used:
 
  .. sourcecode:: pycon+sql
 
    >>> from sqlalchemy.dialects.postgresql import array
    >>> from sqlalchemy import select, func
    >>> stmt = select(func.unnest(array([1, 2])).column_valued())
    >>> print(stmt)
    {printsql}SELECT anon_1
    FROM unnest(ARRAY[%(param_1)s, %(param_2)s]) AS anon_1
 
  The function can of course be used against an existing table-bound column
  that's of type :class:`_types.ARRAY`:
 
  .. sourcecode:: pycon+sql
 
    >>> from sqlalchemy import table, column, ARRAY, Integer
    >>> from sqlalchemy import select, func
    >>> t = table("t", column('value', ARRAY(Integer)))
    >>> stmt = select(func.unnest(t.c.value).column_valued("unnested_value"))
    >>> print(stmt)
    {printsql}SELECT unnested_value
    FROM unnest(t.value) AS unnested_value
 
.. seealso::
 
    :ref:`tutorial_functions_column_valued` - in the :ref:`unified_tutorial`
 
 
Row Types
^^^^^^^^^
 
Built-in support for rendering a ``ROW`` may be approximated using
``func.ROW`` with the :attr:`_sa.func` namespace, or by using the
:func:`_sql.tuple_` construct:
 
.. sourcecode:: pycon+sql
 
    >>> from sqlalchemy import table, column, func, tuple_
    >>> t = table("t", column("id"), column("fk"))
    >>> stmt = t.select().where(
    ...     tuple_(t.c.id, t.c.fk) > (1,2)
    ... ).where(
    ...     func.ROW(t.c.id, t.c.fk) < func.ROW(3, 7)
    ... )
    >>> print(stmt)
    {printsql}SELECT t.id, t.fk
    FROM t
    WHERE (t.id, t.fk) > (:param_1, :param_2) AND ROW(t.id, t.fk) < ROW(:ROW_1, :ROW_2)
 
.. seealso::
 
    `PostgreSQL Row Constructors
    <https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-ROW-CONSTRUCTORS>`_
 
    `PostgreSQL Row Constructor Comparison
    <https://www.postgresql.org/docs/current/functions-comparisons.html#ROW-WISE-COMPARISON>`_
 
Table Types passed to Functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
PostgreSQL supports passing a table as an argument to a function, which it
refers towards as a "record" type. SQLAlchemy :class:`_sql.FromClause` objects
such as :class:`_schema.Table` support this special form using the
:meth:`_sql.FromClause.table_valued` method, which is comparable to the
:meth:`_functions.FunctionElement.table_valued` method except that the collection
of columns is already established by that of the :class:`_sql.FromClause`
itself:
 
.. sourcecode:: pycon+sql
 
    >>> from sqlalchemy import table, column, func, select
    >>> a = table( "a", column("id"), column("x"), column("y"))
    >>> stmt = select(func.row_to_json(a.table_valued()))
    >>> print(stmt)
    {printsql}SELECT row_to_json(a) AS row_to_json_1
    FROM a
 
.. versionadded:: 1.4.0b2
 
 
 
é)Ú annotations)Ú defaultdict)Ú    lru_cacheN)ÚAny)ÚList)ÚOptional)ÚTupleé)Úarray)Úhstore)Újson)Ú
pg_catalog)Úranges)Ú _regconfig_fn)Úaggregate_order_by)ÚCreateDomainType)ÚCreateEnumType)ÚDOMAIN)ÚDropDomainType)Ú DropEnumType)ÚENUM)Ú    NamedType)Ú_DECIMAL_TYPES)Ú _FLOAT_TYPES)Ú
_INT_TYPES)ÚBIT)ÚBYTEA)ÚCIDR)ÚCITEXT)ÚINET)ÚINTERVAL)ÚMACADDR)ÚMACADDR8)ÚMONEY)ÚOID)ÚPGBit)ÚPGCidr)ÚPGInet)Ú
PGInterval)Ú    PGMacAddr)Ú
PGMacAddr8)ÚPGUuid)ÚREGCLASS)Ú    REGCONFIG)ÚTIME)Ú    TIMESTAMP)ÚTSVECTORé)Úexc)Úschema)Úselect)Úsql)Úutil)Úcharacteristics)Údefault)Ú
interfaces)Ú
ObjectKind)Ú ObjectScope)Ú
reflection)ÚReflectionDefaults)Ú    bindparam)Ú    coercions)Úcompiler)Úelements)Ú
expression)Úroles)Úsqltypes)ÚInsertmanyvaluesSentinelOpts)ÚInternalTraversal)ÚBIGINT)ÚBOOLEAN)ÚCHAR)ÚDATE)ÚDOUBLE_PRECISION)ÚFLOAT)ÚINTEGER)ÚNUMERIC)ÚREAL)ÚSMALLINT)ÚTEXT)ÚUUID)ÚVARCHAR)Ú    TypedDictz ^(?:btree|hash|gist|gin|[\w_]+)$ÚallZanalyseZanalyzeÚandÚanyr
ÚasZascZ
asymmetricZbothÚcaseÚcastÚcheckZcollateÚcolumnÚ
constraintÚcreateZcurrent_catalogZ current_dateZ current_roleÚ current_timeZcurrent_timestampZ current_userr8Ú
deferrableÚdescZdistinctZdoÚelseÚendÚexceptÚfalseÚfetchÚforZforeignÚfromZgrantÚgroupZhavingÚinÚ    initiallyZ    intersectZintoÚleadingÚlimitÚ    localtimeZlocaltimestampÚnewÚnotÚnullÚofÚoffÚoffsetÚoldÚonÚonlyÚorÚorderZplacingZprimaryZ
referencesZ    returningr4Z session_userZsomeZ    symmetricÚtableZthenÚtoZtrailingÚtrueÚunionÚuniqueÚuserÚusingZvariadicÚwhenÚwhereZwindowÚwithÚ authorizationZbetweenÚbinaryZcrossZcurrent_schemaÚfreezeÚfullZilikeÚinnerÚisZisnullÚjoinÚleftZlikeZnaturalZnotnullÚouterZoverÚoverlapsÚrightZsimilarÚverbose)2Ú_arrayr r ZjsonbZ    int4rangeZ    int8rangeZnumrangeZ    daterangeZtsrangeZ    tstzrangeZint4multirangeZint8multirangeZ nummultirangeZdatemultirangeZ tsmultirangeZtstzmultirangeÚintegerZbigintZsmallintzcharacter varyingÚ    characterz"char"ÚnameÚtextÚnumericÚfloatÚrealZinetZcidrZcitextÚuuidÚbitú bit varyingZmacaddrZmacaddr8ZmoneyÚoidZregclassúdouble precisionÚ    timestampútimestamp with time zoneútimestamp without time zoneútime with time zoneútime without time zoneÚdateÚtimeZbyteaÚbooleanÚintervalZtsvectorcs@eZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd d„Z    dd„Z
dd„Z dd„Z dd„Z dLdd„ZdMdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Z‡fd2d3„Zd4d5„Zd6d7„Zd8d9„Zd:d;„Zd<d=„Z d>d?„Z!d@dA„Z"dBdC„Z#dDdE„Z$dFdG„Z%dHdI„Z&dJdK„Z'‡Z(S)NÚ
PGCompilercKs|j|f|ŽS©N©Ú_assert_pg_ts_ext©ÚselfÚelementÚkw©r®úZd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/dialects/postgresql/base.pyÚvisit_to_tsvector_func|sz!PGCompiler.visit_to_tsvector_funccKs|j|f|ŽSr§r¨rªr®r®r¯Úvisit_to_tsquery_funcsz PGCompiler.visit_to_tsquery_funccKs|j|f|ŽSr§r¨rªr®r®r¯Úvisit_plainto_tsquery_func‚sz%PGCompiler.visit_plainto_tsquery_funccKs|j|f|ŽSr§r¨rªr®r®r¯Úvisit_phraseto_tsquery_func…sz&PGCompiler.visit_phraseto_tsquery_funccKs|j|f|ŽSr§r¨rªr®r®r¯Úvisit_websearch_to_tsquery_funcˆsz*PGCompiler.visit_websearch_to_tsquery_funccKs|j|f|ŽSr§r¨rªr®r®r¯Úvisit_ts_headline_func‹sz!PGCompiler.visit_ts_headline_funccKs>t|tƒs&t d|j›d|j›d¡‚|j›|j|f|Ž›S)NzCan't compile "zÙ()" full text search function construct that does not originate from the "sqlalchemy.dialects.postgresql" package.  Please ensure "import sqlalchemy.dialects.postgresql" is called before constructing "sqlalchemy.func.zD()" to ensure registration of the correct argument and return types.)Ú
isinstancerr2Ú CompileErrorr“Zfunction_argspecrªr®r®r¯r©Žs
 
ÿ
zPGCompiler._assert_pg_ts_extcCs0|jtjkrtj}|›d|jjj||jd›S)Nz::)Úidentifier_preparer)Ú_type_affinityrDÚStringÚ
STRINGTYPEÚdialectÚtype_compiler_instanceÚprocessÚpreparer)r«Útype_Z
dbapi_typeÚsqltextr®r®r¯Úrender_bind_cast£s ÿÿzPGCompiler.render_bind_castcKsd|j|f|ŽS)Nz    ARRAY[%s])Zvisit_clauselistrªr®r®r¯Ú visit_array®szPGCompiler.visit_arraycKs$d|j|jf|Ž|j|jf|ŽfS)Nz%s:%s)r¾ÚstartÚstoprªr®r®r¯Ú visit_slice±sþzPGCompiler.visit_slicecKs|j|df|ŽS)Nz # )Ú_generate_generic_binary©r«r…Úoperatorr­r®r®r¯Úvisit_bitwise_xor_op_binary·sz&PGCompiler.visit_bitwise_xor_op_binaryFcKsR|s2|jjtjk    r2d|d<|jt ||j¡f|ŽSd|d<|j||sHdndf|ŽS)NTÚ _cast_appliedÚeager_groupingz -> z ->> ©Útyper¹rDÚJSONr¾r5rZrÇ©r«r…rÉrËr­r®r®r¯Úvisit_json_getitem_op_binaryºsÿ þ
ÿÿz'PGCompiler.visit_json_getitem_op_binarycKsR|s2|jjtjk    r2d|d<|jt ||j¡f|ŽSd|d<|j||sHdndf|ŽS)NTrËrÌz #> z #>> rÍrÐr®r®r¯Ú!visit_json_path_getitem_op_binaryÊsÿ þ
ÿÿz,PGCompiler.visit_json_path_getitem_op_binarycKs$d|j|jf|Ž|j|jf|ŽfS)Nz%s[%s])r¾r‹rŽrÈr®r®r¯Úvisit_getitem_binaryÙsþzPGCompiler.visit_getitem_binarycKs$d|j|jf|Ž|j|jf|ŽfS)Nz%s ORDER BY %s)r¾ÚtargetÚorder_byrªr®r®r¯Úvisit_aggregate_order_byßsþz#PGCompiler.visit_aggregate_order_bycKsld|jkrH| |jdtj¡}|rHd|j|jf|Ž||j|jf|ŽfSd|j|jf|Ž|j|jf|ŽfS)NZpostgresql_regconfigz%s @@ plainto_tsquery(%s, %s)z%s @@ plainto_tsquery(%s))Ú    modifiersÚrender_literal_valuerDr»r¾r‹rŽ)r«r…rÉr­Z    regconfigr®r®r¯Úvisit_match_op_binaryås
ÿýþz PGCompiler.visit_match_op_binarycKs|jj|f|ŽSr§)r¬Ú_compiler_dispatchrªr®r®r¯Ú$visit_ilike_case_insensitive_operandõsz/PGCompiler.visit_ilike_case_insensitive_operandcKsL|j dd¡}d|j|jf|Ž|j|jf|Žf|rFd| |tj¡ndS)NÚescapez %s ILIKE %sú ESCAPE Ú©r×Úgetr¾r‹rŽrØrDr»©r«r…rÉr­rÜr®r®r¯Úvisit_ilike_op_binaryøsþÿúz PGCompiler.visit_ilike_op_binarycKsL|j dd¡}d|j|jf|Ž|j|jf|Žf|rFd| |tj¡ndS)NrÜz%s NOT ILIKE %srÝrÞrßrár®r®r¯Úvisit_not_ilike_op_binarysþÿúz$PGCompiler.visit_not_ilike_op_binarycCs‚|jd}|dkr&|j|d|f|ŽSt|tjƒrP|jdkrP|j|d|f|ŽSd|j|jf|Ž||j|f|Ž|j|jf|ŽfS)NÚflagsz %s Úiz %s* z%s %s CONCAT('(?', %s, ')', %s))    r×rÇr¶rAÚ BindParameterÚvaluer¾r‹rŽ)r«Zbase_opr…rÉr­rär®r®r¯Ú _regexp_matchs*
ÿÿÿÿ üzPGCompiler._regexp_matchcKs| d|||¡S)Nú~©rèrÈr®r®r¯Úvisit_regexp_match_op_binary sz'PGCompiler.visit_regexp_match_op_binarycKs| d|||¡S)Nz!~rêrÈr®r®r¯Ú visit_not_regexp_match_op_binary#sz+PGCompiler.visit_not_regexp_match_op_binarycKsr|j|jf|Ž}|j|jf|Ž}|jd}|j|jdf|Ž}|dkrTd|||fSd||||j|f|ŽfSdS)NräÚ replacementzREGEXP_REPLACE(%s, %s, %s)zREGEXP_REPLACE(%s, %s, %s, %s))r¾r‹rŽr×)r«r…rÉr­ÚstringÚpatternrärír®r®r¯Úvisit_regexp_replace_op_binary&s 
ý üz)PGCompiler.visit_regexp_replace_op_binaryc s&dd ‡fdd„|ptƒgDƒ¡fS)NzSELECT %s WHERE 1!=1ú, c3s,|]$}dˆjj |jrtƒn|¡VqdS)zCAST(NULL AS %s)N)r¼r½r¾Ú_isnullrM)Ú.0rÀ©r«r®r¯Ú    <genexpr>>s üÿÿz2PGCompiler.visit_empty_set_expr.<locals>.<genexpr>)rŠrM)r«Z element_typesr­r®rôr¯Úvisit_empty_set_expr9s
 
ûÿzPGCompiler.visit_empty_set_exprcs&tƒ ||¡}|jjr"| dd¡}|S)Nú\z\\)ÚsuperrØr¼Ú_backslash_escapesÚreplace)r«rçrÀ©Ú    __class__r®r¯rØGs zPGCompiler.render_literal_valuecKsd|j |¡S)Nz nextval('%s'))r¿Úformat_sequence)r«Úseqr­r®r®r¯Úvisit_sequenceNszPGCompiler.visit_sequencecKs^d}|jdk    r&|d|j|jf|Ž7}|jdk    rZ|jdkrB|d7}|d|j|jf|Ž7}|S)NrÞz     
 LIMIT z
 LIMIT ALLz OFFSET )Z _limit_clauser¾Ú_offset_clause©r«r4r­r”r®r®r¯Ú limit_clauseQs
 
 
zPGCompiler.limit_clausecCs"| ¡dkrt d|¡‚d|S)NÚONLYzUnrecognized hint: %rzONLY )Úupperr2r·)r«rÁrzÚhintZiscrudr®r®r¯Úformat_from_hint_text[s z PGCompiler.format_from_hint_textc sD|js |jr<|jr6dd ‡‡fdd„|jDƒ¡dSdSndSdS)Nz DISTINCT ON (rñcsg|]}ˆj|fˆŽ‘qSr®©r¾©róÚcol©r­r«r®r¯Ú
<listcomp>hsÿz4PGCompiler.get_select_precolumns.<locals>.<listcomp>z) z    DISTINCT rÞ)Z    _distinctZ _distinct_onrŠ)r«r4r­r®r
r¯Úget_select_precolumns`s  þÿÿùÿ z PGCompiler.get_select_precolumnsc s¢|jjr|jjrd}q.d}n|jjr*d}nd}|jjr~t ¡}|jjD]}| t |¡¡qF|dd     ‡‡fdd„|Dƒ¡7}|jj
rŽ|d    7}|jj rž|d
7}|S) Nz FOR KEY SHAREz
 FOR SHAREz FOR NO KEY UPDATEz  FOR UPDATEz OF rñc3s&|]}ˆj|fdddœˆ—ŽVqdS)TF)ZashintÚ
use_schemaNr)rórzr
r®r¯rõ„sÿz/PGCompiler.for_update_clause.<locals>.<genexpr>z NOWAITz  SKIP LOCKED) Z_for_update_argÚreadZ    key_sharerrr6Z
OrderedSetÚupdateÚsql_utilZsurface_selectables_onlyrŠZnowaitZ skip_locked)r«r4r­ÚtmpZtablesÚcr®r
r¯Úfor_update_clausets& þ zPGCompiler.for_update_clausecKsp|j|jjdf|Ž}|j|jjdf|Ž}t|jjƒdkr`|j|jjdf|Ž}d|||fSd||fSdS)Nrr    ézSUBSTRING(%s FROM %s FOR %s)zSUBSTRING(%s FROM %s))r¾ZclausesÚlen)r«Úfuncr­ÚsrÄÚlengthr®r®r¯Úvisit_substring_funcs zPGCompiler.visit_substring_funcc st|jdk    rdˆj |j¡}nR|jdk    rldd ‡fdd„|jDƒ¡}|jdk    rp|dˆj|jddd7}nd    }|S)
NzON CONSTRAINT %sú(%s)rñc3s4|],}t|tƒrˆj |¡nˆj|dddVqdS)F©Ú include_tabler N)r¶Ústrr¿Úquoter¾©rórrôr®r¯rõ§sýÿz1PGCompiler._on_conflict_target.<locals>.<genexpr>ú     WHERE %sFrrÞ)Zconstraint_targetr¿Ú#truncate_and_render_constraint_nameZinferred_target_elementsrŠZinferred_target_whereclauser¾)r«Úclauser­Ú target_textr®rôr¯Ú_on_conflict_target™s&
ÿÿÿ
ú
 
ý zPGCompiler._on_conflict_targetcKs"|j|f|Ž}|rd|SdSdS)NzON CONFLICT %s DO NOTHINGzON CONFLICT DO NOTHING)r$)r«Ú on_conflictr­r#r®r®r¯Úvisit_on_conflict_do_nothingºsz'PGCompiler.visit_on_conflict_do_nothingcKs²|}|j|f|Ž}g}t|jƒ}|jdd}|jj}|D]¨}    |    j}
|
|krX| |
¡} n|    |kr:| |    ¡} nq:t     | ¡rŒt
j d| |    j d} n$t | t
j ƒr°| j jr°|  ¡} |    j | _ |j|  ¡dd} |j |    j¡} | d| | f¡q:|rvt d|jjjd d    d
„|Dƒ¡f¡| ¡D]Z\}}t |tƒr:|j |¡n |j|dd} |jt tj|¡dd} | d| | f¡qd |¡}|jdk    r¦|d |j|jd dd 7}d||fS)NéÿÿÿÿZ
selectable)rÀF)r ú%s = %szFAdditional column names not matching any column keys in table '%s': %srñcss|]}d|VqdS)z'%s'Nr®rr®r®r¯rõîsz9PGCompiler.visit_on_conflict_do_update.<locals>.<genexpr>r TrzON CONFLICT %s DO UPDATE SET %s) r$ÚdictZupdate_values_to_setÚstackrzrÚkeyÚpopr?Z _is_literalrArærÎr¶ròZ_cloner¾Ú
self_groupr¿rr“Úappendr6ÚwarnZcurrent_executablerŠÚitemsrÚexpectrCZExpressionElementRoleZupdate_whereclause)r«r%r­r"r#Zaction_set_opsZset_parametersZinsert_statementÚcolsrZcol_keyrçZ
value_textZkey_textÚkÚvZ action_textr®r®r¯Úvisit_on_conflict_do_updateÂsd
 
 
ÿþþþÿÿ ý þ
 ÿ
z&PGCompiler.visit_on_conflict_do_updatec s(dˆd<dd ‡‡‡fdd„|Dƒ¡S)NTÚasfromzFROM rñc3s$|]}|jˆfdˆiˆ—ŽVqdS©Z    fromhintsN©rÚ©róÚt©Ú
from_hintsr­r«r®r¯rõ    sÿz0PGCompiler.update_from_clause.<locals>.<genexpr>©rŠ)r«Z update_stmtÚ
from_tableÚ extra_fromsr<r­r®r;r¯Úupdate_from_clausesþzPGCompiler.update_from_clausec s(dˆd<dd ‡‡‡fdd„|Dƒ¡S)z9Render the DELETE .. USING clause specific to PostgreSQL.Tr6zUSING rñc3s$|]}|jˆfdˆiˆ—ŽVqdSr7r8r9r;r®r¯rõsÿz6PGCompiler.delete_extra_from_clause.<locals>.<genexpr>r=)r«Z delete_stmtr>r?r<r­r®r;r¯Údelete_extra_from_clausesþz#PGCompiler.delete_extra_from_clausecKsnd}|jdk    r&|d|j|jf|Ž7}|jdk    rj|d|j|jf|Ž|jdrPdnd|jdr`dndf7}|S)    NrÞz
 OFFSET (%s) ROWSz
 FETCH FIRST (%s)%s ROWS %sÚpercentz PERCENTZ    with_tiesz    WITH TIESr)rr¾Z _fetch_clauseZ_fetch_clause_optionsrr®r®r¯Ú fetch_clauses 
ÿÿ
ÿûzPGCompiler.fetch_clause)F)F))Ú__name__Ú
__module__Ú __qualname__r°r±r²r³r´rµr©rÂrÃrÆrÊrÑrÒrÓrÖrÙrÛrârãrèrërìrðrörØrÿrrr rrr$r&r5r@rArCÚ __classcell__r®r®rûr¯r¦{sN ÿ
ÿ
 
    !C    
r¦cs¤eZdZdd„Zdd„Z‡fdd„Z‡fdd„Zd    d
„Zd d „Zd d„Z    dd„Z
dd„Z dd„Z dd„Z dd„Zdd„Z‡fdd„Zdd„Zdd „Zd!d"„Z‡ZS)#Ú PGDDLCompilercKsh|j |¡}|j |j¡}t|tjƒr,|j}|j    dk    o<|jj
}|j r¾||j j kr¾|jjsdt|tjƒs¾|s¾|jdksˆt|jtjƒr¾|jjr¾t|tjƒrž|d7}qüt|tjƒr´|d7}qü|d7}n>|d|jjj|j||jd7}| |¡}|dk    rü|d|7}|jdk    r|d| |j¡7}|r6|d| |j    ¡7}|jsN|sN|d7}n|jrd|rd|d7}|S)    Nz
 BIGSERIALz  SMALLSERIALz SERIALú )Ztype_expressionr¸z     DEFAULT z     NOT NULLz NULL)r¿Z format_columnrÎZ dialect_implr¼r¶rDZ TypeDecoratorÚimplÚidentityÚsupports_identity_columnsÚ primary_keyrzÚ_autoincrement_columnÚsupports_smallserialZ SmallIntegerr8r3ÚSequenceÚoptionalZ
BigIntegerr½r¾Zget_column_default_stringÚcomputedÚnullable)r«r\ÚkwargsZcolspecZ    impl_typeZ has_identityr8r®r®r¯Úget_column_specification-sZ  
þÿ
þü
ûù    ÷ õ ô 
 
 
 ý
 
 
z&PGDDLCompiler.get_column_specificationcCs|jdd}|rdSdS)NÚ
postgresqlÚ    not_validz
 NOT VALIDrÞ)Údialect_options)r«r]rWr®r®r¯Ú_define_constraint_validitycsz)PGDDLCompiler._define_constraint_validityc s`|jrBt|jƒdj}t|tjƒrBt|jtjƒrB|jj    sBt
  d¡‚t ƒ  |¡}|| |¡7}|S)Nrz’PostgreSQL dialect cannot produce the CHECK constraint for ARRAY of non-native ENUM; please specify create_constraint=False on this Enum datatype.)Z _type_boundÚlistÚcolumnsrÎr¶rDÚARRAYÚ    item_typeÚEnumÚ native_enumr2r·røÚvisit_check_constraintrY)r«r]r­Útypr”rûr®r¯r`gs
ÿ þýÿ z$PGDDLCompiler.visit_check_constraintc stƒ |¡}|| |¡7}|Sr§)røÚvisit_foreign_key_constraintrY)r«r]r­r”rûr®r¯rbys z*PGDDLCompiler.visit_foreign_key_constraintc s0|j}dˆj |¡d ‡fdd„|jDƒ¡fS)NzCREATE TYPE %s AS ENUM (%s)rñc3s$|]}ˆjjt |¡ddVqdS)T©Ú literal_bindsN)Ú sql_compilerr¾r5Úliteral)róÚerôr®r¯rõƒsÿz7PGDDLCompiler.visit_create_enum_type.<locals>.<genexpr>)r¬r¿Ú format_typerŠÚenums)r«r^r­rÀr®rôr¯Úvisit_create_enum_type~s
þþz$PGDDLCompiler.visit_create_enum_typecKs|j}d|j |¡S)Nz DROP TYPE %s©r¬r¿rh)r«Údropr­rÀr®r®r¯Úvisit_drop_enum_type‰sz"PGDDLCompiler.visit_drop_enum_typecKsê|j}g}|jdk    r.| d|j |j¡›¡|jdk    rT| |j¡}| d|›¡|jdk    r||j |j¡}| d|›¡|j    rŒ| d¡|j
dk    r¼|j j |j
ddd}| d|›d    ¡d
|j  |¡›d |j  |j¡›d d  |¡›S) NzCOLLATE zDEFAULT z CONSTRAINT zNOT NULLFT©rrdzCHECK (ú)zCREATE DOMAIN z AS rI)r¬Z    collationr.r¿rr8Zrender_default_stringÚconstraint_namer!Únot_nullr[rer¾rhÚ type_compilerÚ    data_typerŠ)r«r^r­ÚdomainÚoptionsr8r“r[r®r®r¯Úvisit_create_domain_typeŽs.
 
 
ÿ
 
ÿ,ÿz&PGDDLCompiler.visit_create_domain_typecKs|j}d|j |¡›S)Nz DROP DOMAIN rk)r«rlr­rtr®r®r¯Úvisit_drop_domain_typeªsz$PGDDLCompiler.visit_drop_domain_typec  sȈj‰|j‰ˆ ˆ¡d}ˆjr(|d7}|d7}ˆjjrRˆjdd}|rR|d7}|jr`|d7}|dˆjˆd    d
ˆ     ˆj
¡f7}ˆjdd }|r®|d ˆj  |t ¡  ¡7}ˆjdd ‰|dd ‡‡fdd„ˆjDƒ¡7}ˆjdd}|r&‡fdd„|Dƒ}|dd ‡fdd„|Dƒ¡7}ˆjdd}|rZ|dd dd„| ¡Dƒ¡7}ˆjdd}    |    r€|dˆ |    ¡7}ˆjdd}
|
dk    rÄt tj|
¡}
ˆjj|
d    dd} |d| 7}|S)NzCREATE zUNIQUE zINDEX rVÚ concurrentlyú CONCURRENTLY zIF NOT EXISTS z    %s ON %s F©Zinclude_schemar€z    USING %s ÚopsrrñcsXg|]P}ˆjjt|tjƒs"| ¡n|dddt|dƒrN|jˆkrNdˆ|jnd‘qS)FTrnr+rIrÞ)rer¾r¶rBZ ColumnClauser-Úhasattrr+)róÚexpr)r{r«r®r¯r Îs ô
ÿ
û    ÿÿöz4PGDDLCompiler.visit_create_index.<locals>.<listcomp>Úincludecs&g|]}t|tƒrˆjj|n|‘qSr®)r¶rrzrr)Úindexr®r¯r âsÿz  INCLUDE (%s)csg|]}ˆ |j¡‘qSr®)rr“r©r¿r®r¯r çsrƒz
 WITH (%s)cSsg|] }d|‘qS)r(r®)róZstorage_parameterr®r®r¯r îsÿÚ
tablespacez TABLESPACE %sr‚Trnz WHERE )r¿r¬Z_verify_index_tabler~r¼Ú#_supports_create_index_concurrentlyrXZ if_not_existsÚ_prepared_index_nameÚ format_tablerzÚvalidate_sql_phraseÚ    IDX_USINGÚlowerrŠÚ expressionsr0rr?r1rCZDDLExpressionRolerer¾) r«r^r­r”rxr€Z includeclauseZ
inclusionsZ
withclauseÚtablespace_nameZ whereclauseZwhere_compiledr®)rr{r¿r«r¯Úvisit_create_index®s‚
 
þÿÿ óÿÿ
þÿþÿÿ    
ÿÿ z PGDDLCompiler.visit_create_indexcKsP|j}d}|jjr,|jdd}|r,|d7}|jr:|d7}||j|dd7}|S)Nz
DROP INDEX rVrxryz
IF EXISTS Trz)r¬r¼Ú!_supports_drop_index_concurrentlyrXZ    if_existsrƒ)r«rlr­rr”rxr®r®r¯Úvisit_drop_index    szPGDDLCompiler.visit_drop_indexc    Ksðd}|jdk    r"|d|j |¡7}g}d|d<d|d<|jD]V\}}}|jj|f|Žt|dƒrz|j|jkrzd|j|jnd}|     d    ||f¡q<|d
|j 
|j t ¡  ¡d  |¡f7}|jdk    rÞ|d |jj|jdd 7}|| |¡7}|S)NrÞzCONSTRAINT %s FrTrdr+rIz
%s WITH %szEXCLUDE USING %s (%s)rñz  WHERE (%s)rc)r“r¿Úformat_constraintZ _render_exprsrer¾r|r+r{r.r…r€r†r‡rŠr‚Zdefine_constraint_deferrability)    r«r]r­r”rAr}r“ÚopZexclude_elementr®r®r¯Úvisit_exclude_constraint    s>
 
ÿÿ
ÿýÿü
 
ÿ
z&PGDDLCompiler.visit_exclude_constraintcsüg}|jd}| d¡}|dk    rZt|ttfƒs4|f}| dd ‡fdd„|Dƒ¡d¡|drt| d    |d¡|d
d krŒ| d ¡n|d
d kr¢| d¡|drÌ|d dd¡ ¡}| d|¡|drò|d}| dˆj     
|¡¡d |¡S)NrVÚinheritsz
 INHERITS ( rñc3s|]}ˆj |¡VqdSr§)r¿r)rór“rôr®r¯rõ>    sz2PGDDLCompiler.post_create_table.<locals>.<genexpr>z )Ú partition_byz
 PARTITION BY %sÚ    with_oidsTz
 WITH OIDSFz
 WITHOUT OIDSÚ    on_commitÚ_rIz
 ON COMMIT %srz
 TABLESPACE %srÞ) rXràr¶rZÚtupler.rŠrúrr¿r)r«rzZ
table_optsZpg_optsrZon_commit_optionsr‰r®rôr¯Úpost_create_table4    s8
 
ÿþÿ   
ÿzPGDDLCompiler.post_create_tablecKs,|jdkrt d¡‚d|jj|jdddS)NFzƒPostrgreSQL computed columns do not support 'virtual' persistence; set the 'persisted' flag to None or True for PostgreSQL support.zGENERATED ALWAYS AS (%s) STOREDTrn)Ú    persistedr2r·rer¾rÁ)r«Ú    generatedr­r®r®r¯Úvisit_computed_columnV    s
ÿÿz#PGDDLCompiler.visit_computed_columnc s<d}|jjdk    r$d|j |jj¡}tƒj|fd|i|—ŽS)Nz AS %sÚprefix)r¬rsrrr¾røÚvisit_create_sequence)r«r^r­ršrûr®r¯r›b    s  ÿz#PGDDLCompiler.visit_create_sequencecCsB|j}|jdkr"t d|›d¡‚|jdkr>t d|›d¡‚dS)Nz%Can't emit COMMENT ON for constraint z: it has no namez: it has no associated table)r¬r“r2r·rz)r«Z ddl_instancer]r®r®r¯Ú_can_comment_on_constraintk    s
 
ÿ
 
ÿz(PGDDLCompiler._can_comment_on_constraintcKs@| |¡d|j |j¡|j |jj¡|j |jjt     
¡¡fS)Nz$COMMENT ON CONSTRAINT %s ON %s IS %s) rœr¿rr¬r„rzrerØÚcommentrDrº)r«r^r­r®r®r¯Úvisit_set_constraint_commentx    s
 ÿýz*PGDDLCompiler.visit_set_constraint_commentcKs,| |¡d|j |j¡|j |jj¡fS)Nz&COMMENT ON CONSTRAINT %s ON %s IS NULL)rœr¿rr¬r„rz)r«rlr­r®r®r¯Úvisit_drop_constraint_comment‚    s
 
 þz+PGDDLCompiler.visit_drop_constraint_comment)rDrErFrUrYr`rbrjrmrvrwrŠrŒrr–r™r›rœržrŸrGr®r®rûr¯rH,s"6   X"      
rHcsŒeZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd d„Z    dd„Z
dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„Zd;d<„Z d=d>„Z!d?d@„Z"‡fdAdB„Z#d^dDdE„Z$d_dFdG„Z%dHdI„Z&dJdK„Z'dLdM„Z(dNdO„Z)‡fdPdQ„Z*dRdS„Z+dTdU„Z,dVdW„Z-dXdY„Z.dZd[„Z/d\d]„Z0‡Z1S)`ÚPGTypeCompilercKsdS)Nr0r®©r«rÀr­r®r®r¯Úvisit_TSVECTOR‹    szPGTypeCompiler.visit_TSVECTORcKsdS)NZTSQUERYr®r¡r®r®r¯Ú visit_TSQUERYŽ    szPGTypeCompiler.visit_TSQUERYcKsdS)Nrr®r¡r®r®r¯Ú
visit_INET‘    szPGTypeCompiler.visit_INETcKsdS)Nrr®r¡r®r®r¯Ú
visit_CIDR”    szPGTypeCompiler.visit_CIDRcKsdS)Nrr®r¡r®r®r¯Ú visit_CITEXT—    szPGTypeCompiler.visit_CITEXTcKsdS)Nr!r®r¡r®r®r¯Ú visit_MACADDRš    szPGTypeCompiler.visit_MACADDRcKsdS)Nr"r®r¡r®r®r¯Úvisit_MACADDR8    szPGTypeCompiler.visit_MACADDR8cKsdS)Nr#r®r¡r®r®r¯Ú visit_MONEY     szPGTypeCompiler.visit_MONEYcKsdS)Nr$r®r¡r®r®r¯Ú    visit_OID£    szPGTypeCompiler.visit_OIDcKsdS)Nr-r®r¡r®r®r¯Úvisit_REGCONFIG¦    szPGTypeCompiler.visit_REGCONFIGcKsdS)Nr,r®r¡r®r®r¯Úvisit_REGCLASS©    szPGTypeCompiler.visit_REGCLASScKs|js
dSdd|jiSdS)NrLzFLOAT(%(precision)s)Ú    precision)r­r¡r®r®r¯Ú visit_FLOAT¬    szPGTypeCompiler.visit_FLOATcKs|jtf|ŽSr§)Zvisit_DOUBLE_PRECISIONrÎr¡r®r®r¯Ú visit_double²    szPGTypeCompiler.visit_doublecKsdS)NrGr®r¡r®r®r¯Ú visit_BIGINTµ    szPGTypeCompiler.visit_BIGINTcKsdS)NÚHSTOREr®r¡r®r®r¯Ú visit_HSTORE¸    szPGTypeCompiler.visit_HSTOREcKsdS)NrÏr®r¡r®r®r¯Ú
visit_JSON»    szPGTypeCompiler.visit_JSONcKsdS)NÚJSONBr®r¡r®r®r¯Ú visit_JSONB¾    szPGTypeCompiler.visit_JSONBcKsdS)NÚINT4MULTIRANGEr®r¡r®r®r¯Úvisit_INT4MULTIRANGEÁ    sz#PGTypeCompiler.visit_INT4MULTIRANGEcKsdS)NÚINT8MULTIRANGEr®r¡r®r®r¯Úvisit_INT8MULTIRANGEÄ    sz#PGTypeCompiler.visit_INT8MULTIRANGEcKsdS)NÚ NUMMULTIRANGEr®r¡r®r®r¯Úvisit_NUMMULTIRANGEÇ    sz"PGTypeCompiler.visit_NUMMULTIRANGEcKsdS)NÚDATEMULTIRANGEr®r¡r®r®r¯Úvisit_DATEMULTIRANGEÊ    sz#PGTypeCompiler.visit_DATEMULTIRANGEcKsdS)NÚ TSMULTIRANGEr®r¡r®r®r¯Úvisit_TSMULTIRANGEÍ    sz!PGTypeCompiler.visit_TSMULTIRANGEcKsdS)NÚTSTZMULTIRANGEr®r¡r®r®r¯Úvisit_TSTZMULTIRANGEР   sz#PGTypeCompiler.visit_TSTZMULTIRANGEcKsdS)NÚ    INT4RANGEr®r¡r®r®r¯Úvisit_INT4RANGEÓ    szPGTypeCompiler.visit_INT4RANGEcKsdS)NÚ    INT8RANGEr®r¡r®r®r¯Úvisit_INT8RANGEÖ    szPGTypeCompiler.visit_INT8RANGEcKsdS)NÚNUMRANGEr®r¡r®r®r¯Úvisit_NUMRANGEÙ    szPGTypeCompiler.visit_NUMRANGEcKsdS)NÚ    DATERANGEr®r¡r®r®r¯Úvisit_DATERANGEÜ    szPGTypeCompiler.visit_DATERANGEcKsdS)NÚTSRANGEr®r¡r®r®r¯Ú visit_TSRANGEß    szPGTypeCompiler.visit_TSRANGEcKsdS)NÚ    TSTZRANGEr®r¡r®r®r¯Úvisit_TSTZRANGEâ    szPGTypeCompiler.visit_TSTZRANGEcKsdS)NÚINTr®r¡r®r®r¯Úvisit_json_int_indexå    sz#PGTypeCompiler.visit_json_int_indexcKsdS)NrQr®r¡r®r®r¯Úvisit_json_str_indexè    sz#PGTypeCompiler.visit_json_str_indexcKs|j|f|ŽSr§)Úvisit_TIMESTAMPr¡r®r®r¯Úvisit_datetimeë    szPGTypeCompiler.visit_datetimec s0|jr|jjstƒj|f|ŽS|j|f|ŽSdSr§)r_r¼Úsupports_native_enumrøÚ
visit_enumÚ
visit_ENUMr¡rûr®r¯rÔî    szPGTypeCompiler.visit_enumNcKs|dkr|jj}| |¡Sr§©r¼r¸rh©r«rÀr¸r­r®r®r¯rÕô    szPGTypeCompiler.visit_ENUMcKs|dkr|jj}| |¡Sr§rÖr×r®r®r¯Ú visit_DOMAINù    szPGTypeCompiler.visit_DOMAINcKs4dt|ddƒdk    rd|jnd|jr(dp*ddfS)NzTIMESTAMP%s %sr­ú(%d)rÞÚWITHÚWITHOUTú
 TIME ZONE©Úgetattrr­Útimezoner¡r®r®r¯rÑþ    s ÿ üzPGTypeCompiler.visit_TIMESTAMPcKs4dt|ddƒdk    rd|jnd|jr(dp*ddfS)Nz    TIME%s %sr­rÙrÞrÚrÛrÜrÝr¡r®r®r¯Ú
visit_TIME
s ÿ üzPGTypeCompiler.visit_TIMEcKs8d}|jdk    r|d|j7}|jdk    r4|d|j7}|S)Nr rIz (%d))Úfieldsr­)r«rÀr­r”r®r®r¯Úvisit_INTERVAL
s 
 
zPGTypeCompiler.visit_INTERVALcKs2|jr$d}|jdk    r.|d|j7}n
d|j}|S)Nz BIT VARYINGrÙzBIT(%d))Úvaryingr)r«rÀr­Zcompiledr®r®r¯Ú    visit_BIT
s 
 
zPGTypeCompiler.visit_BITc s(|jr|j|f|ŽStƒj|f|ŽSdSr§)Z native_uuidÚ
visit_UUIDrøÚ
visit_uuidr¡rûr®r¯ræ
szPGTypeCompiler.visit_uuidcKsdS)NrRr®r¡r®r®r¯rå%
szPGTypeCompiler.visit_UUIDcKs|j|f|ŽSr§)Ú visit_BYTEAr¡r®r®r¯Úvisit_large_binary(
sz!PGTypeCompiler.visit_large_binarycKsdS)Nrr®r¡r®r®r¯rç+
szPGTypeCompiler.visit_BYTEAcKs:|j|jf|Ž}tjddd|jdk    r*|jnd|ddS)Nz((?: COLLATE.*)?)$z%s\1ú[]r    )Úcount)r¾r]ÚreÚsubZ
dimensions)r«rÀr­rˆr®r®r¯Ú visit_ARRAY.
sÿþözPGTypeCompiler.visit_ARRAYcKs|j|f|ŽSr§)Úvisit_JSONPATHr¡r®r®r¯Úvisit_json_path=
szPGTypeCompiler.visit_json_pathcKsdS)NÚJSONPATHr®r¡r®r®r¯rî@
szPGTypeCompiler.visit_JSONPATH)N)N)2rDrErFr¢r£r¤r¥r¦r§r¨r©rªr«r¬r®r¯r°r²r³rµr·r¹r»r½r¿rÁrÃrÅrÇrÉrËrÍrÏrÐrÒrÔrÕrØrÑràrârärærårèrçrírïrîrGr®r®rûr¯r Š    s\ 
 
     r c@s"eZdZeZdd„Zddd„ZdS)ÚPGIdentifierPreparercCs*|d|jkr&|dd… |j|j¡}|S)Nrr    r')Z initial_quoterúZescape_to_quoteZ escape_quote)r«rçr®r®r¯Ú_unquote_identifierG
s  ÿz(PGIdentifierPreparer._unquote_identifierTcCs\|jst d|jj›d¡‚| |j¡}| |¡}|jsX|rX|dk    rX| |¡›d|›}|S)Nz PostgreSQL z type requires a name.Ú.)    r“r2r·rürDrÚschema_for_objectZ omit_schemaZ quote_schema)r«rÀr r“Úeffective_schemar®r®r¯rhN
sÿ 
ÿþýz PGIdentifierPreparer.format_typeN)T)rDrErFÚRESERVED_WORDSZreserved_wordsròrhr®r®r®r¯rñD
srñc@s*eZdZUdZded<ded<ded<dS)ÚReflectedNamedTypez"Represents a reflected named type.rr“r3ÚboolÚvisibleN©rDrErFÚ__doc__Ú__annotations__r®r®r®r¯r÷`
s
 
r÷c@s"eZdZUdZded<ded<dS)ÚReflectedDomainConstraintz2Represents a reflect check constraint of a domain.rr“r[Nrúr®r®r®r¯rýk
s
rýc@s2eZdZUdZded<ded<ded<ded    <d
S) ÚReflectedDomainúRepresents a reflected enum.rrÎrørSú Optional[str]r8zList[ReflectedDomainConstraint]Ú constraintsNrúr®r®r®r¯rþt
s
rþc@seZdZUdZded<dS)Ú ReflectedEnumrÿú    List[str]ÚlabelsNrúr®r®r®r¯r…
s
rc@sveZdZUded<dddddœdd    „Zddd
d œd d „Zdddd œdd„Zdddd œdd„Zddddddœdd„ZdS)Ú PGInspectorÚ    PGDialectr¼NrrÚint)Ú
table_namer3Úreturnc
Cs6| ¡$}|jj||||jdW5QR£SQRXdS)aQReturn the OID for the given table name.
 
        :param table_name: string name of the table.  For special quoting,
         use :class:`.quoted_name`.
 
        :param schema: string schema name; if omitted, uses the default schema
         of the database connection.  For special quoting,
         use :class:`.quoted_name`.
 
        ©Ú
info_cacheN)Ú_operation_contextr¼Ú get_table_oidr )r«rr3Úconnr®r®r¯r 
s
ÿzPGInspector.get_table_oidzList[ReflectedDomain])r3r    c
Cs4| ¡"}|jj|||jdW5QR£SQRXdS)aÐReturn a list of DOMAIN objects.
 
        Each member is a dictionary containing these fields:
 
            * name - name of the domain
            * schema - the schema name for the domain.
            * visible - boolean, whether or not this domain is visible
              in the default search path.
            * type - the type defined by this domain.
            * nullable - Indicates if this domain can be ``NULL``.
            * default - The default value of the domain or ``None`` if the
              domain has no default.
            * constraints - A list of dict wit the constraint defined by this
              domain. Each element constaints two keys: ``name`` of the
              constraint and ``check`` with the constraint text.
 
        :param schema: schema name.  If None, the default schema
         (typically 'public') is used.  May also be set to ``'*'`` to
         indicate load domains for all schemas.
 
        .. versionadded:: 2.0
 
        r
N)r r¼Ú _load_domainsr ©r«r3rr®r®r¯Ú get_domains¢
s 
ÿzPGInspector.get_domainszList[ReflectedEnum]c
Cs4| ¡"}|jj|||jdW5QR£SQRXdS)a.Return a list of ENUM objects.
 
        Each member is a dictionary containing these fields:
 
            * name - name of the enum
            * schema - the schema name for the enum.
            * visible - boolean, whether or not this enum is visible
              in the default search path.
            * labels - a list of string labels that apply to the enum.
 
        :param schema: schema name.  If None, the default schema
         (typically 'public') is used.  May also be set to ``'*'`` to
         indicate load enums for all schemas.
 
        r
N)r r¼Ú _load_enumsr rr®r®r¯Ú    get_enumsÁ
s 
ÿzPGInspector.get_enumsrc
Cs4| ¡"}|jj|||jdW5QR£SQRXdS)zøReturn a list of FOREIGN TABLE names.
 
        Behavior is similar to that of
        :meth:`_reflection.Inspector.get_table_names`,
        except that the list is limited to those tables that report a
        ``relkind`` value of ``f``.
 
        r
N)r r¼Ú_get_foreign_table_namesr rr®r®r¯Úget_foreign_table_namesÖ
s
ÿz#PGInspector.get_foreign_table_namesrrø)Ú    type_namer3r­r    c
Ks6| ¡$}|jj||||jdW5QR£SQRXdS)aJReturn if the database has the specified type in the provided
        schema.
 
        :param type_name: the type to check.
        :param schema: schema name.  If None, the default schema
         (typically 'public') is used.  May also be set to ``'*'`` to
         check in all schemas.
 
        .. versionadded:: 2.0
 
        r
N)r r¼Úhas_typer )r«rr3r­rr®r®r¯ræ
s
ÿzPGInspector.has_type)N)N)N)N)N)    rDrErFrür rrrrr®r®r®r¯rŒ
s
ÿÿÿÿrcs$eZdZdd„Z‡fdd„Z‡ZS)ÚPGExecutionContextcCs| d|j |¡|¡S)Nzselect nextval('%s'))Ú_execute_scalarr¸rý)r«rþrÀr®r®r¯Ú fire_sequenceû
s 
ÿûz PGExecutionContext.fire_sequencec s2|jr&||jjkr&|jr:|jjr:| d|jj|j¡S|jdksX|jj    r&|jj
r&z
|j }Wntt k
rÖ|jj }|j }|ddtddt|ƒƒ…}|ddtddt|ƒƒ…}d||f}||_ }YnX|jdk    rò|j |j¡}nd}|dk    rd||f}n
d|f}| ||j¡Stƒ |¡S)Nz    select %sréz    %s_%s_seqzselect nextval('"%s"."%s"')zselect nextval('"%s"'))rMrzrNZserver_defaultZ has_argumentrÚargrÎr8Z is_sequencerQZ_postgresql_seq_nameÚAttributeErrorr“ÚmaxrÚ
connectionrôrøÚget_insert_default)r«r\Zseq_nameÚtabr    r“rõr2rûr®r¯r  sB
ÿ
ÿÿ
 
ÿ
þ
z%PGExecutionContext.get_insert_default)rDrErFrr rGr®r®rûr¯rú
s    rc@s(eZdZdZdd„Zdd„Zdd„ZdS)    Ú"PGReadOnlyConnectionCharacteristicTcCs| |d¡dS©NF©Ú set_readonly©r«r¼Ú
dbapi_connr®r®r¯Úreset_characteristic6 sz7PGReadOnlyConnectionCharacteristic.reset_characteristiccCs| ||¡dSr§r$©r«r¼r'rçr®r®r¯Úset_characteristic9 sz5PGReadOnlyConnectionCharacteristic.set_characteristiccCs
| |¡Sr§)Ú get_readonlyr&r®r®r¯Úget_characteristic< sz5PGReadOnlyConnectionCharacteristic.get_characteristicN©rDrErFZ transactionalr(r*r,r®r®r®r¯r"1 sr"c@s(eZdZdZdd„Zdd„Zdd„ZdS)    Ú$PGDeferrableConnectionCharacteristicTcCs| |d¡dSr#©Úset_deferrabler&r®r®r¯r(E sz9PGDeferrableConnectionCharacteristic.reset_characteristiccCs| ||¡dSr§r/r)r®r®r¯r*H sz7PGDeferrableConnectionCharacteristic.set_characteristiccCs
| |¡Sr§)Úget_deferrabler&r®r®r¯r,K sz7PGDeferrableConnectionCharacteristic.get_characteristicNr-r®r®r®r¯r.@ sr.c    s„eZdZdZdZdZdZdZej    j
Z dZ dZ dZdZdZdZdZdZdZdZejejBejBZdZdZdZdZdZdZ dZ!dZ"e#Z#e$Z$e%Z&e'Z(e)Z*e+Z,e-Z.e/Z0dZ1dZ2dZ3dZ4dZ5e6j7j8Z8e8 9e:ƒe;ƒdœ¡Z8e<j=dddididdœfe<j>ddddddd    œfe<j?d
dife<j@d
difgZAd ZBdZCdZDdZEd›d d „ZF‡fdd„ZGdd„ZHdd„ZIdd„ZJdd„ZKdd„ZLdd„ZMdd„ZNdd„ZOd d!„ZPdœd"d#„ZQdd$d%„ZRd&d'„ZSd(d)„ZTeUjVd*d+„ƒZWdžd,d-„ZXdŸd.d/„ZYeZƒd0d1„ƒZ[eUjVd d2d3„ƒZ\eUjVd¡d4d5„ƒZ]eUjVd¢d6d7„ƒZ^d8d9„Z_eUjVd£d:d;„ƒZ`eUjVd<d=„ƒZad>d?„ZbeUjVd¤d@dA„ƒZceUjVdBdC„ƒZdeUjVd¥dDdE„ƒZeeUjVd¦dFdG„ƒZfeUjVd§dHdI„ƒZgeUjVd¨dJdK„ƒZheUjVd©dLdM„ƒZieUjVdªdNdO„ƒZjdPdQ„ZkdRdS„ZldTdUdVœdWdX„ZmeUjVd«dYdZ„ƒZneZƒd[d\„ƒZod]d^„Zpd_d`„ZqeZƒdadb„ƒZreU sdcetjufddetjvfdeetjwfdfetjwf¡dgdh„ƒZxeyjzdidj„ƒZ{dkdl„Z|eUjVd¬dmdn„ƒZ}dodp„Z~eUjVd­dqdr„ƒZeZƒdsdt„ƒZ€eyjzdudv„ƒZd®dwdx„Z‚eUjVd¯dydz„ƒZƒeyjzd{d|„ƒZ„d}d~„Z…eUjVd°dd€„ƒZ†dd‚„Z‡eUjVd±dƒd„„ƒZˆeZƒd…d†„ƒZ‰d‡dˆ„ZŠeUjVd²d‰dŠ„ƒZ‹eZƒd‹dŒ„ƒZŒddŽ„Zdd„ZŽeZƒd‘d’„ƒZeUjVd³d“d”„ƒZeZƒd•d–„ƒZ‘eUjVd´d—d˜„ƒZ’d™dš„Z“‡Z”S)µrrVTé?FZpyformat)Zpostgresql_readonlyZpostgresql_deferrableN)r€r~r‚r{rxrƒr)Zignore_search_pathrr‘r’r“rrW)Úpostgresql_ignore_search_pathcKs tjj|f|Ž||_||_dSr§)r8ÚDefaultDialectÚ__init__Z_json_deserializerZ_json_serializer)r«Zjson_serializerZjson_deserializerrTr®r®r¯r5½ szPGDialect.__init__cs>tƒ |¡|jdk|_| |¡|jdk|_|jdk|_dS)N)é    r©é
)røÚ
initializeÚserver_version_inforOÚ_set_backslash_escapesr‹rL©r«rrûr®r¯r9à s
 
 zPGDialect.initializecCsdS)N)Z SERIALIZABLEzREAD UNCOMMITTEDzREAD COMMITTEDzREPEATABLE READr®)r«r'r®r®r¯Úget_isolation_level_valuesÑ sz$PGDialect.get_isolation_level_valuescCs.| ¡}| d|›¡| d¡| ¡dS)Nz;SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ZCOMMIT)ÚcursorÚexecuteÚclose)r«Údbapi_connectionÚlevelr>r®r®r¯Úset_isolation_levelÛ s ÿ
zPGDialect.set_isolation_levelcCs.| ¡}| d¡| ¡d}| ¡| ¡S)Nz show transaction isolation levelr)r>r?Zfetchoner@r)r«rAr>Úvalr®r®r¯Úget_isolation_levelä s
 
 zPGDialect.get_isolation_levelcCs
tƒ‚dSr§©ÚNotImplementedError©r«rrçr®r®r¯r%ë szPGDialect.set_readonlycCs
tƒ‚dSr§rFr<r®r®r¯r+î szPGDialect.get_readonlycCs
tƒ‚dSr§rFrHr®r®r¯r0ñ szPGDialect.set_deferrablecCs
tƒ‚dSr§rFr<r®r®r¯r1ô szPGDialect.get_deferrablecCs| |j¡dSr§)Zdo_beginr©r«rÚxidr®r®r¯Údo_begin_twophase÷ szPGDialect.do_begin_twophasecCs| d|¡dS)NzPREPARE TRANSACTION '%s')Úexec_driver_sqlrIr®r®r¯Údo_prepare_twophaseú szPGDialect.do_prepare_twophasecCsH|r8|r| d¡| d|¡| d¡| |j¡n | |j¡dS)NÚROLLBACKzROLLBACK PREPARED '%s'ÚBEGIN)rLÚ do_rollbackr©r«rrJZ is_preparedZrecoverr®r®r¯Údo_rollback_twophaseý s
 
zPGDialect.do_rollback_twophasecCsH|r8|r| d¡| d|¡| d¡| |j¡n | |j¡dS)NrNzCOMMIT PREPARED '%s'rO)rLrPrZ    do_commitrQr®r®r¯Údo_commit_twophase s
 
zPGDialect.do_commit_twophasecCs| t d¡¡ ¡S)Nz!SELECT gid FROM pg_prepared_xacts)Úscalarsr5r”rUr<r®r®r¯Údo_recover_twophase sÿzPGDialect.do_recover_twophasecCs| d¡ ¡S)Nzselect current_schema())rLÚscalarr<r®r®r¯Ú_get_default_schema_name sz"PGDialect._get_default_schema_namecKs,ttjjjƒ tjjj|k¡}t| |¡ƒSr§)r4r Ú pg_namespacerÚnspnamer‚rørV)r«rr3r­Úqueryr®r®r¯Ú
has_schema! s ÿzPGDialect.has_schemacCs¦|dkrtj}| tjtjjj|jjk¡}|tjkrH|     |jj
dk¡}n|tj krd|     |jj
dk¡}|dkrŽ|     t  |jj¡tjjj dk¡}n|     tjjj |k¡}|S)Nr:r )r Úpg_classrŠrXrr›Ú relnamespacer;ÚDEFAULTr‚ZrelpersistenceÚ    TEMPORARYZpg_table_is_visiblerY)r«rZr3ÚscopeÚpg_class_tabler®r®r¯Ú_pg_class_filter_scope_schema( s"þ
 
  ýz'PGDialect._pg_class_filter_scope_schemacCs&|dkrtj}|jjt t |¡¡kSr§)r r\rÚrelkindr5Úany_rr
)r«Úrelkindsrar®r®r¯Ú_pg_class_relkind_conditionA sz%PGDialect._pg_class_relkind_conditioncCs>ttjjjƒ tjjjtdƒk| tj¡¡}|j    ||t
j dS)Nr©r`) r4r r\rÚrelnamer‚r>rfÚRELKINDS_ALL_TABLE_LIKErbr;ÚANY)r«r3rZr®r®r¯Ú_has_table_queryH sÿþÿzPGDialect._has_table_querycKs(| |¡| |¡}t| |d|i¡ƒS)Nr)Z_ensure_has_table_connectionrkrørV)r«rrr3r­rZr®r®r¯Ú    has_tableT s
 
zPGDialect.has_tablecKsJttjjjƒ tjjjdktjjj|k¡}|j||tj    d}t
|  |¡ƒS)NÚSrg) r4r r\rrhr‚rcrbr;rjrørV)r«rZ sequence_namer3r­rZr®r®r¯Ú has_sequenceZ s  þÿzPGDialect.has_sequencecKsŽttjjjƒ tjtjjjtjjjk¡     tjjj|k¡}|dkrd|     t 
tjjj¡tjjj dk¡}n|dkr€|     tjjj |k¡}t |  |¡ƒS©Nr Ú*)r4r Úpg_typerÚtypnamerŠrXr›Ú typnamespacer‚Úpg_type_is_visiblerYrørV)r«rrr3r­rZr®r®r¯re s"ÿý úÿ     ýzPGDialect.has_typecCsF| d¡ ¡}t d|¡}|s*td|ƒ‚tdd„| ddd¡DƒƒS)    Nzselect pg_catalog.version()zQ.*(?:PostgreSQL|EnterpriseDB) (\d+)\.?(\d+)?(?:\.(\d+))?(?:\.\d+)?(?:devel|beta)?z,Could not determine version from string '%s'cSsg|]}|dk    rt|ƒ‘qSr§)r©róÚxr®r®r¯r † sz6PGDialect._get_server_version_info.<locals>.<listcomp>r    rr1)rLrVrëÚmatchÚAssertionErrorr•ri)r«rr4Úmr®r®r¯Ú_get_server_version_info{ sýÿz"PGDialect._get_server_version_infocKslttjjjƒ tjjj|k| tj¡¡}|j    ||t
j d}|  |¡}|dkrht  |rb|›d|›n|¡‚|S)z$Fetch the oid for schema.table_name.rgNró)r4r r\rr›r‚rhrfrirbr;rjrVr2ÚNoSuchTableError)r«rrr3r­rZZ    table_oidr®r®r¯r ˆ s" ÿþÿ
ÿzPGDialect.get_table_oidcKs:ttjjjƒ tjjj d¡¡ tjjj¡}| |¡     ¡S)Nzpg_%)
r4r rXrrYr‚Znot_likerÕrTrU)r«rr­rZr®r®r¯Úget_schema_names› sÿþÿzPGDialect.get_schema_namescCs8ttjjjƒ | |¡¡}|j|||d}| |¡     ¡S©Nrg)
r4r r\rrhr‚rfrbrTrU)r«rr3rer`rZr®r®r¯Ú_get_relnames_for_relkinds¤ s
ÿz$PGDialect._get_relnames_for_relkindscKs|j||tjtjdSr})r~r ÚRELKINDS_TABLE_NO_FOREIGNr;r^©r«rr3r­r®r®r¯Úget_table_names« s üzPGDialect.get_table_namescKs|j|dtjtjdS)N)r3rer`)r~r rr;r_)r«rr­r®r®r¯Úget_temp_table_names´ s üzPGDialect.get_temp_table_namescKs|j||dtjdS)N)Úf©rer`©r~r;rjr€r®r®r¯r½ s ÿz"PGDialect._get_foreign_table_namescKs|j||tjtjdSr})r~r Ú RELKINDS_VIEWr;r^r€r®r®r¯Úget_view_namesà s üzPGDialect.get_view_namescKs|j||tjtjdSr})r~r ÚRELKINDS_MAT_VIEWr;r^r€r®r®r¯Úget_materialized_view_namesÌ s üz%PGDialect.get_materialized_view_namescKs|j||tjtjdSr})r~r r†r;r_r€r®r®r¯Úget_temp_view_namesÕ s úzPGDialect.get_temp_view_namescKs|j||dtjdS)N)rmr„r…r€r®r®r¯Úget_sequence_namesà s ÿzPGDialect.get_sequence_namescKs†tt tjjj¡ƒ tj¡ tjjj|k|     tj
tj ¡¡}|j ||t jd}| |¡}|dkr~t |rv|›d|›n|¡‚n|SdS)Nrgró)r4r Zpg_get_viewdefr\rr›Ú select_fromr‚rhrfr†rˆrbr;rjrVr2r{)r«rZ    view_namer3r­rZÚresr®r®r¯Úget_view_definitionæ s(ÿ 
ÿüÿ
ÿ
ÿzPGDialect.get_view_definitioncCsJzt|ƒ||fWStk
rDt |r8|›d|›n|¡d‚YnXdS)Nró)r)ÚKeyErrorr2r{)r«Údatarzr3r®r®r¯Ú_value_or_raiseý sÿþzPGDialect._value_or_raisecCs|rdd|ifSdifSdS)NTÚ filter_namesFr®)r«r’r®r®r¯Ú_prepare_filter_names s zPGDialect._prepare_filter_namesr:zTuple[str, ...])Úkindr    cCsT|tjkrtjSd}tj|kr(|tj7}tj|kr<|tj7}tj|krP|tj    7}|S)Nr®)
r:rjr riZTABLEZRELKINDS_TABLEZVIEWr†ZMATERIALIZED_VIEWrˆ)r«r”rer®r®r¯Ú_kind_to_relkinds s
 
 
 
 
 
 
zPGDialect._kind_to_relkindscKs0|j|f||gtjtjdœ|—Ž}| |||¡S©N)r3r’r`r”)Úget_multi_columnsr;rjr:r‘©r«rrr3r­rr®r®r¯Ú get_columns sÿûúzPGDialect.get_columnsc
Cs˜|jdkrtjjj d¡n t ¡ d¡}|jdkröttj     
dtjjj dkdtj jj dtj jjdtj jjd    tj jjd
tj jjd tj jj¡ƒ tj ¡ tjjj d ktj jjt t t t t tjjjt¡t¡tjjj¡t¡t¡k¡ tj¡ ¡ d ¡}nt ¡ d ¡}tt tj jj!tj jj"¡ƒ tj ¡ tj jj"tjjjktj jj#tjjj$ktjjj%¡ tj¡ ¡ d¡}| &|¡}ttjjj d¡t 'tjjj(tjjj)¡ d¡|tjjj* d¡tj+jj, d¡tj-jj. d¡||ƒ tj+¡ /tjt 0tj+jj1tjjjktjjj$dktjjj2¡¡ /tj-t 0tj-jj3tjjjktj-jj4tjjj$k¡¡ | 5|¡¡ 6tj+jj,tjjj$¡}    |j7|    ||d}    |r”|     tj+jj, 8t9dƒ¡¡}    |    S)N)é r˜r7ÚalwaysÚarÄÚ    incrementZminvalueZmaxvalueÚcacheÚcyclerÞÚidentity_optionsr8r“rhrqrrrrgr’):r:r Ú pg_attributerZ attgeneratedÚlabelr5rqr4rZjson_build_objectZ attidentityZ pg_sequenceZseqstartZ seqincrementZseqminZseqmaxZseqcacheZseqcyclerŒr‚ZseqrelidrZZpg_get_serial_sequenceÚattrelidr,rQÚattnamer$Z    correlateZscalar_subqueryÚ pg_get_exprZ
pg_attrdefZadbinZadrelidZadnumÚattnumZ    atthasdefr•rhZatttypidZ    atttypmodZ
attnotnullr\rhÚpg_descriptionÚ descriptionÚ    outerjoinÚand_r›Z attisdroppedÚobjoidÚobjsubidrfrÕrbÚin_r>)
r«r3Úhas_filter_namesr`r”r˜rKr8rerZr®r®r¯Ú_columns_query# sòÿ ý
 òÿî þûø
õ òÿé)×+Õÿ/þÿúÿÿôòðÿ
þýõ óÿ 
üíÿÿýä#Ý%Ûÿ)ÿzPGDialect._columns_querycKsŠ| |¡\}}| ||||¡}    | |    |¡ ¡}
dd„|j|d| d¡dDƒ} tdd„|j|d| d¡dDƒƒ} | |
| | |¡} |      ¡S)NcSs0i|](}|ds |d|dfn|df|“qS)rùr3r“r®)róÚdr®r®r¯Ú
<dictcomp>­ sÿ z/PGDialect.get_multi_columns.<locals>.<dictcomp>rpr )r3r css8|]0}|dr|df|fn|d|df|fVqdS)rùr“r3Nr®)róZrecr®r®r¯rõ¶ sþÿz.PGDialect.get_multi_columns.<locals>.<genexpr>)
r“r¯r?Úmappingsrràr)rÚ_get_columns_infor0)r«rr3r’r`r”r­r®ÚparamsrZÚrowsÚdomainsrir[r®r®r¯r—¤ s&ÿþ    ÿü    zPGDialect.get_multi_columnsc$sžt d¡‰t d¡}t d¡}t d¡}t d¡}‡fdd„}    ttƒ}
|D]L} | ddkrrt ¡|
|| d    f<qJ|
|| d    f} | d
} | d }| d}| d }| d }| dkrÄd}d}} d}nd}| d| ¡}|    |ƒ\}}tt     |¡ƒ}| d }| 
| ¡}|r|  d¡}| 
| ¡}|rD|  d¡rDt|  |  d¡¡ƒ}nd}i}|dkr‚|r||  d¡\}}t |ƒt |ƒf}nd}nú|dkr’d}nê|dkr¢d}nÚ|dkrÌd|d<|rÆt |ƒ|d<d}n°|dkröd|d<|rðt |ƒ|d<d}n†|dkr d|d<|rt |ƒf}nd}n\| d ¡rlt d!|tj¡}|rNt |ƒ|d<|rb|  d¡|d"<d }d}n|r|t |ƒf}||jkr˜|j|}qNn²||krâ||}t}|d|d<|d#sÐ|d$|d$<t|d%ƒ}qNnh||krB||}|d&}|    |ƒ\}}tt     |¡ƒ}|o"|d'}|d r||s||d }q|nd}qNq||rt|||Ž}|rª|jd(|ƒ}n6|r’t d)|f¡tj}nt d*||f¡tj}|d+krÊt||d,kd-} d}nd} d}!|dk    rJt 
d.|¡}"|"dk    rJt|jtjƒrd}!d/|"  d0¡krJ|dk    rJ|"  d¡d1|d/|"  d0¡|"  d2¡}|||||!p^|dk    | d3d4œ}#| dk    r|| |#d5<|dk    rŽ||#d6<|  |#¡qJ|
S)7Nz\[\]$z\(.*\)z \(([\d,]+)\)z\((.*)\)ú\s*,\s*csˆ d|¡| d¡fS)NrÞré)rìÚendswith)Úattype©Zarray_type_patternr®r¯Ú_handle_array_typeÊ s
ýz7PGDialect._get_columns_info.<locals>._handle_array_typer“rrhr8r˜r Tzno format_type()FrÞrqr    r®r•ú,rœ)é5r‘)ržr rßr­)rŸr¡r£ršrãr¥z interval (.+)rárùr3rrÎrSrz6PostgreSQL format_type() returned NULL for column '%s'z*Did not recognize type '%s' of column '%s')NrÞó)rós)rÁr—z(nextval\(')([^']+)('.*$)rórz"%s"r1r)r“rÎrSr8Ú autoincrementrrRrK)rëÚcompilerrZr=r[rìr•r6Zquoted_token_parserÚsearchriÚsplitrÚ
startswithrwÚIÚ ischema_namesrr/rDZNULLTYPEr)Ú
issubclassr¹ZIntegerr.)$r«rµr¶rir3Zattype_patternZcharlen_patternZ args_patternZargs_split_patternr»r[Úrow_dictZ
table_colsrhr8r“r˜rKZno_format_typer¹Zis_arrayZenum_or_domain_keyrSZcharlenÚargsrTÚprecZscaleZ field_matchZcoltypeÚenumrtrRrÀrwZ column_infor®rºr¯r³à s*
 
 
 
 
 
 þ
ÿ  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 ÿ
ÿÿÿÿ
ÿ
 
ÿþýüÿ     ú
 
 zPGDialect._get_columns_infocCs^| |¡}ttjjjtjjjƒ | |¡¡}|j    |||d}|rZ| tjjj 
t dƒ¡¡}|S)Nrgr’) r•r4r r\rr›rhr‚rfrbr­r>)r«r3r®r`r”reÚoid_qr®r®r¯Ú_table_oids_queryŠs
ÿþÿzPGDialect._table_oids_queryr3r’r”r`c Ks2| |¡\}}| ||||¡}    | |    |¡}
|
 ¡Sr§)r“rÍr?rU) r«rr3r’r`r”r­r®r´rÌÚresultr®r®r¯Ú_get_table_oids˜s     zPGDialect._get_table_oidscCsVttjjjtjjjtj tjjj    ¡ 
d¡tj  tjjj    d¡ 
d¡tj jj ƒ tj tj jjtjjjk¡ tjjjtdƒktjjj tdƒ¡¡ d¡}t|jj|jj|jj |jjtjjjƒ tj¡ |t tjjj|jjktjjj|jjk¡¡ d¡}t|jjtj t|jj|jjƒ¡ 
d¡|jjtj  |jj ¡ 
d    ¡ƒ !|jj|jj¡ "|jj|jj¡S)
Nr¦r    ÚordÚcontypeÚoidsÚconÚattrr2r¨)#r4r Ú pg_constraintrÚconrelidÚconnamer5rÚunnestZconkeyr¢Úgenerate_subscriptsr§r¨r©r«r›r‚rÑr>r­ÚsubqueryrÐr¡r¤rŒrŠrªr¦r£Ú    array_aggrÚminÚgroup_byrÕ)r«Úcon_sqÚattr_sqr®r®r¯Ú_constraint_query¦sxÿÿþ÷ ÿóîìÿûù    þöñÿÿþúø    ÷ÿzPGDialect._constraint_querycksØ|j|||||f|Ž}t|ƒ}    |    rÔ|    dd…}
g|    dd…<| |jdd„|
Dƒ|dœ¡} ttƒ} | D] \} }}}| |  |||f¡qd|
D]F\} }|  | d¡}|rÂ|D]\}}}||||fVq¦qŠ|dddfVqŠqdS)Nré¸ cSsg|] }|d‘qS©rr®©róÚrr®r®r¯r îsz1PGDialect._reflect_constraint.<locals>.<listcomp>)rÒrÑr®)rÏrZr?ràrr.rà)r«rrÑr3r’r`r”r­Ú
table_oidsÚbatchesÚbatchrÎÚ result_by_oidr›r2rprZ    tablenameZfor_oidr]r®r®r¯Ú_reflect_constraintàs4ÿÿ  þ  zPGDialect._reflect_constraintcKs0|j|f||gtjtjdœ|—Ž}| |||¡Sr–)Úget_multi_pk_constraintr;rjr:r‘r˜r®r®r¯Úget_pk_constraintýsÿûúzPGDialect.get_pk_constraintc s2|j|dˆ|||f|Ž}tj‰‡‡fdd„|DƒS)NÚpc3sD|]<\}}}}ˆ|f|dk    r4|dkr(gn|||dœnˆƒfVqdS)N)Úconstrained_columnsr“rr®)rórr2Zpk_namer©r8r3r®r¯rõs
÷ûýøz4PGDialect.get_multi_pk_constraint.<locals>.<genexpr>)rér=Z pk_constraint)r«rr3r’r`r”r­rÎr®rîr¯rê    sÿÿ õz!PGDialect.get_multi_pk_constraintcKs2|j|f||g|tjtjdœ|—Ž}| |||¡S)N)r3r’r3r`r”)Úget_multi_foreign_keysr;rjr:r‘)r«rrr3r3r­rr®r®r¯Úget_foreign_keys!s    ÿúù    zPGDialect.get_foreign_keysc        Cs:tj d¡}tj d¡}| |¡}ttjjjtjjj    t
j tjjj   d¡t tjjj d¡fdd|jjtjjjƒ tj¡ tjt
 tjjj tjjjktjjjdk¡¡ ||jj tjjjk¡ ||jj|jj k¡ tjtjjjtjjj k¡ tjjjtjjj    ¡ | |¡¡}| |||¡}|r6| tjjj tdƒ¡¡}|S)NZcls_refZnsp_refT©Zelse_rƒr’) r r\ÚaliasrXr•r4rrhrÕr×r5rYr›Úis_notÚpg_get_constraintdefrYr§r¨rŒr©rªrÖrÑZ    confrelidr]r«rÕr‚rfrbr­r>)    r«r3r®r`r”Z pg_class_refZpg_namespace_refrerZr®r®r¯Ú_foreing_key_query5sf  
ÿþù    ñïÿ ýìäà#ÿÜ(×+Õÿ.ÿzPGDialect._foreing_key_querycCs
t d¡S)Na/FOREIGN KEY \((.*?)\) REFERENCES (?:(.*?)\.)?(.*?)\((.*?)\)[\s]?(MATCH (FULL|PARTIAL|SIMPLE)+)?[\s]?(ON UPDATE (CASCADE|RESTRICT|NO ACTION|SET NULL|SET DEFAULT)+)?[\s]?(ON DELETE (CASCADE|RESTRICT|NO ACTION|SET NULL|SET DEFAULT)+)?[\s]?(DEFERRABLE|NOT DEFERRABLE)?[\s]?(INITIALLY (DEFERRED|IMMEDIATE)+)?)rërÁrôr®r®r¯Ú_fk_regex_patternosÿzPGDialect._fk_regex_patternc" s˜|j‰| |¡\}}    | ||||¡}
| |
|    ¡} |j} ttƒ} tj}| D]D\}}}}}|dkrp|ƒ| ||f<qH| ||f}t     
| |¡  ¡}|\ }}}}}}}}}}}}}|dk    rÂ|dkr¾dnd}‡fdd„t      d|¡Dƒ}|rö||j krð|}n|}n*|rˆ |¡}n|dk    r ||kr |}ˆ |¡}‡fdd„t      d|¡Dƒ}d    d
„d |fd |fd |fd|fd|ffDƒ} |||||| |dœ}!| |!¡qH|  ¡S)NZ
DEFERRABLETFcsg|]}ˆ |¡‘qSr®©ròrur€r®r¯r ¬sÿz4PGDialect.get_multi_foreign_keys.<locals>.<listcomp>r·csg|]}ˆ |¡‘qSr®r÷rur€r®r¯r Ãsÿz\s*,\scSs&i|]\}}|dk    r|dkr||“qS)Nz    NO ACTIONr®)rór3r4r®r®r¯r±Çs
øz4PGDialect.get_multi_foreign_keys.<locals>.<dictcomp>ÚonupdateÚondeleterkr`rw)r“ríÚreferred_schemaÚreferred_tableÚreferred_columnsrur)r¸r“rõr?rörrZr=Z foreign_keysrërÂÚgroupsrÃZdefault_schema_nameròr.r0)"r«rr3r’r`r”r3r­r®r´rZrÎZFK_REGEXZfkeysr8rr×ZcondefZ    conschemarZ    table_fksryrírúrûrür”rwrørùr`rkruZfkey_dr®r€r¯rï}s~
  ò
 
þ
 
 
 
þûþ ù     z PGDialect.get_multi_foreign_keyscKs0|j|f||gtjtjdœ|—Ž}| |||¡Sr–)Úget_multi_indexesr;rjr:r‘r˜r®r®r¯Ú get_indexesÞsÿûúzPGDialect.get_indexescCstj d¡}ttjjjtjjjtj     
tjjj ¡  d¡tj      tjjj d¡  d¡ƒ tjjjtjjj tdƒ¡¡ d¡}t|jj|jj|jjtj|jjdkt |jj|jjdd¡ft tjjjtƒ¡d      d
¡|jjdk  d ¡ƒ |¡ tjt tjjj|jjktjjj|jjk¡¡ |jj tdƒ¡¡ d ¡}t|jjtj     |jj¡tj      t!|jj"|jjƒ¡  d ¡tj      t!|jj#|jjƒ¡  d¡ƒ $|jj¡ d¡}|j%dkr®tjjj&}nt '¡  d¡}ttjjj|jj(  d¡tjjj)tj*jj+ ,d¡  d¡tjjj-|jj.tj/jj0tjtjjj1 ,d¡t 2tjjj1tjjj¡fdd      d¡||jj3|jj4ƒ  tj¡ tjjj tdƒ¡tjjj¡ 5|tjjj|jj6k¡ 5tj/|jj7tj/jj6k¡ |tjjj|jjk¡ tj*t tjjjtj*jj+ktjjjtj*jj8ktj*jj9t :t; <d¡¡k¡¡ =tjjj|jj(¡S)NZcls_idxr¦r    rÐrÒÚidxrTrñr¬Úis_exprZidx_attrrAÚelements_is_exprZidx_cols©é rÚ indnkeyattsÚ relname_indexÚhas_constraintÚfilter_definition)rìÚurv)>r r\ròr4Zpg_indexrZ
indexrelidÚindrelidr5rrØZindkeyr¢rÙr‚Z indisprimaryr­r>rÚrÐrYr¦Zpg_get_indexdefrZr¡r¤rQrŒr©rªr£rÜrÛrr¬rrÝr:rrqrhÚ indisuniquerÕrÖróÚ    indoptionÚ
reloptionsZpg_amÚamnameZindpredr¥rArrŠr›ZrelamZconindidrÑrdrr
rÕ)r«Zpg_class_indexZidx_sqrßZcols_sqrr®r®r¯Ú _index_queryêsþ ÿþü    
ö ôÿ
 
ÿþ    ö õ îìþèãâÿ#ÿþÿþú
ö õÿ   ÿþþø    ÷
èæ
ã ß$Û(×,ÿÿÿûÓ6ÊÿzPGDialect._index_queryc!Ks¾|j|||||f|Ž}ttƒ}tj}    t|ƒ}
|
r¶|
dd…} g|
dd…<| |jddd„| Dƒi¡ ¡} ttƒ} | D]}| |d |¡qv| D]\}}|| kr´|    ƒ|||f<q’| |D]ò}|d}|||f}|d}|d    }|d
}|rHt    |ƒ|krH||d…}|d|…}|d|…}t
d d „||d…DƒƒsTt ‚n |}|}g}||d dœ}t |ƒrŽdd„t ||ƒDƒ|d<||d<n||d<i}t|dƒD]X\}}d}|d@rØ|d7}|d@sê|d7}n|d@rê|d7}|r¦||||<q¦|r||d<|dr ||d<i}|drHtdd„|dDƒƒ|d<|d} | d krf|d|d!<|d"r||d"|d#<|jd$kr˜||d%<||d&<|r¦||d'<| |¡q¼q’q,| ¡S)(NrrárÒcSsg|] }|d‘qSrâr®rãr®r®r¯r sz/PGDialect.get_multi_indexes.<locals>.<listcomp>r
rrArrcss|] }| VqdSr§r®)rórr®r®r¯rõ¥sÿz.PGDialect.get_multi_indexes.<locals>.<genexpr>r )r“r~cSsg|]\}}|rdn|‘qSr§r®)rór}rr®r®r¯r °sÿÚ column_namesrˆr r®r    )rar)Z
nulls_last)Z nulls_firstZcolumn_sortingrZduplicates_constraintr cSsg|]}| d¡‘qS)ú=)rÃ)róÚoptionr®r®r¯r ÐsZpostgresql_withrZbtreeZpostgresql_usingrZpostgresql_whererZinclude_columnsZpostgresql_includerX)rÏrrZr=Úindexesr?rr²r.rrUrxrWÚzipÚ    enumerater)r:r0)!r«rr3r’r`r”r­rårr8rærçrÎrèrÈr›rÚrowZ
index_nameZ table_indexesZ all_elementsZall_elements_is_exprrZinc_colsZ idx_elementsZidx_elements_is_exprrZsortingZ    col_indexZ    col_flagsZ col_sortingrXrr®r®r¯rþps°ÿÿ  ÿ   ÿ
þ
ÿþ
 
 
 
 
 
 
 
ÿ
 
ÿ zPGDialect.get_multi_indexescKs0|j|f||gtjtjdœ|—Ž}| |||¡Sr–)Úget_multi_unique_constraintsr;rjr:r‘r˜r®r®r¯Úget_unique_constraintsèsÿûúz PGDialect.get_unique_constraintscKsr|j|d||||f|Ž}ttƒ}tj}    |D]>\}
} } } | dkrN|    ƒ|||
f<q*|||
f | | | dœ¡q*| ¡S)Nr    )rr“r)rérrZr=Zunique_constraintsr.r0)r«rr3r’r`r”r­rÎZuniquesr8rr2Zcon_namerr®r®r¯rös.    ÿÿ ýÿz&PGDialect.get_multi_unique_constraintscKs0|j|||gftjtjdœ|—Ž}| |||¡S©N)r`r”)Úget_multi_table_commentr;rjr:r‘r˜r®r®r¯Úget_table_commentsýûúzPGDialect.get_table_commentcCs| |¡}ttjjjtjjjƒ tj¡     tjt
  tjjj tjjj ktjjjdk¡¡ | |¡¡}| |||¡}|rŒ| tjjj tdƒ¡¡}|S)Nrr’)r•r4r r\rrhr§r¨rŒr©r5rªr›r«r¬r‚rfrbr­r>©r«r3r®r`r”rerZr®r®r¯Ú_comment_query"s0
þüÿ ýù óÿÿzPGDialect._comment_queryc  sD| |¡\}}| ˆ|||¡}    | |    |¡}
tj‰‡‡fdd„|
DƒS)Nc3s0|](\}}ˆ|f|dk    r d|inˆƒfVqdS)Nr”r®)rórzrrîr®r¯rõDsýþz4PGDialect.get_multi_table_comment.<locals>.<genexpr>)r“rr?r=Z table_comment) r«rr3r’r`r”r­r®r´rZrÎr®rîr¯r<s  ûz!PGDialect.get_multi_table_commentcKs0|j|||gftjtjdœ|—Ž}| |||¡Sr)Úget_multi_check_constraintsr;rjr:r‘r˜r®r®r¯Úget_check_constraintsLsýûúzPGDialect.get_check_constraintsc    Csð| |¡}ttjjjtjjjtj    tjjj
  d¡t  tjjj
d¡fddtj jjƒ tj¡ tjt tjjj
tjjjktjjjdk¡¡ tj tj jjtjjj
k¡ tjjjtjjj¡ | |¡¡}| |||¡}|rì| tjjj tdƒ¡¡}|S)NTrñrr’)r•r4r r\rrhrÕr×r5rYr›rórôr§r¨rŒr©rªrÖrÑr«rÕr‚rfrbr­r>rr®r®r¯Ú_check_constraint_queryXsT
ÿþù    òðÿ ýíÿåà"Þÿ%ÿz!PGDialect._check_constraint_querycKsò| |¡\}}| ||||¡}    | |    |¡}
ttƒ} tj} |
D]¬\} }}}|dkrh|dkrh| ƒ| || f<q<tjd|tj    d}|s’t
  d|¡d}ntj dtj    d  d| d¡¡}|||dœ}|rÖ| d    ¡rÖd
d i|d <| || f |¡q<|  ¡S) Nz^CHECK *\((.+)\)( NOT VALID)?$)räz)Could not parse CHECK constraint text: %rrÞz^[\s\n]*\((.+)\)[\s\n]*$z\1r    )r“rÁrrrWTrX)r“r r?rrZr=Úcheck_constraintsrërwÚDOTALLr6r/rÁrìrir.r0)r«rr3r’r`r”r­r®r´rZrÎr!r8rZ
check_nameÚsrcrryrÁÚentryr®r®r¯r‡sJÿ ÿÿþý z%PGDialect.get_multi_check_constraintscCsL|dkr,| t tjjj¡tjjjdk¡}n|dkrH| tjjj|k¡}|Sro)r‚r rtrqrr›rXrY)r«rZr3r®r®r¯Ú_pg_type_filter_schema³s ýz PGDialect._pg_type_filter_schemacCsättjjjtj ttjjj    tjjj
ƒ¡  d¡ƒ  tjjj¡  d¡}ttjjj  d¡t tjjj¡  d¡tjjj  d¡|jj  d¡ƒ tjtjjjtjjjk¡ |tjjj|jjk¡ tjjjdk¡ tjjjtjjj¡}| ||¡S)NrZlbl_aggr“rùr3rg)r4r Zpg_enumrZ    enumtypidr5rrÛrZ    enumlabelZ enumsortorderr¢rÝrÚrqrrrtr›rXrYrrŠrsr©r‚ÚtyptyperÕr%)r«r3Z
lbl_agg_sqrZr®r®r¯Ú _enum_query¾sNþÿûþ    ÷
öÿÿ ú    ÿöò ðîÿzPGDialect._enum_queryc    KsT|js
gS| | |¡¡}g}|D],\}}}}| ||||dkrDgn|dœ¡q"|S)N)r“r3rùr)rÓr?r'r.)    r«rr3r­rÎrir“rùrr®r®r¯rçsüÿzPGDialect._load_enumsc    Cs@ttjjjtj t tjjj    d¡¡ 
d¡tj tjjj ¡ 
d¡ƒ  tjjjdk¡  tjjj¡ d¡}ttjjj 
d¡t tjjjtjjj¡ 
d¡tjjj 
d¡tjjj 
d    ¡t tjjj    ¡ 
d
¡tjjj 
d ¡|jj|jjƒ tjtjjj    tjjjk¡ |tjjj    |jjk¡  tjjjd k¡ tjjjtjjj¡}|  ||¡S) NTÚcondefsÚconnamesrZdomain_constraintsr“r¹rSr8rùr3r°)!r4r rÕrZcontypidr5rrÛrôr›r¢r×r‚rÝrÚrqrrrhZ typbasetypeZ    typtypmodZ
typnotnullZ
typdefaultrtrXrYr(r)rŠrsr©r&rÕr%)r«r3rÞrZr®r®r¯Ú _domain_queryúsjÿÿüÿù ô óòÿþýÿóÿïê èæÿzPGDialect._domain_queryc    KsÂ| | |¡¡}g}| ¡D] }t d|d¡ d¡}g}|drŠtt|d|dƒdd„d}    |    D]$\}
} | d    d
…} | |
| d œ¡qd|d |d |d||d|d|dœ} | | ¡q|S)Nz([^\(]+)r¹r    r)r(cSs|dS)Nrr®)r:r®r®r¯Ú<lambda>=óz)PGDialect._load_domains.<locals>.<lambda>)r+ér')r“r[r“r3rùrSr8)r“r3rùrÎrSr8r)    r?r*r²rërÂriÚsortedrr.)r«rr3r­rÎr¶rtr¹rZsorted_constraintsr“Zdef_r[Z
domain_recr®r®r¯r.s. þ  ù     zPGDialect._load_domainscCs| d¡ ¡}|dk|_dS)Nz show standard_conforming_stringsrs)rLrVrù)r«rZ
std_stringr®r®r¯r;Rsÿz PGDialect._set_backslash_escapes)NN)TF)TF)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)NF)F)N)N)N)N)N)N)•rDrErFr“Zsupports_statement_cacheZsupports_alterZmax_identifier_lengthZsupports_sane_rowcountr9Z
BindTypingZ RENDER_CASTSZ bind_typingrÓZsupports_native_booleanZsupports_native_uuidrOZsupports_sequencesZsequences_optionalZ"preexecute_autoincrement_sequencesZpostfetch_lastrowidZuse_insertmanyvaluesZreturns_native_bytesrEZANY_AUTOINCREMENTZUSE_INSERT_FROM_SELECTZRENDER_SELECT_COL_CASTSZ"insertmanyvalues_implicit_sentinelZsupports_commentsZsupports_constraint_commentsZsupports_default_valuesZsupports_default_metavalueZsupports_empty_insertZsupports_multivalues_insertrLZdefault_paramstylerÆÚcolspecsr¦Zstatement_compilerrHZ ddl_compilerr Ztype_compiler_clsrñr¿rZexecution_ctx_clsrZ    inspectorZupdate_returningZdelete_returningZinsert_returningZupdate_returning_multifromZdelete_returning_multifromr8r4Zconnection_characteristicsr}r"r.r3ZIndexZTableZCheckConstraintZForeignKeyConstraintZconstruct_argumentsZreflection_optionsrùr‚r‹r5r9r=rCrEr%r+r0r1rKrMrRrSrUrWr<ržr[rbrfrrkrlrnrrzr r|r~rr‚rr‡r‰rŠr‹rŽr‘r“r•r™r¯r—r³rÍZ flexi_cacherFZ    dp_stringZdp_string_listZ dp_plain_objrÏr6Zmemoized_propertyràrérërêrðrõrörïrÿrrþrrrrrrr rr%r'rr*rr;rGr®r®rûr¯rO s˜ÿþÿÿþÿ    ùþ úþ ÿþÿþâ&
 
    ÿ
ÿ
 
ÿ
 
 
 
 
 
 
 
H
ü
 
9 û 
9
a 
xÿ   
 
., 
( 
3 #r)•rûÚ
__future__rÚ collectionsrÚ    functoolsrrëÚtypingrrrrrÞr
rr Z_hstorer Ú_jsonr rÚ_rangesÚextrrZ named_typesrrrrrrrÚtypesrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r2r3r4r5r6Zenginer7r8r9r:r;r<Zengine.reflectionr=r>r?r@rArBrCrDrZ sql.compilerrEZ sql.visitorsrFrGrHrIrJrKrLrMrNrOrPrQrRrSZ util.typingrTrÁrÅr†rör\ZIntervalr^rÏZ JSONPathTyperðr/r±r´rÂrÄrÆrÈrÊrÌr¶r¸rºr¼r¾rÀrºrÆZ SQLCompilerr¦Z DDLCompilerrHZGenericTypeCompilerr ZIdentifierPreparerrñr÷rýrþrZ    InspectorrZDefaultExecutionContextrZConnectionCharacteristicr"r.r4rr®r®r®r¯Ú<module>    s8{                                                                                  šjú Î64`;     n7
ÿ
ÿ