postgresql

PostgreSQL TypeError: not all arguments converted during string formatting

淺唱寂寞╮ 提交于 2020-12-29 11:59:38
问题 I am executing a query in psycopg2 linked up to a PostgreSQL database. Here is the code in question: with open('dataFile.txt', 'r') as f: lines = f.readlines() newLines = [line[:-1] for line in lines] curr=conn.cursor() lineString = ','.join(newLines) curr.execute("SELECT fields.fieldkey FROM fields LEFT JOIN zone ON zone.fieldkey=fields.fieldkey WHERE zone.zonekey = %s;", (newLines[0])) rows = curr.fetchall() There's no issue connecting to the DB, and the type of lines[0] is definitely

Import Postgres data into RDS using S3 and aws_s3

ⅰ亾dé卋堺 提交于 2020-12-29 10:54:29
问题 I'm having a hard time importing data from S3 into an RDS postgres instance. According to the docs, you can use this syntax: aws_s3.table_import_from_s3 ( table_name text, column_list text, options text, bucket text, file_path text, region text, access_key text, secret_key text, session_token text ) So, in pgAdmin, I did this: SELECT aws_s3.table_import_from_s3( 'contacts_1', 'firstname,lastname,imported', '(format csv)', 'com.foo.mybucket', 'mydir/subdir/myfile.csv', 'us-east-2',

Import Postgres data into RDS using S3 and aws_s3

孤街醉人 提交于 2020-12-29 10:53:26
问题 I'm having a hard time importing data from S3 into an RDS postgres instance. According to the docs, you can use this syntax: aws_s3.table_import_from_s3 ( table_name text, column_list text, options text, bucket text, file_path text, region text, access_key text, secret_key text, session_token text ) So, in pgAdmin, I did this: SELECT aws_s3.table_import_from_s3( 'contacts_1', 'firstname,lastname,imported', '(format csv)', 'com.foo.mybucket', 'mydir/subdir/myfile.csv', 'us-east-2',

Django ORM leaks connections when using ThreadPoolExecutor

女生的网名这么多〃 提交于 2020-12-29 10:44:46
问题 I'm using ThreadPoolExecutor to speed up data processing. The problem is that the thread pool creates new database connections and Django doesn't close them. I do have CONN_MAX_AGE in settings.py and I already tried to call django.db.close_old_connections() . Here is a code example: def compute(job): result = FooModel.objects.filter(...).aggregate(...) return BarModel.objects.create(result) def process(dataset): thread_pool = ThreadPoolExecutor(max_workers=20) futures = [] for job in dataset:

Querying Postgres 9.6 JSONB array of objects

丶灬走出姿态 提交于 2020-12-29 10:16:52
问题 I have the following table: CREATE TABLE trip ( id SERIAL PRIMARY KEY , gps_data_json jsonb NOT NULL ); The JSON in gps_data_json contains an array of of trip objects with the following fields (sample data below): mode timestamp latitude longitude I'm trying to get all rows that contain a certain "mode". SELECT * FROM trip where gps_data_json ->> 'mode' = 'WALK'; I pretty sure I'm using the ->> operator wrong, but I'm unsure who to tell the query that the JSONB field is an array of objects?

Querying Postgres 9.6 JSONB array of objects

ぃ、小莉子 提交于 2020-12-29 10:15:13
问题 I have the following table: CREATE TABLE trip ( id SERIAL PRIMARY KEY , gps_data_json jsonb NOT NULL ); The JSON in gps_data_json contains an array of of trip objects with the following fields (sample data below): mode timestamp latitude longitude I'm trying to get all rows that contain a certain "mode". SELECT * FROM trip where gps_data_json ->> 'mode' = 'WALK'; I pretty sure I'm using the ->> operator wrong, but I'm unsure who to tell the query that the JSONB field is an array of objects?

Querying Postgres 9.6 JSONB array of objects

ぃ、小莉子 提交于 2020-12-29 10:14:50
问题 I have the following table: CREATE TABLE trip ( id SERIAL PRIMARY KEY , gps_data_json jsonb NOT NULL ); The JSON in gps_data_json contains an array of of trip objects with the following fields (sample data below): mode timestamp latitude longitude I'm trying to get all rows that contain a certain "mode". SELECT * FROM trip where gps_data_json ->> 'mode' = 'WALK'; I pretty sure I'm using the ->> operator wrong, but I'm unsure who to tell the query that the JSONB field is an array of objects?

Querying Postgres 9.6 JSONB array of objects

限于喜欢 提交于 2020-12-29 10:14:35
问题 I have the following table: CREATE TABLE trip ( id SERIAL PRIMARY KEY , gps_data_json jsonb NOT NULL ); The JSON in gps_data_json contains an array of of trip objects with the following fields (sample data below): mode timestamp latitude longitude I'm trying to get all rows that contain a certain "mode". SELECT * FROM trip where gps_data_json ->> 'mode' = 'WALK'; I pretty sure I'm using the ->> operator wrong, but I'm unsure who to tell the query that the JSONB field is an array of objects?

Querying Postgres 9.6 JSONB array of objects

寵の児 提交于 2020-12-29 10:14:20
问题 I have the following table: CREATE TABLE trip ( id SERIAL PRIMARY KEY , gps_data_json jsonb NOT NULL ); The JSON in gps_data_json contains an array of of trip objects with the following fields (sample data below): mode timestamp latitude longitude I'm trying to get all rows that contain a certain "mode". SELECT * FROM trip where gps_data_json ->> 'mode' = 'WALK'; I pretty sure I'm using the ->> operator wrong, but I'm unsure who to tell the query that the JSONB field is an array of objects?

Add plpython3 Extension to Postgres/timescaledb Alpine Docker Image

十年热恋 提交于 2020-12-29 09:57:47
问题 I try to add the plpython3 extension to my timescaledb / postgres (based on linux alpine) image: FROM timescale/timescaledb:0.9.0-pg10 RUN set -ex \ && apk add --no-cache --virtual .plpython3-deps --repository http://nl.alpinelinux.org/alpine/edge/testing \ postgresql-plpython3 When I try to create the extension I get the following error: postgres=# CREATE EXTENSION plpython3u; ERROR: could not open extension control file "/usr/local/share/postgresql/extension/plpython3u.control": No such