Senior
When you perform a regular SELECT, how many queries does the driver send to Postgres? What are these queries and what will be there?
sobes.tech AI
Answer from AI
When performing a regular SELECT through the JDBC driver to Postgres, usually one SQL query is sent — the SELECT itself.
The process is approximately as follows:
- The client (application) sends one SQL query to the Postgres server.
- The server processes the query and retrieves the data.
- The server returns the result (a set of rows) to the client.
This means the driver does not send additional queries unless something like prepared statements with separate preparation or additional metadata is used. In a simple case, it is one query and one response with data.
If a prepared statement (PreparedStatement) is used, the driver may first send a prepare request (Parse), then execute it (Execute), but all this happens within the framework of a single logical request.
Example:
SELECT id, name FROM users WHERE active = true;
One query is sent, and a set of rows with id and name of active users is returned.