Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to add an Array Column to existing Postgres table

Tags:

postgresql

Why doesn't this command work?

ALTER TABLE candidate ADD COLUMN blocked_companies ARRAY;
like image 370
Suraj Kapoor Avatar asked Nov 14 '14 15:11

Suraj Kapoor


1 Answers

You need to specify a datatype. If you want an array of strings, use text:

ALTER TABLE candidate ADD COLUMN blocked_companies text[];

if you want an array of numbers, use int:

ALTER TABLE candidate ADD COLUMN blocked_companies int[];

More details can be found in the manual:
http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-DECLARATION

But in most cases using arrays is not such a good idea (despite Postgres' awesome array support). A properly normalized model might work better for your.

like image 185
a_horse_with_no_name Avatar answered Oct 19 '22 07:10

a_horse_with_no_name