On Wed, Dec 21, 2016 at 7:55 PM, Joel Jacobson <j...@trustly.com> wrote:
> Attached is the function SET_NOT_NULL(_Schema name, _Table name, _Column > name) which does the following: > > 1. LOCK TABLE %I.%I IN ACCESS EXCLUSIVE MODE > just like the normal DDL commands would do > > 2. SELECT EXISTS (SELECT 1 FROM %I.%I WHERE %I IS NULL) > which is fast if there is an index on the column > > 3. UPDATE pg_catalog.pg_attribute SET attnotnull = TRUE > WHERE attrelid = %L::oid > AND attname = %L > > Pragmatically, would this be a safe approach? > Hmm, I don't see a problem with it. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company