mirror of
https://github.com/grafana/grafana.git
synced 2025-09-26 09:04:02 +08:00
add query to find metric table
This commit is contained in:
@ -6,6 +6,53 @@ export class PostgresMetaQuery {
|
|||||||
return this.queryModel.quoteLiteral(this.queryModel.unquoteIdentifier(value));
|
return this.queryModel.quoteLiteral(this.queryModel.unquoteIdentifier(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findMetricTable() {
|
||||||
|
// query that returns first table found that has a timestamptz column and a float column
|
||||||
|
let query = `
|
||||||
|
SELECT
|
||||||
|
table_schema,
|
||||||
|
table_name,
|
||||||
|
( SELECT
|
||||||
|
column_name
|
||||||
|
FROM information_schema.columns c
|
||||||
|
WHERE
|
||||||
|
c.table_schema = t.table_schema AND
|
||||||
|
c.table_name = t.table_name AND
|
||||||
|
udt_name IN ('timestamptz','timestamp')
|
||||||
|
ORDER BY ordinal_position LIMIT 1
|
||||||
|
) AS time_column,
|
||||||
|
( SELECT
|
||||||
|
column_name
|
||||||
|
FROM information_schema.columns c
|
||||||
|
WHERE
|
||||||
|
c.table_schema = t.table_schema AND
|
||||||
|
c.table_name = t.table_name AND
|
||||||
|
udt_name='float8'
|
||||||
|
ORDER BY ordinal_position LIMIT 1
|
||||||
|
) AS value_column
|
||||||
|
FROM information_schema.tables t
|
||||||
|
WHERE
|
||||||
|
table_schema !~* '^_|^pg_|information_schema' AND
|
||||||
|
EXISTS
|
||||||
|
( SELECT 1
|
||||||
|
FROM information_schema.columns c
|
||||||
|
WHERE
|
||||||
|
c.table_schema = t.table_schema AND
|
||||||
|
c.table_name = t.table_name AND
|
||||||
|
udt_name IN ('timestamptz','timestamp')
|
||||||
|
)
|
||||||
|
( SELECT 1
|
||||||
|
FROM information_schema.columns c
|
||||||
|
WHERE
|
||||||
|
c.table_schema = t.table_schema AND
|
||||||
|
c.table_name = t.table_name AND
|
||||||
|
udt_name='float8'
|
||||||
|
)
|
||||||
|
LIMIT 1
|
||||||
|
;`;
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
buildSchemaQuery() {
|
buildSchemaQuery() {
|
||||||
let query = 'SELECT quote_ident(schema_name) FROM information_schema.schemata WHERE';
|
let query = 'SELECT quote_ident(schema_name) FROM information_schema.schemata WHERE';
|
||||||
query += " schema_name NOT LIKE 'pg_%' AND schema_name NOT LIKE '\\_%' AND schema_name <> 'information_schema';";
|
query += " schema_name NOT LIKE 'pg_%' AND schema_name NOT LIKE '\\_%' AND schema_name <> 'information_schema';";
|
||||||
|
Reference in New Issue
Block a user