My objective is to get a primary key field automatically inserted when inserting new row in the table.
How to get a sequence going from session to session in Postg
The currval will return the last value generated for the sequence within the current session. So if another session generates a new value for the sequence you still can retrieve the last value generated by YOUR session, avoiding errors.
But, to get the last generated value on any sessions, you can use the above:
SELECT last_value FROM your_sequence_name;
Be careful, if the value was used by other session with an uncommited (or aborted) transaction and you use this value as a reference, you may get an error. Even after getting this value it may already be out of date. Generally people just need the currval or even the return of setval.