Skip to content

Suggestion: PG::Connection#complile#726

Open
intale wants to merge 2 commits into
ged:masterfrom
intale:pg_connection_compile
Open

Suggestion: PG::Connection#complile#726
intale wants to merge 2 commits into
ged:masterfrom
intale:pg_connection_compile

Conversation

@intale

@intale intale commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Introduce PG::Connection#complile that take sql string and position parameters and compiles it into a plain sql. I couldn't find another way how to do it using built-in tools. The motivation behind this implementation:

  • debugging sql queries. When you have queries with dozens(or even hundreds) of positional parameters - it is pretty cancer to replace each positional param by hands for later inspection
  • such feature as PostreSQL view does not support positional parameters and requires pre-computed sql string. So, imaging you have some sql builder in your app that results in sql with positional params. And now you need to work with PostgreSQL view which does not support them. You will end up implementing very similar to the changes in this PR or somehow compute an sql string based on your app's logic. Both variants would be annoying.

The downside of this implementation is that it can't reliably encode binary data into a string representation except some common cases like with booleans, but do we need them at all?

@intale intale force-pushed the pg_connection_compile branch from 2cd9444 to b0a2666 Compare June 28, 2026 12:20
@intale intale force-pushed the pg_connection_compile branch from b0a2666 to 6b746e9 Compare June 28, 2026 18:42
@larskanis

Copy link
Copy Markdown
Collaborator

That sounds like a great idea! It's because I manually inserted too many parameters into too many queries from rails debug log in order to execute it in psql. That way a more useful debug output in rails would be possible and that would be my intention.

.. to replace code specific to the classes derived from PG::TypeMap.

Also:
- Deny binary format in SQL text
- Make BinaryString working
@larskanis

Copy link
Copy Markdown
Collaborator

I added a commit to use generic PG::TypeMap methods only and regarding binary data and binary format.

The method name "compile" is not very specific. Is it used in any other database driver? How sounds embed_params instead?

@intale

intale commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@larskanis thank you. Could you please explain how your changes apply to PG::TypeMapAllStrings as well? Because it has its own interface, all static, not exposed to public and PG::TypeMapAllStrings the default class for type mapping. Nvm, I'm blind. pg_tmas_type is inherited from pg_typemap_type and you added changes exactly into pg_typemap_type. I mixed it with PG::TypeMapByClass. Lgtm

@intale

intale commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

The method name "compile" is not very specific. Is it used in any other database driver? How sounds embed_params instead?

I don't have any strong preferences regarding this. embed_params works as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants