question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Grafana 6.4.3 + Crate 4.0.7: Cannot use relation "t" in this context.

See original GitHub issue

CrateDB version: 4.0.7

Environment description:

  • JVM version: java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
  • Kernel: uname -a
Linux de1.l7dev.co.cc 4.4.0-142-generic #168-Ubuntu SMP Wed Jan 16 21:00:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • Distribution: cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
  • Number of nodes; 1 dev node

Problem description:

I am following your blog post to get Grafana 6.4.3 use Crate.io as Data Backend (in Postgre ). When I proceed to Add Query Grafana send SQL as below:

SELECTquote_ident(table_name) as table_name,
( SELECT
    quote_ident(column_name) as 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
      quote_ident(column_name) AS 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 IN (
  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
) 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')
  ) 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='float8'
  )
LIMIT 1

which results in Crate.io throwing an error:

ERROR. Cannot use relation "t" in this context. It is only accessible in the parent context..C0A000.FFullQualifiedNameFieldProvider.java.L141.RraiseUnsupportedFeatureIfInParentScope

Steps to reproduce:

Follow steps in this blog post using Grafana 6.4.3 and Crate 4.0.7

Regards, Chris

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mfusseneggercommented, Sep 27, 2022

Correlated subquery & EXISTS support was merged and the query works now:

(The TypeORM query still misses other functionality, but the correlated join use would work)

0reactions
jayeffcommented, Mar 3, 2022

Another sample query produced by TypeORM with correlated sub-query:

SELECT
    columns.*,
    pg_catalog.col_description(
        (
            '"' || table_catalog || '"."' || table_schema || '"."' || table_name || '"'
        ) :: regclass :: oid,
        ordinal_position
    ) AS description,
    (
        '"' || "udt_schema" || '"."' || "udt_name" || '"'
    ) :: "regtype" AS "regtype",
    pg_catalog.format_type("col_attr"."atttypid", "col_attr"."atttypmod") AS "format_type"
FROM
    "information_schema"."columns"
    LEFT JOIN "pg_catalog"."pg_attribute" AS "col_attr" ON "col_attr"."attname" = "columns"."column_name"
    AND "col_attr"."attrelid" = (
        SELECT
            "cls"."oid"
        FROM
            "pg_catalog"."pg_class" AS "cls"
            LEFT JOIN "pg_catalog"."pg_namespace" AS "ns" ON "ns"."oid" = "cls"."relnamespace"
        WHERE
            "cls"."relname" = "columns"."table_name"
            AND "ns"."nspname" = "columns"."table_schema"
    )
WHERE
    (
        "table_schema" = 'doc'
        AND "table_name" = 'user'
    )

Error message: QueryFailedError: missing FROM-clause entry for relation '[doc.columns]'

I supect issue is that inner SELECT is not aware of parent context and tries to query doc.columns table which doesn’t exist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Download Grafana | Grafana Labs
Overview of how to download and install different versions of Grafana on different operating systems.
Read more >
Download Grafana | Grafana Labs
Overview of how to download and install different versions of Grafana on different operating systems.
Read more >
Configure Grafana | Grafana documentation
Grafana has default and custom configuration files. You can customize your Grafana instance by modifying the custom configuration file or by using environment ......
Read more >
Download Grafana | Grafana Labs
Overview of how to download and install different versions of Grafana on ... can be used for free and can be upgraded to...
Read more >
Data sources | Grafana documentation
You can also query data sources without building a dashboard by using the Explore ... You can't change an existing query to use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found