Skip to content

Tag: constraints

SQL – make a column unique after some timestamp?

Here is my use case. I am using Postgres 13.3 I have a people table under a draft schema that has multiple columns.. email and created_at. The email should have been unique but it was not. If I alter the table to be unique, there were duplicate emails inserted before and I don’t want to lose the data by…

Create CHECK constraint SQL

I hope you can help me. I would like to create a check constraint that ensure the column INKOOPBEDRAG has to be higher than PRIJS_PER_D. In the table INKOOPOVEREENKOMST.[BARCODE] it is a FK to ARTIKEL.[BARCODE]. I have created the following CHECK constraint, but I get an error: Answer I solved this using the …

Passing parameters for a constraint function

I have the following table that joins driver and truck tables in order to assign trucks to drivers. I need to constraint entries that belong to the same driver on the same day, and DO NOT include the same truck code. It was suggested to create a boolean function to pass along dateval, truckval and driverval, …

DROP Constraint without knowing the name

I know there are a lot of references out there for what I am going to mention. I am rather sharing something I feel should be very useful and consolidating in one place – Q&A-style. I have struggled earlier finding this for different constraints on different time. The following constraints are commo…

Postgresql constraint violated at restore

I have a problem with a constraint that is being violated by some rows when restoring my DB, but has never been violated at usage. I have 3 tables : some_table here is another table, which I think is not relevant for this problem. Now what I want is to have a unicity constraint between as.id and bs.some_id th…