3 ms·
I ran into this last week when wanting to upgrade a column to non-null and discovering we were running Postgres 9.something It made me curious, since the solut
by Lewton 8y ago
I ran into this last week when wanting to upgrade a column to non-null and discovering we were running Postgres 9.something
It made me curious, since the solution is so simple and fairly obvious, and it covers a common use case. How come it’s taken so long to be implemented? Similarly, it wasn’t added in oracle until version 11, so I must be missing something
- ddorian43 8y agoBecause someone didn't need + implement it.
- pilif 8y agoMainly because it's somewhat of a convenience feature for which a viable workaround exists: do a normal update, concurrently add a conditional `where ... is null` index, repeat in a loop (begin transaction, normal update, add constraint, commit) until it stops failing. This will still take a lock, but thanks to most rows already updated and because of the conditional index, the lock will only last a very short amount of time.
- lazyjones 8y agoPerhaps it wasn't really that simple? It seems to have taken more than 2 years according to https://www.postgresql-archive.org/ALTER-TABLE-ADD-COLUMN-fast-default-td5995655.html https://www.postgresql-archive.org/ALTER-TABLE-ADD-COLUMN-fa... and Tom Lane found it a bit scary first.
- Lewton 8y agoThanks for the link! That definitely illuminates some of the complexity involved