News for hackers. Stuff that matters.
Re:Supabase Wrappers: A Framework for Building Postgres Fore... by ako on Thursday December 15, 2022 @04:12PM (#34005849)
Materialized views enable you to "cache" the response, and only refresh it periodically.
Re:Supabase Wrappers: A Framework for Building Postgres Fore... by chrisjc on Thursday December 15, 2022 @05:51PM (#34006926)
Wait, you're telling me that you can create materialized views using foreign tables in Postgres?

Is there a way to propagate changes from the foreign data source through the FDW to Postgres?

Or would it just be some kind of task polls the foreign data source pulling a delta?

Re:Supabase Wrappers: A Framework for Building Postgres Fore... by radiowave on Thursday December 15, 2022 @06:43PM (#34007468)
The only option that Postgres's materialized views give you is to "refresh" the view, meaning: re-run the query used to define the view, fetching an entirely new dataset, and use that to replace all the existing data in the view.

There's no facility for deltas, or any other way of propagating changes.

Edit: And to answer your original question, yes you can absolutely base the materialized view on data obtained from a foreign table.

Re:Supabase Wrappers: A Framework for Building Postgres Fore... by burmecia on Thursday December 15, 2022 @06:59PM (#34007609)
You can create a custom function doing all the delta logic and use pg_cron to schedule it to periodically materialize data using FDW.
Re:Supabase Wrappers: A Framework for Building Postgres Fore... by chrisjc on Friday December 16, 2022 @09:59AM (#34015225)
Yeah, this was the approach I was imagining before someone mentioned Materialized View (proper).

Once I heard those words mentioned, I began to imagine what sort of interaction with a foreign data source's operations log FDW might have.

Of course, and depending on the foreign data source, you could probably even expose an operations log to Postgres via a FDW by defining it as a foreign table... Effectively opening up the possibility of eventually consistent replication. Lots of data stores' operations logs are accessible data collections/tables anyways.

All of this is exciting stuff!