Home > OS >  How can I create a record with an ID from a variable?
How can I create a record with an ID from a variable?

Time:09-20

I'm trying to create a record in SurrealQL with a variable:

CREATE student:$name SET age = 38

but for some reason the syntax isn't allowed. Any idea why this is the case?

CodePudding user response:

CREATE type::thing("student", $name) SET age 38

https://surrealdb.com/docs/surrealql/functions/type#thing covers this, but you can use a type function to create a record link, which in your case can be passed to CREATE.

  • Related