SQL命令只适用于postgres中的一个表

时间:2016-03-21 06:37:33

标签: mysql django postgresql

SQL命令只适用于postgres中的一个表

我在使用 postgres 数据库的django项目中工作。

SQL查询适用于所有表,但不适用于common_designprofilecontent

工作

reader=# SELECT COUNT(*) FROM  common_document;
 count 
-------
 20046
(1 row)

无效

reader=# SELECT COUNT(*) FROM  common_designprofilecontent;

此查询没有结果,此表中至少存在20046 * 4行。

完成以下操作后:

reader=# select * from pg_stat_activity;

5:30 | 2016-03-21 10:22:27.240863+05:30 | 2016-03-21 10:22:28.614431+05:30 | t       | SELECT "common_designprofilecontent"."id", "common_designprofil
econtent"."page_id", "common_designprofilecontent"."doc_id", "common_designprofilecontent"."profilename", "common_designprofilecontent"."profileconten
t", "common_designprofilecontent"."page_rev_no", "common_designprofilecontent"."createdDate", "common_designprofilecontent"."createdAgent_id", "common
_designprofilecontent"."modifiedDate", "common_designprofilecontent"."modifiedAgent_id" FROM "common_designprofilecontent" WHERE "common_designprofile
content"."doc_id" = 26952 
 16440 | reader        |   28783 |       10 | postgres | vacuumdb         |             |                 |          -1 | 2016-03-19 23:37:15.579589+0
5:30 | 2016-03-19 23:37:15.581737+05:30 | 2016-03-19 23:37:15.581737+05:30 | t       | VACUUM (FULL, ANALYZE);                                        



                                   +

日志文件/var/log/pgsql

中也没有任何内容

1 个答案:

答案 0 :(得分:0)

Django对于大表来说可能很棘手,我尝试过原始SQL查询,但它们似乎在django上运行不佳。我认为最简单,最快捷的选择是使用计数

x = pg_stat_activity.objects.all()
x.count()

len(x)

len更快......