ALTER TABLE: change precision for VARCHAR column

4,996 views
Skip to first unread message

Victor Pyankov

unread,
Jan 24, 2012, 2:47:29 AM1/24/12
to h2-da...@googlegroups.com
Hi,

I am using H2 1.2.145 (if it matters). And I try to change precision for VARCHAR column in very big table.

Some thing like this:

ALTER TABLE news ALTER COLUMN body VARCHAR(16777216) DEFAULT NULL;

for "body VARCHAR(64000) DEFAULT NULL".

I think that the precision for VARCHAR type is only a size constraint. But H2 makes no optimisations for such ALTER TABLE statement.

Can you suggest some nonstandard/lowlevel method for change or drop this constraint? Is it theoretically possible to change MetaRecord for example? Do you have any idea?


Noel Grandin

unread,
Jan 24, 2012, 2:50:30 AM1/24/12
to h2-da...@googlegroups.com, Victor Pyankov
pretty much the only way at the moment would be to edit the on-disk file
using a hex editor.

By the way, if you're using varchar columns that big, you should really
be using a CLOB column.

> --
> You received this message because you are subscribed to the Google
> Groups "H2 Database" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/h2-database/-/esH-_jZEzaIJ.
> To post to this group, send email to h2-da...@googlegroups.com.
> To unsubscribe from this group, send email to
> h2-database...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.

Victor Pyankov

unread,
Jan 24, 2012, 3:15:07 AM1/24/12
to h2-da...@googlegroups.com, Victor Pyankov
вторник, 24 января 2012 г. 13:50:30 UTC+6 пользователь Noel Grandin написал:
pretty much the only way at the moment would be to edit the on-disk file
using a hex editor.

It is not good idea. We have many geographically distributed H2 databases and schema changes are propagated in fully automatic mode.

Noel Grandin

unread,
Jan 24, 2012, 3:22:41 AM1/24/12
to h2-da...@googlegroups.com, Victor Pyankov
Yeah, then there really isn't an answer.

You are welcome to try adding this feature to H2, patches are always accepted with joy :-)

On 2012-01-24 10:15, Victor Pyankov wrote:
О©╫О©╫О©╫О©╫О©╫О©╫О©╫, 24 О©╫О©╫О©╫О©╫О©╫О©╫ 2012О©╫О©╫. 13:50:30 UTC+6 О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫ Noel Grandin О©╫О©╫О©╫О©╫О©╫О©╫О©╫:
pretty much the only way at the moment would be to edit the on-disk file
using a hex editor.

It is not good idea. We have many geographically distributed H2 databases and schema changes are propagated in fully automatic mode.
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/snp29_xkju8J.

Victor Pyankov

unread,
Jan 24, 2012, 3:23:27 AM1/24/12
to h2-da...@googlegroups.com, Victor Pyankov

вторник, 24 января 2012 г. 13:50:30 UTC+6 пользователь Noel Grandin написал:

By the way, if you're using varchar columns that big, you should really

be using a CLOB column.

Realy size is not so big. We need only to drop the constraint. This constraint was introduced at design time by mistake.

vrota...@gmail.com

unread,
Jan 24, 2012, 3:32:43 AM1/24/12
to h2-da...@googlegroups.com
Will the following work?

alter table YOUR_TABLE add COPY_OF_REAL_COLUMN varchar default REAL_COLUMN;
alter table YOUR_TABLE drop column REAL_COLUMN;
alter table YOUR_TABLE alter column COPY_OF_REAL_COLUMN to REAL_COLUMN;

Or a variation with update?

--
   Vasile Rotaru

Noel Grandin

unread,
Jan 24, 2012, 3:43:46 AM1/24/12
to h2-da...@googlegroups.com, vrota...@gmail.com
try this patch, but please test thoroughly.
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
patch.txt

Victor Pyankov

unread,
Jan 24, 2012, 4:04:42 AM1/24/12
to h2-da...@googlegroups.com, vrota...@gmail.com
Noel Grandin wrote:
try this patch, but please test thoroughly.

Very interesting. I will check.

Victor Pyankov

unread,
Jan 25, 2012, 2:12:09 AM1/25/12
to h2-da...@googlegroups.com
Thank you very much, Noel! Your patch is exactly what I am looking for. I have done small refactoring. Also class for debugging was added. See attached file.
alter_table.patch

Noel Grandin

unread,
Jan 25, 2012, 2:41:06 AM1/25/12
to h2-da...@googlegroups.com, Victor Pyankov
Excellent.
This will be in the next release of H2. Not sure when that will be, Thomas might still be on holiday.

Victor Pyankov

unread,
Jan 25, 2012, 5:55:18 AM1/25/12
to h2-da...@googlegroups.com
A slight change. I forgot about the STRING_IGNORECASE type.

25.01.2012 13:41, Noel Grandin пишет:
alter_table.patch

Noel Grandin

unread,
Jan 25, 2012, 7:00:09 AM1/25/12
to h2-da...@googlegroups.com, Victor Pyankov
thanks, SVN updated

Thomas Mueller

unread,
Jan 30, 2012, 1:31:04 PM1/30/12
to h2-da...@googlegroups.com
Hi,

I have changed the code slightly now. In any case, the next version of H2 will support this feature.

Regards,
Thomas

Victor Pyankov

unread,
Jan 30, 2012, 2:35:44 PM1/30/12
to h2-da...@googlegroups.com
It is very good. Thank you!

31.01.2012 0:31, Thomas Mueller пишет:
Reply all
Reply to author
Forward
0 new messages