↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

44000 — with_check_option_violation(WITH CHECK OPTION 违规)

通过视图写入的行不满足 WITH CHECK OPTION。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
WITH CHECK OPTION Violation
condition name
with_check_option_violation
lang
en
sqlstate
44000

版本定义 PG 18

44000 — with_check_option_violation(WITH CHECK OPTION 违规)

速览 {#at-a-glance}

44000 表示通过视图写入的行不满足该视图的 WITH CHECK OPTION 谓词。它保护的是视图写入不变量,不是表级 CHECK 对应的 23514。

含义 {#meaning}

可自动更新的视图声明 WITH CHECK OPTION 后,PostgreSQL 会检查插入或更新后的行是否仍能通过该视图看到。执行器把视图谓词的 FALSE 和 NULL 都视为失败,因此可空谓词列的未知结果也不能通过。ExecWithCheckOptions 报告 new row violates check option for view "%s";只有权限允许描述该行时才附带动态失败行 DETAIL。LOCAL 只检查当前视图直接定义的条件;底层视图条件不会检查,除非那些底层视图也指定了 CHECK OPTION。CASCADED 检查当前视图以及所有底层视图条件。CHECK OPTION 只支持没有 INSTEAD OF 触发器或规则的自动可更新视图;底层可由触发器更新的视图和 INSTEAD 重写都是独立边界,级联检查可能在这些边界停止或全部被忽略。选定自然案例使用的是直接可更新视图。

诊断 {#diagnosis}

保存 SQLSTATE、视图名称、存在时的 DETAIL,以及通过视图发送的实际行值。用 pg_get_viewdef() 查看定义,并按 SQL 三值逻辑计算谓词:只有 TRUE 可见,FALSE 和 NULL 都会失败。确认视图是否自动可更新、使用的是 LOCAL 还是 CASCADED,以及底层视图是否有 INSTEAD OF 触发器或 INSTEAD 重写。不要只搜索表 CHECK 约束:LOCAL 不检查普通底层视图谓词,而 CASCADED 会检查这些谓词,除非遇到可由触发器更新或被重写的边界。缺少 DETAIL 可能是权限边界,不能据此判断没有进行行检查。

处理 {#response}

让行的谓词结果为 TRUE;只有确认模式契约和 LOCAL/CASCADED 范围后才修改视图定义。如果视图是受保护的过滤写入接口,应保留 check option。如果涉及底层触发器可更新的视图或 INSTEAD 重写,应检查该边界及其实际生效的检查,不要假定级联检查已经到达那里。选定自动提交案例的错误后连接仍为 IDLE;若在显式事务中发生,则先回滚失败块,再用合法行重试。

报文 {#messages}

固定源码模板是 new row violates check option for view "%s" 和 Failing row contains %s.。视图名称和行渲染都是动态值。DETAIL 是诊断数据,解析器必须考虑用户值和格式变化。

代表案例 {#case}

共享 registry verify/cases/44000/snippets.json(SHA-256 7b227bca904c860388c6cf1f5b7f551412b4d67832fb91aaa682f4126072e41c)创建过滤视图,先尝试谓词外的行,再插入合法行。见公开案例导出和结构化证据。

CREATE TABLE items(id integer PRIMARY KEY, visible boolean NOT NULL, note text NOT NULL);
CREATE VIEW visible_items AS SELECT id, visible, note FROM items WHERE visible WITH CHECK OPTION;
INSERT INTO visible_items VALUES (1, false, 'hidden');
INSERT INTO visible_items VALUES (1, true, 'visible');
SELECT id, visible, note FROM visible_items ORDER BY id;

运行器会在私有 schema 中限定 registry 的表名。它断言服务器自然产生的 SQLSTATE 和视图诊断,并核对只有可见行被接受。

选定案例在 PostgreSQL 18.6 和 10.21 通过带 WITH CHECK OPTION 的视图插入 visible = false 行时观察到 44000。DETAIL 给出失败行;自动提交连接保持 IDLE,满足谓词的行随后插入成功。

版本 {#versions}

锁定目录从早期历史边界到正式快照都记录了该条件。固定源码在 18.6 和 10.23 都包含同一机制;选定运行只覆盖 18.6 与 10.21 的简单视图插入,不涵盖所有视图规则组合。

相关 {#related}

可对照表 CHECK 的23514 检查约束违规和触发器驱动的27000 触发的数据更改违规。

来源 {#sources}

  • src.errcodes.18.6(SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba)
  • src.execMain.18.6(SHA-256 33b97337fa23a649c5e7a092e1bd405a54e8503529236c62c9d5bb93a1774a8d)
  • CREATE VIEW 官方文档 · 本地调用扫描 src.calls.REL_18_6(SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf)

比较版本

SQLSTATE 证据与已记录的运行版本

cases · view_check_option_recovery
{
  "assertions": [
    "SQLSTATE is 44000",
    "The diagnostic identifies the view",
    "The rejected row leaves autocommit usable",
    "A row satisfying the view predicate is accepted"
  ],
  "case_id": "view_check_option_recovery",
  "cleanup": "Drop the case schema with an owner connection.",
  "has_snippet": true,
  "position": 0,
  "preconditions": [
    "A runner-owned disposable target is provisioned."
  ],
  "repair": "Fix the row or the view predicate deliberately; do not bypass the view invariant by treating this as a table constraint failure.",
  "trigger": "Insert a row through a view with a visible-row predicate and WITH CHECK OPTION, then insert a row satisfying the predicate.",
  "versions": [
    "10",
    "18"
  ]
}
claims · identity
{
  "claim_id": "identity",
  "limits": "This is a view write invariant, not a table CHECK constraint code.",
  "method": "Read the fixed errcodes.txt row and macro mapping.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "44000 is the with_check_option_violation condition in Class 44."
}
claims · view-path
{
  "claim_id": "view-path",
  "limits": "The row representation and view name are dynamic.",
  "method": "Trace ERRCODE_WITH_CHECK_OPTION_VIOLATION in execMain.c.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.execMain.18.6",
    "src.calls.REL_18_6"
  ],
  "statement": "ExecWithCheckOptions emits new row violates check option for view \"%s\" with a dynamic failing-row DETAIL."
}
claims · three-valued-check
{
  "claim_id": "three-valued-check",
  "limits": "This describes the executor check; the selected case uses a directly updatable view.",
  "method": "Read the fixed ExecWithCheckOptions comment and branch before the ERRCODE_WITH_CHECK_OPTION_VIOLATION report.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.execMain.18.6"
  ],
  "statement": "ExecWithCheckOptions treats a view check qual that evaluates to NULL or FALSE as a violation because the new tuple would not be visible through the view."
}
claims · detail-permission
{
  "claim_id": "detail-permission",
  "limits": "DETAIL may be absent even when the check ran.",
  "method": "Trace the WCO_VIEW_CHECK permission guard before ExecBuildSlotValueDescription.",
  "position": 3,
  "runtime": [],
  "sources": [
    "src.execMain.18.6"
  ],
  "statement": "The failing-row DETAIL for a view check option is conditional on permissions that allow the row description."
}
claims · scope-and-trigger-boundary
{
  "claim_id": "scope-and-trigger-boundary",
  "limits": "The selected runtime case is a direct automatically updatable view; it does not exercise nested views, a trigger-updatable base, or an INSTEAD rewrite.",
  "method": "Read the fixed CREATE VIEW documentation and compare the selected case definition.",
  "position": 4,
  "runtime": [],
  "sources": [
    "doc.create-view.18.6"
  ],
  "statement": "LOCAL checks only conditions defined directly in the current view; ordinary underlying-view conditions are not checked unless those base views also specify CHECK OPTION. CASCADED checks the current view and all underlying base-view conditions. CHECK OPTION is supported only on automatically updatable views without an INSTEAD OF trigger or rule; a trigger-updatable base view stops a cascade, and an INSTEAD rule rewrite can cause all checks to be ignored."
}
claims · repair
{
  "claim_id": "repair",
  "limits": "LOCAL/CASCADED view composition and UPDATE paths can add further predicates.",
  "method": "Use the shared visible=true/false view case.",
  "position": 5,
  "runtime": [],
  "sources": [
    "doc.create-view.18.6"
  ],
  "statement": "A write through a view with WITH CHECK OPTION must satisfy the view predicate; correcting the row preserves the invariant."
}
claims · runtime
{
  "claim_id": "runtime",
  "limits": "This covers the selected directly updatable view path; it does not test nested LOCAL/CASCADED views or INSTEAD OF triggers.",
  "method": "Read the selected runner summaries and raw outputs tied to the shared snippet registry.",
  "position": 6,
  "runtime": [],
  "sources": [
    "runtime.44000-batch34-20260909.latest",
    "runtime.44000-batch34-20260909.pg10"
  ],
  "statement": "The selected 44000 case passed on PostgreSQL 18.6 and 10.21 with the structured SQLSTATE, transaction-state, and repair assertions recorded in the runtime entries."
}
messages · message.view-check
{
  "limits": "Both the view identifier and row rendering are dynamic.",
  "message_id": "message.view-check",
  "path": "",
  "position": 0,
  "raw": {
    "detail_template": "Failing row contains %s.",
    "id": "message.view-check",
    "limits": "Both the view identifier and row rendering are dynamic.",
    "primary_template": "new row violates check option for view \"%s\"",
    "severity_source": "ERROR",
    "sources": [
      "src.execMain.18.6"
    ],
    "sqlstate": "44000"
  },
  "severity": "ERROR",
  "sources": [
    "src.execMain.18.6"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "new row violates check option for view \" \"",
      "position": 0,
      "role": "",
      "template": "new row violates check option for view \"%s\""
    },
    {
      "kind": "detail",
      "literal": "Failing row contains .",
      "position": 1,
      "role": "",
      "template": "Failing row contains %s."
    }
  ]
}
runtimes · runtime.44000-batch34-20260909.latest · 18.6 (Homebrew) · passed
{
  "cases": [
    "view_check_option_recovery"
  ],
  "limits": "",
  "position": 0,
  "raw": {
    "case_manifest": {
      "path": "verify/cases/44000/cases.json",
      "sha256": "5512b051ff6459a4e3e6b5c35dcd1f30b1fff6f96d2513634382573954224f5a"
    },
    "cases": [
      "view_check_option_recovery"
    ],
    "id": "runtime.44000-batch34-20260909.latest",
    "observed": {
      "connection_autocommit": true,
      "primary": "new row violates check option for view \"visible_items\"",
      "repair": {
        "rows": [
          [
            1,
            true,
            "visible"
          ]
        ]
      },
      "severity": "ERROR",
      "sqlstate": "44000",
      "statuses": {
        "after_error": "IDLE",
        "after_valid": "IDLE"
      }
    },
    "raw": "verify/results/44000-batch34-20260909/latest/raw.jsonl",
    "raw_sha256": "5b79b8c867bb95b70d22cff85bc3893ea16034731fb8a207c19b2910276efaa0",
    "run_id": "44000-batch34-20260909",
    "server_version": "18.6 (Homebrew)",
    "snippet_registry": {
      "path": "verify/cases/44000/snippets.json",
      "sha256": "7b227bca904c860388c6cf1f5b7f551412b4d67832fb91aaa682f4126072e41c"
    },
    "status": "passed",
    "summary": "verify/results/44000-batch34-20260909/latest/summary.json",
    "summary_sha256": "3d674692d53f36522eb3c818be06c41fc9b4386bb7dd37e65f8410a88629162f",
    "target": "latest"
  },
  "run_id": "44000-batch34-20260909",
  "runtime_id": "runtime.44000-batch34-20260909.latest",
  "server_version": "18.6 (Homebrew)",
  "status": "passed",
  "target": "latest"
}
runtimes · runtime.44000-batch34-20260909.pg10 · 10.21 (Debian 10.21-1.pgdg90+1) · passed
{
  "cases": [
    "view_check_option_recovery"
  ],
  "limits": "",
  "position": 1,
  "raw": {
    "case_manifest": {
      "path": "verify/cases/44000/cases.json",
      "sha256": "5512b051ff6459a4e3e6b5c35dcd1f30b1fff6f96d2513634382573954224f5a"
    },
    "cases": [
      "view_check_option_recovery"
    ],
    "id": "runtime.44000-batch34-20260909.pg10",
    "observed": {
      "connection_autocommit": true,
      "primary": "new row violates check option for view \"visible_items\"",
      "repair": {
        "rows": [
          [
            1,
            true,
            "visible"
          ]
        ]
      },
      "severity": "ERROR",
      "sqlstate": "44000",
      "statuses": {
        "after_error": "IDLE",
        "after_valid": "IDLE"
      }
    },
    "raw": "verify/results/44000-batch34-20260909/pg10/raw.jsonl",
    "raw_sha256": "baf0278700f3e0f15b3b12de0f97bdf31173c6e9470a12b198ee7e696568998a",
    "run_id": "44000-batch34-20260909",
    "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
    "snippet_registry": {
      "path": "verify/cases/44000/snippets.json",
      "sha256": "7b227bca904c860388c6cf1f5b7f551412b4d67832fb91aaa682f4126072e41c"
    },
    "status": "passed",
    "summary": "verify/results/44000-batch34-20260909/pg10/summary.json",
    "summary_sha256": "24148b05266cf9fe1cda71058dd89ac856f1c4020c886b3a5ab33a51186377e8",
    "target": "pg10"
  },
  "run_id": "44000-batch34-20260909",
  "runtime_id": "runtime.44000-batch34-20260909.pg10",
  "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
  "status": "passed",
  "target": "pg10"
}
sources · src.errcodes.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt"
}
sources · src.calls.REL_18_6
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 1,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6",
  "tag": "",
  "url": ""
}
sources · src.execMain.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/executor/execMain.c",
  "position": 2,
  "sha256": "33b97337fa23a649c5e7a092e1bd405a54e8503529236c62c9d5bb93a1774a8d",
  "source_id": "src.execMain.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/execMain.c#L2322-L2327"
}
sources · src.execMain.10.23
{
  "commit": "02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/executor/execMain.c",
  "position": 3,
  "sha256": "386d09f7e964ebc426a554cf51ac7cb505c67cc95b971ee7acad1a6e0a9d0c1a",
  "source_id": "src.execMain.10.23",
  "tag": "REL_10_23",
  "url": "https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/executor/execMain.c#L2178-L2183"
}
sources · doc.create-view.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "https://www.postgresql.org/docs/18/sql-createview.html",
  "kind": "upstream_source",
  "location": "",
  "path": "doc/src/sgml/ref/create_view.sgml",
  "position": 4,
  "sha256": "d2c2aae6e102594deaa2f5aabc7910cdaada11d714e49e818511a57bb21fec57",
  "source_id": "doc.create-view.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/ref/create_view.sgml"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:8d310609fce53b96cf483736a9fffa6ccb8c07ade69cb1c0bf23ae25b64bb342

正文语言: zh-Hans · english-manuals:8d310609fce53b96cf483736a9fffa6ccb8c07ade69cb1c0bf23ae25b64bb342