It may sound silly, but I would need to identify which kind of SQL statement (INSERT, SELECT, UDATE, others) has an already prepared statement on PostgreSQL, while working on a C program with libpq.
Let me explain it a bit different: I am developing a small application on C, using the libpq library that provides access to PostgreSQL databases. I have a prepared statement on PostgreSQL (using the PQprepare command) but I would like to know, before running it what kind of SQL statement is (SELECT, ...).
Why you may ask? Let's just say that the application reads the SQL queries from another source, that is, they are not hard-coded. Of course, I may just parse the SQL on my app before sending it to PostgreSQL but for me it would be VERY convenient that PostgreSQL could do it for me.
Just as an example, Oracle via its OCI library can return this information.
You can query the system catalog:
SELECT * FROM pg_prepared_statements
It holds detailed information on prepared statements, including the "the query string submitted by the client" in the column statement
.
Read more in the manual here.
Be aware that a single valid SQL statement can hold all of these keywords at the same time: INSERT
, SELECT
, UDATE
(in a writable WITH clause for instance).