Skip to content

Cypher: Types are not automatically created when creating a constraint #3760

Closed

Description

@Orkie

When I try to create a constraint via Cypher, it seems that the types are not automatically created as they are when you just create a node, and the command fails. I'm not sure if this is intentional.

e.g.

CREATE CONSTRAINT type_id_constraint IF NOT EXISTS FOR (t:Type) REQUIRE t.id IS UNIQUE

yields

Error executing Cypher command: CREATE CONSTRAINT type_id_constraint IF NOT EXISTS FOR (t:Type) REQUIRE t.id IS UNIQUE

But if I run CREATE (t:Type {id:"test"}) first, then it succeeds.

There seems to be no way to create types (or indices?) via Cypher based on the documentation, it looks like you have to drop into SQL to do this - it'd be nice not to need multiple different connections and languages to set up the DB programmatically. Maybe a small extension to opencypher is needed? Or is it possible to specify SQL for a single query run via Bolt?

Activity

  1. self-assigned this
    on Apr 1, 2026
  2. added theissue type on Apr 1, 2026
  3. added this to the 26.4.1 milestone on Apr 1, 2026
  4. lvca commented on Apr 1, 2026

    @lvca
    Member

    On it.

  5. lvca commented on Apr 1, 2026

    @lvca
    Member

    FIxed.

  6. Orkie commented on Apr 1, 2026

    @Orkie
    Author

    Thanks! Just built locally and tested, seems to be working.

    On indices, is there a way to create them with Cypher / through the bolt connector somehow at the moment?

  7. lvca commented on Apr 1, 2026

    @lvca
    Member

    What's the cypher command you would use to create indexes? I meant, with neo4j? We could implement that too.

  8. Orkie commented on Apr 1, 2026

    @Orkie
    Author

    Something like this for example is what we have used in the past:

    CREATE INDEX snapshot_index IF NOT EXISTS FOR (sn:Snapshot) ON (sn.id, sn.event)
    

    Memgraph has a different syntax:

    CREATE INDEX ON :Snapshot(id, event)
    
  9. lvca commented on Apr 1, 2026

    @lvca
    Member

    After a quick research, I can confirm, this is part of OpenCypher v25 we already parse:

    CREATE INDEX name IF NOT EXISTS FOR (n:Label) ON (n.prop)

    I'm going to implement this in a new issue.

  10. lvca commented on Apr 1, 2026

    @lvca
    Member
  11. lvca commented on Apr 1, 2026

    @lvca
    Member

    Already implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions