Tag Info

New answers tagged


This unicity constraint can be enforced with this unique index: CREATE UNIQUE INDEX idxname ON mytable(least(col1,col2),greatest(col1,col2)); Demo: test=> insert into mytable (col1,col2) values(1,2); INSERT 0 1 test=> insert into mytable (col1,col2) values(2,1); ERROR: duplicate key value violates unique constraint "idxname" DETAIL: Key ((LEAST(col1, ...


You need to create a function and then check result of this funcion. Ex. CREATE FUNCTION fn_region_en_region_pais(_region varchar(50)) RETURNS BIGINT AS $$ SELECT count(*) FROM region_pais WHERE region = _region $$ LANGUAGE SQL IMMUTABLE; ALTER TABLE indice_arm_global ADD CONSTRAINT chk_region_en_region_pais ...


This is what I ended up going with: create table blog_posts ( id uuid not null, tenant_id uuid not null, title text not null, content text not null, primary key (id) ); create unique index blog_posts_tenant_id_id_idx on blog_posts (tenant_id, id); create table comments ( id uuid not null, tenant_id uuid not null, ...


Use KEEP INDEX. drop table demo purge; create table demo (id number, constraint demo_pk primary key (id)); alter table demo drop constraint demo_pk keep index; select index_name from user_indexes where table_name = 'DEMO'; INDEX_NAME ------------------------------ DEMO_PK

Top 50 recent answers are included