-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schema Cache queries as boostrap prepared statements #3700
Comments
I was mostly thinking of this in the context of embedding postgrest-openapi somehow, to avoid telling the users to create the extension first. I've been checking the code and it's mostly functions (with a few types, which are not strictly necessary). If we could somehow embed the postgrest-openapi main function as a prepared statement, this could work. By removing the types and the plpgsql functions, it seems possible to have a build step that inlines all the SQL and then creates a prepared statement. |
Prepared statements are only available in the same session, so I don't see how this can help debugging things. |
This is mostly for development. Although for debugging we could provide something like:
Then the user can do |
Oh, I like this idea.. but instead of outputting a Then I can just pipe that query directly into So something like: |
Hm, I guess it's possible but we would have to do the replacing in Haskell code. I was thinking to leave most of the work to SQL/psql. Another option could be to add our scache config as psql variables (for another flag) to do: \set pgrst_db_schemas test,api
PREPARE pgrst_accessible_tables... And then: $ postgrest --output-scache-queries-psql | psql -c "execute pgrst_accessible_tables (:'pgrst_db_schemas');" |
Problem
Modifying/maintaining the schema cache queries is a difficult process, to run them on
psql
we have to extract them from the Haskell code and replace the placeholders manually.In the past, we've tried to put them in functions inside
pg_temp
(#1511), however creating functions is invasive (require privileges plus a no go on replicas).Solution
Create prepared statements at PostgREST startup, then refer to them by name. This will allow us to develop schema cache queries in other files and run them easily. Unlike functions they're ephemeral database objects and don't require privileges.
The main idea. Take for example our accessibleTables query.
Which can be stored as:
Which then allows us to call it like:
And from PostgREST codebase we can use the same way to call them and pass them parameters.
Notes
The text was updated successfully, but these errors were encountered: