How can I inspect the SQL statements generated by PostgREST? #4141
-
Is it possible to inspect the raw SQL statements that postgREST is generating for requests? For example, for a request like this:
I'd like to be able to review the generated SQL:
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hah! Funny you ask because I had the same challenge yesterday. Here’s what I did. First, enable statement logging in the db (see also the # Add this to Docker compose, or however you run the Postgres server.
postgres-db:
image: postgres/postgres:17-alpine3.21@sha256:f325a29ec9deb7039c5f07761d77d79d537dac836ecd99f982f6ca5476724604
command: [postgres, -c, log_statement=all]
... and then you’ll see output like this:
You have both, the setup for the endpoint statement (i.e. setting role and configs) and the actual endpoint implementation. A little tedious to rummage through, and maybe there are better ways/filters, but it’s a start I suppose. Notice the:
in the |
Beta Was this translation helpful? Give feedback.
-
The answer above is the most complete option right now. However, In PostgREST v13 there's another way to log the SQL query (see this section in the docs); for now, it only logs the main query and does not show the parameter values. |
Beta Was this translation helpful? Give feedback.
The answer above is the most complete option right now. However, In PostgREST v13 there's another way to log the SQL query (see this section in the docs); for now, it only logs the main query and does not show the parameter values.