Lesser-known Postgres features
I want to stress the importance of not using<p><pre><code>  id int SERIAL
</code></pre>
If you are on a somewhat recent version of postgres, please do yourself a favor and use:<p><pre><code>  id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
</code></pre>
An "identity column", the part here:<p><a href="https://hakibenita.com/postgresql-unknown-features#prevent-setting-the-value-of-an-auto-generated-key" rel="nofollow">https://hakibenita.com/postgresql-unknown-features#prevent-s...</a><p>You might think this is trivial -- but SERIAL creates an "owned" (by a certain user) sequence behind the scenes, and so you run into massive headaches if you try to move things around.<p>Identity columns don't, and avoid the issue altogether.<p><a href="https://www.2ndquadrant.com/en/blog/postgresql-10-identity-columns/" rel="nofollow">https://www.2ndquadrant.com/en/blog/postgresql-10-identity-c...</a>