I think you're trying to avoid writing:
UPDATE mytable SET
door_open = door_open + INTERVAL '1' HOUR,
door_close = door_close + INTERVAL '1' HOUR,
car_open = car_open + INTERVAL '1' HOUR,
car_close = car_close + INTERVAL '1' HOUR,
... blah blah ...
WHERE
...
and instead want a way to match column names by wildcard.
If that is the case, then no, there is no built-in way to do that.
You can construct a query dynamically using PL/PgSQL: Use a query against the information_schema.columns
view to get column names, then string concatenation to form the query. Then you can run it with EXECUTE
. There are many examples of such dynamic SQL elsewhere on Stack Overflow.
e.g.
DO
$$
DECLARE
sqlstring text;
BEGIN
SELECT INTO sqlstring
'UPDATE blah SET '
|| string_agg(format('%I = %I + INTERVAL ''1'' HOUR', column_name, column_name), ', ')
|| ' WHERE true'
FROM information_schema.columns
WHERE table_name = 'blah'
AND table_schema = 'public';
EXECUTE sqlstring;
END;
$$;