Array columns
A column that holds a list is genuinely useful for tags and small fixed sets. PostgreSQL makes it a first-class type; Oracle offers collections; SQL Server, MySQL and SQLite make you model it another way.
- Family
- JSON & semi-structured
- Missing in
- SQL Server, MySQL, SQLite
- Gotchas
- 5 listed
Engine by engine
PostgreSQL arrays are real columns with indexing and operators; Oracle has VARRAY/nested-table collections; SQL Server, MySQL and SQLite have no array column type, and the honest substitute is JSON or a child table.
| 엔진 | 타입 | 저장소 | 메모 |
|---|---|---|---|
| SQL Server |
none (child table or OPENJSON)
Workaround
|
해당 없음 | No array columns. Model as a child table, or store JSON and shred with OPENJSON (2016+) or STRING_SPLIT for flat lists. |
| PostgreSQL |
ARRAY (e.g. integer[], text[])
|
Per element + overhead | One-dimensional or multidimensional, with operators (ANY, @>, &&), unnest(), and GIN indexes for containment. A declared size such as integer[3] is not enforced. |
| MySQL |
none (JSON workaround)
Workaround
|
해당 없음 | No arrays. A JSON column is the accepted stand-in; FIND_IN_SET over a CSV string survives in old code but cannot use indexes. |
| SQLite |
none (TEXT workaround)
Workaround
|
해당 없음 | No arrays. Common patterns: a TEXT column with a delimiter (unqueryable except by LIKE), JSON over the JSON1 functions, or a child table. |
| Oracle |
VARRAY or nested table
|
Declared max for VARRAY | Collection types defined with CREATE TYPE, used as columns; query their contents with TABLE(collection) unnesting. Nested tables can be stored as IOTs. |
Gotchas
Where the engines disagree. These tend to surface as bugs during a migration or a port.
- PostgreSQL arrays update as a whole: SET tags = tags || 'x' rewrites the value, and row growth is real; arrays of arrays (multidimensional ragged) do not exist, dimensions must be rectangular.
- Oracle collections are schema objects: a VARRAY type must exist before the table, and you cannot drop the type while a column uses it. Porting 'just a list' into Oracle means CREATE TYPE ceremony.
- SQL Server's STRING_SPLIT arrived in 2016, takes a single-character separator, and only returns element positions with the enable_ordinal argument (2022+). A CSV column also cannot carry a foreign key to the values it lists.
- MySQL JSON arrays can be indexed with a multi-valued index (8.0.17+), which serves MEMBER OF, JSON_CONTAINS and JSON_OVERLAPS; without one, every containment check scans the table.
- A delimited TEXT list in SQLite accepts '1,x,3' as readily as '1,2,3'. JSON arrays at least parse (json_each() unnests them), and child rows can be constrained.
Common questions
Should I store arrays or a child table?
Rows when you will query, join, or constrain the elements (foreign keys, counts); an array or JSON list when the list is read as a whole attribute, like tags on a note.
How do I index a PostgreSQL array?
CREATE INDEX ... USING GIN on the column; then tags @> ARRAY['x'] and && (overlap) become index scans. Equality on the whole array uses a b-tree instead, which is rarely what you want.
What replaces arrays in SQL Server?
A child table with a foreign key for anything durable, or OPENJSON over an NVARCHAR(MAX) column for document-style payloads. There is no array column type in any released SQL Server.
Related on SQLly
Map a type to the other four engines
The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.