age
age copied to clipboard
Added date() function to Cypher
I've begun implementing Cypher's temporal functions in AGE, beginning with date().
Here it is in action.
SELECT * FROM cypher('graph', $$
RETURN date()
$$) as (today agtype);
today
--------------
"2023-08-13"
(1 row)
It could also be converted to PostgreSQL's date
type, but the record returned by AGE must first be converted to any of PostgreSQL's character types (char
, varchar
, or text
).
SELECT TO_DATE(today, 'YYYY/MM/DD') FROM cypher('graph', $$
RETURN date()
$$) as (today text);
--
-- or
--
SELECT today::date FROM cypher('graph', $$
RETURN date()
$$) AS (today varchar(255));
Limitations
Although the date()
function in Cypher accepts an optional zone
parameter to specify what timezone to return, it isn't implemented here yet. Currently, the local time zone is returned. Hopefully, that will be implemented soon.
@Allison-E
I did not find date
function in the openCypher specification (your link refers to Neo4J doc, not openCypher).
Also, I was able to achieve the result using a PG function. Do you think we should add another implementaiton of date while we can use PG's?
(pg-15.4) agedev=# SELECT TO_DATE(today, 'YYYY/MM/DD') FROM cypher('graph', $$
RETURN pg_catalog.now()
$$) as (today text);
to_date
------------
2023-10-23
(1 row)
@Allison-E You are not using the current master branch. The master is on 1.4.0, not 1.3.0.
@rafsun42 I think it is okay to include Neo4j functions as they created the openCypher documentation. Considering how vague and incomplete the openCypher specification can be, it is a good idea to look at Neo4j for clarifications.
Hi @rafsun42, thanks for pointing out that pg_catalog.now()
could be used in your comment. I think, however, that having the date()
function alongside PostgreSQL's pg_catalog.now()
would make for an easier adaptation for the people who move from Neo4j to Apache AGE. @jrgemignani's comment is also valid.
@jrgemignani, I'll rebase the code to the current master branch.
@Allison-E The conflicts still exist. Also, there should not be any 'rebase' or 'merge' commit.
@Allison-E The conflicts still exist. Also, there should not be any 'rebase' or 'merge' commit.
All done, @rafsun42.
@Allison-E The date
function does not work with the examples in this page.
@Allison-E The
date
function does not work with the examples in this page.
Sorry, I don't think I understand, @rafsun42. Could you please describe what you are trying to do that isn't working?
@Allison-E
The following query does not work. The date
function should be able to take a single argument as shown in the PG's doc.
SELECT * FROM cypher('graph', $$ RETURN date('1999-01-08') $$) as (a agtype);
ERROR: function ag_catalog.age_date(agtype) does not exist
LINE 1: SELECT * FROM cypher('graph', $$ RETURN date('1999-01-08') $...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
@rafsun42, I was hoping to work on that soon.
This PR is stale because it has been open 45 days with no activity. Remove "Abondoned" label or comment or this will be closed in 7 days.
This PR was closed because it has been stalled for further 7 days with no activity