Re: why generated columsn cannot be used in COPY TO?

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: why generated columsn cannot be used in COPY TO?
Date: 2023-10-06 13:16:35
Message-ID: 2fc8c4ab-4ecc-2adb-4236-3142fde13bde@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/6/23 07:20, Andreas Kretschmer wrote:
>
>
> Am 06.10.23 um 13:53 schrieb Luca Ferrari:
>> Hi all,
>> I'm wondering why in COPY TO (file or program) I cannot use generated
>> columns: since I'm pushing data out of the table, why they are not
>> allowed?
>>
>> Example:
>>
>> testdb=# CREATE TABLE test( pk int generated always as identity primary key
>> , ts timestamp default current_timestamp
>> , month int generated always as ( extract( month from ts ) ) stored
>> );
>>
>> testdb=# insert into test( ts ) values( current_timestamp );
>>
>> testdb=# copy test to program 'head'; -- ok but silently removes the column
>> COPY 1
>> testdb=# copy test( month ) to program 'head';
>> ERROR:  column "month" is a generated column
>> DETAIL:  Generated columns cannot be used in COPY.
>
> you can use copy (select * ...) to ...

But why not?

--
Born in Arizona, moved to Babylonia.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2023-10-06 13:47:51 Re: why generated columsn cannot be used in COPY TO?
Previous Message Andreas Kretschmer 2023-10-06 12:20:35 Re: why generated columsn cannot be used in COPY TO?