We want to enforce a policy, partly just to protect those who might forget, for every table in a particular schema to have a primary key. This can't be done with event triggers as far as I can see, because it is quite legitimate to do:
BEGIN; CREATE TABLE foo (id int); ALTER TABLE foo ADD PRIMARY KEY (id); COMMIT;
It would be nice to have some kind of "deferrable event trigger" or some way to enforce that no transaction commits which added a table without a primary key.
As Adrian pointed out, by definition, PK's create a constraint which are NOT NULLABLE;
Here is the SQL to check for tables with no primary key.
SELECT n.nspname, c.relname as table, c.reltuples::bigint FROM pg_class c JOIN pg_namespace n ON (n.oid =c.relnamespace ) WHERE relkind = 'r' AND relhaspkey = FALSE ORDER BY n.nspname, c.relname;