pg_squeeze icon indicating copy to clipboard operation
pg_squeeze copied to clipboard

Unique constraint on squeeze table

Open shruthikc-gowda opened this issue 1 year ago • 6 comments

Hi, This query is regarding the README information that says make sure that your table has either primary key or unique constraint.

postgres=# create table test ( id int, age int  NOT NULL );
CREATE TABLE
postgres=# alter table test add constraint unique_const UNIQUE (id);
ALTER TABLE
postgres=# insert into test values (generate_series(1, 5000), 30);
INSERT 0 5000
postgres=# SELECT squeeze.squeeze_table('public', 'test');
ERROR:  Table "public"."test" has no identity index

The code expects the table to either have a replica identity index or a primary key and does not check for the unique constraint. I am a little confused about the "primary key or unique constraint" mention in the README.

shruthikc-gowda avatar Mar 13 '24 04:03 shruthikc-gowda

Why a table to be squeezed requires a primary key or unique constraint, is that your question?

kovmir avatar Mar 14 '24 05:03 kovmir

My question is can pg_squeeze work when the table has a unique constraint and no primary key ?

shruthikc-gowda avatar Mar 14 '24 06:03 shruthikc-gowda

Hi, As per my understanding, pg_squeeze expects the table to have a primary key or a replica identity configured. I was wondering if the below line in the README needs an update ?

**Register table for regular processing**
First, make sure that your table has either primary key or unique constraint.

First, make sure that your table has either primary key or replica identity.

Also, one more observation is the README has the description for skip_analyze but is not part of any function definitions.

shruthikc-gowda avatar Mar 21 '24 04:03 shruthikc-gowda

The problem is that the id column is nullable. You fix your test this way:

ALTER TABLE test ALTER COLUMN id SET NOT NULL;
ALTER TABLE test REPLICA IDENTITY USING INDEX "unique_const";

I'll adjust the documentation. Thanks.

ahouska avatar Mar 22 '24 06:03 ahouska

skip_analyze is a column of the squeeze.tables table, not a function argument.

ahouska avatar Mar 22 '24 06:03 ahouska

Ok. Thanks for the response

shruthikc-gowda avatar Mar 22 '24 06:03 shruthikc-gowda