Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
e07513bd
Commit
e07513bd
authored
Sep 19, 2018
by
Sven Klemm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use unnest in queries for redshift compatibility
parent
fe9d86c0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
25 deletions
+15
-25
public/app/plugins/datasource/postgres/meta_query.ts
+15
-25
No files found.
public/app/plugins/datasource/postgres/meta_query.ts
View file @
e07513bd
...
@@ -25,7 +25,7 @@ export class PostgresMetaQuery {
...
@@ -25,7 +25,7 @@ export class PostgresMetaQuery {
findMetricTable
()
{
findMetricTable
()
{
// query that returns first table found that has a timestamp(tz) column and a float column
// query that returns first table found that has a timestamp(tz) column and a float column
cons
t
query
=
`
le
t
query
=
`
SELECT
SELECT
quote_ident(table_name) as table_name,
quote_ident(table_name) as table_name,
( SELECT
( SELECT
...
@@ -47,11 +47,9 @@ SELECT
...
@@ -47,11 +47,9 @@ SELECT
ORDER BY ordinal_position LIMIT 1
ORDER BY ordinal_position LIMIT 1
) AS value_column
) AS value_column
FROM information_schema.tables t
FROM information_schema.tables t
WHERE
WHERE `
;
table_schema IN (
query
+=
this
.
buildSchemaConstraint
();
SELECT CASE WHEN trim(unnest) = '"$user"' THEN user ELSE trim(unnest) END
query
+=
` AND
FROM unnest(string_to_array(current_setting('search_path'),','))
) AND
EXISTS
EXISTS
( SELECT 1
( SELECT 1
FROM information_schema.columns c
FROM information_schema.columns c
...
@@ -76,8 +74,14 @@ LIMIT 1
...
@@ -76,8 +74,14 @@ LIMIT 1
buildSchemaConstraint
()
{
buildSchemaConstraint
()
{
const
query
=
`
const
query
=
`
table_schema IN (
table_schema IN (
SELECT CASE WHEN trim(unnest) = \'"$user"\' THEN user ELSE trim(unnest) END
SELECT
FROM unnest(string_to_array(current_setting(\'search_path\'),\',\'))
CASE WHEN trim(s[i]) = '"$user"' THEN user ELSE trim(s[i]) END
FROM
generate_series(
array_lower(string_to_array(current_setting('search_path'),','),1),
array_upper(string_to_array(current_setting('search_path'),','),1)
) as i,
string_to_array(current_setting('search_path'),',') s
)`
;
)`
;
return
query
;
return
query
;
}
}
...
@@ -92,11 +96,7 @@ table_schema IN (
...
@@ -92,11 +96,7 @@ table_schema IN (
query
+=
' AND table_name = '
+
this
.
quoteIdentAsLiteral
(
parts
[
1
]);
query
+=
' AND table_name = '
+
this
.
quoteIdentAsLiteral
(
parts
[
1
]);
return
query
;
return
query
;
}
else
{
}
else
{
query
=
`
query
=
this
.
buildSchemaConstraint
();
table_schema IN (
SELECT CASE WHEN trim(unnest) = \'"$user"\' THEN user ELSE trim(unnest) END
FROM unnest(string_to_array(current_setting(\'search_path\'),\',\'))
)`
;
query
+=
' AND table_name = '
+
this
.
quoteIdentAsLiteral
(
table
);
query
+=
' AND table_name = '
+
this
.
quoteIdentAsLiteral
(
table
);
return
query
;
return
query
;
...
@@ -149,18 +149,8 @@ table_schema IN (
...
@@ -149,18 +149,8 @@ table_schema IN (
}
}
buildDatatypeQuery
(
column
:
string
)
{
buildDatatypeQuery
(
column
:
string
)
{
let
query
=
`
let
query
=
'SELECT udt_name FROM information_schema.columns WHERE '
;
SELECT udt_name
query
+=
this
.
buildSchemaConstraint
();
FROM information_schema.columns
WHERE
table_schema IN (
SELECT schema FROM (
SELECT CASE WHEN trim(unnest) = \'"$user"\' THEN user ELSE trim(unnest) END as schema
FROM unnest(string_to_array(current_setting(\'search_path\'),\',\'))
) s
WHERE EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = s.schema)
)
`
;
query
+=
' AND table_name = '
+
this
.
quoteIdentAsLiteral
(
this
.
target
.
table
);
query
+=
' AND table_name = '
+
this
.
quoteIdentAsLiteral
(
this
.
target
.
table
);
query
+=
' AND column_name = '
+
this
.
quoteIdentAsLiteral
(
column
);
query
+=
' AND column_name = '
+
this
.
quoteIdentAsLiteral
(
column
);
return
query
;
return
query
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment