Re: Accommodating alternative column values

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Accommodating alternative column values
Date: 2024-07-03 14:39:03
Message-ID: 39759897-4e11-4c3d-a7ab-f7e6a8c479aa@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 now an array.
>
> I thought that this expression would work, but it doesn't:
> bustrac=# alter table people alter column email set data type
> varchar(64)[] using email::varchar(64)[];
> RROR:  malformed array literal: "frank(at)dmipx(dot)com"
> DETAIL:  Array value must start with "{" or dimension information.
>
> If I correctly understand the error detail I'd need to change the contents
> of that column for all 1280 rows to enclose the contents in curly braces
> before I can convert the datatype to an array. Is that correct?

An example:

create table array_conv(id integer, email varchar(64));

insert into array_conv values (1, 'adrian(dot)klaver(at)aklaver(dot)com'), (2,
'aklaver(at)example(dot)com');

select * from array_conv ;
id | email
----+---------------------------
1 | adrian(dot)klaver(at)aklaver(dot)com
2 | aklaver(at)example(dot)com

alter table array_conv alter column email type varchar[] using array[email];

select * from array_conv ;
id | email
----+-----------------------------
1 | {adrian(dot)klaver(at)aklaver(dot)com}
2 | {aklaver(at)example(dot)com}
>
> Rich
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2024-07-03 15:12:32 Re: Accommodating alternative column values [RESOLVED]
Previous Message Peter J. Holzer 2024-07-03 14:32:09 Re: Accommodating alternative column values