2 ms·
Postgres has built in functions for turning rows into JSON and JSON into rows. As long as you don’t add non-nullable columns, you can build a schema chan
by jitl 2y ago
Postgres has built in functions for turning rows into JSON and JSON into rows. As long as you don’t add non-nullable columns, you can build a schema change tolerant audit log storing the previous row as JSONB. Of course before making a schema in production, it would be good to test the JSON coercion handles the new column correctly.
I haven’t built an audit log using this functionality, but I have used it for bulk insert statements where binding each row/column individually would exceeded the parameter limit, and COPY was too awkward.