Low-level prepared statements API (PQprepare, PQdescribePrepared)
See original GitHub issueFrom the docs it looks like prepared statements can only be created and then immediately executed.
I want to create a prepared statement without executing it, and I also need the equivalent of PQdescribePrepared
I am trying to do something similar to the \gdesc
command of psql:
https://github.com/postgres/postgres/blob/e24a815c1c8550fcba5cc5aeb0d130db46570872/src/bin/psql/common.c#L1569
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
Top Results From Across the Web
15: 34.3. Command Execution Functions - PostgreSQL
PQprepare creates a prepared statement for later execution with PQexecPrepared . This feature allows commands to be executed repeatedly without being parsed ...
Read more >6.1 Overview of the C API Prepared Statement Interface
To prepare the statement on the server, call mysql_stmt_prepare() and pass it a string containing the SQL statement. Set the values of any...
Read more >Why use prepared statements instead of Query / Exec with go ...
Prepared statement already bound to concrete connection to DB, contains low-level driver.Stmt and can be used concurrently by multiple go-routings.
Read more >Data Retrieval And Manipulation - Doctrine
PHP has a generic abstraction layer for this kind of API called PDO ... Prepared statements separate these two concepts by requiring the ......
Read more >(The only proper) PDO tutorial - Treating PHP Delusions
Unlike mysql and mysqli, both of which are low level bare APIs not intended ... For all other cases you cannot use PDO...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks. I’ve had some time to look at all this, and I’ve made some progress.
I will share some code I was able to come up with.
Here is a function to create a prepared statement (without executing it):
The “describe prepared” is more difficult, because
Connection.prototype.parseMessage
is missing a case for the ‘t’ (0x74 ParameterDescription).What I have chosen to do for now is to monkey patch this function, so that it just ignores that message:
After a connection has been monkey-patched, we can issue a “describe prepared” statement. Here is a function that does it:
This will successfully provide the information about the result columns of the prepared statement. Unfortunately, because we are ignoring the “ParameterDescription” message from the backend, we don’t get the info about the parameters of the prepared statement. Adding code to parse the “ParameterDescription” message (instead of ignoring it) should not be too difficult.
For now, this code is working for my needs. It would be great if the functionality could be added to this library, but I am still a bit confused as to how best to add it.
if someone plans to work on this, IMHO it would be relevant to add feature to release prepared statements as well, see https://github.com/brianc/node-postgres/issues/1889