sql - Intervals: How can I make sure there is just one row with a null value in a timstamp column in table? -


i have table column contains 'valid until' date , want make sure can set null in single row within table. there easy way this?

my table looks (postgres):

create table 123.mytable( some_id integer not null, valid_from timestamp without time zone not null default now(), valid_until timestamp without time zone, somestring character varying) 

some_id , valid_from pk. want nobody enter line null value in column valid_until if there line null pk.

thank you

in postgresql, have 2 basic approaches.

  1. use 'infinity' instead of null. unique constraint works expected. or if cannot that:
  2. create unique index null_valid_from on mytable(someid) valid_until null

i have used both approaches. find first approach cleaner , allows use range types , exclude constraints in newer versions of postgresql better (to ensure no 2 time ranges overlap based on given given someid), bt second approach useful first cannot done.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -