bitnine-oss / agensgraph

AgensGraph, a transactional graph database based on PostgreSQL
http://www.agensgraph.org
Other
1.33k stars 148 forks source link

How to remove quotes from text. btrim() not working in Cypher #535

Closed joefagan closed 3 years ago

joefagan commented 3 years ago

btrim() not working in Cyper but works using Hybrid query

DROP GRAPH IF EXISTS btrim CASCADE;
CREATE GRAPH btrim;
SET graph_path = btrim;

CREATE ({name:'Adam'});
MATCH (n) RETURN btrim(n.name::text,'"');

"Adam" (1 row)

quotes are not removed

SELECT btrim(name::text,'"') 
FROM (
    MATCH (n) RETURN n.name AS name
) AS x;

Adam (1 row)

quotes correctly removed.

emotionbug commented 3 years ago

btrim function works. However, the reason why it does not work as intended is that it returns the data with jsonb type. Therefore, it can be removed as below.

SELECT name #>> '{}' FROM (MATCH (n) RETURN n.name) cypher;

https://www.postgresql.org/docs/9.3/functions-json.html

>> | array of text | Get JSON object at specified path as text | '{"a":[1,2,3],"b":[4,5,6]}'::json#>>'{a,2}'

-- | -- | -- | --

joefagan commented 3 years ago

Thank you @emotionbug