Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpOxB-0002YG-90 for pgsql-general@arkaria.postgresql.org; Tue, 14 Aug 2018 02:21:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fpOx6-0003UM-05 for pgsql-general@arkaria.postgresql.org; Tue, 14 Aug 2018 02:20:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpOx5-0003UF-OV for pgsql-general@lists.postgresql.org; Tue, 14 Aug 2018 02:20:55 +0000 Received: from troy.meta-dynamic.com ([204.11.35.233] helo=mail.meta-dynamic.com) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fpOwx-00077V-Vt for pgsql-general@lists.postgresql.org; Tue, 14 Aug 2018 02:20:54 +0000 Received: by mail.meta-dynamic.com (Postfix, from userid 1000) id E2B66FB1; Mon, 13 Aug 2018 22:20:05 -0400 (EDT) To: pgsql-general@lists.postgresql.org From: "David Favro" Date: Mon, 13 Aug 2018 22:19:30 -0400 Content-Type: text/plain; charset=UTF-8; format=flowed Subject: 'Identifier' columns Message-Id: <20180814022005.E2B66FB1@mail.meta-dynamic.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk A couple of questions about auto-assigned identifier columns, forgive my ignorance, I'm used to other methods to create IDs... 1. If creating a new application [i.e. no "legacy" reasons to do anything] using PostgreSQL 10, when creating an "auto-assigned integer ID" column, what are the advantages/disadvantages of using the 'SERIAL' datatype [or equivalent explicitly created SEQUENCE w/ nextval() used as default for column] versus the SQL-standard 'integer GENERATED AS IDENTITY'? All other things being equal, it would seem a no-brainer to follow the standard. 2. When using the SQL-standard 'integer GENERATED AS IDENTITY' column, after inserting a column, what is the recommended method to find the ID of the just-inserted row? Is there no SQL-standard way? The docs seem to imply (without explicitly stating) that a SEQUENCE is used behind the scenes hence 'currval()' could be used, but I didn't see in the docs any mention of what the underlying sequence's name is, or how to specify a name. Perhaps 'lastval()' would work, but not in all cases and in any event it has a sloppy feel to me. Thank you in advance for any advice that can be offered. -- David