If you want to get the identifier and return it, you can use nextval() , which promotes the sequence without inserting any data.
Note that if this is a SERIAL column, you need to find the sequence name based on the table name and column, as shown below:
Select nextval(pg_get_serial_sequence('my_table', 'id')) as new_id;
There is no cast-iron guarantee of the order in which these identifiers will be returned (since several sessions may require the identifier and not use it, or even roll back INSERT ), but there is a guarantee that they will be unique, which is usually important.
If you often do this without actually using an identifier, you will end up using all the possible values ββof the column (i.e. reach the maximum number represented), but if you use it only when there is a high probability that you will really be inserting a line with this identifier, it should be in order.
IMSoP source share