Skip to content
Advertisement

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 removing

Enforce 2 unique constraints on upserts in Postgres

I have a table where I save contacts data I add data to this table from several sources. Some sources have Linkedin profiles data about people, other sources have email data. Sometimes the full names are not equal, even if they refer to the same person. And I want to do upserts to not have duplicated data. For now I’m

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 following: Then I added a Constraint as

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, and returns the following.

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 commonly used: Primary key Constraint Foreign key Constraint Unique

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 through the

Advertisement