Grafana not plotting TEXT on Graph

I am trying to plot a 2D graph in Grafana by this query to my DB:

SELECT
  time_index AS "time",
  raw
FROM "doc"."test"
WHERE
  $__timeFilter(time_index)
ORDER BY 1

But raw field is TEXT type

CREATE TABLE IF NOT EXISTS
“doc”.“test” (
“entity_id” TEXT,
“entity_type” TEXT,
“time_index” TIMESTAMP WITH TIME ZONE,
“fiware_servicepath” TEXT,
original_ngsi_entity” OBJECT(DYNAMIC),
“raw” TEXT

How could I cast TEXT type to number?

Hi @rafluq,

you can try to cast raw to an integer:

SELECT cast('123' as INTEGER);
SELECT try_cast('123' as INTEGER);

Also take a look at the documentation for type conversion: Data types — CrateDB: Reference

Thank you @jayeff for your answer. Is there no options for float? Float values give me NULL

Okey, I’m sorry, I tried FLOAT and it works. Thank you very much

You can cast to float as well:

SELECT try_cast('1.2' as DOUBLE);
SELECT try_cast('5' as DOUBLE);

Note that with try_cast for incompatible type casts NULL is returned.

For example when casting text to double:

SELECT try_cast('hello' as DOUBLE);
1 Like