pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Primary key using generated column

Open grachevko opened this issue 1 year ago • 2 comments

CREATE TABLE IF NOT EXISTS commit (
    id text PRIMARY KEY,
    git_repository_id integer NOT NULL REFERENCES git.repository (git_repository_id)
);

Plan after dump && plan without file modifications

ALTER TABLE commit DROP CONSTRAINT commit_git_repository_id_fkey;

ALTER TABLE dependency.commit
    ADD CONSTRAINT commit_git_repository_id_fkey FOREIGN KEY (git_repository_id) REFERENCES git.repository (git_repository_id) NOT VALID;

ALTER TABLE dependency.commit VALIDATE CONSTRAINT commit_git_repository_id_fkey;

grachevko avatar Sep 24 '25 16:09 grachevko

Could you please describe the workflow in more details?

tianzhou avatar Sep 25 '25 06:09 tianzhou

I just reproduce it on clean pg, it related to generated columns.

CREATE TABLE IF NOT EXISTS git.repository
(
    data              jsonb NOT NULL,
    git_repository_id integer PRIMARY KEY GENERATED ALWAYS AS ( (data ->> 'iid')::integer) STORED
);

grachevko avatar Sep 25 '25 09:09 grachevko