In PostgreSQL ( as well as in other rdbms ) you can define columns as arrays. What I wondered is: What is more efficient when it comes to space: Creating several columns or just creating once column as array? The result, at least for me, is rather surprising. First, let’s create a table with columns of type int:

```postgres=# create table single_values ( a int, b int, c int, d int, e int, f int, g int, h int, i int, j int );
CREATE TABLE
postgres=# \d single_values
Table "public.single_values"
Column |  Type   | Modifiers
--------+---------+-----------
a      | integer |
b      | integer |
c      | integer |
d      | integer |
e      | integer |
f      | integer |
g      | integer |
h      | integer |
i      | integer |
j      | integer |
```

Next create a table with just one column of type array[int]:

```postgres=# create table arr_values ( a int[] );
CREATE TABLE
```

Ready for populating the first table;

```truncate table single_values;
\timing on
Timing is on.
DO \$\$DECLARE
ln int := 1000;
BEGIN
for i in 0..1e6 loop
insert into single_values (a,b,c,d,e,f,g,h,i,j)
values (ln,ln,ln,ln,ln,ln,ln,ln,ln,ln);
end loop;
END\$\$;
DO
Time: 4225.313 ms
postgres=#
```

And the table with the array column:

```truncate table arr_values;
\timing on
Timing is on.
DO \$\$DECLARE
larr int[] := '{1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}';
BEGIN
for i in 0..1e6 loop
insert into arr_values (a)
values (larr);
end loop;
END\$\$;```
```postgres=# \i populate_arr_values.sql
TRUNCATE TABLE
DO
Time: 4033.523 ms
postgres=#```

```postgres=# select pg_size_pretty(pg_relation_size('single_values'));
pg_size_pretty
----------------
65 MB
(1 row)

Time: 0.227 ms
postgres=# select pg_size_pretty(pg_relation_size('arr_values'));
pg_size_pretty
----------------
89 MB
(1 row)

Time: 0.737 ms```

I did expect the table with the array to be smaller but it is the other way around. The table with the 10 columns is smaller. In the next post I’ll do the same for oracle.
{"ft_lang_label":"__label__en","ft_lang_prob":0.515257,"math_prob":0.97071755,"size":1897,"snap":"2022-40-2023-06","text_gpt3_token_len":524,"char_repetition_ratio":0.18172213,"word_repetition_ratio":0.052459016,"special_character_ratio":0.34528202,"punctuation_ratio":0.20987654,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9682058,"pos_list":[0,1,2],"im_url_duplicate_count":[null,6,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-09T02:08:18Z\",\"WARC-Record-ID\":\"<urn:uuid:12dbff0b-6276-4433-8913-e4943b90306d>\",\"Content-Length\":\"63494\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a028ec18-8afd-4f55-b693-e1ba2d7a6fcc>\",\"WARC-Concurrent-To\":\"<urn:uuid:86577d50-9fe3-4b55-b9fc-93c8a3b28239>\",\"WARC-IP-Address\":\"172.67.141.39\",\"WARC-Target-URI\":\"https://www.dbi-services.com/blog/what-is-more-efficient-arrays-or-single-column-values/\",\"WARC-Payload-Digest\":\"sha1:SFF4WYFBBPGFV3Z56XGNZOWO6KXKWEAX\",\"WARC-Block-Digest\":\"sha1:GWIEAVB2MD5X25TQDXWKVJTW6OOLV3KB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764501066.53_warc_CC-MAIN-20230209014102-20230209044102-00866.warc.gz\"}"}