Commit ecdb963
committed
Migrate from psycopg2 to psycopg3
psycopg3 is mostly built as a drop-in upgrade from psycopg2.
Differences are detailed here: https://www.psycopg.org/psycopg3/docs/basic/from_pg2.html
A few highlights:
* Cancelling running queries
One major DX improvement is that Ctrl-C can now cancel a running
query. With psycopg2, the python process can be killed but a running
query usually could not be killed (without knowing the PID and running
`pg_cancel_backend(pid)` from a separate connection), to the immediate
regret of all we who sometimes accidentally execute an unfortunately
large query.
See https://www.psycopg.org/psycopg3/docs/advanced/async.html#interrupting-async-operations
* Breaking changes to parameterization
A few parameterization patterns that worked with psycopg2 no longer
work with psycopg3. They are detailed on the migration guide linked
above, but these in particular should be highlighted:
** You can no longer use `IN %s` with a tuple
This would work with psycopg2 but will not work with psycopg3:
`conn.execute("SELECT * FROM foo WHERE id IN %s", parameters=[(10,20,30)])`
Instead, this format is advised:
`conn.execute("SELECT * FROM foo WHERE id = ANY(%s)", parameters=[[10,20,30]])`
** You can no longer use `IS %s`
This would work with psycopg2 but will not work with psycopg3:
`conn.execute("SELECT * FROM foo WHERE field IS %s", [None])`
Instead, `IS NOT DISTINCT FROM %s` should be used
`conn.execute("SELECT * FROM foo WHERE field IS NOT DISTINCT FROM %s", [None])`
* Breaking changes to psycopg2 `copy` methods
`copy` methods are refactored and consolidated in psycopg3. See the
migration guide for details.1 parent 9da2ebc commit ecdb963
File tree
3 files changed
+11
-9
lines changed- parsons/databases/redshift
3 files changed
+11
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
128 | 127 | | |
129 | 128 | | |
130 | 129 | | |
131 | | - | |
| 130 | + | |
132 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
133 | 135 | | |
134 | | - | |
135 | | - | |
| 136 | + | |
| 137 | + | |
136 | 138 | | |
137 | 139 | | |
138 | 140 | | |
| |||
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
152 | | - | |
| 154 | + | |
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
| 47 | + | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
0 commit comments