Say the original table has DEFAULT nextval('some_sequence')
. I'm looking for a way to specify DEFAULT nextval('another_sequence')
on a table view/alias so that I can just insert into the alias as usual instead of repeating int_col = nextval('another_sequence')
with every insert. In other words, the user/application only needs to be concerned with a table name and not whichever sequence is being used. Is this possible?
1 Answer
Found a clean solution thanks to a_horse_with_no_name for the idea and the syntax example set in this answer
CREATE VIEW tbl_view AS
SELECT * FROM tbl;
ALTER TABLE tbl_view ALTER int_col SET DEFAULT nextval('another_sequence');
-
1Cool. I didn't know you can have defaults on view columns.– user1822Aug 1, 2019 at 5:41
instead of trigger
comes to mind