Create temporary table with another table structure while maintaining the primary key constraints

Asked

Viewed 37 times

0

I am layman still in postgresql and would like someone’s help.

I created a temporary table (as mentioned in the postgresql manual):

CREATE TEMP TABLE IF NOT EXISTS s_agendatemp (like s_agendamento INCLUDING INDEXES)

The source table s_scheduling has as its primary key the ID field. This source table is already populated (for example: it contains the ID’s: 5,7,9,10,15 registered), so by logic, if I inserted another record, the next ID would be 16. By postgresql manual the index restrictions, PRIMARY KEY , UNIQUE and EXCLUDE in the original table will be created in the new table only if INCLUDING INDEXES is specified.

I am specifying this in the create table command, but when I enter a new record in the temporary table it ignores the primary key restrictions.

What I’m doing wrong?

  • From your description I believe the problem lies in sequence associated with the table’s Primary key. I don’t think the behavior of the new table’s Quence is what you expect. Check the sequences of each of the tables and compare them.

  • Thank you! I will check your suggestion.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.