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
28ff8a67
Unverified
Commit
28ff8a67
authored
Sep 19, 2018
by
Marcus Efraimsson
Committed by
GitHub
Sep 19, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13342 from svenklemm/unnest
Don't use unnest in queries for redshift compatibility
parents
978284bc
e07513bd
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 @
28ff8a67
...
...
@@ -25,7 +25,7 @@ export class PostgresMetaQuery {
findMetricTable
()
{
// query that returns first table found that has a timestamp(tz) column and a float column
cons
t
query
=
`
le
t
query
=
`
SELECT
quote_ident(table_name) as table_name,
( SELECT
...
...
@@ -47,11 +47,9 @@ SELECT
ORDER BY ordinal_position LIMIT 1
) AS value_column
FROM information_schema.tables t
WHERE
table_schema IN (
SELECT CASE WHEN trim(unnest) = '"$user"' THEN user ELSE trim(unnest) END
FROM unnest(string_to_array(current_setting('search_path'),','))
) AND
WHERE `
;
query
+=
this
.
buildSchemaConstraint
();
query
+=
` AND
EXISTS
( SELECT 1
FROM information_schema.columns c
...
...
@@ -76,8 +74,14 @@ LIMIT 1
buildSchemaConstraint
()
{
const
query
=
`
table_schema IN (
SELECT CASE WHEN trim(unnest) = \'"$user"\' THEN user ELSE trim(unnest) END
FROM unnest(string_to_array(current_setting(\'search_path\'),\',\'))
SELECT
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
;
}
...
...
@@ -92,11 +96,7 @@ table_schema IN (
query
+=
' AND table_name = '
+
this
.
quoteIdentAsLiteral
(
parts
[
1
]);
return
query
;
}
else
{
query
=
`
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
=
this
.
buildSchemaConstraint
();
query
+=
' AND table_name = '
+
this
.
quoteIdentAsLiteral
(
table
);
return
query
;
...
...
@@ -149,18 +149,8 @@ table_schema IN (
}
buildDatatypeQuery
(
column
:
string
)
{
let
query
=
`
SELECT udt_name
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)
)
`
;
let
query
=
'SELECT udt_name FROM information_schema.columns WHERE '
;
query
+=
this
.
buildSchemaConstraint
();
query
+=
' AND table_name = '
+
this
.
quoteIdentAsLiteral
(
this
.
target
.
table
);
query
+=
' AND column_name = '
+
this
.
quoteIdentAsLiteral
(
column
);
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