-
-
Save treble37/dc03e31206b000f95f47efa760d825ee to your computer and use it in GitHub Desktop.
PostgreSQL rename column if not exists
This file contains 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
DO $$ | |
BEGIN | |
IF NOT EXISTS(SELECT * | |
FROM information_schema.columns | |
WHERE table_name='my_table' and column_name='my_column') | |
THEN | |
ALTER TABLE "public"."my_table" RENAME COLUMN "my_column" TO "my_new_column"; | |
END IF; | |
END $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment