Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ruo6e-007lrl-H0 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Apr 2024 06:40:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ruo6d-00Dzdi-G1 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Apr 2024 06:40:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ruo6d-00Dzda-6X for pgsql-hackers@lists.postgresql.org; Thu, 11 Apr 2024 06:40:19 +0000 Received: from mail-ua1-x92e.google.com ([2607:f8b0:4864:20::92e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1ruo6b-000Kbq-L3 for pgsql-hackers@lists.postgresql.org; Thu, 11 Apr 2024 06:40:18 +0000 Received: by mail-ua1-x92e.google.com with SMTP id a1e0cc1a2514c-7e7cf5cc1d0so339831241.0 for ; Wed, 10 Apr 2024 23:40:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712817616; x=1713422416; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=H3L3Fr14Bh/QAPbTRB0TGCC+Mu4mk92fh2O/zVu9b2A=; b=VfBH5ueQhs8wd5fLr7gdWtoSVbhJVIf1EhsAsye5+aRIDTMict8vRrlg5SVGwav36r PSVQOM1gfeL0S0zXDP1frN9Kc7NMTa5i3+pyZhDRsO76Y7nHII3OitzSa3Y2j40mksro 1gjyZRr/EHB5xxO57uLxHkYycq9tCAa8RkRVQiXm1NXeg/OYRSMz1JBzaOa0nLp6HJTE GSzaS4wHNFV35cn174gZxmMYwi5MMexgjacglWz7iiJGSc44fiSDQMPvsZhKZyAAOPIm pbjzloWfI2ZcKnKFnavS0jhumB6gzwvZaIiGBzaC6nEE+IDTp+OgUkk6kU/ZnhhwwZ0Y 4ZYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712817616; x=1713422416; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H3L3Fr14Bh/QAPbTRB0TGCC+Mu4mk92fh2O/zVu9b2A=; b=JXuK3coFDQ6pfIfJfVBLBHBJCv2RX8eiYNcJPYT8c19O2zPzIkZqub5NJLoM4OwNPv lmff2yEXGlY10HROeS+hHSDOxKffCGAHHWBFctB6Eox5YN2V0hzqykXi6dJ/82r+Hv00 xOhcYJ3G0CYm7FTZYTzhwEq2IguFee+WpEVtABLMllK2cfmfnqfhjOC/xx0V05aBy/GS QPn97hNDhfdvM4IIZwyz10AcT0kkdQkbIBgl3cJPnZasmHQH7atCjwEg9zqwuAYI/1Ni S6HUMaqFC8V6nOpITnrCscfZo7n8kP01xlZTPMcd/4z6/6Q3Be5IrAaLklgpu14C/m4R 6Q6w== X-Forwarded-Encrypted: i=1; AJvYcCWHD9Aypyo/ClaVgH9hWBWIzGPv6FNkCwH6A99/ONPtzVJQMCQSBVO5Fy7RCp584GBW1dXaJnKb2xnH5heSt1RwkT4yl16E/SPxTOuRRBDrJ2kS X-Gm-Message-State: AOJu0YwgUvy88oaZhpgvUwFHXPK2YwbF+gg8Fj2fd1+sw9yxKlunDf/J dER8EwutU7rk7WfC6Dy5yqVXuNyrFiGZlAwbtmGTmN3G1Cu6s63LQs1v3mRpUFDcsV3iMOH40+2 MRSDJFNzP3m7I7ls3K9wgGv6l0+4CrXomJcc= X-Google-Smtp-Source: AGHT+IEu95L+UzF1HRrgFrmD2oLsH2FMTS5sANZlrug8y1km++s0VUNo5OJQNl1utTIGL3Xian3J7HQW1ffujwP8ZyA= X-Received: by 2002:a05:6102:58da:b0:479:dd05:63df with SMTP id jv26-20020a05610258da00b00479dd0563dfmr1189352vsb.11.1712817615965; Wed, 10 Apr 2024 23:40:15 -0700 (PDT) MIME-Version: 1.0 References: <202404101358.iet3euazs5zf@alvherre.pgsql> <202404101723.4ag5z2mbgmsl@alvherre.pgsql> In-Reply-To: <202404101723.4ag5z2mbgmsl@alvherre.pgsql> From: jian he Date: Thu, 11 Apr 2024 14:40:04 +0800 Message-ID: Subject: Re: Can't find not null constraint, but \d+ shows that To: Alvaro Herrera Cc: Tender Wang , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Apr 10, 2024 at 2:10=E2=80=AFPM jian he wrote: > > DROP TABLE if exists notnull_tbl2; > CREATE TABLE notnull_tbl2 (c0 int generated by default as IDENTITY, c1 in= t); > ALTER TABLE notnull_tbl2 ADD CONSTRAINT Q PRIMARY KEY(c0, c1); > ALTER TABLE notnull_tbl2 DROP CONSTRAINT notnull_tbl2_c0_not_null; > ALTER TABLE notnull_tbl2 DROP c1; > \d notnull_tbl2 > ALTER TABLE notnull_tbl2 DROP CONSTRAINT notnull_tbl2_c0_not_null; per above sequence execution order, this should error out? otherwise which "not null" (attribute|constraint) to anchor "generated by default as identity" not null property? "DROP c1" will drop the not null property for "c0" and "c1". if "DROP CONSTRAINT notnull_tbl2_c0_not_nul" not error out, then " ALTER TABLE notnull_tbl2 DROP c1;" should either error out or transform "c0" from "c0 int generated by default as identity" to "c0 int" On Thu, Apr 11, 2024 at 1:23=E2=80=AFAM Alvaro Herrera wrote: > > On 2024-Apr-10, Alvaro Herrera wrote: > > > One thing missing here is pg_dump support. If you just dump this table= , > > it'll end up with no constraint at all. That's obviously bad, so I > > propose we have pg_dump add a regular NOT NULL constraint for those, to > > avoid perpetuating the weird situation further. > > Here's another crude patchset, this time including the pg_dump aspect. > +DROP TABLE notnull_tbl1; +-- make sure attnotnull is reset correctly when a PK is dropped indirectly +CREATE TABLE notnull_tbl1 (c0 int, c1 int, PRIMARY KEY (c0, c1)); +ALTER TABLE notnull_tbl1 DROP c1; +\d+ notnull_tbl1 + Table "public.notnull_tbl1" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+---------+-----------+----------+---------+---------+------------= --+------------- + c0 | integer | | not null | | plain | = | + this is not what we expected? "not null" for "c0" now should be false? am I missing something?