Use psycopg2 to create connectionless requests

I have several cases where I want to collect data in a field. This happens in situations where I do not always have access to my postgres database.

To keep things in sync, it would be great if I could use psycopg2 functions offline to generate queries that could be contained, and as soon as I could connect to the database; handle everything that is held back.

One thing that I am facing right now is that the psycopg2 cursor requires a connection to be created.

My question is:

Is there a way to use the cursor to perform actions like mogrify without an active connection object? Or a connection object that is not connected to a database? Then I would like to temporarily write mogrify results so that they can be processed later.

+3
source share
2 answers

It seems to be easier and more universal to store data that will be added later to another structure. Perhaps the csv file. Then, when you connect, you can go through this table, but you can also easily do other things with this CSV, if necessary.

0
source

This would be a fragile approach, since the connection is used to detect some parameters used for escaping (encoding, standard string, etc.).

" mogrify" psycopg2.extensions.adapt(x).getquoted() , Python %.

psycopg ( 2.3.2) NoneNULL. , None: , .

+7

Source: https://habr.com/ru/post/1789596/


All Articles