Change Column name

Hello.

I’m in a situation where I know for definite that a column name WILL change in the future, but which one and to what name is not known at the moment. This will obviously change how queries are run and also how “past” data (with the old name) is dealt with as at the moment it would mean adding another column.

I know CrateDB does not support the ALTER COLUMN statement at the moment, as I could just change the name, but is it possible to update the column name in pg_catalog.pg_attribute table ?

OK, I might win “heretic of the day” medal, but is it a way around the issue ?

Many thanks
David.

Hi David,
Renaming a column by updating system tables is not really a possibility, but you could use a view in this case to present a stable interface to the clients/the new name for the column.
A view can also UNION results from both an old table and a new table.

Feel free to also upvote the GH issue Rename column · Issue #10297 · crate/crate · GitHub

Depending on what you want to do with the data, might also be to use an OBJECT(IGNORED) which deactivates type mapping and gives you the flexibility to store any property with any data type.

The pg_catalog.pg_attribute table is basically only a view and can not be altered.

Hi

Thanks for the help, much appreciated. I thought it would be a problem.
Its not really the data type that’s the issue, but the name ( the type will never change )

The data we insert is in a structure, and each parameter has a name, but some are not actually “named” for a while or some are changed at a later date.
e.g. a parameter might be
Re => Rex1 (after 6 months of data ingress)

The problem is the historical data and yes union with a view would get around that for querying, no problem. I’m thinking more the ingress side and having to use the “old” name without creating a new column for the new parameter.

I suppose if I named the fields
field1
field2

field64

for all the non identifier fields and used a view to “translate” each one for querying, the business logic would be maintained in the view.

Thanks again.