Linked Questions

1 vote
2 answers
1k views

I have a table structured as below, tests --------------------------- schoolId | name | isDeleted I don't want to allow duplicate test name for an school if it is active i.e isDeleted = false I am ...
confusedWarrior's user avatar
1 vote
0 answers
2k views

I have this table: CREATE TABLE mitg.tbl_gch_customers ( pe character varying(10)NOT NULL, name character varying NOT NULL, city character varying, address character varying NOT NULL, ...
Mike Jarvis's user avatar
0 votes
1 answer
314 views

In Postgres 13.4, trying to create a unique constraint where a record in a cars table is unique by name and user_id. The purchased_at date starts out as NULL but can change to a value once a car is ...
Nona's user avatar
  • 5,504
316 votes
5 answers
257k views

I have a table in PostgreSQL where the schema looks like this: CREATE TABLE "foo_table" ( "id" serial NOT NULL PRIMARY KEY, "permalink" varchar(200) NOT NULL, ...
Baishampayan Ghose's user avatar
408 votes
4 answers
279k views

I would like to set up a table in PostgreSQL such that two columns together must be unique. There can be multiple values of either value, so long as there are not two that share both. For instance: ...
PearsonArtPhoto's user avatar
8 votes
1 answer
4k views

I have models with this layout: class SafeDeleteModel(models.Model): ..... deleted = models.DateTimeField(editable=False, null=True) ...... class MyModel(SafeDeleteModel): ...
Vito235's user avatar
  • 81
5 votes
1 answer
2k views

I have the following table CREATE TABLE "prm_project_service_product_and_services" ( "id" BIGSERIAL NOT NULL, "name" VARCHAR(60) NOT NULL, "note" VARCHAR(256) NOT NULL, "version" BIGINT ...
Dimitri Kopriwa's user avatar
0 votes
1 answer
4k views

Help me please resolve next issue. I use NestJS + TypeORM softRemove/softDelete for delete records. And I want to apply @Unique decorator only for undeleted records. My remove method like: public ...
V.Tur's user avatar
  • 1,447
1 vote
1 answer
2k views

Have a table named People, column address_id (int) and is_deleted (boolean), how can I add a unique constraint to allow unique address_id + false, and allow multiple address_id + true. e.g. ...
user8355591's user avatar
1 vote
2 answers
1k views

I have this table: CREATE TABLE public.data_source__instrument ( instrument_id int4 NOT NULL, data_source_id int4 NOT NULL, CONSTRAINT data_source__instrument__pk PRIMARY KEY (data_source_id, ...
kYuZz's user avatar
  • 1,762
0 votes
1 answer
735 views

The table should have behavior similar to the primary key(Item_id, Date, Status). However, multiple cancel status is allowed. Item_id |Date |Status -------------------------------- 1 ...
RoastDuck's user avatar
  • 122
0 votes
2 answers
786 views

Table holds the images of the products. Each row points to URL of the product's image. Many products have multiple images. url > Image url product_id > Product's ID Some products have duplicate ...
buraktokman's user avatar
0 votes
1 answer
485 views

Is it possible to enforce a constraint and foreign key only when all values are not null? For example in a polymorphic relation one object would have multiple foreign keys, but often only one is used, ...
jjuser19jj's user avatar
  • 1,709
1 vote
1 answer
508 views

I am using a postgres with daterange field called valid_period in thing_thing table. The query I use to add the constraint CREATE EXTENSION IF NOT EXISTS btree_gist; ALTER TABLE thing_thing ADD ...
Kim Stacks's user avatar
  • 10.9k
1 vote
3 answers
175 views

I have a table orders with the columns: id, user_id and status. The status column is enum with values: pending, in_process, completed, declined. I need to disallow a user to have more than one order ...
Farad's user avatar
  • 1,125

15 30 50 per page