In SQL, is there a way to create a multi-column UNIQUE constraint for a formatted value?
In my case, I'm trying to prevent two items with the same title being created on the same day, using their created_at
timestamp, without resorting to adding an additional column.
Something like the following.
CREATE TABLE daily_things (
title text,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
UNIQUE(title, created_at::date)
);