public inbox for [email protected]  
help / color / mirror / Atom feed
Re: Q: limit the length of log file entries?
2+ messages / 2 participants
[nested] [flat]

* Re: Q: limit the length of log file entries?
@ 2025-09-04 19:43  Albrecht Dreß <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Albrecht Dreß @ 2025-09-04 19:43 UTC (permalink / raw)
  To: Adrian Klaver <[email protected]>; +Cc: Tom Lane <[email protected]>; [email protected]

Am 04.09.25 20:21 schrieb(en) Adrian Klaver:
> > "Psycopg 3 sends the query and the parameters to the server separately, 
> > instead of merging them on the client side. Server-side binding works 
> > for normal SELECT and data manipulation statements (INSERT, UPDATE, 
> > DELETE), but it doesn’t work with many other statements. For instance, 
> > it doesn’t work with SET or with NOTIFY:"
> 
> As example:
> 
> import psycopg2
> import psycopg
> 
> conpsyc2 = psycopg2.connect("dbname=test user=postgres")
> conpsyc3 = psycopg.connect("dbname=test user=postgres")
> 
> cur2 = conpsyc2.cursor()
> cur3 = conpsyc3.cursor()
> 
> cur2.execute("select * from csv_test where id = %s", [1])
> cur3.execute("select * from csv_test where id = %s", [1])
> 
> yields:
> 
> --cur2
> 2025-09-04 11:17:30.246 PDT [29695] postgres@test LOG:  statement: BEGIN
> 2025-09-04 11:17:30.246 PDT [29695] postgres@test LOG:  statement: 
> select * from csv_test where id = 1
> 
> --cur3
> 2025-09-04 11:18:07.158 PDT [29703] postgres@test LOG:  statement: BEGIN
> 2025-09-04 11:18:07.159 PDT [29703] postgres@test LOG:  execute 
> <unnamed>: select * from csv_test where id = $1
> 2025-09-04 11:18:07.159 PDT [29703] postgres@test DETAIL:  Parameters: 
> $1 = '1'

Very nice example!  Looks as if the (anyway broken) script should be migrated to the the newer Python module – which, looking into the docs, shouldn't be too complex…

Thanks a lot for all your helpful insight,
Albrecht.

Attachments:

  [application/pgp-signature] openpgp-digital-signature.asc (488B, 2-openpgp-digital-signature.asc)
  download

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Q: limit the length of log file entries?
@ 2025-09-04 20:16  Adrian Klaver <[email protected]>
  parent: Albrecht Dreß <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Adrian Klaver @ 2025-09-04 20:16 UTC (permalink / raw)
  To: Albrecht Dreß <[email protected]>; +Cc: Tom Lane <[email protected]>; [email protected]

On 9/4/25 12:43, Albrecht Dreß wrote:
> Am 04.09.25 20:21 schrieb(en) Adrian Klaver:
>>> "Psycopg 3 sends the query and the parameters to the server separately,
>>> instead of merging them on the client side. Server-side binding works
>>> for normal SELECT and data manipulation statements (INSERT, UPDATE,
>>> DELETE), but it doesn’t work with many other statements. For instance,
>>> it doesn’t work with SET or with NOTIFY:"
>>
>> As example:
>>
>> import psycopg2
>> import psycopg
>>
>> conpsyc2 = psycopg2.connect("dbname=test user=postgres")
>> conpsyc3 = psycopg.connect("dbname=test user=postgres")
>>
>> cur2 = conpsyc2.cursor()
>> cur3 = conpsyc3.cursor()
>>
>> cur2.execute("select * from csv_test where id = %s", [1])
>> cur3.execute("select * from csv_test where id = %s", [1])
>>
>> yields:
>>
>> --cur2
>> 2025-09-04 11:17:30.246 PDT [29695] postgres@test LOG:  statement: BEGIN
>> 2025-09-04 11:17:30.246 PDT [29695] postgres@test LOG:  statement:
>> select * from csv_test where id = 1
>>
>> --cur3
>> 2025-09-04 11:18:07.158 PDT [29703] postgres@test LOG:  statement: BEGIN
>> 2025-09-04 11:18:07.159 PDT [29703] postgres@test LOG:  execute
>> <unnamed>: select * from csv_test where id = $1
>> 2025-09-04 11:18:07.159 PDT [29703] postgres@test DETAIL:  Parameters:
>> $1 = '1'
> 
> Very nice example!  Looks as if the (anyway broken) script should be migrated to the the newer Python module – which, looking into the docs, shouldn't be too complex…

Just be sure to read:

https://www.psycopg.org/psycopg3/docs/basic/from_pg2.html

Things that I had to deal with:

1) These:

https://www.psycopg.org/docs/extras.html#fast-execution-helpers

don't exist in psycopg(3).

Made up for, in my cases, because executemany() is faster in psycopg as 
it uses pipeline mode when libpq 14+ is available.

2) COPY is not file based, so it's usage has changed. The examples here:

https://www.psycopg.org/psycopg3/docs/basic/copy.html#copy

are clear and it was not that difficult to change over.

3) with connection has changed. It now closes the connection as well as 
the transaction.

FYI, you can use:

https://www.psycopg.org/psycopg3/docs/advanced/cursors.html#client-side-binding-cursors

to keep the old client side binding style of parameters to help migrate 
code over in stages.

> 
> Thanks a lot for all your helpful insight,
> Albrecht.


-- 
Adrian Klaver
[email protected]






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2025-09-04 20:16 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-09-04 19:43 Re: Q: limit the length of log file entries? Albrecht Dreß <[email protected]>
2025-09-04 20:16 ` Adrian Klaver <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox