agensgraph icon indicating copy to clipboard operation
agensgraph copied to clipboard

ERROR: syntax error at or near "::"

Open VinACE opened this issue 6 years ago • 3 comments

i tried to follow the below example for my case to type cast a value MATCH (n:dev) WHERE n.year::int < (SELECT year FROM history WHERE event = 'AgensGraph') RETURN properties(n) AS n;

MATCH (po: p_order) WHERE (po.b_amount::int) < (SELECT amt FROM master WHERE v = '3') RETURN properties(po) AS p_order LIMIT 10;

ERROR: syntax error at or near "::" LINE 2: WHERE (pu_o.buy_amount::int) < (SELECT amt

please share an example to convert to integer...

VinACE avatar Sep 17 '18 09:09 VinACE

Hi @VinACE You can use to_jsonb() function.

e.g.) MATCH (po: p_order) WHERE (po.b_amount) < to_jsonb((SELECT amt FROM master WHERE v = '3')) RETURN properties(po) AS p_order LIMIT 10;

htlim avatar Sep 17 '18 09:09 htlim

you answer return results, good, but I need to compare against the integer value, WHERE po.b_amount::int po.b_amount is in "123" string type. also the results that I am getting are invalid as its is comparing to string i guess, I am still validating the way I am forming the query. please have your input as well.

or how to cast WHERE (po.b_amount) as value1 -- to integer and compare with another value2. the below example,

MATCH (po: p_order) WHERE (po.b_amount) < 1000 RETURN po;

Return in correct answers less and greater than 1000 as i think its comparing to strings. without the type cast. Appreciate your help

VinACE avatar Sep 17 '18 10:09 VinACE

@VinACE You can use int4(), int8() function, too.

e.g.) MATCH (po: p_order) WHERE int4(po.b_amount) < (SELECT amt FROM master WHERE v = '3') RETURN properties(po) AS p_order LIMIT 10;

htlim avatar Sep 20 '18 04:09 htlim