-1

I am trying to alter a column in my ingres DB to expand the size of the column.

The query i'm running is

ALTER TABLE test_table ALTER COLUMN address varchar(100) NOT NULL

Which gives error

Error: ALTER TABLE: invalid change of attributes on an ALTER COLUMN

SQLState: 42000 ErrorCode: 3859

Anyone any idea why I'm getting this error? I've checked the syntax for altering tables.

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
gio10245
  • 37
  • 2
  • 13

1 Answers1

0

Probably you have NULL in data. Update your table first (set to empty string or any value you want):

LiveDemo

UPDATE test_table
SET address = ''         -- or another value indicating missing addres like 'none'
WHERE address IS NULL;

And then try:

ALTER TABLE test_table ALTER COLUMN address varchar(100) NOT NULL;

EDIT:

If you don't want to enforce NOT NULL use just:

LiveDemo2

ALTER TABLE test_table ALTER COLUMN address varchar(100);
Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
  • I just deleted the NOT NULL from my original query and it worked? – gio10245 Oct 14 '15 at 13:47
  • @gio10245 The point is you have NULL in data. When you ALTER TABLE and set NOT NULL it can't be enforced because of NULL. Update table then alter it and it should work – Lukasz Szozda Oct 14 '15 at 13:48
  • But it's working now by simply just removing the NOT NULL from my original query so why do I need to do this? – gio10245 Oct 14 '15 at 13:50
  • @gio10245 Question is do you want address that contain `NULL` or not? See demo I provided. – Lukasz Szozda Oct 14 '15 at 13:56
  • All i want to do is expand size, I wasn't sure if I needed "NOT NULL". The value in this column can be NULL if it wants to be so I removed the NOT NULL and it works? – gio10245 Oct 14 '15 at 13:57
  • @gio10245 Then yes use just `ALTER TABLE test_table ALTER COLUMN address varchar(100);` and allow to be NULL. – Lukasz Szozda Oct 14 '15 at 13:58