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
    A view with an instead of trigger comes to mind
    – user1822
    Jul 31, 2019 at 5:38
  • Can you use a function to insert new values instead of an INSERT sentence?
    – McNets
    Jul 31, 2019 at 7:14

1 Answer 1


Found a clean solution thanks to a_horse_with_no_name for the idea and the syntax example set in this answer

    SELECT * FROM tbl;

ALTER TABLE tbl_view ALTER int_col SET DEFAULT nextval('another_sequence');
  • 1
    Cool. I didn't know you can have defaults on view columns.
    – user1822
    Aug 1, 2019 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.