Fix SQL query for camelCase tables row estimation

This commit is contained in:
Dan Sosedoff 2019-02-08 13:27:40 -06:00
parent 12717f15cc
commit 5af4332593
2 changed files with 13 additions and 4 deletions

View File

@ -224,9 +224,7 @@ func (client *Client) TableRows(table string, opts RowsOptions) (*Result, error)
func (client *Client) EstimatedTableRowsCount(table string, opts RowsOptions) (*Result, error) {
schema, table := getSchemaAndTable(table)
sql := fmt.Sprintf(`SELECT reltuples FROM pg_class WHERE oid = '%s.%s'::regclass;`, schema, table)
result, err := client.query(sql)
result, err := client.query(statements.EstimatedTableRowCount, schema, table)
if err != nil {
return nil, err
}

View File

@ -33,7 +33,18 @@ SELECT
inet_client_port(),
inet_server_addr(),
inet_server_port(),
version()`
version()`
// ---------------------------------------------------------------------------
EstimatedTableRowCount = `
SELECT
reltuples
FROM
pg_class
WHERE
oid = ('"' || $1::text || '"."' || $2::text || '"')::regclass
`
// ---------------------------------------------------------------------------