10
CREATE TABLE user (
...
columnName int ARRAY[7][7] DEFAULT null,
...
)

I have to create a table where one of the columns has to store a 7x7 array, but i can't figure it out!

Is it even possible in SQL?

-- UPDATE So, I've decided I am going to cheat it and store it as a TEXT and then with code I'll work with that string

7
  • 4
    Some databases, such as postgres support this, but in terms of relational design it is not a good idea in the long run. Commented Jun 5, 2015 at 10:34
  • 3
    This is not part of the SQL standard, except for strings composed of characters. Some databases might support arrays or similar constructs. Commented Jun 5, 2015 at 10:36
  • 2
    In standard SQL, there's one data type designed for holding multiple values - the table. You can construct one with two columns with meaningful names for the indices, and constraint those to only contain values between 0-6 (or 1-7, depending on your outlook), one column with a meaningful name for the values, and then additional column(s) to foreign key back to the user table. Commented Jun 5, 2015 at 10:45
  • Maybe you want to read this... that's one way to solve your problem... Commented Jun 5, 2015 at 11:00
  • Will your database have any interactionwith this column, accept from storing it? If the answer is yes, then it's a teribble idea. Commented Jun 5, 2015 at 12:11

1 Answer 1

6

SQL 2003 (and to a lesser extent SQL 99) provide array types, see for instance here: http://farrago.sourceforge.net/design/CollectionTypes.html I've used them extensively with PostgreSQL to simplify my designs. For clients that don't support array semantics yet, it's possible to provide views which "unnest" the arrays.

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

Comments

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.