Browse Source

fix: Wrong count correction in postgres

Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
pull/341/head
Pranav C 3 years ago
parent
commit
6601e922d6
  1. 13
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts

13
packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts

@ -805,13 +805,14 @@ class BaseModelSql extends BaseModel {
async countByPk({where = '', conditionGraph = null}) {
try {
if (this.isPg() && !conditionGraph && !where) {
return (await this._run(
this.dbDriver.raw(`SELECT c.reltuples::bigint AS count
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = ?
AND n.nspname = ?`, [this.tn,this.config?.searchPath?.[0] || 'public'])
const res = (await this._run(
this.dbDriver.raw(`select reltuples::int8 as count
from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace
where nspname=? AND relname=?`, [this.config?.searchPath?.[0] || 'public', this.tn])
))?.rows?.[0];
if (res?.count > 1000) {
return res;
}
}
return await this._run(this.$db

Loading…
Cancel
Save