Hot answers tagged postgresql
Use the CASE function: SELECT c.id, CASE WHEN COALESCE(bv.affidavit, '') = '' THEN False ELSE True END FROM component c, base_vee bv WHERE c.id IN (SELECT component_id FROM registry_row WHERE registry_id = 199) AND c.id = bv.component_id;
Simple with hstore If you have the additional module hstore installed (instructions in link below), there is a surprisingly simple way to replace the value(s) of individual field(s) without knowing anything about other columns: Basic example: duplicate the row with id = 2 but replace 2 with 3: INSERT INTO people SELECT (p #= '"id"=>"3"'::hstore).* FROM ...
COALESCE will let you get away with a lot of interesting things when you're dealing with the situation of "if it's null do one thing, otherwise do something else".. SELECT c.id, CASE WHEN COALESCE(bv.affidavit, '') = '' THEN FALSE ELSE TRUE END AS emptyish FROM component c JOIN base_vee bv ON c.id = bv.component_id WHERE c.id IN (SELECT component_id FROM ...
Only top voted, non community-wiki answers of a minimum length are eligible