orientechnologies / orientdb

OrientDB is the most versatile DBMS supporting Graph, Document, Reactive, Full-Text and Geospatial models in one Multi-Model product. OrientDB can run distributed (Multi-Master), supports SQL, ACID Transactions, Full-Text indexing and Reactive Queries.
https://orientdb.dev
Apache License 2.0
4.75k stars 871 forks source link

Convenience command for renaming a field through SQL API #3350

Closed martinpengellyphillips closed 3 years ago

martinpengellyphillips commented 9 years ago

It would be helpful to have a convenience command in SQL API for renaming a field for all documents (even when no property exists).

Something like:

UPDATE <class> RENAME <field> <newFieldName>

At present, you have copy all the values to the new field and then drop the old field which is non-obvious for newbies like me ;-)

phpnode commented 9 years ago

renaming a property in the class should have this effect, a new command should not be required.

martinpengellyphillips commented 9 years ago

True, but wouldn't that workflow be:

  1. Create property
  2. Alter property
  3. Drop property
  4. Drop old field

which isn't obvious and also seems a bit overkill.

a-unite commented 9 years ago

@martinpengellyphillips , I think @phpnode meant this syntax:

ALTER PROPERTY <class>.<property> NAME NewNameValue

Look here, please: https://github.com/orientechnologies/orientdb/wiki/SQL-Alter-Property

But be aware, that altering property and class names could detach dependent custom indexes, which is another issue I still think I have to analyze and submit.

martinpengellyphillips commented 9 years ago

Yeah, I understood that. However, I am talking about when in schemaless mode and not using a property. Attempting to use ALTER PROPERTY before creating the property failed for me (or is that a bug?).

Chatting to Luca over on the forum, I see the solution currently is:

UPDATE <class> SET <newField> = <oldField>
UPDATE <class> REMOVE <oldField>

I still think there is a case for a more obvious RENAME command though. I searched for quite a bit on the forum and docs on how to rename a field and came up blank when ALTER PROPERTY didn't work. Perhaps just an addition to the documentation would suffice though, although perhaps a RENAME would help for the case you mention of handling custom indexes.

zifnab87 commented 9 years ago

@lvca @luigidellaquila when I changed the schema from studio, by renaming a property, all the existing properties still exist and only when I insert something new it has the proper schema/property name. Is this the expected behavior?

Edit: Actually checked again and it leaves both the old and the new field name