Search code examples
postgresqlinsertzend-framework2lastinsertid

Zend 2 + Postgresql views - getGeneratedValue()


I'm using views in Postgresql and I encounter a problem in Zend: I can't retrieve the last inserted value of an insert request.

Example: I have an user_view and when I insert in, it does instead:

INSERT INTO basic_user(name, email) VALUES [...]; INSERT INTO extended_user(id, phone) VALUES (lastval(), [...]);

When I execute the request in Zend and call getGeneratedValue() it returns NULL...

How can I get the lastval() ?

I tried to use the RETURNING clause in my INSERT but without success..

Thx for your help.


Solution

  • The solution in PGSQL is currval(Sequence name) PG Doc.

    Example

    INSERT INTO basic_user(name, email) VALUES [...]; INSERT INTO extended_user(id, phone) VALUES (currval(basic_user_seq)(), [...]);