Pq_driver: [PGRES_FATAL_ERROR]ERROR: duplicate key value violates unique constraint "tablename_pkey"

A relative newbie (I’m a couple of months in), and I have a small problem (I hope):

I have a single form application that addresses a single table in a remote PostGresSQL database. The form contains a mainform, which is a list of the records as a grid, and a subform that contains the individual fields for view, edit and addition. The view/editing works fine, but when I try to add from the subform, I get a duplication error.

I investigated and note the documentation here with some concern(!) regarding Master and Detail fields; I think that instead of inserting an auto-increment value, the system is pulling the current key field from the master table which results in the duplication error:

pq_driver: [PGRES_FATAL_ERROR]ERROR: duplicate key value violates unique constraint "tablename_pkey"

I note topic 43893 and topic 26040 .but at this point I’m tearing out my hair…

Is there a workaround for this? Or must I completely rethink the structure of my form in order to add data?

Best wishes,

Candido Bandido

Ask the administrator of your PostgreSQL database.

Hi Villeroy!

Thank you for replying so soon. I am fairly certain this is a BASE and not a Postgres problem, as when I add data directly to the table from the LO Base application window, the table auto-increments as expected.

It is only when I try to add data through the form that I experience this error; moreover, the value of the key field duplication error is the same value as the record on the grid of the main form.

Best wishes,

CB

This is not a problem at all. Your database works as designed. It refuses to store duplicates. Your database administrator can tell you what goes wrong with your Base form and how to fix it.

Hi again, Villeroy

No-one here but us chickens … which is to say there is only me! The administrator who runs the Postgres DB does not know BASE, so it is down to yours truly. Which is why I am asking for help.

I have since tried to move the pointer of the grid control on the main form down to the New position (oForm.MoveToInsertRow) before trying to save at the subform level, but I get the error ‘INSERT privilege not available’. I will try other avenues.

Best wishes

CB

He does not need to know Base. Base is just an ordinary (and quite simplistic) frontend (a user interface) to your PostgreSQL database. He is the one to explain to you what happens.