Skip to content

Instantly share code, notes, and snippets.

@julp
julp / README.md
Last active August 21, 2024 02:02
PostgreSQL: migrate a primary key from serial (or whatever) to UUID

Just change the value of the _TABLE_NAME variable (constant):

DO $$
    DECLARE
        _fk TEXT[];
        _primary_key TEXT;
        _column TEXT;
        _foreign_keys TEXT[];
        _TABLE_NAME CONSTANT TEXT NOT NULL := 'the name name of the table to migrate';