---
# System prepended metadata

title: Reorder Integer Primary Key
tags: [postgresql]

---

# Reorder Integer Primary Key

[TOC]

###### tags: `postgresql`

---

```sql
WITH "xyz" AS (
	SELECT
	*,
	"row_number"() OVER (ORDER BY "some_column") AS "ordinal"
	FROM"some_table"
)
UPDATE "some_table"
SET "id"="xyz"."ordinal"
FROM "xyz"
WHERE "xyz"."id"="some_table"."id"
```

## Reference

- [StackExchange: How to update column with ascending value column](https://dba.stackexchange.com/questions/227833/how-to-update-column-with-ascending-value-column#answer-227834)
