psycopg2

Why PostgreSQL adapter psycopg2 fail in Google App Engine dev_appserver.py?

坚强是说给别人听的谎言 提交于 2020-01-11 11:58:54
问题 I want connect my app that are in GAE with ElephantDB. I want use the lib psycopg2 and I found a problem. I installed the lib in local to test it and work perfectly and then I installed the lib in lib folder on my app as I have done many times with other libs. This time with pip install -t appname/lib/ psycopg2 So, dev server dectect the lib, but say me that : ImportError: No module named psycopg2._psycopg At first I thought that the problem was python version that dev_server was executing,

use try/except with psycopg2 or “with closing”?

為{幸葍}努か 提交于 2020-01-10 22:30:06
问题 I'm using Psycopg2 in Python to access a PostgreSQL database. I'm curious if it's safe to use the with closing() pattern to create and use a cursor, or if I should use an explicit try/except wrapped around the query. My question is concerning inserting or updating, and transactions. As I understand it, all Psycopg2 queries occur within a transaction, and it's up to calling code to commit or rollback the transaction. If within a with closing(... block an error occurs, is a rollback issued? In

getting ids of multiple rows inserted in psycopg2

懵懂的女人 提交于 2020-01-10 05:16:25
问题 I'd like to use psycopg2 to INSERT multiple rows and then return all the id s (in order) using a single query. This is what PostgreSQL's RETURNING extension is designed for, and it seems to work fine using cursor.execute : cursor.execute( "INSERT INTO my_table (field_1, field_2) " "VALUES (0, 0), (0, 0) RETURNING id;" ) print cursor.fetchall() [(1,), (2,)] Now, in order to pass in dynamically-generated data, it seems like cursor.executemany is the way to go: data = [(0, 0), (0, 0)] cursor

Psycopg2 Python SSL Support is not compiled in

孤街醉人 提交于 2020-01-10 01:01:30
问题 I am trying to connect to my postgres database using psycopg2 with sslmode='required' param; however, I get the following error psycopg2.OperationalError: sslmode value "require" invalid when SSL support is not compiled in Heres a couple details about my system Mac OS X El Capitan Python 2.7 Installed psycopg2 via pip Installed python via homebrew Here is what I tried to do to fix the problem brew uninstall python which python still shows python living in /usr/local/bin/python , tried to

Marshmallow result customization

大憨熊 提交于 2020-01-06 11:17:28
问题 I have the sqlalchemy model with jsonb field and marshmallow schema for this model: class Settings(db.Model): id = db.Column(UUID, primary_key=True, server_default=text("uuid_generate_v4()")) settings = db.Column(JSONB) class SettingsSchema(ma.ModelSchema): class Meta: model = Settings I'm serializing it in json like: settings = Settings(settings={'qwerty': 'test'}) settings_schema = SettingsSchema(many=False, exclude=('id', )) body = settings_schema.dump(settings).data and json view of the

Pandas - Error inserting text column into Redshift table

痞子三分冷 提交于 2020-01-06 06:41:40
问题 I am trying to insert a text column of into a Redshift DB. I get an error DataError: value too long for type character varying(256) Given below is the code I tried. The description column has text and the length goes upto 2000 characters. Could anyone assist on how I could have this column inserted into the table. DF['description'] = DF['description'].str[:200].astype(str) Could anyone assist, thanks. 回答1: You should be using str.slice . df['description'] = df['description'].str.slice(0,255)

Pandas - Error inserting text column into Redshift table

六眼飞鱼酱① 提交于 2020-01-06 06:41:14
问题 I am trying to insert a text column of into a Redshift DB. I get an error DataError: value too long for type character varying(256) Given below is the code I tried. The description column has text and the length goes upto 2000 characters. Could anyone assist on how I could have this column inserted into the table. DF['description'] = DF['description'].str[:200].astype(str) Could anyone assist, thanks. 回答1: You should be using str.slice . df['description'] = df['description'].str.slice(0,255)

Error when create database from pgadmin4

前提是你 提交于 2020-01-06 05:14:47
问题 When I create database from pgadmin 4, it always show error popup: Error saving properties. My computer info: Linux Mint 18.3 pgAdmin 4 2.1 from https://wiki.postgresql.org/wiki/Apt Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] My error in pgadmin4.log: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 180, in run_wsgi execute(self.server.app) File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 168, in execute

Psycopg2 - copy_expert permission denied error

独自空忆成欢 提交于 2020-01-05 13:17:09
问题 I'm attempting to make the switch from Windows to ubuntu (am using 12.04 LTS) and am trying to use some of my old scripts to run my old databases. Previously I used postgresql and psycopg2 to maintain them and I am trying to do so again here. My error is around importing a csv file to a table using the copy expert command. Code is as follows: #!/usr/bin/env python import psycopg2 as psy import sys conn = psy.connect("dbname, user, host, password") # with the appropriate values curs = conn

connecting to amazon rds with psycopg2 via lambda

点点圈 提交于 2020-01-05 09:26:33
问题 my code on aws lambda: import sys, boto3, logging, rds_config, psycopg2 rds_host = "hostname" name = rds_config.db_username password = rds_config.db_password db_name = rds_config.db_name s3 = boto3.resource('s3') rds_client = boto3.client('rds',aws_access_key_id=Access_Key,aws_secret_access_key=Secret_Access_Key) instances = rds_client.describe_db_instances() print (instances) try: conn = psycopg2.connect(host=rds_host, database=db_name, user=name, password=password) cur = conn.cursor()