postgresql

Postgresql 9.4 query gets progressively slower when joining TSTZRANGE with &&

感情迁移 提交于 2021-02-07 12:19:45
问题 I am running a query that gets progressively slower as records are added. Records are added continuously via an automated process (bash calling psql). I would like to correct this bottle neck; however, I don't know what my best option is. This is the output from pgBadger: Hour Count Duration Avg duration 00 9,990 10m3s 60ms <---ignore this hour 02 1 60ms 60ms <---ignore this hour 03 4,638 1m54s 24ms <---queries begin with table empty 04 30,991 55m49s 108ms <---first full hour of queries

How to select integer values only from a varchar column in PostgreSQL

徘徊边缘 提交于 2021-02-07 12:17:30
问题 How to select integer values only from a varchar column in PostgreSQL? If the column contains: abc 70 3g 71 1.5 I'd like to select only: 70 71 I'm struggling to find functions like: is_numeric, is_integer, to do something like this: SELECT column FROM table WHERE isinteger(column) Any ideas? Thank you. 回答1: SELECT column FROM table WHERE column ~ '^\d+$' 来源: https://stackoverflow.com/questions/15163793/how-to-select-integer-values-only-from-a-varchar-column-in-postgresql

How to select integer values only from a varchar column in PostgreSQL

孤者浪人 提交于 2021-02-07 12:15:28
问题 How to select integer values only from a varchar column in PostgreSQL? If the column contains: abc 70 3g 71 1.5 I'd like to select only: 70 71 I'm struggling to find functions like: is_numeric, is_integer, to do something like this: SELECT column FROM table WHERE isinteger(column) Any ideas? Thank you. 回答1: SELECT column FROM table WHERE column ~ '^\d+$' 来源: https://stackoverflow.com/questions/15163793/how-to-select-integer-values-only-from-a-varchar-column-in-postgresql

db.create_all() 'NoneType' object has no attribute 'drivername'

a 夏天 提交于 2021-02-07 12:14:34
问题 I am following the CS50's Web Programming with Python and Javascript and in Lecture4 I have had the following error trying to create a postgresql database table: Traceback (most recent call last): File "create.py", line 19, in <module> main() File "create.py", line 15, in main db.create_all() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 963, in create_all self._execute_for_all_tables(app, bind, 'create_all') File "

db.create_all() 'NoneType' object has no attribute 'drivername'

别等时光非礼了梦想. 提交于 2021-02-07 12:14:26
问题 I am following the CS50's Web Programming with Python and Javascript and in Lecture4 I have had the following error trying to create a postgresql database table: Traceback (most recent call last): File "create.py", line 19, in <module> main() File "create.py", line 15, in main db.create_all() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 963, in create_all self._execute_for_all_tables(app, bind, 'create_all') File "

Setting constraint deferrable doesn't work on PostgreSQL transaction

喜你入骨 提交于 2021-02-07 11:31:47
问题 This is the situation: I have two tables where the one references the other (say, table2 references table1). When creating these tables, I did set the foreign key constraint as DEFERRABLE and the ON UPDATE and ON DELETE clauses as NO ACTION (which is the default). But still, when running the transaction below, I get the following error. Transaction: START TRANSACTION; SET CONSTRAINTS ALL DEFERRED; UPDATE table1 SET blah blah; UPDATE table2 SET blah blah; COMMIT; Error: ERROR: update or delete

PotgreSQL- ERROR: invalid byte sequence for encoding “UTF8”: 0xeb 0x6e 0x74

被刻印的时光 ゝ 提交于 2021-02-07 11:00:46
问题 I am working on PostgreSQL and getting below error during insert statement execution from batch script(command line). ERROR: invalid byte sequence for encoding "UTF8": 0xeb 0x6e 0x74 I have checked client_encoding by show client_encoding command and it is showing UTF-8. Also checked database properties by using command select * from pg_database where datname='<mydbName>' In Output : datcollate = English_United States.1252 datctype = English_United States.1252 How to resolve this issue? 回答1:

PotgreSQL- ERROR: invalid byte sequence for encoding “UTF8”: 0xeb 0x6e 0x74

允我心安 提交于 2021-02-07 11:00:31
问题 I am working on PostgreSQL and getting below error during insert statement execution from batch script(command line). ERROR: invalid byte sequence for encoding "UTF8": 0xeb 0x6e 0x74 I have checked client_encoding by show client_encoding command and it is showing UTF-8. Also checked database properties by using command select * from pg_database where datname='<mydbName>' In Output : datcollate = English_United States.1252 datctype = English_United States.1252 How to resolve this issue? 回答1:

Proper way to annotate a rank field for a queryset

折月煮酒 提交于 2021-02-07 10:22:25
问题 Assume models like this: class Person(models.Model): name = models.CharField(max_length=20) class Session(models.Model): start_time = models.TimeField(auto_now_add=True) end_time = models.TimeField(blank=True, null=True) person = models.ForeignKey(Person) class GameSession(models.Model): game_type = models.CharField(max_length=2) score = models.PositiveIntegerField(default=0, blank=True) session = models.ForeignKey(Session) I want to have a queryset function to return total score of each

Proper way to annotate a rank field for a queryset

[亡魂溺海] 提交于 2021-02-07 10:21:13
问题 Assume models like this: class Person(models.Model): name = models.CharField(max_length=20) class Session(models.Model): start_time = models.TimeField(auto_now_add=True) end_time = models.TimeField(blank=True, null=True) person = models.ForeignKey(Person) class GameSession(models.Model): game_type = models.CharField(max_length=2) score = models.PositiveIntegerField(default=0, blank=True) session = models.ForeignKey(Session) I want to have a queryset function to return total score of each