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 1utrYz-00F4eS-MC for pgsql-admin@arkaria.postgresql.org; Wed, 03 Sep 2025 17:46:30 +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 1utrYw-00AhCJ-Qo for pgsql-admin@arkaria.postgresql.org; Wed, 03 Sep 2025 17:46:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1utrYw-00AhCB-Fd for pgsql-admin@lists.postgresql.org; Wed, 03 Sep 2025 17:46:26 +0000 Received: from jakobs.com ([85.214.83.89] helo=plausibolo.de) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1utrYt-000OEZ-1i for pgsql-admin@lists.postgresql.org; Wed, 03 Sep 2025 17:46:26 +0000 Received: from localhost (localhost [127.0.0.1]) by rs.plausibolo.de (Postfix) with ESMTP id 536D6380320; Wed, 3 Sep 2025 19:46:23 +0200 (CEST) Received: from plausibolo.de ([127.0.0.1]) by localhost (h2367442.stratoserver.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wU4Z77iH17c0; Wed, 3 Sep 2025 19:46:23 +0200 (CEST) Received: from [10.76.219.86] (dynamic-176-003-039-161.176.3.pool.telefonica.de [176.3.39.161]) by rs.plausibolo.de (Postfix) with ESMTPSA id 3CD0E380294; Wed, 3 Sep 2025 19:46:19 +0200 (CEST) Message-ID: <2aa85cf2-dfb1-474e-b190-0a96d7afeb2b@jakobs.com> Date: Wed, 3 Sep 2025 19:46:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Adding timestamp column To: pgsql-admin@lists.postgresql.org References: From: Holger Jakobs 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 03.09.25 um 17:50 schrieb Mauricio Fernandez: > Hi admins, greetings. > > I'm trying to add a timestamp column in an existent table. > > This query works fine: > > select timecreated, timezone('America/Santiago'::text, > to_timestamp(timecreated::double precision)) datecreated > from MDL_LOGSTORE_STANDARD_LOG; > > But, when I want to alter the table I get  a syntax error > > alter table MDL_LOGSTORE_STANDARD_LOG >   add column datecreated timestamp >   generated always as ( timezone ('America/Santiago'::text, > to_timestamp(timecreated::double precision))); > > SQL Error [42601]: ERROR: syntax error at end of input >   Position: 185 > > I would appreciate some tips > > Thanks in advanced > > kind regards > > Mauricio Fernández Instead of alter table MDL_LOGSTORE_STANDARD_LOG   add column datecreated timestamp   generated always as ( timezone ('America/Santiago'::text, to_timestamp(timecreated::double precision))); I would suggest ALTER TABLE MDL_LOGSTORE_STANDARD_LOG ADD COLUMN datecreated TIMESTAMP   GENERATED ALWAYS AS (timecreated AT TIME ZONE 'America/Santiago') STORED; You didn't tell us the data type of the column timecreated. It should be 'TIMESTAMPTZ DEFAULT current_timestamp' for it to work properly. As of Version 18 you can leave out STORED, creating a virtual generated column. Kind Regards, Holger -- Holger Jakobs, Bergisch Gladbach