In Postgres 13.4, trying to create a unique constraint where a record in a cars table is unique by name and user_id. The purchased_at date starts out as NULL but can change to a value once a car is purchased. I run the following but get a syntax error:
ALTER TABLE cars ADD CONSTRAINT cars_user_id_name_purchased_at_key UNIQUE (user_id, name) WHERE purchased_at IS NULL Error:
ERROR 42601 (syntax_error) syntax error at or near "WHERE"
What is the issue and how to fix?