public inbox for [email protected]  
help / color / mirror / Atom feed
From: Adrian Klaver <[email protected]>
To: Rich Shepard <[email protected]>
To: [email protected] <[email protected]>
Subject: Re: Accommodating alternative column values
Date: Wed, 3 Jul 2024 07:39:03 -0700
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAKFQuwYGP6geSx61RUuvH07D+CDHWOiZNXi+WpB3U=QJ7h_Dgg@mail.gmail.com>
	<[email protected]>

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: "[email protected]"
> 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, '[email protected]'), (2, 
'[email protected]');

select * from array_conv ;
  id |           email
----+---------------------------
   1 | [email protected]
   2 | [email protected]

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

select * from array_conv ;
  id |            email
----+-----------------------------
   1 | {[email protected]}
   2 | {[email protected]}
> 
> Rich
> 
> 

-- 
Adrian Klaver
[email protected]







view thread (7+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Accommodating alternative column values
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox