Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qojp8-002eo6-2M for pgsql-general@arkaria.postgresql.org; Fri, 06 Oct 2023 12:20:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qojp5-006Qv0-Sp for pgsql-general@arkaria.postgresql.org; Fri, 06 Oct 2023 12:20:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qojp5-006Qtw-9G for pgsql-general@lists.postgresql.org; Fri, 06 Oct 2023 12:20:52 +0000 Received: from ssl.schlittermann.de ([46.38.236.101]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qojp2-000JFM-P4 for pgsql-general@lists.postgresql.org; Fri, 06 Oct 2023 12:20:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=schlittermann.de; s=dd201504; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:To:Subject:MIME-Version:Date:Message-ID:Cc: Content-Description:Content-ID:Resent-Cc:Resent-To; bh=jFjZgA0rrJ2/BZR1PioVcNP4pMmXe54bKccUC4KcP58=; b=hjChYW4jQo0R1cPKY78y5x1KFh 2BUlyFpwqxCH7UuQ2P0a5LeVTPFw88YhCf2LLpQZ0gyHQL4ubW2+sc5cZHzzBj65ZldyOQi52fImP GrXICIOlNqV8S5LYYVkobafa2dADbqCOg8mK4eVm3XxvibJ/LKFnu0Qn6LA4GbC0Cz0I=; Received: by ssl.schlittermann.de with esmtpsa (TLS1.3:TLS_AES_128_GCM_SHA256:128) (Exim 4.x) (envelope-from ) id 1qojoz-002Gm9-Od for pgsql-general@lists.postgresql.org; Fri, 06 Oct 2023 14:20:45 +0200 Message-ID: <3183166f-ff95-7ca3-48fe-8e87827bf202@a-kretschmer.de> Date: Fri, 6 Oct 2023 14:20:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: why generated columsn cannot be used in COPY TO? Content-Language: en-US To: pgsql-general@lists.postgresql.org References: From: Andreas Kretschmer In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 ... test=*# 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 ); CREATE TABLE test=*# commit; COMMIT test=# insert into test( ts ) values( current_timestamp ); INSERT 0 1 test=*# select * from test;  pk |            ts             | month ----+---------------------------+-------   1 | 06-OCT-23 14:18:28.742152 |    10 (1 row) test=*# commit; COMMIT test=# copy test to stdout; 1    06-OCT-23 14:18:28.742152 test=*# copy test to stdout; 1    06-OCT-23 14:18:28.742152 test=*# copy (select * from test) to stdout; 1    06-OCT-23 14:18:28.742152    10 test=*# Andreas -- Andreas Kretschmer - currently still (garden leave) Technical Account Manager (TAM) www.enterprisedb.com