@@ -309,14 +309,13 @@ RI_FKey_check(PG_FUNCTION_ARGS)
309
309
pk_rel = heap_open (riinfo .pk_relid , RowShareLock );
310
310
311
311
/* ----------
312
- * SQL3 11.9 <referential constraint definition>
313
- * General rules 2) a):
312
+ * SQL:2008 4.17.3 <Table constraints>
314
313
* If Rf and Rt are empty (no columns to compare given)
315
314
* constraint is true if 0 < (SELECT COUNT(*) FROM T)
316
315
*
317
316
* Note: The special case that no columns are given cannot
318
- * occur up to now in Postgres, it's just there for
319
- * future enhancements.
317
+ * occur at present in Postgres (and is disallowed by the
318
+ * standard too); it's just there for future enhancements.
320
319
* ----------
321
320
*/
322
321
if (riinfo .nkeys == 0 )
@@ -376,10 +375,8 @@ RI_FKey_check(PG_FUNCTION_ARGS)
376
375
case RI_KEYS_ALL_NULL :
377
376
378
377
/*
379
- * No check - if NULLs are allowed at all is already checked by
380
- * NOT NULL constraint.
381
- *
382
- * This is true for MATCH FULL, MATCH PARTIAL, and MATCH SIMPLE.
378
+ * No further check needed - an all-NULL key passes every type of
379
+ * foreign key constraint.
383
380
*/
384
381
heap_close (pk_rel , RowShareLock );
385
382
return PointerGetDatum (NULL );
@@ -410,7 +407,8 @@ RI_FKey_check(PG_FUNCTION_ARGS)
410
407
case FKCONSTR_MATCH_SIMPLE :
411
408
412
409
/*
413
- * MATCH SIMPLE - if ANY column is null, we have a match.
410
+ * MATCH SIMPLE - if ANY column is null, the key passes
411
+ * the constraint.
414
412
*/
415
413
heap_close (pk_rel , RowShareLock );
416
414
return PointerGetDatum (NULL );
@@ -578,8 +576,8 @@ ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel,
578
576
case FKCONSTR_MATCH_SIMPLE :
579
577
580
578
/*
581
- * MATCH SIMPLE/FULL - if ANY column is null, we
582
- * can't be matching to this row already .
579
+ * MATCH SIMPLE/FULL - if ANY column is null, nothing
580
+ * could have been referencing this row.
583
581
*/
584
582
return true;
585
583
@@ -734,10 +732,10 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS)
734
732
switch (riinfo .confmatchtype )
735
733
{
736
734
/* ----------
737
- * SQL3 11.9 <referential constraint definition >
738
- * General rules 6 ) a) iv):
735
+ * SQL:2008 15.17 <Execution of referential actions >
736
+ * General rules 9 ) a) iv):
739
737
* MATCH SIMPLE/FULL
740
- * ... ON DELETE CASCADE
738
+ * ... ON DELETE NO ACTION
741
739
* ----------
742
740
*/
743
741
case FKCONSTR_MATCH_SIMPLE :
@@ -751,8 +749,8 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS)
751
749
case RI_KEYS_SOME_NULL :
752
750
753
751
/*
754
- * No check - MATCH FULL means there cannot be any
755
- * reference to old key if it contains NULL
752
+ * No check needed - there cannot be any reference to old
753
+ * key if it contains a NULL
756
754
*/
757
755
heap_close (fk_rel , RowShareLock );
758
756
return PointerGetDatum (NULL );
@@ -905,10 +903,10 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
905
903
switch (riinfo .confmatchtype )
906
904
{
907
905
/* ----------
908
- * SQL3 11.9 <referential constraint definition >
909
- * General rules 6 ) a) iv):
906
+ * SQL:2008 15.17 <Execution of referential actions >
907
+ * General rules 10 ) a) iv):
910
908
* MATCH SIMPLE/FULL
911
- * ... ON DELETE CASCADE
909
+ * ... ON UPDATE NO ACTION
912
910
* ----------
913
911
*/
914
912
case FKCONSTR_MATCH_SIMPLE :
@@ -922,8 +920,8 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
922
920
case RI_KEYS_SOME_NULL :
923
921
924
922
/*
925
- * No check - MATCH FULL means there cannot be any
926
- * reference to old key if it contains NULL
923
+ * No check needed - there cannot be any reference to old
924
+ * key if it contains a NULL
927
925
*/
928
926
heap_close (fk_rel , RowShareLock );
929
927
return PointerGetDatum (NULL );
@@ -1090,8 +1088,8 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
1090
1088
switch (riinfo .confmatchtype )
1091
1089
{
1092
1090
/* ----------
1093
- * SQL3 11.9 <referential constraint definition >
1094
- * General rules 6 ) a) i):
1091
+ * SQL:2008 15.17 <Execution of referential actions >
1092
+ * General rules 9 ) a) i):
1095
1093
* MATCH SIMPLE/FULL
1096
1094
* ... ON DELETE CASCADE
1097
1095
* ----------
@@ -1107,8 +1105,8 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
1107
1105
case RI_KEYS_SOME_NULL :
1108
1106
1109
1107
/*
1110
- * No check - MATCH FULL means there cannot be any
1111
- * reference to old key if it contains NULL
1108
+ * No check needed - there cannot be any reference to old
1109
+ * key if it contains a NULL
1112
1110
*/
1113
1111
heap_close (fk_rel , RowExclusiveLock );
1114
1112
return PointerGetDatum (NULL );
@@ -1209,7 +1207,7 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
1209
1207
/* ----------
1210
1208
* RI_FKey_cascade_upd -
1211
1209
*
1212
- * Cascaded update/delete foreign key references at update event on PK table.
1210
+ * Cascaded update foreign key references at update event on PK table.
1213
1211
* ----------
1214
1212
*/
1215
1213
Datum
@@ -1258,8 +1256,8 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
1258
1256
switch (riinfo .confmatchtype )
1259
1257
{
1260
1258
/* ----------
1261
- * SQL3 11.9 <referential constraint definition >
1262
- * General rules 7 ) a) i):
1259
+ * SQL:2008 15.17 <Execution of referential actions >
1260
+ * General rules 10 ) a) i):
1263
1261
* MATCH SIMPLE/FULL
1264
1262
* ... ON UPDATE CASCADE
1265
1263
* ----------
@@ -1275,8 +1273,8 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
1275
1273
case RI_KEYS_SOME_NULL :
1276
1274
1277
1275
/*
1278
- * No update - MATCH FULL means there cannot be any
1279
- * reference to old key if it contains NULL
1276
+ * No check needed - there cannot be any reference to old
1277
+ * key if it contains a NULL
1280
1278
*/
1281
1279
heap_close (fk_rel , RowExclusiveLock );
1282
1280
return PointerGetDatum (NULL );
@@ -1401,12 +1399,10 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
1401
1399
*
1402
1400
* Restrict delete from PK table to rows unreferenced by foreign key.
1403
1401
*
1404
- * SQL3 intends that this referential action occur BEFORE the
1405
- * update is performed, rather than after. This appears to be
1406
- * the only difference between "NO ACTION" and "RESTRICT".
1407
- *
1408
- * For now, however, we treat "RESTRICT" and "NO ACTION" as
1409
- * equivalent.
1402
+ * The SQL standard intends that this referential action occur BEFORE
1403
+ * the delete is performed, rather than after. This appears to be
1404
+ * the only difference between "NO ACTION" and "RESTRICT". In Postgres
1405
+ * we still implement this as an AFTER trigger, but it's non-deferrable.
1410
1406
* ----------
1411
1407
*/
1412
1408
Datum
@@ -1451,10 +1447,10 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
1451
1447
switch (riinfo .confmatchtype )
1452
1448
{
1453
1449
/* ----------
1454
- * SQL3 11.9 <referential constraint definition >
1455
- * General rules 6 ) a) iv):
1450
+ * SQL:2008 15.17 <Execution of referential actions >
1451
+ * General rules 9 ) a) iv):
1456
1452
* MATCH SIMPLE/FULL
1457
- * ... ON DELETE CASCADE
1453
+ * ... ON DELETE RESTRICT
1458
1454
* ----------
1459
1455
*/
1460
1456
case FKCONSTR_MATCH_SIMPLE :
@@ -1468,8 +1464,8 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
1468
1464
case RI_KEYS_SOME_NULL :
1469
1465
1470
1466
/*
1471
- * No check - MATCH FULL means there cannot be any
1472
- * reference to old key if it contains NULL
1467
+ * No check needed - there cannot be any reference to old
1468
+ * key if it contains a NULL
1473
1469
*/
1474
1470
heap_close (fk_rel , RowShareLock );
1475
1471
return PointerGetDatum (NULL );
@@ -1574,12 +1570,10 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
1574
1570
*
1575
1571
* Restrict update of PK to rows unreferenced by foreign key.
1576
1572
*
1577
- * SQL3 intends that this referential action occur BEFORE the
1578
- * update is performed, rather than after. This appears to be
1579
- * the only difference between "NO ACTION" and "RESTRICT".
1580
- *
1581
- * For now, however, we treat "RESTRICT" and "NO ACTION" as
1582
- * equivalent.
1573
+ * The SQL standard intends that this referential action occur BEFORE
1574
+ * the update is performed, rather than after. This appears to be
1575
+ * the only difference between "NO ACTION" and "RESTRICT". In Postgres
1576
+ * we still implement this as an AFTER trigger, but it's non-deferrable.
1583
1577
* ----------
1584
1578
*/
1585
1579
Datum
@@ -1627,10 +1621,10 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
1627
1621
switch (riinfo .confmatchtype )
1628
1622
{
1629
1623
/* ----------
1630
- * SQL3 11.9 <referential constraint definition >
1631
- * General rules 6 ) a) iv):
1624
+ * SQL:2008 15.17 <Execution of referential actions >
1625
+ * General rules 10 ) a) iv):
1632
1626
* MATCH SIMPLE/FULL
1633
- * ... ON DELETE CASCADE
1627
+ * ... ON UPDATE RESTRICT
1634
1628
* ----------
1635
1629
*/
1636
1630
case FKCONSTR_MATCH_SIMPLE :
@@ -1644,8 +1638,8 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
1644
1638
case RI_KEYS_SOME_NULL :
1645
1639
1646
1640
/*
1647
- * No check - MATCH FULL means there cannot be any
1648
- * reference to old key if it contains NULL
1641
+ * No check needed - there cannot be any reference to old
1642
+ * key if it contains a NULL
1649
1643
*/
1650
1644
heap_close (fk_rel , RowShareLock );
1651
1645
return PointerGetDatum (NULL );
@@ -1802,8 +1796,8 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
1802
1796
switch (riinfo .confmatchtype )
1803
1797
{
1804
1798
/* ----------
1805
- * SQL3 11.9 <referential constraint definition >
1806
- * General rules 6 ) a) ii):
1799
+ * SQL:2008 15.17 <Execution of referential actions >
1800
+ * General rules 9 ) a) ii):
1807
1801
* MATCH SIMPLE/FULL
1808
1802
* ... ON DELETE SET NULL
1809
1803
* ----------
@@ -1819,8 +1813,8 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
1819
1813
case RI_KEYS_SOME_NULL :
1820
1814
1821
1815
/*
1822
- * No update - MATCH FULL means there cannot be any
1823
- * reference to old key if it contains NULL
1816
+ * No check needed - there cannot be any reference to old
1817
+ * key if it contains a NULL
1824
1818
*/
1825
1819
heap_close (fk_rel , RowExclusiveLock );
1826
1820
return PointerGetDatum (NULL );
@@ -1977,8 +1971,8 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
1977
1971
switch (riinfo .confmatchtype )
1978
1972
{
1979
1973
/* ----------
1980
- * SQL3 11.9 <referential constraint definition >
1981
- * General rules 7 ) a) ii) 2 ):
1974
+ * SQL:2008 15.17 <Execution of referential actions >
1975
+ * General rules 10 ) a) ii):
1982
1976
* MATCH SIMPLE/FULL
1983
1977
* ... ON UPDATE SET NULL
1984
1978
* ----------
@@ -1994,8 +1988,8 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
1994
1988
case RI_KEYS_SOME_NULL :
1995
1989
1996
1990
/*
1997
- * No update - MATCH FULL means there cannot be any
1998
- * reference to old key if it contains NULL
1991
+ * No check needed - there cannot be any reference to old
1992
+ * key if it contains a NULL
1999
1993
*/
2000
1994
heap_close (fk_rel , RowExclusiveLock );
2001
1995
return PointerGetDatum (NULL );
@@ -2158,8 +2152,8 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
2158
2152
switch (riinfo .confmatchtype )
2159
2153
{
2160
2154
/* ----------
2161
- * SQL3 11.9 <referential constraint definition >
2162
- * General rules 6 ) a) iii):
2155
+ * SQL:2008 15.17 <Execution of referential actions >
2156
+ * General rules 9 ) a) iii):
2163
2157
* MATCH SIMPLE/FULL
2164
2158
* ... ON DELETE SET DEFAULT
2165
2159
* ----------
@@ -2175,8 +2169,8 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
2175
2169
case RI_KEYS_SOME_NULL :
2176
2170
2177
2171
/*
2178
- * No update - MATCH FULL means there cannot be any
2179
- * reference to old key if it contains NULL
2172
+ * No check needed - there cannot be any reference to old
2173
+ * key if it contains a NULL
2180
2174
*/
2181
2175
heap_close (fk_rel , RowExclusiveLock );
2182
2176
return PointerGetDatum (NULL );
@@ -2344,8 +2338,8 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
2344
2338
switch (riinfo .confmatchtype )
2345
2339
{
2346
2340
/* ----------
2347
- * SQL3 11.9 <referential constraint definition >
2348
- * General rules 7 ) a) iii):
2341
+ * SQL:2008 15.17 <Execution of referential actions >
2342
+ * General rules 10 ) a) iii):
2349
2343
* MATCH SIMPLE/FULL
2350
2344
* ... ON UPDATE SET DEFAULT
2351
2345
* ----------
@@ -2361,8 +2355,8 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
2361
2355
case RI_KEYS_SOME_NULL :
2362
2356
2363
2357
/*
2364
- * No update - MATCH FULL means there cannot be any
2365
- * reference to old key if it contains NULL
2358
+ * No check needed - there cannot be any reference to old
2359
+ * key if it contains a NULL
2366
2360
*/
2367
2361
heap_close (fk_rel , RowExclusiveLock );
2368
2362
return PointerGetDatum (NULL );
0 commit comments