PostgreSQL varchar without length specification defaulted to 15 - custom datatype


I created a very simple String PhoneDataType ‘phone’ and assigned to a property like

@MetaProperty(datatype="phone") @Column(name = "PHONE") protected String phone;

This yielded as expected a ‘varchar’ column in DDL, which as per PostgreSQL documentation should be of unlimited length.

However, I was quite surprised when inserting a String of length 16 failed with message “too long for character varying(15)”.

So I forced a varchar(20) in column definition like below and then it worked.

@MetaProperty(datatype="phone") @Column(name = "PHONE", columnDefinition = "varchar(20)") protected String phone;

Not sure if anyone met this issue before, is there some hidden parameter somewhere in PgSQL that I missed ?



@Lob - annotation - Indicates that the attribute does not have any length restrictions.
Default length is 255, See column_annotation

Thanks but Lob for a phone string is a bit large isn’t it ?

I already tried length = 20, which is enough in our case, and it does not work : setting length on @Column with datatype does not work with Cuba, length is removed by Studio.

However column definition varchar(20) works.

I’m not sure wether this 15 comes from Cuba or Postgre.

We cannot reproduce the issue. Could you prepare a little demo-project or share the source code of the PhoneDataType class?
Also, check which scripts were generated by Studio and which type has the column in the database (use DBMS manager).

Hi Mike,

Try to define sqlType attribute for your datatype in metadata.xml like in this example:

<metadata xmlns="">
        <datatype id="phone"

I think I finally narrowed the problem. Changing the SQL definition of a varchar datatype is not detected as an update by Studio when you click on “generate DB scripts”.

This is why I was thinking there was a limitation to 15 chars somewhere, but there is none. Simply, the phone attribute was initially varchar(15) and then we moved to a datatype with no precise SQL definition, which makes Studio yields “varchar” (unlimited). But there was no update script generated, so the column stayed to varchar(15) in PGSQL, hence the issue.

Attached a small project, which show another similar issue : using Konstantin solution to define sqlType, Studio changes correctly the DDL of the entity for the ‘create-db’ but does not detect there should be an update script generated.

Seems like when Studio generates DB update scripts, the length of the varchar is not taken into account to decide if there is a DDL change on the column.

(Cuba Studio SE 6.7.6) (452.2 KB)

Hi Michael,

You are right, Studio does not generate required scripts when the length of the custom varchar sqlType is changed. We have created a YouTrack issue.

Thank you.