Re: Accommodating alternative column values [RESOLVED]

2024-07-03 Thread Rich Shepard
On Wed, 3 Jul 2024, Adrian Klaver wrote: alter table array_conv alter column email type varchar[] using array[email]; select * from array_conv ; id |email +- 1 | {adrian.kla...@aklaver.com} 2 | {akla...@example.com} Adrian, Given my inexperience

Re: Accommodating alternative column values

2024-07-03 Thread Adrian Klaver
On 7/3/24 07:13, Rich Shepard wrote: On Wed, 3 Jul 2024, David G. Johnston wrote: Yeah, the simply cast suggested will not work. You’d have to apply an expression that turns the current contents into an array. The current contents are not likely to be an array literal. David, No, it's not no

Re: Accommodating alternative column values

2024-07-03 Thread Peter J. Holzer
On 2024-07-03 07:13:47 -0700, Rich Shepard wrote: > On Wed, 3 Jul 2024, David G. Johnston wrote: > > Yeah, the simply cast suggested will not work. You’d have to apply an > > expression that turns the current contents into an array. The current > > contents are not likely to be an array literal. >

Re: Accommodating alternative column values

2024-07-03 Thread David G. Johnston
On Wed, Jul 3, 2024 at 7:13 AM Rich Shepard wrote: > On Wed, 3 Jul 2024, David G. Johnston wrote: > > > Yeah, the simply cast suggested will not work. You’d have to apply an > > expression that turns the current contents into an array. The current > > contents are not likely to be an array litera

Re: Accommodating alternative column values

2024-07-03 Thread Torsten Förtsch
Check this out https://www.postgresql.org/docs/16/arrays.html#ARRAYS-INPUT You can use ('{' || email || '}')::varchar(64)[] or the syntax I suggested earlier. On Wed, Jul 3, 2024 at 4:13 PM Rich Shepard wrote: > On Wed, 3 Jul 2024, David G. Johnston wrote: > > > Yeah, the simply cast sugge

Re: Accommodating alternative column values

2024-07-03 Thread Rich Shepard
On Wed, 3 Jul 2024, David G. Johnston wrote: Yeah, the simply cast suggested will not work. You’d have to apply an expression that turns the current contents into an array. The current contents are not likely to be an array literal. David, No, it's not now an array. I thought that this expre

Re: Accommodating alternative column values

2024-07-03 Thread Torsten Förtsch
The USING phrase basically answers the question how do I convert an existing value of the old type to the new type. On Wed, Jul 3, 2024 at 4:03 PM Rich Shepard wrote: > On Wed, 3 Jul 2024, Rich Shepard wrote: > > > What I've tried: > > bustrac=# alter table people alter column email set data typ

Re: Accommodating alternative column values

2024-07-03 Thread David G. Johnston
On Wednesday, July 3, 2024, Rich Shepard wrote: > On Wed, 3 Jul 2024, Rich Shepard wrote: > > 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 mi

Re: Accommodating alternative column values

2024-07-03 Thread Torsten Förtsch
You could try ALTER TABLE ... SET TYPE TEXT[] USING ARRAY[email]::TEXT[] something along these lines. On Wed, Jul 3, 2024 at 3:58 PM Rich Shepard wrote: > On Tue, 2 Jul 2024, Christophe Pettus wrote: > > > To be clear, I wasn't suggesting stuffing them all into a text column > with > > a delim

Re: Accommodating alternative column values

2024-07-03 Thread Rich Shepard
On Wed, 3 Jul 2024, Rich Shepard wrote: 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)[]". What

Re: Accommodating alternative column values

2024-07-03 Thread David G. Johnston
On Wednesday, July 3, 2024, Rich Shepard wrote: > > I'm not using the proper syntax and the postgres alter table doc has no > 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? > ALTE

Re: Accommodating alternative column values

2024-07-03 Thread Rich Shepard
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. Christophe, I'm not using the proper syntax and the postgres alter tabl

Re: Accommodating alternative column values

2024-07-02 Thread Christophe Pettus
> On Jul 2, 2024, at 15:11, Rich Shepard wrote: > This data set is the > only one I've encountered that has a very few multiple email addresses for a > person. That's pretty common out in the world. Just pulling a small dataset I have available, 4+ email addresses per customer happen frequen

Re: Accommodating alternative column values

2024-07-02 Thread Rich Shepard
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

Re: Accommodating alternative column values

2024-07-02 Thread Christophe Pettus
> On Jul 2, 2024, at 14:57, Rich Shepard wrote: > Using text rather than varchar() is a good suggestion. 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.

Re: Accommodating alternative column values

2024-07-02 Thread Rich Shepard
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 rec

Re: Accommodating alternative column values

2024-07-02 Thread Christophe Pettus
> On Jul 2, 2024, at 14:47, Rich Shepard wrote: > 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? If you are absolutely 100% sure there will never be any metadata associated with

Accommodating alternative column values

2024-07-02 Thread Rich Shepard
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