Merge pull request #414 from sosedoff/fix-estimation-for-camelcase-schemas
Fix estimation for camelcase schemas
This commit is contained in:
commit
26cd70cbaa
@ -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
|
||||
}
|
||||
|
@ -327,6 +327,29 @@ func testTableConstraints(t *testing.T) {
|
||||
assert.Equal(t, Row{"integrity", "CHECK (book_id IS NOT NULL AND edition IS NOT NULL)"}, res.Rows[1])
|
||||
}
|
||||
|
||||
func testTableNameWithCamelCase(t *testing.T) {
|
||||
testClient.db.MustExec(`CREATE TABLE "exampleTable" (id int, name varchar);`)
|
||||
testClient.db.MustExec(`INSERT INTO "exampleTable" (id, name) VALUES (1, 'foo'), (2, 'bar');`)
|
||||
|
||||
_, err := testClient.Table("exampleTable")
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = testClient.TableInfo("exampleTable")
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = testClient.TableConstraints("exampleTable")
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = testClient.TableIndexes("exampleTable")
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = testClient.TableRowsCount("exampleTable", RowsOptions{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = testClient.EstimatedTableRowsCount("exampleTable", RowsOptions{})
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func testQuery(t *testing.T) {
|
||||
res, err := testClient.Query("SELECT * FROM books")
|
||||
|
||||
@ -444,6 +467,7 @@ func TestAll(t *testing.T) {
|
||||
testTableRowsCountWithLargeTable(t)
|
||||
testTableIndexes(t)
|
||||
testTableConstraints(t)
|
||||
testTableNameWithCamelCase(t)
|
||||
testQuery(t)
|
||||
testQueryError(t)
|
||||
testQueryInvalidTable(t)
|
||||
|
@ -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
|
||||
`
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user