psycopg2

Error Connecting To PostgreSQL can't pickle psycopg2.extensions.connection objects

こ雲淡風輕ζ 提交于 2020-05-17 09:05:26
问题 I am trying to create an architecture that will have a main parent process & it can create new child processes. The main parent process will always be on loop to check if there is any child process available. I have used ThreadedConnectionPool of psycopg2.pool module in order to have a common database connection for all child processes created. That means the program will be connecting once to the database and execute all the SQL queries for each of the child processes. So there is no need to

PostgreSQL psycopg2 Python3.7.4 UnicodeDecodeError: 'ascii' codec can't decode byte

吃可爱长大的小学妹 提交于 2020-05-17 05:54:12
问题 I'm trying to query from a PostgreSQL database with ANSI drivers but for some queries it fails, giving me the following error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xfd in position 10: ordinal not in range(128) Here is the function to set the connection and query: import psycopg2 import pandas as pd def query_cdk_database(query): conn = psycopg2.connect(host="some_host", port = xxx, database="xxx", user="xxxx", password="xxx", client_encoding ='auto') cur = conn.cursor() cur

PostgreSQL psycopg2 Python3.7.4 UnicodeDecodeError: 'ascii' codec can't decode byte

拥有回忆 提交于 2020-05-17 05:53:36
问题 I'm trying to query from a PostgreSQL database with ANSI drivers but for some queries it fails, giving me the following error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xfd in position 10: ordinal not in range(128) Here is the function to set the connection and query: import psycopg2 import pandas as pd def query_cdk_database(query): conn = psycopg2.connect(host="some_host", port = xxx, database="xxx", user="xxxx", password="xxx", client_encoding ='auto') cur = conn.cursor() cur

psycopg2 ImportError: undefined symbol: PQconninfo

筅森魡賤 提交于 2020-05-15 04:58:48
问题 Couldn't able to import psycopg2 Output in python console: import psycopg2 Traceback (most recent call last): File "", line 1, in File "/home/user/.py_virtualenvs/verb_py3/lib/python3.5/site-packages/psycopg2/ init .py", line 50, in from psycopg2._psycopg import ( # noqa ImportError: /home/user/.py_virtualenvs/verb_py3/lib/python3.5/site-packages/psycopg2/_psycopg.cpython-35m-x86_64-linux-gnu.so: undefined symbol: PQconninfo 回答1: Installed the psycopg2-binary package solved my issue. pip

Postgres psycopg2 create user

那年仲夏 提交于 2020-05-14 05:32:01
问题 To create a user through psycopg2, I am using the following code : cur=conn.cursor() cur.execute("create user %s with password %s",('abcdefgh','0h/9warrAttrgd8EF0gkvQ==',)) This gives the following error : syntax error at or near "'abcdefgh'" LINE 1: create user 'abcdefgh' with password '0h/9warrAttrgd8EF0gkvQ. It seems that %s is placing quotes around the username, which postgres doesn't like while creating a user. The following code works fine : cur.execute("create user abcdefgh with

Postgres psycopg2 create user

一曲冷凌霜 提交于 2020-05-14 05:28:07
问题 To create a user through psycopg2, I am using the following code : cur=conn.cursor() cur.execute("create user %s with password %s",('abcdefgh','0h/9warrAttrgd8EF0gkvQ==',)) This gives the following error : syntax error at or near "'abcdefgh'" LINE 1: create user 'abcdefgh' with password '0h/9warrAttrgd8EF0gkvQ. It seems that %s is placing quotes around the username, which postgres doesn't like while creating a user. The following code works fine : cur.execute("create user abcdefgh with

Fetching data from postgres database in batch (python)

ⅰ亾dé卋堺 提交于 2020-04-30 11:46:45
问题 I have the following Postgres query where I am fetching data from table1 with rows ~25 million and would like to write the output of the below query into multiple files. query = """ WITH sequence AS ( SELECT a, b, c FROM table1 ) select * from sequence;""" Below is the python script to fetch the complete dataset. How can I modify the script to fetch it to multiple files (eg. each file has 10000 rows) #IMPORT LIBRARIES ######################## import psycopg2 from pandas import DataFrame

Fetching data from postgres database in batch (python)

◇◆丶佛笑我妖孽 提交于 2020-04-30 11:45:34
问题 I have the following Postgres query where I am fetching data from table1 with rows ~25 million and would like to write the output of the below query into multiple files. query = """ WITH sequence AS ( SELECT a, b, c FROM table1 ) select * from sequence;""" Below is the python script to fetch the complete dataset. How can I modify the script to fetch it to multiple files (eg. each file has 10000 rows) #IMPORT LIBRARIES ######################## import psycopg2 from pandas import DataFrame

Multiprocessing result of a psycopg2 request. “Can't pickle psycopg2.extensions.connection objects”

房东的猫 提交于 2020-04-17 19:25:46
问题 I'm currently trying to use multiprocessing to process a big result obtained after a psycopg2 query. I split the result in several lists of 100 then send them for multiprocessing. When I do so though, I get the following error TypeError: can't pickle psycopg2.extensions.connection objects Here is my psycopg2 query: def get_employees(self): logging.info('POSTGRESQL QUERY: get_employees') try: self.cur = self.conn.cursor(cursor_factory=RealDictCursor) self.cur.execute( "SELECT ..." ) employees

SqlAlchemy: getting the id of the last record inserted

蹲街弑〆低调 提交于 2020-04-07 17:39:29
问题 I am using SQLAlchemy without the ORM, i.e. using hand crafted SQL statememts to directly interact with the backend db. I am using PG as my backend db (psycopg2 as DB driver) in this instance - I don't know if that affects the answer. I have statements like this (for brevity, assume that conn is a valid connection to the db): conn.execute("INSERT INTO user (name, country_id) VALUES ('Homer', 123)") Assume also that the user table consists of the columns (id [SERIAL PRIMARY KEY], name, country