psycopg2

What is the proper formatting for a jsonb array in Python for Postgres?

吃可爱长大的小学妹 提交于 2020-07-09 07:19:25
问题 I have a schema that looks like Column | Type | ------------------------------------------------------- message_id | integer | user_id | integer | body | text | created_at | timestamp without time zone | source | jsonb | symbols | jsonb[] | I am trying to use psycopg2 to insert data via psycopg2.Cursor.copy_from() but I am getting numerous issues trying to figure out how a jsonb[] object should be formatted. When I do a straight list of JSON objects, I get an error that looks like psycopg2

What is the proper formatting for a jsonb array in Python for Postgres?

怎甘沉沦 提交于 2020-07-09 07:19:06
问题 I have a schema that looks like Column | Type | ------------------------------------------------------- message_id | integer | user_id | integer | body | text | created_at | timestamp without time zone | source | jsonb | symbols | jsonb[] | I am trying to use psycopg2 to insert data via psycopg2.Cursor.copy_from() but I am getting numerous issues trying to figure out how a jsonb[] object should be formatted. When I do a straight list of JSON objects, I get an error that looks like psycopg2

(Python) psycopg2 installation

大兔子大兔子 提交于 2020-07-04 01:49:08
问题 I have a fairly light amount of experience with Python and got stuck on what should be a pretty simple issue. I am using Jupyter Notebook on a Mac. I wanted to install psycopg2 in Python so I typed in import psycopg2 as pg2 But, I got the following error: ModuleNotFoundError Traceback (most recent call last) <ipython-input-1-32fa0c891bdd> in <module> ----> 1 import psycopg2 as pg2 ModuleNotFoundError: No module named 'psycopg2' I then went over to the terminal and typed in: pip install

(Python) psycopg2 installation

时间秒杀一切 提交于 2020-07-04 01:49:05
问题 I have a fairly light amount of experience with Python and got stuck on what should be a pretty simple issue. I am using Jupyter Notebook on a Mac. I wanted to install psycopg2 in Python so I typed in import psycopg2 as pg2 But, I got the following error: ModuleNotFoundError Traceback (most recent call last) <ipython-input-1-32fa0c891bdd> in <module> ----> 1 import psycopg2 as pg2 ModuleNotFoundError: No module named 'psycopg2' I then went over to the terminal and typed in: pip install

Retreiving original notice text from PostgreSQL

橙三吉。 提交于 2020-06-26 05:23:52
问题 I'm using PL/pgSQL trying to emulate what I can do in Oracle PL/SQL with dbms_output as an equivalent to stdout. I have read that RAISE NOTICE is probably the best way to handle this. However my problem is when I retrieve the text from psycopg2 notices object I get the extra NOTICE: prefix and an extra linefeed. I know I can just remove the problem characters from the string, however it seems a little clunky, and it's annoying me that I can't work out how to retrieve the original text. Is it

Could not translate host name “db” to address using Postgres, Docker Compose and Psycopg2

限于喜欢 提交于 2020-06-24 06:13:18
问题 In one folder I have 3 files: base.py, Dockerfile and docker-compose.yml. base.py: import psycopg2 conn = psycopg2.connect("dbname='base123' user='postgres' host='db' password='pw1234'") Dockerfile: FROM ubuntu:16.04 RUN apt-get update RUN apt-get -y install python-pip RUN apt-get update RUN pip install --upgrade pip RUN pip install psycopg2-binary COPY base.py base.py RUN python base.py docker-compose.yml: version: '3' services: db: image: 'postgres:latest' expose: - "5432" environment:

Could not translate host name “db” to address using Postgres, Docker Compose and Psycopg2

ぃ、小莉子 提交于 2020-06-24 06:13:14
问题 In one folder I have 3 files: base.py, Dockerfile and docker-compose.yml. base.py: import psycopg2 conn = psycopg2.connect("dbname='base123' user='postgres' host='db' password='pw1234'") Dockerfile: FROM ubuntu:16.04 RUN apt-get update RUN apt-get -y install python-pip RUN apt-get update RUN pip install --upgrade pip RUN pip install psycopg2-binary COPY base.py base.py RUN python base.py docker-compose.yml: version: '3' services: db: image: 'postgres:latest' expose: - "5432" environment:

psycopg2 - Unkeyed Connection

谁说胖子不能爱 提交于 2020-06-17 03:08:09
问题 I'm trying to concurrently insert items into a postgres table via ThreadedConnectionPool , but I keep getting psycopg2.pool.PoolError: trying to put unkeyed connection - not sure why this is happening. I've tried running it sequentially also but still getting the same error. Essentially the code scrapes a website's sitemap for products and inserts the scraped items into a database. Code: class items: def __init__(self): self.conn = ThreadedConnectionPool(10, 100, dbname='postgres', user='xxx'

How to save results of postgresql to csv/excel file using psycopg2?

我的梦境 提交于 2020-05-24 20:01:09
问题 I use driving_distance in postgresql to find distances between all nodes, and here's my python script in pyscripter, import sys #set up psycopg2 environment import psycopg2 #driving_distance module query = """ select * from driving_distance ($$ select gid as id, start_id::int4 as source, end_id::int4 as target, shape_leng::double precision as cost from network $$, %s, %s, %s, %s ) ;""" #make connection between python and postgresql conn = psycopg2.connect("dbname = 'routing_template' user =

How to save results of postgresql to csv/excel file using psycopg2?

我与影子孤独终老i 提交于 2020-05-24 20:00:48
问题 I use driving_distance in postgresql to find distances between all nodes, and here's my python script in pyscripter, import sys #set up psycopg2 environment import psycopg2 #driving_distance module query = """ select * from driving_distance ($$ select gid as id, start_id::int4 as source, end_id::int4 as target, shape_leng::double precision as cost from network $$, %s, %s, %s, %s ) ;""" #make connection between python and postgresql conn = psycopg2.connect("dbname = 'routing_template' user =