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

Loading…
Cancel
Save