trino-python-client icon indicating copy to clipboard operation
trino-python-client copied to clipboard

Document how to use prepared statements

Open hashhar opened this issue 3 years ago • 1 comments

The client is based on Python DB-API so the usage is cursor.execute(sql, params). We use ? for params.

So an example would look like:

cursor.execute("SELECT * FROM tbl WHERE col_1 = ? AND col_2 = ?", ("value_1", "value_2",))

Note that params can either be a tuple or list.

hashhar avatar Nov 16 '21 08:11 hashhar

I figured this out on my own but I got an error of trino.exceptions.FailedToObtainAddedPrepareHeader

After a bit of debugging it seems maybe because my server is an older version which return presto in the header. What I mean is that the current version of the library is looking for HEADER_ADDED_PREPARE = 'X-Trino-Added-Prepare' but the response from the server I'm using has 'X-Presto-Added-Prepare': 'st_...

callado4 avatar Jan 16 '22 20:01 callado4