1

In my table definition I have default values for auditing i.e logging the database user creating the record and time

date_created date NULL DEFAULT now(),
edited_by varchar NULL DEFAULT "current_user"(),

When a record is inserted via Geoserver WFS-T these default values are not triggered. I am curious to why and if I can do something about it?

Both these basic examples triggers the default values to inject expected default values

INSERT INTO test_table
(notes, dato, edited_by)
VALUES('test', now(), "current_user"());

INSERT INTO test_table
(notes)
VALUES('test2');

Make me belive Geoserver actually produces this SQL?

INSERT INTO test_table
    (notes, dato, edited_by)
    VALUES('test', null, null);
3
  • Turn the logging up to geotools dev and you should see the actual query that's sent
    – Ian Turton
    Commented Feb 21, 2022 at 17:30
  • Thanks, will look into geotools, thats new to me. I tried to check to running queries, but pgadmin3 has removed this option so I need to find out that too =)
    – geogrow
    Commented Feb 22, 2022 at 7:42
  • Bumped up logging to geotools dev and could see the queries. As expected GS is setting the "date" and "edited_by" to null so the default is not triggered. Is there a clever way of avoiding that or maybe using trigger functions in postgres is the way to go?
    – geogrow
    Commented Mar 1, 2022 at 11:19

1 Answer 1

0

Solved using triggers in the database for the operation rather than rely on default table definitions.

Your Answer

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

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