Hello,
Can anyone tell me if there is a way to complete the following tasks in one command or in a more “automatic” way??
I mean that instead of manually entering values to the type_id column if it’s possible for the PSQL to fill the column based on the values of the type column.
To complete this task:
- I created the column:
ALTER TABLE properties ADD COLUMN INT REFERENCES type(type_id);
- Updated the column:
UPDATE properties SET type_id = 1 WHERE type = 'metal'; etc...
- And then added the NOT NULL constraint:
ALTER TABLE properties ALTER COLUMN type_id SET NOT NULL;
Instead of that, is there a way to check the value of type in a row and automatically set a value to type_id?
Thank you