Postgres 的 pg_dump --section=pre-data 包含 CHECK 约束,尽管文档另有说明?

Postgres's pg_dump --section=pre-data includes CHECK constraints, despite documentation saying otherwise?

我正在尝试使用 pg_dump --section=pre-data 来抑制 pg_dump 输出中的 CHECK 约束,但我发现它无论如何都包含 CHECK 约束。这是我遵循的步骤,首先在 psql:

CREATE DATABASE test_pre_data_check_db;
\connect test_pre_data_check_db
CREATE TABLE the_table (the_column INT CONSTRAINT the_check CHECK (the_column > 0));

然后在shell:

$ pg_dump --section=pre-data -d test_pre_data_check_db
--
-- PostgreSQL database dump
--

-- Dumped from database version 12.1
-- Dumped by pg_dump version 12.1

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: the_table; Type: TABLE; Schema: public; Owner: acolombi
--

CREATE TABLE public.the_table (
    the_column integer,
    CONSTRAINT the_check CHECK ((the_column > 0))
);


ALTER TABLE public.the_table OWNER TO acolombi;

--
-- PostgreSQL database dump complete
--

这是 pg_dump 中的错误还是我做错了?

来自 Postgres 的相关文档:

--section=sectionname

Only dump the named section. The section name can be pre-data, data, or post-data. This option can be specified more than once to select multiple sections. The default is to dump all sections.

The data section contains actual table data, large-object contents, and sequence values. Post-data items include definitions of indexes, triggers, rules, and constraints other than validated check constraints. Pre-data items include all other data definition items.

https://www.postgresql.org/docs/current/app-pgdump.html

您的报价包含答案:

--section=sectionname

The data section contains actual table data, large-object contents, and sequence values. Post-data items include definitions of indexes, triggers, rules, and constraints other than validated check constraints. Pre-data items include all other data definition items.

也就是说,经过验证的检查约束位于数据前部分,这正是您所观察到的。

这很有意义:大多数约束都在 post-data 部分,因为它们在加载数据(主键)后创建时速度更快,或者在加载数据部分时避免违反约束加载(外键)。检查约束不属于任何一类,因为它们只允许依赖于 table 行本身。