postgrest-docs icon indicating copy to clipboard operation
postgrest-docs copied to clipboard

Return Full object from INSERT Trigger

Open Mithrandir21 opened this issue 9 years ago • 1 comments

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 avatar Aug 02 '16 15:08 Mithrandir21

@Mithrandir21 are you interested in sending a PR to document this tip?

begriffs avatar Jan 23 '17 03:01 begriffs