postgrest-docs
postgrest-docs copied to clipboard
Return Full object from INSERT Trigger
The issue: As stated several places in the docs, you can return a full object from a POST. But this is especially difficult in regards to the "Multiple Tables Insertion or Update" guide section.
This is because a Trigger returns the "NEW" data, which is only the data passed in the actual POST. If your trigger, for example, does an INSERT that creates a PK for a row, that data will not be in the "NEW" data.
A very easy fix for this would be to do a SELECT into the "NEW" before returning "NEW".
SELECT * INTO NEW FROM [table] WHERE [field]=[row PK]; RETURN NEW;
As someone in the Gitter channel pointed out, this might be something others have issues with, so this could be something to add into the docs. See pastebin link for Gitter conversation.
@Mithrandir21 are you interested in sending a PR to document this tip?