0

While going through the documentation (data-types) of Apache AGE, I ran into some interesting queries that demonstrated the input/output format of data types. Such as: -

SELECT *
FROM cypher('graph_name', $$
    RETURN 1
$$) AS (int_result agtype);

Which as expected outputs

int_result
1
(1 row) 

However, if the query is modified to

SELECT *
FROM cypher('graph_name', $$
    RETURN 1.4
$$) AS (int_result agtype);

It still outputs

int_result
1.4
(1 row) 

The behavior is also noticed in boolean datatype in which you can enter any numeric value, and it outputs it as it is, for an instance

SELECT *
FROM cypher('graph_name', $$
    RETURN 1.5
$$) AS (boolean_result agtype);

Will output

boolean_result
1.5
(1 row) 

It is also interesting to note that any other input (except numeric, true, or false), for example 't' gives an error for the same boolean query.

SELECT *
FROM cypher('graph_name', $$
    RETURN t
$$) AS (boolean_result agtype);

Will output

ERROR: could not find rte for t

I was expecting similar behavior for other inputs that did not match the data types, however, they proceeded just fine. What may be the developmental reason for such behavior?

Ken White
  • 123,280
  • 14
  • 225
  • 444

2 Answers2

1

What you see as the first row of the output is not the datatype of the returned value but the table column name which was passed in the query. The general datatype is agtype for AGE.

Tito
  • 289
  • 8
  • Tito Osadebey, what additional insight do you contribute beyond what is already (much better and in more detail) explained in the existing answer https://stackoverflow.com/a/75491197/7733418 ? Please help me to see the relevant difference which makes you think that adding your post is in any way helpful. – Yunnosch Aug 28 '23 at 14:23
0

The confusion here is that in (int_result agtype), int_result is not the data type, but instead just the name of the column that will be displayed in the result. The data type itself is agtype, which is handled internally. AGE itself sets the correct data type for agtype.

SELECT *
FROM cypher('graph_name', $$
    RETURN t
$$) AS (boolean_result agtype);

For this case, it gives an error because it expects to return a variable named 't'. However, since no 't' was declared in the cypher query, it throws an error.

moeed865
  • 304
  • 1
  • 6