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.

  • August 2, 2021
  • 5 replies
  • 48 views

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

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

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

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

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.