Subject: Accommodating alternative column values

From: Rich Shepard <[email-masked]>
Date: Tue, 2 Jul 2024 14:47:12 -0700 (PDT)

In data made available from a state regulatory agency I find a few instances
where a facility contact has two email addresses. While multiple locations
are accommodated because they're in a table separate from the facility name
and details, all people associated with a facility and location are in a
'people' table with only one column for an email addresse.

While I could enter an additional email address in the 'comment' column if
I'm entering data for a single facility, I'm reformatting the downloaded
data so I can insert all new table data from one .sql file. Is there a way
to accommodate multiple email addresses other than entering both with a
forward slash separating them in the varchar(64) email address column?

Suggestions appreciated,

Rich

---

From: Christophe Pettus <[email-masked]>
Date: Tue, 2 Jul 2024 14:50:27 -0700

> On Jul 2, 2024, at 14:47, Rich Shepard <[email-masked]> wrote:
> Is there a way

If you are absolutely 100% sure there will never be any metadata associated with each email address (like a "valid" flag), you can use TEXT[] array to store them.  Otherwise, it's best to move them into a table with a foreign key back to the owning record.

---

From: Rich Shepard <[email-masked]>
Date: Tue, 2 Jul 2024 14:57:46 -0700 (PDT)

On Tue, 2 Jul 2024, Christophe Pettus wrote:

> If you are absolutely 100% sure there will never be any metadata
> associated with each email address (like a "valid" flag), you can use
> TEXT[] array to store them. Otherwise, it's best to move them into a table
> with a foreign key back to the owning record.

Christophe,

Using text rather than varchar() is a good suggestion.

Thank you,

Rich

---

From: Christophe Pettus <[email-masked]>
Date: Tue, 2 Jul 2024 14:59:19 -0700

> On Jul 2, 2024, at 14:57, Rich Shepard <[email-masked]> wrote:

To be clear, I wasn't suggesting stuffing them all into a text column with a delimiter, but storing them in a text *array* field, each email address one component of the array.

---

From: Rich Shepard <[email-masked]>
Date: Tue, 2 Jul 2024 15:11:08 -0700 (PDT)

On Tue, 2 Jul 2024, Christophe Pettus wrote:

> To be clear, I wasn't suggesting stuffing them all into a text column with
> a delimiter, but storing them in a text *array* field, each email address
> one component of the array.

Okay. I've not before done that and will learn how. This data set is the
only one I've encountered that has a very few multiple email addresses for a
person.

Thanks,

Rich

---

From: Rich Shepard <[email-masked]>
Date: Wed, 3 Jul 2024 06:58:31 -0700 (PDT)

Christophe,

I'm not using the proper syntax and the postgres alter table doc has no
example in the alter column choices.

What I've tried:
bustrac=# alter table people alter column email set data type varchar(64) [];
ERROR:  column "email" cannot be cast automatically to type character varying[]
HINT:  You might need to specify "USING email::character varying(64)[]".

How do I incorporate the "USING email::..." string?

TIA,

Rich

---

From: "David G. Johnston" <[email-masked]>
Date: Wed, 3 Jul 2024 07:03:13 -0700

> example in the alter column choices.

Simpler syntax forms tend to get skipped over when doing examples.

> How do I incorporate the "USING email::..." string?

ALTER [ COLUMN ] *column_name* [ SET DATA ] TYPE *data_type* [ COLLATE
*collation* ] [ USING *expression* ]

David J.