Question

From the Postgresql Writer, when a table is truncated and then inserted with new data is it possible to reset the Primary Key sequence to '1'? It currently restarts at the last PK value (+1) from previous entry.

  • 2 August 2021
  • 5 replies
  • 7 views

Badge
From the Postgresql Writer, when a table is truncated and then inserted with new data is it possible to reset the Primary Key sequence to '1'? It currently restarts at the last PK value (+1) from previous entry.

5 replies

Userlevel 5
Badge +29

it looks possible, before writing/truncating you could do something like the following

https://stackoverflow.com/questions/4678110/how-to-reset-sequence-in-postgres-and-fill-id-column-with-new-data

Userlevel 4
Badge +26

Could you drop the table instead of truncating? I would think that should reset it to 1. Of course that might come with it's own set of headaches...

Badge

it looks possible, before writing/truncating you could do something like the following

https://stackoverflow.com/questions/4678110/how-to-reset-sequence-in-postgres-and-fill-id-column-with-new-data

Interesting option. I'll look in to that. Thanks.

Badge

Could you drop the table instead of truncating? I would think that should reset it to 1. Of course that might come with it's own set of headaches...

I could but there are going to be views associated to it so, as you said, "it's own set of headaches"...

Badge

it looks possible, before writing/truncating you could do something like the following

https://stackoverflow.com/questions/4678110/how-to-reset-sequence-in-postgres-and-fill-id-column-with-new-data

Worked perfectly.

Reply