Make a non-ordinal numeric ID in PostgreSQL
but I'd rather they weren't, as it seems like asking for a sequence number attack of some kind


Aside from the fact that I think you are giving yourself a false sense of security, you can do what you want by reserving the upper half of the identifier for the 'real' sequence and filling the lower half with random bits:




create sequence seq;






create table tab(
  foo bigint 
      default (nextval('seq')&lt;&lt;32)+(random()*(1&lt;&lt;32))::integer
      primary key
);






insert into tab select from generate_series(1,9);






select foo, foo&gt;&gt;32 seq from tab;



        foo | seq
----------: | --:
 4294967296 |   1
 8589934592 |   2
12884901889 |   3
17179869185 |   4
21474836481 |   5
25769803777 |   6
30064771073 |   7
34359738369 |   8
38654705664 |   9



dbfiddle here