Does PostgreSQL ever retry failed transactions internally? I am writing an application in Python and PostgreSQL (using psycopg2) and in one section we are using the following pattern.

As separate python commands which I assume translates to separate calls to PostgreSQL

1) BEGIN

2) create temporary table AAA as select ... from ...

3) create temporary table BBB as select ... from AAA

4) create temporary table CCC as select ... from BBB

5) insert into YYY select ... from CCC

6) END

At no point do we ever read any data back from the transaction making it a blind write.
If this series of statements would cause a conflict with another transaction and fail would PostgreSQL restart it internally or would that revert to me the same as if I was mixing in select statements into the above code.

Would it make a difference if I converted all the temporary statements to common table expressions using the "with" construct? From the perspective of needing to do manual transaction restarts that is.

At what point if ever does PostgreSQL ever restart transactions internally, does multiple statements like that work? Will it work for a single statement as with "with"? Will it never work?

ps. I can not release the full code as it apart from being several pages long is the property of my employer.
AFAIK PostgreSQL does not retry failed transaction. Even if this would be the case you can never be 100% sure your transaction will succeed: coding your application with any DBMS assuming transaction will never fail in the database would be wrong.

the proof is in the pudding

I know that other database may in some very special cases retry statement (not transaction): for example Oracle see https://asktom.oracle.com/pls/asktom/f?p=100:11:0%3a%3a%3a%3aP11_QUESTION_ID:11504247549852#3950826900346316085.