TonicAI / condenser

Condenser is a database subsetting tool
https://www.tonic.ai
MIT License
312 stars 48 forks source link

Skip generated columns in copy_rows method #41

Closed Ceda closed 1 year ago

Ceda commented 1 year ago

I have same issue like #40 this PR detect generated columns from schema and prevent inserting. Is working for Postgres, same issue for MySQL here #28

bricct commented 1 year ago

This looks good except for one small problem and that is that some Identity columns can be generated.

There are two cases for generated identity columns GENERATED BY DEFAULT and GENERATED ALWAYS The latter of which causes problems by making insert statements fail.

In the case that an IDENTITY column is GENERATED BY DEFAULT the column should simply be inserted as normal.

In the case that an IDENTITY column is GENERATED ALWAYS the insert statement should have OVERRIDING SYSTEM VALUE following the column list e.g.

INSERT INTO user 
     (id, name, password) 
OVERRIDING SYSTEM VALUE 
VALUES
      (1, 'user', 'password123');

An identity columns' generated status can be discerned via the pg_attribute.attidentity field. This field can be one of three values:

I'll do my best to include these changes in my free-time but feel free to take care of it yourself as well. Thank you!

P.S. here's some relevant links to this problem Stack Overflow, PG Docs

bricct commented 1 year ago

I have made a PR off of your PR that will add the requested changes that I commented. Once you merge that PR, I can merge this one as well. Thanks!

Link to PR

Ceda commented 1 year ago

I have made a PR off of your PR that will add the requested changes that I commented. Once you merge that PR, I can merge this one as well. Thanks!

Link to PR

Nice work, thank you... I squashed your code into my branch...

bricct commented 1 year ago

Thank you @Ceda !