I want to write a single Postgres SQL statement that says look for a user with color X and brightness Y. If that user exists, return all of its row data. If not, create a new
If your columns participate in unique index constraint you can use an approach which is avaible since version 9.5:
INSERT INTO mytable (color, brightness, size, age)
VALUES ('X', 'Y', 'big', 'old')
ON CONFLICT (color) DO NOTHING;
(assuming you have unique index on color
).
Docs are gere: https://www.postgresql.org/docs/9.5/static/sql-insert.html