postgresql

ProgrammingError: can't adapt type 'set'

≡放荡痞女 提交于 2021-02-07 14:50:29
问题 I am importing Excel data into postgreSQL using Python and running into an Programming Error. I did research the issue and found out it has something to do with postgreSQL. Can someone please provide assistance. import psycopg2 import xlrd book = xlrd.open_workbook("T:\data.xlsx") sheet = book.sheet_by_name("HCSData") database = psycopg2.connect (database = "", user="") cursor = database.cursor() delete = """Drop table if exists "Python".hcsdata""" print (delete) mydata = cursor.execute

How to get the result of SELECT statement inside a transaction?

£可爱£侵袭症+ 提交于 2021-02-07 14:25:17
问题 I can't get information of that simple question over the PostgreSQL documentation, over the Web or even here on StackOverflow... I must not unsertand something essential here. I am making a simple SELECT / UPDATE transaction in PostgreSQL: START TRANSACTION; SELECT "column" FROM "table" WHERE "criterion" = 'value' AND "activated" = true; UPDATE "table" SET "activated" = false WHERE "criterion" = 'value'; COMMIT Basically, I need to get the value of a column when its activated state is true

How to get the result of SELECT statement inside a transaction?

爱⌒轻易说出口 提交于 2021-02-07 14:23:57
问题 I can't get information of that simple question over the PostgreSQL documentation, over the Web or even here on StackOverflow... I must not unsertand something essential here. I am making a simple SELECT / UPDATE transaction in PostgreSQL: START TRANSACTION; SELECT "column" FROM "table" WHERE "criterion" = 'value' AND "activated" = true; UPDATE "table" SET "activated" = false WHERE "criterion" = 'value'; COMMIT Basically, I need to get the value of a column when its activated state is true

Jooq batch record insert

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-07 14:18:27
问题 I'm currently trying to insert in batch many records (~2000) and Jooq's batchInsert is not doing what I want. I'm transforming POJOs into UpdatableRecords and then I'm performing batchInsert which is executing insert for each record. So Jooq is doing ~2000 queries for each batch insert and it's killing database performance. It's executing this code (jooq's batch insert): for (int i = 0; i < records.length; i++) { Configuration previous = ((AttachableInternal) records[i]).configuration(); try

How to set '5 day' (datetime interval) in jdbc for PostgreSQL?

自闭症网瘾萝莉.ら 提交于 2021-02-07 14:18:22
问题 Considering the following example select * from foo where time +'10 day' >current_timestamp I would like to make this query parametrized for Java, and I don't know how to set the 10 day ?! (String doesn't work) 回答1: select * from foo where time +'10 day'::interval >current_timestamp; 回答2: You may either pass a String parameter and cast it, e.g. select * from foo where (time + CAST(? AS interval)) > current_timestamp or pass an int parameter multiplied by a fixed interval, which is better if

How can I quote a named argument passed in to psql?

牧云@^-^@ 提交于 2021-02-07 13:54:19
问题 psql has a construct for passing named arguments: psql -v name='value' which can then be referenced inside a script: SELECT :name; which will give the result ?column? ---------- value (1 row) During development, I need to drop and recreate copies of the database fairly frequently, so I'm trying to automate the process. So I need to run a query that forcibly disconnects all users and then drops the database. But the database this operates on will vary, so the database name needs to be an

postgresql ON CONFLICT with multiple constraints

拜拜、爱过 提交于 2021-02-07 13:40:57
问题 There is a constraint violation handling "On conflict" statement, working fine if i want to check 1 (!) constraint For example : INSERT INTO my_table (co1,col2..colN) VALUES (...) ON CONFLICT (col1, col2) DO NOTHING --or update But if i have 2 constaints unique(col1,col2) and unique(col5,col6,col7) , the query below is not working : INSERT INTO my_table (co1,col2..colN) VALUES (...) ON CONFLICT (col1, col2) DO NOTHING --or update ON CONFLICT (col5, col6, col7) DO NOTHING --or update This

postgresql ON CONFLICT with multiple constraints

↘锁芯ラ 提交于 2021-02-07 13:40:40
问题 There is a constraint violation handling "On conflict" statement, working fine if i want to check 1 (!) constraint For example : INSERT INTO my_table (co1,col2..colN) VALUES (...) ON CONFLICT (col1, col2) DO NOTHING --or update But if i have 2 constaints unique(col1,col2) and unique(col5,col6,col7) , the query below is not working : INSERT INTO my_table (co1,col2..colN) VALUES (...) ON CONFLICT (col1, col2) DO NOTHING --or update ON CONFLICT (col5, col6, col7) DO NOTHING --or update This

Why is this Django (1.6) annotate count so slow?

萝らか妹 提交于 2021-02-07 13:31:49
问题 Summary: I'm getting very slow queries using few queries and annotate vs. two queries extra per item when counting related objects. Database is PostgreSQL 9.3.5. I have a model that looks something like this: class Collection(models.Model): have = models.ManyToManyField(Item, related_name='item_have', through='Have') want = models.ManyToManyField(Item, related_name='item_want', through='Want') added = models.DateTimeField() class Meta: ordering = ['-last_bump'] class Have(models.Model): item

Why is this Django (1.6) annotate count so slow?

 ̄綄美尐妖づ 提交于 2021-02-07 13:30:29
问题 Summary: I'm getting very slow queries using few queries and annotate vs. two queries extra per item when counting related objects. Database is PostgreSQL 9.3.5. I have a model that looks something like this: class Collection(models.Model): have = models.ManyToManyField(Item, related_name='item_have', through='Have') want = models.ManyToManyField(Item, related_name='item_want', through='Want') added = models.DateTimeField() class Meta: ordering = ['-last_bump'] class Have(models.Model): item