Skip to content

Self referencing foreign keys unsupported #170

@benkilimnik

Description

@benkilimnik

Encountered in the sample application schema for commento located in experiments/schema-annot/annotated/commento-annotated.sql

In the table comments we would like to have a self referencing foreign key on the column parentHex with ACCESSED_BY to support deletion of the row when the parent comment given by parentHex is deleted.

CREATE TABLE comments ( \
  commentHex TEXT NOT NULL UNIQUE PRIMARY KEY, \
  domain TEXT NOT NULL, \
  path TEXT NOT NULL, \
  commenterHex TEXT NOT NULL, \
  parentHex TEXT NOT NULL, \
  score INTEGER NOT NULL, \
  state TEXT NOT NULL, \
  FOREIGN KEY (commenterHex) OWNED_BY commenters(commenterHex), \
  FOREIGN KEY (domain) ACCESSED_BY domains(domain), \
  ON DEL parentHex DELETE_ROW, \
  FOREIGN KEY (parentHex) ACCESSED_BY comments(parentHex), \ -- > throws error
  ON GET parentHex ANON (commenterHex, score, state), \
  ON GET domain ANON (commenterHex, score, state) \
);

K9db throws this error:

INVALID_ARGUMENT: FK points to nonexisting table

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions