Skip to content

Commit

Permalink
Add example of parameterised JSON query
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Aug 26, 2023
1 parent bef56da commit c9aba5e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ JSON can always be sent in serialized form to the server:
>>>
>>> con.close()

JSON queries can be have parameters:

>>> import pg8000.native
>>>
>>> with pg8000.native.Connection("postgres", password="cpsnow") as con:
... con.run(""" SELECT CAST('{"a":1, "b":2}' AS jsonb) @> :v """, v={"b": 2})
[[True]]


Retrieve Column Metadata From Results
`````````````````````````````````````
Expand Down Expand Up @@ -1022,6 +1030,17 @@ JSON is sent to the server serialized, and returned de-serialized. Here's an exa
>>>
>>> con.close()

JSON queries can be have parameters:

>>> import pg8000.dbapi
>>>
>>> with pg8000.dbapi.connect("postgres", password="cpsnow") as con:
... cur = con.cursor()
... cur.execute(""" SELECT CAST('{"a":1, "b":2}' AS jsonb) @> %s """, ({"b": 2},))
... for row in cur.fetchall():
... print(row)
[True]


Retrieve Column Names From Results
``````````````````````````````````
Expand Down

0 comments on commit c9aba5e

Please sign in to comment.