postgres-elasticsearch-fdw: Could it support the `RETURNING` ?

First, thank you for this awesome project ! Easy to set up and works very well.

I use RETURNING * almost every time I do an INSERT in postgres to retrieve the real inserted data (e.g: with default values). When using it on a foreign table using this foreign data wrapper, I get an empty row. Is it the expected behavior? If not, even if I am very new to FDW and python, I could try to fix it.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 20 (20 by maintainers)

Most upvoted comments

Looks good to me. Thanks !

I would say the DELETE method still miss the refresh query parameter to match the behavior of the other two methods (document may be still searchable until index refresh).

Regarding the main subject of RETURNING, it can be considered closed.

I think it could look like this:

    def delete(self, document_id):
        """ Delete documents from Elastic Search """

        if self.complete_returning:
            document = self._read_by_id(document_id)

        try:
            response = self.client.delete(id=document_id, refresh=self.refresh, **self.arguments)
            if self.complete_returning:
                return document
            return {self.rowid_column: document_id}
        except Exception as exception:
            log2pg(
                "DELETE for {path}/{document_id} failed: {exception}".format(
                    path=self.path, document_id=document_id, exception=exception
                ),
                logging.ERROR,
            )
            return (0, 0)
  • read document first if needed
  • add refresh parameter to the delete query
  • return id or document depending on self.complete_returning (to match insert/update behavior)