SELECT INTO causes An undefined variable X in current scope

I have this query:

CREATE DISTRIBUTED QUERY orkhan_test_v2() FOR GRAPH redacted_dev { 
  INT X;
  X = 10;
  

  SELECT tgt.id INTO data
    FROM DATASET:tgt
    LIMIT X;

  PRINT data;
}

Query editor says: (1, 0) Error: An undefined variable X in current scope

But it work when I remove INTO statement:

  data = SELECT tgt
    FROM DATASET:tgt
    LIMIT X;

Tigergraph version is 3.10.1

Hi @Orkhan_Alikhanov ,

Thank you for the information! I am able to replicate this issue in TG Cloud version 3.10.1 too. At this time, I’ve submitted the information for our QA Engineer and Engineering team to investigate.

Seems like you’ve identified one workaround for this. Another workaround is to use a fixed number in the LIMIT clause:

  SELECT tgt.id INTO data
    FROM DATASET:tgt
    LIMIT 10;

  PRINT data;
}

Best,
Supawish Limprasert (Jim)
Solution Engineer, TigerGraph

1 Like

With INTO statement, following query also fails to run:

CREATE DISTRIBUTED QUERY orkhan_test_v2(INT X) FOR GRAPH redacted_dev {   

  SELECT tgt.id INTO data
    FROM DATASET:tgt
    LIMIT X;

  PRINT data;
}

It fails with:

Unsupported feature in query : line [0, 0]
The feature is not supported yet in interpreted mode query.
Please contact support@tigergraph.com for more details.

Hi @Orkhan_Alikhanov ,

Running distributed query is currently not supported in GSQL interpreted mode:

You’ll have to install the query before you run it. If it still showed the error in interpreted mode when you use CREATE QUERY instead of CREATE DISTRIBUTED QUERY, please let us know.

In addition to that, we currently have unexpected behavior with using a variable as a LIMIT in the SELECT … INTO clause right now. It’ll get an empty results currently. The fix for that error is coming in TigerGraph version 4.1.

If you want to be able to limit the output of a table by a variable (e.g. X), you should do something like this in the meantime:

  data = SELECT tgt
    FROM DATASET:tgt
    LIMIT X;

Best,
Supawish Limprasert (Jim)
Solution Engineer, TigerGraph