{
    "mode": "man",
    "parameter": "SET_CONSTRAINTS",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/SET_CONSTRAINTS/7/json",
    "generated": "2026-06-03T01:36:44Z",
    "synopsis": "SET CONSTRAINTS { ALL | name [, ...] } { DEFERRED | IMMEDIATE }",
    "sections": {
        "NAME": {
            "content": "SETCONSTRAINTS - set constraint check timing for the current transaction\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "SET CONSTRAINTS { ALL | name [, ...] } { DEFERRED | IMMEDIATE }\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "SET CONSTRAINTS sets the behavior of constraint checking within the current transaction.\nIMMEDIATE constraints are checked at the end of each statement.  DEFERRED constraints are not\nchecked until transaction commit. Each constraint has its own IMMEDIATE or DEFERRED mode.\n\nUpon creation, a constraint is given one of three characteristics: DEFERRABLE INITIALLY\nDEFERRED, DEFERRABLE INITIALLY IMMEDIATE, or NOT DEFERRABLE. The third class is always\nIMMEDIATE and is not affected by the SET CONSTRAINTS command. The first two classes start\nevery transaction in the indicated mode, but their behavior can be changed within a\ntransaction by SET CONSTRAINTS.\n\nSET CONSTRAINTS with a list of constraint names changes the mode of just those constraints\n(which must all be deferrable). Each constraint name can be schema-qualified. The current\nschema search path is used to find the first matching name if no schema name is specified.\nSET CONSTRAINTS ALL changes the mode of all deferrable constraints.\n\nWhen SET CONSTRAINTS changes the mode of a constraint from DEFERRED to IMMEDIATE, the new\nmode takes effect retroactively: any outstanding data modifications that would have been\nchecked at the end of the transaction are instead checked during the execution of the SET\nCONSTRAINTS command. If any such constraint is violated, the SET CONSTRAINTS fails (and does\nnot change the constraint mode). Thus, SET CONSTRAINTS can be used to force checking of\nconstraints to occur at a specific point in a transaction.\n\nCurrently, only UNIQUE, PRIMARY KEY, REFERENCES (foreign key), and EXCLUDE constraints are\naffected by this setting.  NOT NULL and CHECK constraints are always checked immediately when\na row is inserted or modified (not at the end of the statement). Uniqueness and exclusion\nconstraints that have not been declared DEFERRABLE are also checked immediately.\n\nThe firing of triggers that are declared as “constraint triggers” is also controlled by this\nsetting — they fire at the same time that the associated constraint should be checked.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "Because PostgreSQL does not require constraint names to be unique within a schema (but only\nper-table), it is possible that there is more than one match for a specified constraint name.\nIn this case SET CONSTRAINTS will act on all matches. For a non-schema-qualified name, once a\nmatch or matches have been found in some schema in the search path, schemas appearing later\nin the path are not searched.\n\nThis command only alters the behavior of constraints within the current transaction. Issuing\nthis outside of a transaction block emits a warning and otherwise has no effect.\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "This command complies with the behavior defined in the SQL standard, except for the\nlimitation that, in PostgreSQL, it does not apply to NOT NULL and CHECK constraints. Also,\nPostgreSQL checks non-deferrable uniqueness constraints immediately, not at end of statement\nas the standard would suggest.\n\n\n\nPostgreSQL 14.23                                2026                              SET CONSTRAINTS(7)",
            "subsections": []
        }
    },
    "summary": "SETCONSTRAINTS - set constraint check timing for the current transaction",
    "flags": [],
    "examples": [],
    "see_also": []
}