title: How to check in postgres that lastval() is defined
body: <p>I'm creating a mini DB handling class and for convinience purposes, I want my generated INSERT queries are always try to return last insert id or null, if not applicable. I had tried to use:<br>
  <code>INSERT INTO ... RETURNING lastval();</code>
  <br>it works fine with tables which have a sequence, but if table have no sequence key field, that insert nothing and falls with error: <code>lastval is not yet defined in this session</code>.</p>
  
  <p>How to check in <code>RERURNING</code> block, is sequence generator was used in this session or silently return last id or null, without error raising?</p>
  
  <p>Note: for usablity purposes, I want to avoid direct specifing of PK field name.</p>