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

Zaki Aziz
  • 3,592
  • 11
  • 43
  • 61
  • 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 – mic4ael Sep 01 '16 at 19:46
  • http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557 –  Sep 01 '16 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. – Zaki Aziz Sep 01 '16 at 20:19

1 Answers1

19

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

ALTER TABLE tablename DROP CONSTRAINT constraint_name;
Zaki Aziz
  • 3,592
  • 11
  • 43
  • 61
  • Could you please specify what `coinstraint_name` refers to? Is it `type`? `type::text`? What is it, where do I find it? – DavidsKanal Jan 03 '23 at 16:10
  • @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: https://www.postgresql.org/docs/15/ddl-constraints.html – Zaki Aziz Jan 14 '23 at 03:42
  • 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. – DavidsKanal Jan 14 '23 at 09:25