Skip to main content
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.


fhyde
Contributor
Forum|alt.badge.img+3
  • Contributor
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

hkingsbury
Celebrity
Forum|alt.badge.img+53
  • Celebrity
  • August 2, 2021

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


virtualcitymatt
Celebrity
Forum|alt.badge.img+35

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...


fhyde
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • August 3, 2021
hkingsbury wrote:

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.


fhyde
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • August 3, 2021
virtualcitymatt wrote:

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"...


fhyde
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • August 3, 2021
hkingsbury wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings