Replies: 2 comments 5 replies
-
Why not just call the procedure directly with POST? Instead of a view, you can also have a wrapper function.
Yes, documented here: https://postgrest.org/en/stable/api.html#immutable-and-stable-functions. Maybe it needs to be more visible. We want to preserve GET semantics by enforcing read-only transactions. I don't think we'll lift this restriction, otherwise we wouldn't be conforming to HTTP standards. https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
|
Beta Was this translation helpful? Give feedback.
-
I was in a similar situation with an RPC for a very complex query that I was calling via I think there are valid use-cases such as these, where a GET / HEAD request would be better called in a writable transaction. That being said.. I'm still not sure whether we should allow do it. I fully agree with this:
While a config option or a marker on functions/views could help.. it's also dangerous because it would allow people to break those GET semantics. And that's something that we don't want to allow... |
Beta Was this translation helpful? Give feedback.
-
Environment
Description of issue
TLDR: Is there a way to perform a GET request against a view with write transaction instead of read?
I have a view that aims to lazy evaluate some heavy computation only when needed and using a persisted (cached) data when previously available.
Below I just wrote a simplified version of my actual problem having a function
lazily_heavy_procedure_and_cache
that returns asetof computed_data
and my viewlazily_computed_data
that returns rows of the exactly same type.(Obs.: I haven't run this, but only my version, I am not 100% if previous code works, but you will get the idea...)
The issue is that I can't perform GET requests against this view, receiving this error:
It seems that because it is a GET request, it runs inside a read transaction and PostgREST can't recognize that I use a function that is neither
immutable
orstable
, so it can perform mutation and this is actually expected.There is a way to force this transaction to behave differently allowing mutation?
I believe that this mutation don't hurts HTTP semantics, because even though internally I am performing a mutation, it is still a lazy mutation that otherwise would be performed after a trigger or something else.
In the client perspective, it is only an implementation detail that this is lazy evaluated, this should be transparent to him and is done only due to performance, so I guess other people may have similar issues depending on this use or do you really think that all GET performs no mutation, even if is a cache of data already present being computed?
Beta Was this translation helpful? Give feedback.
All reactions