0

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.

Vincent Caggiari
  • 307
  • 2
  • 10

1 Answers1

0

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

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Darkroll
  • 16
  • 1