age icon indicating copy to clipboard operation
age copied to clipboard

Added date() function to Cypher

Open Allison-E opened this issue 1 year ago • 9 comments

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 avatar Aug 13 '23 22:08 Allison-E

@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)

rafsun42 avatar Oct 23 '23 18:10 rafsun42

@Allison-E You are not using the current master branch. The master is on 1.4.0, not 1.3.0.

image

@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.

jrgemignani avatar Oct 24 '23 22:10 jrgemignani

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 avatar Oct 25 '23 14:10 Allison-E

@Allison-E The conflicts still exist. Also, there should not be any 'rebase' or 'merge' commit.

rafsun42 avatar Oct 26 '23 19:10 rafsun42

@Allison-E The conflicts still exist. Also, there should not be any 'rebase' or 'merge' commit.

All done, @rafsun42.

Allison-E avatar Oct 29 '23 23:10 Allison-E

@Allison-E The date function does not work with the examples in this page.

rafsun42 avatar Oct 30 '23 22:10 rafsun42

@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 avatar Oct 31 '23 13:10 Allison-E

@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 avatar Oct 31 '23 16:10 rafsun42

@rafsun42, I was hoping to work on that soon.

Allison-E avatar Nov 01 '23 14:11 Allison-E

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.

github-actions[bot] avatar May 11 '24 00:05 github-actions[bot]

This PR was closed because it has been stalled for further 7 days with no activity

github-actions[bot] avatar May 19 '24 00:05 github-actions[bot]