Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert independently of match and delete #254

Open
nikolaimerritt opened this issue Nov 23, 2022 · 2 comments
Open

Insert independently of match and delete #254

nikolaimerritt opened this issue Nov 23, 2022 · 2 comments

Comments

@nikolaimerritt
Copy link
Contributor

nikolaimerritt commented Nov 23, 2022

Description

Calling match and delete with one variable, and insert with another, results in a TypeQL Error. The insert should be independent of the match and delete.

Environment

  1. OS (where TypeDB server runs): Mac OS 12.6
  2. TypeDB version (and platform): TypeDB Cluster 2.13
  3. TypeDB client: TypeDB Studio 12.13

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Create the minimal schema
define 

name sub attribute,
    value string;

person sub entity,
    owns name @key;
  1. Run the minimal query
match  $a isa person, has name "alice"; delete  $a isa person;
insert $b isa person, has name "bob";

Expected Output

alice to be deleted, if exists. bob to be created.

Actual Output

The TypeQL error is generated

[TQL18] TypeQL Error: None of the variables in 'insert' ('[$b isa person,
    has name "bob"]') is within scope of 'match' ('[$a]')
@nikolaimerritt nikolaimerritt changed the title Insert independently of match and delete causes error Insert independently of match and delete Nov 23, 2022
@flyingsilverfin
Copy link
Member

Can I clarify whether you intended the insert to be a separate query from the match-delete or a part of a match-delete-insert query flow?

Thanks!

@bradenmacdonald
Copy link

I'm encountering the same issue... I'm trying to write a big insert script like this example to populate a database, but I need to be able to run it over and over to iterate on it. So I want it to start with a "delete all data from the database" like those examples do (unless there's an upsert statement, which I couldn't see).

However, if I put match $all isa thing; delete $all isa thing; at the beginning of the .tql file, before a bunch of unrelated insert statements, it gives that error: None of the variables in 'insert' ... is within scope of 'match' ('[$all]').

It seems like you have to use a hack to work around this, by putting a single insert statement immediately following the match $all isa thing; delete $all isa thing;, such as insert $all isa ______, has....; and then you can follow it with as many unrelated inserts as you want. This is an awkward constraint though; I would rather just be able to run the "delete all" and then specify that the following inserts are unrelated and don't need to be tied to the same variables.

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

No branches or pull requests

3 participants