Created
April 14, 2023 10:10
-
-
Save kearfy/5d081644507dba937dc3183b201b34cd to your computer and use it in GitHub Desktop.
How to "rename" a field in SurrealDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BEGIN; | |
| -- Starting point | |
| DEFINE TABLE test SCHEMAFULL; | |
| DEFINE FIELD one ON test; | |
| CREATE test:1 SET one = 123; | |
| CREATE test:2 SET one = 456; | |
| -- "rename" the field | |
| DEFINE FIELD two ON test; | |
| UPDATE test SET two = one; | |
| REMOVE FIELD one ON test; | |
| UPDATE test; | |
| -- Store the result | |
| LET $result = SELECT * FROM test; | |
| -- cleanup for test | |
| REMOVE TABLE test; | |
| REMOVE FIELD two ON test; | |
| DELETE test; | |
| -- return the data | |
| RETURN $result; | |
| COMMIT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, but wow, that's convoluted for such a simple task. A UX flaw in SurrealDB, IMO.
It's a one-liner in SQL: