psycopg2

how to get user input from qdateEdit and select it from database in postgres

夙愿已清 提交于 2021-02-17 04:00:32
问题 i want to know how to get the user input in QDateEdit and select it in a table in postgres? here is my code def date(self): try: date = self.dateEdit.date() print(date) conn = psycopg2.connect(dbname="sample", user="postgres", password="admin", host="localhost", port="5432") cur = conn.cursor() cur.execute("SELECT * FROM data WHERE stdate = '%s'",date) result = cur.fetchall() self.tableWidget.setRowCount(0) for row_number, row_data in enumerate(result): self.tableWidget.insertRow(row_number)

How to read and insert bytea columns using psycopg2?

[亡魂溺海] 提交于 2021-02-16 16:17:04
问题 I am working on a Python script to replicate some Postgresql tables from one environment to another (which does a little more than pg_dump ). It works except when I am copying a table that has bytea data type. I read the source table data in memory, then I dump the memory in the target database with concatenated inserts. Here is my method that produces an insert statement: def generateInsert(self, argCachedRow): colOrd = 0; valClauseList = [] hasBinary = False for colData in argCachedRow:

Dokku Compilation Error - django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'

喜欢而已 提交于 2021-02-11 14:54:17
问题 I've been attempting to setup my built-up Django Instance as a Database Server. Had chosen DigitalOcean as my platform and had read that Dokku is a useful PaaS system that will enable better scalability for this API I'm trying to deploy. I have been at this problem for the last 3-4 days straight and really had gone through every potential means of solution I could have found online. Being more of a front-end developer, I'm pretty bad at this backend installation matter. At first I thought

TypeError: not all arguments converted during string formatting in psycopg2

十年热恋 提交于 2021-02-11 14:34:54
问题 When I run the below code with psycopg2: cur.execute( """INSERT INTO logmsg (msg_type, file, msg) VALUES %s;""", ["Error", str(file), str(sys.exc_info()[0])]) I get the following error: TypeError: not all arguments converted during string formatting Can someone help me with this? 回答1: VALUES needs a list of values enclosed in brackets: cur.execute( """INSERT INTO logmsg (msg_type, file, msg) VALUES (%s, %s, %s);""", ["Error", str(file), str(sys.exc_info()[0])]) Do not forget to commit the

Django Psycopg2 Error When Running Migrations in Testing

痞子三分冷 提交于 2021-02-11 12:31:27
问题 I developed a basic version of a Django app in SQLite3. Then, it came time to switch it to Postgres and put in production. When doing so, I noticed that I was able to create and run migrations for the new database. However, when trying to run tests for the Postgres version, I run into an issue. Here it is. I run tests with coverage run --source='.' manage.py test ; however, the same thing happens when running via python manage.py test Creating test database for alias 'default'... Got an error

Python psycopg2 cursor.fetchall() returns empty list but cursor.rowcount is > 1

早过忘川 提交于 2021-02-09 07:20:51
问题 I am getting an issue here: conn = psycopg2.connect(conn_string) cursor = conn.cursor() sql = """ SELECT DISTINCT (tenor_years) FROM bond_pnl WHERE country = '%s' """ % country cursor.execute(sql) print(cursor.fetchall()) print(cursor.rowcount) It gives the following output: [] 11 which means that cursor.rowcount is 11 but cursor.fetchall() is empty list. I have already tried doing this: conn.set_session(readonly=True, autocommit=True) and this solution as well :Click to see Any help

Python psycopg2 cursor.fetchall() returns empty list but cursor.rowcount is > 1

蹲街弑〆低调 提交于 2021-02-09 07:19:25
问题 I am getting an issue here: conn = psycopg2.connect(conn_string) cursor = conn.cursor() sql = """ SELECT DISTINCT (tenor_years) FROM bond_pnl WHERE country = '%s' """ % country cursor.execute(sql) print(cursor.fetchall()) print(cursor.rowcount) It gives the following output: [] 11 which means that cursor.rowcount is 11 but cursor.fetchall() is empty list. I have already tried doing this: conn.set_session(readonly=True, autocommit=True) and this solution as well :Click to see Any help

To drop an index with psycopg2 takes effect before or after commit?

浪子不回头ぞ 提交于 2021-02-08 20:54:14
问题 I'm doing a python script to insert several data into a postgresql database. Following the postgresql documentation in order to speed up the load process my script has this sort of structure Connect to the database and create a cursor Drop all the indexes Load all the data using the 'copy' command Recreate back all the indexes Commit and close of the cursor and connection (only commit in the whole script) So my question is: Is dropping the indexes before the commit, taking any effect in terms

No module named psycopg2

安稳与你 提交于 2021-02-08 15:23:41
问题 I have Django project which uses postgresql 9. I installed psycopg2 and when I run project I receive 'Error loading psycopg2 module: dll load failed'. I met this issue for the first time. I have windows 7 x64 with python2.7. How can I solve this one? 回答1: I had the same problem, it was that psycopg2 does not install well in Windows with _easy_install_, I followed the instructions on the follow SO answer: Installing psycopg2 (postgresql) in virtualenv on windows You need to manually install

How to use psycopg2 to retrieve a certain key's value from a postgres table which has key-value pairs

…衆ロ難τιáo~ 提交于 2021-02-08 10:01:59
问题 New to python, trying to use psycopg2 to read Postgres I am reading from a database table called deployment and trying to handle a Value from a table with three fields id, Key and Value import psycopg2 conn = psycopg2.connect(host="localhost",database=database, user=user, password=password) cur = conn.cursor() cur.execute("SELECT \"Value\" FROM deployment WHERE (\"Key\" = 'DUMPLOCATION')") records = cur.fetchall() print(json.dumps(records)) [["newdrive"]] I want this to be just "newdrive" so