0
Pas un bug

"Type not supported" error for the default varchar in Postgres. Why?

willie witten il y a 8 ans mis à jour il y a 8 ans 2

In developing an ER diagram for Postgres, I always get "type not supported" error for the default varchar. If I don't change anything, it warns me about % sign, if I leave the () blank then I get a warning, which is better than an error, but this isn't great.


Am I missing something?


Thanks,

willie

Solution

Solution
Pas un bug

I believe the behavior is correct. Let's go through all the cases you described.


First of all, the default varchar (that is one without lenght) has syntax: "varchar" or "character varying". You can write it this way in "Type" field and you get no error:


Database accepts it without warning:

tests=> CREATE TABLE def_varchar (
tests(>    id int  NOT NULL,
tests(>    code varchar  NOT NULL,
tests(>    CONSTRAINT def_varchar_pk PRIMARY KEY (id)
tests(> );
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "def_varchar_pk" for table "def_varchar"
CREATE TABLE


Then, if you try either "varchar()" or "varchar(%)", both Vertabelo and PostgreSQL will raise an error:


tests=> CREATE TABLE def_varchar (
tests(>    id int  NOT NULL,
tests(>    code varchar()  NOT NULL,
tests(>    CONSTRAINT def_varchar_pk PRIMARY KEY (id)
tests(> );
ERROR:  syntax error at or near ")"
LINE 3:    code varchar()  NOT NULL,
                        ^



tests=> CREATE TABLE def_varchar (
tests(>    id int  NOT NULL,
tests(>    code varchar(%)  NOT NULL,
tests(>    CONSTRAINT def_varchar_pk PRIMARY KEY (id)
tests(> );
ERROR:  syntax error at or near "%"
LINE 3:    code varchar(%)  NOT NULL,
                        ^

Please note that the list of data types is only a helper to choose the most common ones. You can provide any text you want into the "Type" field. Vertabelo either warns you or raises an error if it doesn't recognize the type, but you can ignore it if you like.


Hope this helps.

JE SUIS SATISFAIT
Note de satisfaction par willie witten il y a 8 ans
Solution
Pas un bug

I believe the behavior is correct. Let's go through all the cases you described.


First of all, the default varchar (that is one without lenght) has syntax: "varchar" or "character varying". You can write it this way in "Type" field and you get no error:


Database accepts it without warning:

tests=> CREATE TABLE def_varchar (
tests(>    id int  NOT NULL,
tests(>    code varchar  NOT NULL,
tests(>    CONSTRAINT def_varchar_pk PRIMARY KEY (id)
tests(> );
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "def_varchar_pk" for table "def_varchar"
CREATE TABLE


Then, if you try either "varchar()" or "varchar(%)", both Vertabelo and PostgreSQL will raise an error:


tests=> CREATE TABLE def_varchar (
tests(>    id int  NOT NULL,
tests(>    code varchar()  NOT NULL,
tests(>    CONSTRAINT def_varchar_pk PRIMARY KEY (id)
tests(> );
ERROR:  syntax error at or near ")"
LINE 3:    code varchar()  NOT NULL,
                        ^



tests=> CREATE TABLE def_varchar (
tests(>    id int  NOT NULL,
tests(>    code varchar(%)  NOT NULL,
tests(>    CONSTRAINT def_varchar_pk PRIMARY KEY (id)
tests(> );
ERROR:  syntax error at or near "%"
LINE 3:    code varchar(%)  NOT NULL,
                        ^

Please note that the list of data types is only a helper to choose the most common ones. You can provide any text you want into the "Type" field. Vertabelo either warns you or raises an error if it doesn't recognize the type, but you can ignore it if you like.


Hope this helps.

Thanks Michal,


That does look like it answers the question. Cheers.