Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/backend/utils/adt/cypher_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "utils/jsonb.h"
#include "utils/memutils.h"
#include "utils/typcache.h"
#include <string.h>
#include "utils/datetime.h"

/* global variable - see postgres.c*/
extern GraphWriteStats graphWriteStats;
Expand Down Expand Up @@ -1651,3 +1651,27 @@ tofloatornull(PG_FUNCTION_ARGS)
else
PG_RETURN_NULL();
}

Datum
e(PG_FUNCTION_ARGS)
{
PG_RETURN_FLOAT8(2.718281828459045);
}

Datum
date(PG_FUNCTION_ARGS)
{
time_t t = time(NULL);
struct tm *tm = localtime(&t);
char s[11];
sprintf(s, "%04d-%02d-%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
PG_RETURN_TEXT_P(cstring_to_text(s));
}

Datum
localtime_c(PG_FUNCTION_ARGS)
{
time_t t = time(NULL);
struct tm *tm = localtime(&t);
PG_RETURN_TEXT_P(cstring_to_text(tm->tm_zone));
}
11 changes: 11 additions & 0 deletions src/include/catalog/pg_proc.dat
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,9 @@
proname => 'in_range', prorettype => 'bool',
proargtypes => 'date date interval bool bool',
prosrc => 'in_range_date_interval' },
{ oid => '8008', descr => 'returns the current date in YYYY-MM-DD format',
proname => 'date', prorettype => 'text', pronargs => '0',
proargtypes => '', prosrc => 'date' },

# OIDS 1100 - 1199

Expand Down Expand Up @@ -2246,6 +2249,9 @@
{ oid => '1145',
proname => 'time_eq', proleakproof => 't', prorettype => 'bool',
proargtypes => 'time time', prosrc => 'time_eq' },
{ oid => '8009', descr => 'returns the local timezone',
proname => 'localtime_c', prorettype => 'text', pronargs => '0',
proargtypes => '', prosrc => 'localtime_c' },

{ oid => '1146',
proname => 'circle_add_pt', prorettype => 'circle',
Expand Down Expand Up @@ -12050,4 +12056,9 @@
{ oid => '8005', descr => 'return float equivalents or null',
proname => 'tofloatornull', prorettype => 'float8', proisstrict => 't', pronargs => '1',
proargtypes => 'any', prosrc => 'tofloatornull' },

# functions for returning constant values
{ oid => '8007', descr => 'return the constant value of logarithmic base',
proname => 'e', prorettype => 'float8', pronargs => '0',
proargtypes => '', prosrc => 'e' },
]
3 changes: 3 additions & 0 deletions src/include/utils/cypher_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,8 @@ extern Datum get_last_graph_write_stats(PG_FUNCTION_ARGS);
extern Datum tointeger(PG_FUNCTION_ARGS);
extern Datum tofloat(PG_FUNCTION_ARGS);
extern Datum tofloatornull(PG_FUNCTION_ARGS);
extern Datum e(PG_FUNCTION_ARGS);
extern Datum date(PG_FUNCTION_ARGS);
extern Datum localtime_c(PG_FUNCTION_ARGS);

#endif /* CYPHER_FUNCS_H */
6 changes: 6 additions & 0 deletions src/test/regress/expected/cypher_expr.out
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,12 @@ MATCH (n:coll) RETURN n;
coll[7.1]{"l": "graphdatabase", "u": "GRAPHDATABASE", "name": "GraphDatabase"}
(1 row)

RETURN e();
e
-------------------
2.718281828459045
(1 row)

-- Text matching
CREATE (:ts {v: 'a fat cat sat on a mat and ate a fat rat'::tsvector});
MATCH (n:ts) WHERE n.v::tsvector @@ 'cat & rat'::tsquery RETURN n;
Expand Down
12 changes: 12 additions & 0 deletions src/test/regress/expected/date.out
Original file line number Diff line number Diff line change
Expand Up @@ -1495,3 +1495,15 @@ select make_time(10, 55, 100.1);
ERROR: time field value out of range: 10:55:100.1
select make_time(24, 0, 2.1);
ERROR: time field value out of range: 24:00:2.1
RETURN date() = (SELECT CAST(NOW() as date)) AS equality;
equality
----------
t
(1 row)

RETURN date() = (SELECT NOW()) AS equality;
equality
----------
f
(1 row)

2 changes: 2 additions & 0 deletions src/test/regress/sql/cypher_expr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ MATCH (n:coll) SET n.l = tolower(n.name);
MATCH (n:coll) SET n.u = toupper(n.name);
MATCH (n:coll) RETURN n;

RETURN e();

-- Text matching

CREATE (:ts {v: 'a fat cat sat on a mat and ate a fat rat'::tsvector});
Expand Down
3 changes: 3 additions & 0 deletions src/test/regress/sql/date.sql
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,6 @@ select make_date(2013, 13, 1);
select make_date(2013, 11, -1);
select make_time(10, 55, 100.1);
select make_time(24, 0, 2.1);

RETURN date() = (SELECT CAST(NOW() as date)) AS equality;
RETURN date() = (SELECT NOW()) AS equality;