There was not enough space to write the comment. First of all, I want to thank to @a_horse_with_no_name for his solution provided in his answer. It has some minor bug that is easy to fix.
The bug is the following: If there is null in the x it will be transformed as {null} and not as null. In order to demonstrate the bug, consider the following script:
CREATE TABLE ALX_TEST (
id integer generated by default as identity (start with 1 cycle),
name varchar(100),
PRIMARY KEY (id)
);
insert into ALX_TEST(name)
values(null);
insert into ALX_TEST(name)
values('');
insert into ALX_TEST(name)
values('Film');
ALTER TABLE ALX_TEST
ALTER COLUMN NAME TYPE NAME[] USING ARRAY[NAME]);
select * from ALX_TEST order by id;
You will see the first line will have id=1, name='{null}' in it.
The fix is really simple:
ALTER TABLE ALX_TEST
ALTER COLUMN NAME TYPE NAME[] USING NULLIF(ARRAY[NAME], '{null}');
select * from ALX_TEST order by id;
You will see the first line will have id=1, name=null in it.
255
is by no means more efficient than e.g. 42, 392 or 783? Thecharacter
data type is a bad choice to begin with - do you really need all values to be blank padded to a length of 255? Even a single character?character varying
is very different fromcharacter
;)