Created
February 4, 2026 16:46
-
-
Save dcube9/064ebc00258730144c86bff5ed75fd6c to your computer and use it in GitHub Desktop.
POSTGRESQL - Trasforma una colonna numerica in un indice unico auto incrementato
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- opzionale: assicurati che id sia NOT NULL | |
| ALTER TABLE public.mia_tabella | |
| ALTER COLUMN id SET NOT NULL; | |
| -- aggiungi l'identity (auto-increment) | |
| ALTER TABLE public.mia_tabella | |
| ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY; | |
| SELECT setval( | |
| pg_get_serial_sequence('mia_tabella', 'id'), | |
| (SELECT COALESCE(MAX(id), 0) FROM public.mia_tabella) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment