pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Favro <postgres@meta-dynamic.com>
To: pgsql-general@lists.postgresql.org
Subject: 'Identifier' columns
Date: Mon, 13 Aug 2018 22:19:30 -0400
Message-ID: <20180814022005.E2B66FB1@mail.meta-dynamic.com> (raw)

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




view thread (2+ messages)  latest in thread

Message-ID: <20180814022005.E2B66FB1@mail.meta-dynamic.com>
Permalink:  ../20180814022005.E2B66FB1@mail.meta-dynamic.com/
Also on:    postgresql.org/message-id/20180814022005.E2B66FB1@mail.meta-dynamic.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: postgres@meta-dynamic.com
  Subject: Re: 'Identifier' columns
  In-Reply-To: <20180814022005.E2B66FB1@mail.meta-dynamic.com>
  References: <20180814022005.E2B66FB1@mail.meta-dynamic.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox