Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "name" a query in postgres

In postgresql a query in the querylog gets something like this:

2009-02-05 00:12:27 CET LOG:  duration: 3781.634 ms  execute <unnamed>: SELECT QUERY ....

Is there a possibility to put something more usable into the "< unnamed >" placed like the url the query was requested from?

Are there any other possibilities to track the origin of a query in postgresql using jdbc from java?

Thanks

like image 857
theomega Avatar asked Feb 04 '09 23:02

theomega


People also ask

How do I name a column in PostgreSQL?

The syntax to rename a column in a table in PostgreSQL (using the ALTER TABLE statement) is: ALTER TABLE table_name RENAME COLUMN old_name TO new_name; table_name. The name of the table to modify.

How do I write a selected PostgreSQL statement?

If you want to select data from all the columns of the table, you can use an asterisk ( * ) shorthand instead of specifying all the column names. The select list may also contain expressions or literal values. Second, specify the name of the table from which you want to query data after the FROM keyword.

How do I create an alias in PostgreSQL?

Summary. Assign a column or an expression a column alias using the syntax column_name AS alias_name or expression AS alias_name . The AS keyword is optional. Use double quotes (“) to surround a column alias that contains spaces.


1 Answers

Short answer is "no"

The name can be set when preparing the statement, using the PREPARE command, but that requires rewriting all your SQL. There is no option to simply add a name parameter to your JDBC methods.

The JDBC driver makes use of both named and unnamed prepared statements. It will give them a name when it wishes to reuse them, which it will deem appropriate if the same PreparedStatement object is executed 5 times (though that is configurable through setting the prepareThreshold).

Documentation is here

More info can also be found by searching the PostgreSQL JDBC mailling list

like image 171
Stephen Denne Avatar answered Oct 13 '22 09:10

Stephen Denne