Answer the question
In order to leave comments, you need to log in
Is it possible to generate a unique key by month and year?
is it possible to create a unique key to prohibit recording if there is already data for such a month?
something like unique constraint with to_char(timestamp,'YYYY-MM')
--
UPD
this way I check that multiple fields are not the same
CONSTRAINT uniq UNIQUE("F_ActualAnaliz_ID", "F_DateAnaliz", "F_User_ID"),
CONSTRAINT uniq UNIQUE(to_char(f_DateAnaliz, 'YYYY-MM')),
Answer the question
In order to leave comments, you need to log in
In Postgresql, yes, you can: www.postgresql.org/docs/9.4/static/indexes-express... You
can build an index for any immutable function, including a custom one.
Only better not to_char, but date_trunc('month', f_DateAnaliz). The index will be more compact.
Yes, you can, moreover, the selection on this field will work faster because you are creating an index.
A unique key in general can be anything. Though a bit field. Problems can start when for some reason you want to add a second entry with the same key and you have to come up with a composite key. Immediately there will be a problem of backward compatibility and data migration.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question