Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert vertex:: or edge:: into text or jsonb types #1944

Open
petrarca opened this issue Jul 2, 2024 · 3 comments
Open

Convert vertex:: or edge:: into text or jsonb types #1944

petrarca opened this issue Jul 2, 2024 · 3 comments
Labels
question Further information is requested

Comments

@petrarca
Copy link

petrarca commented Jul 2, 2024

Hello,
there seems no way to convert a ::vertex or ::edge to a jsonb or ::text.
There is a function agetype_to_text which works only on scalar-values but not on that data types.

SELECT agtype_to_text(p) FROM cypher('graph1', $$
match (p) return p
$$) as (p agtype)

-- does not work

SELECT p::jsonb FROM cypher('graph1', $$
match (p) return p
$$) as (p agtype)

-- does neither work

Any ideas to extract at least the properties for ::vertex or ::edge from SQL?

@petrarca petrarca added the question Further information is requested label Jul 2, 2024
@jrgemignani
Copy link
Contributor

@petrarca Here is a way -

psql-16.2-5432-psql=# SELECT * FROM cypher('test', $$ match (p) return ag_catalog.agtype_out(p) $$) as (p text);
                                      p
------------------------------------------------------------------------------
 {"id": 281474976710657, "label": "", "properties": {"name": "John"}}::vertex
(1 row)

psql-16.2-5432-psql=# SELECT pg_typeof(p) FROM cypher('test', $$ match (p) return ag_catalog.agtype_out(p) $$) as (p text);
 pg_typeof
-----------
 text
(1 row)

psql-16.2-5432-psql=#
psql-16.2-5432-psql=# SELECT * FROM cypher('test', $$ match (p) return ag_catalog.agtype_out(properties(p)) $$) as (p text);                p
------------------
 {"name": "John"}
(1 row)

psql-16.2-5432-psql=# SELECT pg_typeof(p) FROM cypher('test', $$ match (p) return ag_catalog.agtype_out(properties(p)) $$) as (p text);
 pg_typeof
-----------
 text
(1 row)

psql-16.2-5432-psql=#

@petrarca
Copy link
Author

petrarca commented Jul 5, 2024

Great. That works.
Thank you very much!

@jrgemignani
Copy link
Contributor

@petrarca Yw. If this resolves your issue, please consider closing the ticket :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants