Let's say I have a table with generated column.
CREATE TABLE foo (x int, y int, z int GENERATED ALWAYS AS (x + y) STORED);
INSERT INTO foo (x, y) VALUES (1, 1);
Is it possible to do something like this, but somehow omitting the generated column?
INSERT INTO foo SELECT * FROM foo;
I don't want to specify all the column names, because I want the insert to work even if new columns are added to the table.
I couldn't find any clever solution. this question provides some idea, but I don't know whether it could be adapted. The only way I could think of is to set z
value in before trigger instead of using generated column. Are there any recommendations in this area?
1条答案
按热度按时间mnemlml81#
我建议在几乎所有情况下都避免使用隐式列。在INSERT和SELECT中指定所需的列:
在编程中,显式是一件好事。