Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres: remove check constraint on varchar column

I'm coming from a MySQL world and am having a hard time doing things in PostgreSQL.

I have a column which looks like this in my GUI client: enum column

I'm not sure if it is an enum column, or a varchar with a constraint (are they the same thing in postgres?)

I want to change the type of the column to a varchar/string. I've tried this:

ALTER TABLE tablename ALTER COLUMN type TYPE character varying(255);

but no luck, I still see the constraints on the column

like image 280
Zaki Aziz Avatar asked Sep 01 '16 19:09

Zaki Aziz


People also ask

How do I drop a check constraint in PostgreSQL?

Currently DROP CONSTRAINT drops only CHECK constraints. To remove a PRIMARY or UNIQUE constraint, drop the relevant index using the DROP INDEX command. To remove FOREIGN KEY constraints you need to recreate and reload the table, using other parameters to the CREATE TABLE command.

How do I change the constraint of a column in PostgreSQL?

For modifying the column's default value, we can use the ALTER TABLE ALTER COLUMN SET DEFAULT or DROP DEFAULT command. ALTER TABLE table_name ALTER COLUMN column_name [SET DEFAULT value | DROP DEFAULT]; We will use ALTER TABLE ADD CONSTRAINT command for adding a constraint.

How do I drop a foreign key in PostgreSQL?

To drop a foreign key from a table, use the ALTER TABLE clause with the name of the table (in our example, student ) followed by the clause DROP CONSTRAINT with the name of the foreign key constraint.


1 Answers

I was able to solve this issue with some guidance from @mich4ael's helpful comment

ALTER TABLE tablename DROP CONSTRAINT constraint_name;
like image 150
Zaki Aziz Avatar answered Sep 22 '22 10:09

Zaki Aziz