-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: PostgreSQL varchar limit
PostPosted: Tue Oct 13, 2009 12:10 pm 
Newbie

Joined: Tue Oct 13, 2009 11:45 am
Posts: 1
The PostgreSQL Dialect sets, by default, a 255 character limit on the 'varchar' type. In the wonderful world of Postgres, however, a varchar without a length specification can be arbitrarily large (up to the limits of the data type, which is about 1GB).

Quote:
The notations varchar(n) and char(n) are aliases for character varying(n) and character(n), respectively. character without length specifier is equivalent to character(1). If character varying is used without length specifier, the type accepts strings of any size. The latter is a PostgreSQL extension.
(http://www.postgresql.org/docs/8.0/inte ... acter.html)

Given that I consider this a feature, not a bug, is there a way to unset this default? (e.g. 'CREATE TABLE T1 (TID int, TVALUE varchar);' instead of 'CREATE TABLE T1 (TID int, TVALUE varchar(255));') While I can explicitly set this to a large value, it would be far simpler for the Hibernate PostgreSQL dialect to assume the developer who is using this database understands, accepts, and expects this particularly powerful PostgreSQL extension.

Thanks in advance,

Foo


Top
 Profile  
 
 Post subject: Re: PostgreSQL varchar limit
PostPosted: Wed Oct 14, 2009 9:16 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
Use your own Dialect. Extend PostgreSQL dialect and call method
registerColumnType( Types.VARCHAR, "varchar(8000)" );
in the constructor.
This will generate varchar(8000) for all column (even if you set lengts manually).

Or override method public Dialect#getTypeName(int code, int length, int precision, int scale) throws HibernateException {
if (Types.VARCHAR == code) {
}
}


Top
 Profile  
 
 Post subject: Re: PostgreSQL varchar limit
PostPosted: Wed Oct 14, 2009 9:21 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
I've accidentally sent not finished message.
Or override method public
Dialect#getTypeName(int code, int length, int precision, int scale) throws HibernateException {
// return varchar(8000) for columns with default names
if (Types.VARCHAR /*==12*/ == code && length == org.hibernate.mapping.Column.DEFAULT_LENGTH /*==255*/) {
return "varchar(8000)";
}
return super.getTypeName(code, length, precision, scale);
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.