36

Why doesn't this command work?

ALTER TABLE candidate ADD COLUMN blocked_companies ARRAY;
3
  • What is the error message? Commented Nov 14, 2014 at 15:10
  • syntax error at or near "ARRAY" Commented Nov 14, 2014 at 15:19
  • 1
    I would appreciate if people would explain why a question receives a negative point. Would help future participation. Commented Nov 14, 2014 at 17:23

1 Answer 1

57

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks very much for this, I'll give it a shot. Why are using arrays not a good idea?
@SurajKapoor: because multiple values in a single column violate the normalization principle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.