Zend 2 + Postgresql views - getGeneratedValue()

249 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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)(), [...]);