0

I wonder if anyone has had a similar situation. Delphi 11, postgresql database, FireDAC. This concerns the situation when the Append function is used in TFDQUery, then entering the value and Post.

Let's assume the object is AQ.

when a record is added, shouldn't AQ['id'] return the newly added id? This is how it works in the case of MySQL and UniDac, but shouldn't it behave this way? For PostgeSQL and FireDac, this value is null.

4
  • 3
    Use GetLastAutoGenValue() or RETURNING in your SQL statement Nov 20 at 21:36
  • @FrankHeikens, of course I know those options and I used GetLastAutoGenValue but every time as parameter I had to give name of sequence. I am courius if this case described in my post is problem of FireDac or Postgresql.
    – Stepel
    Nov 20 at 21:44
  • 2
    You have to tell PostgreSQL what value you're looking for, a single table can have multiple sequences. For MySQL this is limited to just one auto generated value. Nov 20 at 21:47
  • @FrankHeikens thank you very much. Now all is clear :)
    – Stepel
    Nov 21 at 7:10

1 Answer 1

0

In postgresql you can obtain the last identifier inserted in your session with

SELECT currval('sequence_name');

NOTE: You must know the name of the sequence (Autoincrement field). The format is usually "table name"_"field name"_seq

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.