6 ms·
> Seems like this tool could essentially pre-create the types for any raw Postgres SQL statement? It's a syntax parser that produces an AST. So only informatio
by aleclarsoniv 2y ago
> Seems like this tool could essentially pre-create the types for any raw Postgres SQL statement?
It's a syntax parser that produces an AST. So only information explicitly defined in the syntax is available. To infer input/output types for an arbitrary SQL command, you need introspection (the most fool-proof way being PQdescribePrepared[1]).
> Being able to use raw SQL and get query types "for free" would be amazing.
That's basically what pg-nano does, but you need to use Postgres functions, rather than "$1" or "?" placeholder templating. Of course, some people prefer co-locating their raw SQL inside their TypeScript files, in which case, pg-nano is not for them.
[1]: https://www.postgresql.org/docs/current/libpq-exec.html#LIBPQ-PQDESCRIBEPREPARED https://www.postgresql.org/docs/current/libpq-exec.html#LIBP...