Error: lastval is not yet defined in this session



So i’m running into an error, and can’t seem to find the solution. the error i’m getting is from PostgreSQL: “lastval is not yet defined in this session”. the error comes up when the on success is being triggered for notifications. the data is being stored in the DB.

The form, from which it’s posted, is generated by a repeat from a card group(like the image below). This to show a grid, on each grid tile there should be a form to add data to the information shown on the tile.


Any one an idea to solve this, or built the structure in a better way?

Kind regards,


assigned patrick #2

Which Server Model do you use? It seems to me that you try to do a database insert, does the table have an id column and if so what type is it?

I looked up the error, the lastval is to get the last inserted id from the database and it seems not to be set in your case.


My apologies for the late reply.

The server is running on PHP(7.3.2). And there is an ID column, it’s set do serial+PK(auto increment) in postgres which translate to an integer. it’s only used for updating values on a particular row.


To add more information after some searching.

The error is comming from the connection.php file:

file: “\dmxConnectLib\lib\db\Connection.php”
line: 95
message: “SQLSTATE[55000]: Object not in prerequisite state: 7 ERROR: lastval is not yet defined in this session”

And line 95 says: ‘identity’ => $this->pdo->lastInsertId()

I’m seeing online, is that it’s not advised to use lastval() with Postgres, but better would be to use “returning ;”.

Some explanation:

here is also some information regarding when you could call lastval:

I also found this:
it shows a way how to get the sequence in postgres and I tried this in the connection.php file to see what would happen. But then I got this error message: “currval of sequence “classassignment__id_seq” is not yet defined in this session"”.

This is what I have found at this moment, but I have no idea what to do now on fixing it besides commenting it off in the connection.php file(this does work and does not give an error, but i guess this does not give any identity back then anymore in the steps?).


Thanks for the research. I checked the lastInsertId documentation from PDO. Seems that Postgres requires the name of a serial object as parameter.

To fix it I have to know which name I have to pass there, will have a look at it.

1 Like