On Thu, 10 Aug 2023 at 14:44, Pavel Stehule <pavel.stehule@gmail.com> wrote: > čt 10. 8. 2023 v 14:05 odesílatel Jelte Fennema <postgres@jeltef.nl> napsal: >> That it is not rolled-back >> in a case like this? >> >> BEGIN; >> \set PROMPT '%N' >> ROLLBACK; > > > surely not. > > \set is client side setting, and it is not transactional. Attention - "\set" and "set" commands are absolutely different creatures.
To clarify: I agree it's the desired behavior that \set is not rolled back.
> It Would be strange (can be very messy) if I had a message like "cannot set a prompt, because you should do ROLLBACK first"
This was a very helpful sentence for my understanding. To double check that I'm understanding you correctly. This is the kind of case that you're talking about.
postgres=# BEGIN; postgres=# SELECT some syntax error; ERROR: 42601: syntax error at or near "some" postgres=# \set PROMPT '%N' ERROR: 25P02: current transaction is aborted, commands ignored until end of transaction block
yes
I agree that it should not throw an error like that. So indeed a dedicated message type is needed for psql too. Because any query will cause that error.
But afaict there's no problem with using pqParseInput3() and PQexecFinish() even if the message isn't handled as part of the transaction. Some other messages that pqParseInput3 handles which are not part of the transaction are 'N' (Notice) and 'K' (secret key).