9

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

3
  • 2
    it looks like it is already a character varying column and the thing that you are talking about is indeed a constraint, if you want to get rid of it you should take a look at DROP CONSTRAINT statement Commented Sep 1, 2016 at 19:46
  • meta.stackoverflow.com/questions/285551/… Commented Sep 1, 2016 at 20:17
  • @a_horse_with_no_name The tables were created with an ORM and my GUI does not give me a "copy as SQL" type function where I would be able to show how this column can be replicated. Commented Sep 1, 2016 at 20:19

1 Answer 1

24

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

ALTER TABLE tablename DROP CONSTRAINT constraint_name;
Sign up to request clarification or add additional context in comments.

3 Comments

Could you please specify what coinstraint_name refers to? Is it type? type::text? What is it, where do I find it?
@DavidsKanal It's been many years since I wrote this answer so i'm missing a lot of context, but if you want to know what constraints are I'd suggest reading over this on the postgres docs: postgresql.org/docs/15/ddl-constraints.html
Ah, it's alright, I managed to find the answer. Turns out that every constraint has a name, even if you didn't specify one. I needed to manually query one of the meta tables in the database to get a list of constraints and their names, and that way, I was able to find the constraint's name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.