pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Generated columns with NOT NULL constraint are not preserved

Open whoward opened this issue 1 year ago • 1 comments

When defining a GENERATED ALWAYS column with the NOT NULL constraint pgschema dump does not preserve the NOT NULL constraint:

create table some_table (
  id serial primary key,
  name varchar(255) not null,
  cleaned_name varchar(255) generated always as (lower(name)) stored not null
);

The output of pgschema dump is:

--
-- pgschema database dump
--

-- Dumped from database version PostgreSQL 17.0
-- Dumped by pgschema version 1.4.0


--
-- Name: some_table; Type: TABLE; Schema: -; Owner: -
--

CREATE TABLE IF NOT EXISTS some_table (
    id SERIAL,
    name varchar(255) NOT NULL,
    cleaned_name varchar(255) GENERATED ALWAYS AS (lower((name)::text)) STORED,
    CONSTRAINT some_table_pkey PRIMARY KEY (id)
);

whoward avatar Oct 15 '25 16:10 whoward

just tested this change and it works great, thanks for taking care of that!

whoward avatar Oct 16 '25 15:10 whoward