【问题标题】:Neo4j Cypher comparing dates in Cypher queryNeo4j Cypher 在 Cypher 查询中比较日期
【发布时间】:2017-05-12 02:02:49
【问题描述】:

现在我正在设计一个带有 Neo4j 数据库的系统,我必须能够查询检查节点中的 Date 属性是否在提供的 Date 之前、等于或之后。

我应该如何将Date 存储在 Neo4j 节点属性中,以便能够与 Cypher 查询进行比较,例如基于 ==>< 等简单运算符的查询

可以像Long timestamp 一样存储Date 吗?它会这样工作吗?如果否,请提出更好的决定。

更新

我没有成功尝试过的查询:

MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId}  MATCH (childD)<-[:SET_FOR]-(filterValue153:Value)-[:SET_ON]->(filterCharacteristic153:Characteristic) WHERE id(filterCharacteristic153) = 153 WITH filterValue153, childD, ru, u WHERE  (filterValue153.value = '60305027689736') 

MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId}  MATCH (childD)<-[:SET_FOR]-(filterValue153:Value)-[:SET_ON]->(filterCharacteristic153:Characteristic) WHERE id(filterCharacteristic153) = 153 WITH filterValue153, childD, ru, u WHERE  (filterValue153.value = 'Mon Dec 27 22:35:56 EET 3880') 

filterValue153.value 的存储位置类似于 java.util.Date 对象在 Value.value 节点属性中

@NodeEntity
public class Value extends Authorable {

    public final static String NODE_NAME = "Value";

    private final static String SET_FOR = "SET_FOR";
    private final static String SET_ON = "SET_ON";

    @Relationship(type = SET_FOR, direction = Relationship.OUTGOING)
    private Decision decision;

    @Relationship(type = SET_ON, direction = Relationship.OUTGOING)
    private Characteristic characteristic;

    private Object value;

...

}

Value 节点的数据库级别,我有以下数据:

id: 848013
value:  1482873001556

更新

这个查询工作正常

MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId}  MATCH (childD)<-[:SET_FOR]-(filterValue153:Value)-[:SET_ON]->(filterCharacteristic153:Characteristic) WHERE id(filterCharacteristic153) = 153 WITH filterValue153, childD, ru, u WHERE  (filterValue153.value = 60305030539682) 

但是如何处理 1970 年 1 月 1 日 00:00:00 GMT 之前的日期? 也可以在此 Cypher 查询中应用 =&gt;&lt; 操作日期吗?

【问题讨论】:

    标签: neo4j cypher spring-data-neo4j


    【解决方案1】:

    相关问题:

    但是,这个问题可以追溯到 2012 年。从那时起,我们就有了支持 date/time conversion 的 APOC。这使您可以将日期/时间值转换为Javadoc of the SimpleDateFormat class 中描述的格式。

    1970/01/01 之前的日期可以使用,它们将简单地用negative numbers 表示。例如:

    CALL apoc.date.parseDefault('1969-07-21 02:56:15', 's')
    YIELD value 
    

    算术比较运算符(=&lt;&gt;&lt;、...)适用于时间戳。

    【讨论】:

    • 感谢您的回答。我已经用更多细节更新了我的问题。你能告诉我我做错了什么吗?另外,您能否举例说明如何使用新旧(使用 APOC)方法来完成?
    • 如果你只是用这个查询返回节点,你会得到什么结果? MATCH (filterCharacteristic153:Characteristic) WHERE id(filterCharacteristic153) = 153 RETURN *
    • 我已经为 Value 节点添加了 Neo4j 的输出
    • 另外,我添加了一个有效的查询.. 但是如何处理 1970 年 1 月 1 日 00:00:00 GMT 之前的日期?也可以在这些日期在此 Cypher 查询中应用 =、>、
    • @alexanoid 我更新了我的答案。您是如何得出 60305030539682 的值的?这是一个巨大的数字(在 2^45-2^46 的范围内),所以它可能是整数溢出的结果。如果您(或某些库)尝试将负值存储在非负整数变量中,则可能会发生这种情况。但我只是在这里猜测。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-01
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多