I'm dealing with a table that has way too many columns for good design. (Close to 100). I can't change the schema.
I need to COALESCE each column to be 0 on NULL. Is there a way to do this without typing out all 100 columns by hand? (Perhaps using some type of data dictionary or meta information?)
You can create a Postgres function to achieve the desired output.
Sample table and data -
Following select statement will create dynamic
select
to get all tables withcoalesce()
.Result:
You can wrap this into a function
Usage:
select * from get_table_t()
Output: