Subject: Arrays vs separate tables

From: Rich Shepard <[email-masked]>
Date: Sun, 19 Oct 2025 13:43:09 -0700 (PDT)

I started developing business and science databases in the mid-1980s using
dBASE III, then Paradox on DOS. I defenestrated in 1997 and have used only
linux for both business and personal needs ever since and using only
PostgreSQL for my databaes (primarily for my own use.) I read Joe Celko's
monthly column in 'Database Advisor' and all his SQL books (in multiple
editions.)

Now I'm slowly cleaning up my business tracking database using features not
available way back when I developed it. That's why I ask questions that must
seem obvious to all of you who work with postgres everyday and have for
years. I'm reading 'SQL Queries for Mere Mortals' and just ordered the 4th
edition of 'Database Design for Mere Mortals' to update my SQL knowledge.

In the former book I read that sometimes it's better to have multiple values
for an atribute in a single row by creating a separate table for that
attribute rather than using the postgres array capability. The people table
in my database (1706 rows) has two attributes using the array type
(direct_phone and email), and only a few indivuals have multiple landline
phone numbers (cell_phone is a separate column) or email addresses (office
and personal?). Would it make sense for me to create new landline and email
address tables and replace the array contents?

Other than remembering to use curly braces {} when entering data into an
array column I don't think there'd be any performance benefit for making the
change. I'm curious to learn about arrays vs separate tables.

TIA,

Rich

---

From: Adrian Klaver <[email-masked]>
Date: Sun, 19 Oct 2025 13:50:32 -0700

> address tables and replace the array contents?

For direct_phone and email entries that have more then one value, how do 
you know what the values are pointing at e.g home vs office vs second 
office location, etc?

-- 
Adrian Klaver
[email-masked]

---

From: Ray O'Donnell <[email-masked]>
Date: Sun, 19 Oct 2025 20:53:10 +0000

> address tables and replace the array contents?
My experience of doing something similar was that arrays work very well 
for the use-case you describe, as long as you don't have to search 
inside the arrays... I found that, if you have to search for a specific 
value inside an array, then performance really goes out the window. Mind 
you, clever use of an index would probably help here.

Ray.

-- 
Ray O'Donnell // Galway // Ireland
[email-masked]

---

From: Rich Shepard <[email-masked]>
Date: Sun, 19 Oct 2025 14:49:01 -0700 (PDT)

On Sun, 19 Oct 2025, Ray O'Donnell wrote:

> for the use-case you describe, as long as you don't have to search inside
> the arrays... I found that, if you have to search for a specific value
> inside an array, then performance really goes out the window. Mind you,
> clever use of an index would probably help here.

Ray,

So far searching has not been an issue so I'll keep the status quo.

Thanks,

Rich

---

From: "Peter J. Holzer" <[email-masked]>
Date: Mon, 20 Oct 2025 13:28:10 +0200

On 2025-10-19 13:43:09 -0700, Rich Shepard wrote:
> attribute rather than using the postgres array capability.

Replace "sometimes" with "usually", or "conventionally".

"No composite values" is the core of the first normal form. And of
course the other normal forms build on the first normal form, so your
dataase will never be normalized if you have arrays or other composite
values (e.g. json) in your database.

That said, sometimes it is advantageous to eschew normalization (if that
wasn't the case, PostgreSQL wouldn't have arrays, json, etc.).

The main reasons (IMHO) are:

* Performance: It's just a lot faster to get a row from a single table
  than to join multiple tables.
* Simplicity: If a set of values is always fetched together and updated
  together, you might as well treat it as a unit and not split it over
  multiple tables

I think the first reason is moot in your case. But it's the reason why
datawarehouses often contain huge tables with hundreds of columns and
lots and lots of redundant data.

The second may be relevant for you. If you always display and edit the
phone numbers of a contact together and your frontend makes it easier to
edit an array than a subset of rows from a table, you might just stuff
them into a table and ignore "purity".

        hjp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | [email-masked]         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"