In Part 1 we implemented the server handshake in Python. With our subterfuge now established, we’ll go ahead and respond to requests. In brief:

Pretending to be PostgreSQL: Part two – responding to queries – Ian's notes

submited by
Style Pass
2024-11-24 19:30:04

In Part 1 we implemented the server handshake in Python. With our subterfuge now established, we’ll go ahead and respond to requests.

In brief: we’ll look at what’s needed to receive the client query (after the handshake is established), implement the three response messages needed to provide a row back to the client, test it, and then have a look at the packets produced on the wire. Refer back to Part 1 for the details on the protocol handshake and the references to the appropriate sections of the PostgreSQL documentation describing the messages used here.

There’s a multitude of queries a client can send to us, but in this case we’ll look at a SELECT and send the correct set of bytes back on the wire to have our response rendered by psql, as if we were a standard PostgreSQL installation.

For our SELECT queries we need to read the query (message type Q) from the client and then respond with (generally) three of our own messages:

Leave a Comment