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 1utrdu-00F6OY-TI for pgsql-admin@arkaria.postgresql.org; Wed, 03 Sep 2025 17:51:35 +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 1utrdt-00Akyn-R8 for pgsql-admin@arkaria.postgresql.org; Wed, 03 Sep 2025 17:51:34 +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 1utrdt-00Akye-Fl for pgsql-admin@lists.postgresql.org; Wed, 03 Sep 2025 17:51:33 +0000 Received: from mail-ua1-x92a.google.com ([2607:f8b0:4864:20::92a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1utrdq-000OGh-26 for pgsql-admin@lists.postgresql.org; Wed, 03 Sep 2025 17:51:33 +0000 Received: by mail-ua1-x92a.google.com with SMTP id a1e0cc1a2514c-8972e215df9so50885241.1 for ; Wed, 03 Sep 2025 10:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756921889; x=1757526689; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=wE3No4iIChsaLswexBrGFdUs6Q9ovHP/vfAHxXN0Ass=; b=M5ZR6ZWVU0gq0Y7/ch1+jpIuAWardNvPFDTnRMUcx05OJfJT8OaZZcbyTfH2K1kzlP 7Gz5Svr1BBrMENv0QlxkIJr0UGhWql3fd00t46wHwdG4y4LklR8WC46nHl3g4xkpQSf9 WJUaXvzt8LjBx8FZhnxMp+PTrvBzu2lP6StmhbgoWzxFgIs/J6X3raWEKxvXrq9lGjeP r8aCGcexnsk1QF0eBXRCo9hWBeQosOt0JV/rACNgkdByG5bxSXp1Zm9JCZPfhTijVsy2 RFdRQsQdqGgThKUo5wFdPPMlL7AklfafXr50438XtRNna8MC6nBd9KyI6r9HMZaWLz3W gVEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756921889; x=1757526689; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wE3No4iIChsaLswexBrGFdUs6Q9ovHP/vfAHxXN0Ass=; b=TnEc7pO0PJysFoKspMSY2N8C2dptkYu+nxIaWLN/TL0Z7hpnJFm41TvSfiZZFMBykU vBU9akqJD6Ym8h7bWq3w719Iveg6mRhWwkObiBWdJYZKq6qoGn/dtAF644IfdTNZvcMQ qq8iE4CDbpWhdzF4JcDbplZmkNpweTCDqx5MIBhLI4EXa8ZWJvlNcB5l2LJkkKRGVsw4 z4TBdSmvTxnMD1sjQ1gjjAFoG0z/AT43P8w0n5CXzCWZ/aaEmep+YGygY/vOuCaVsK8I f3RghAz4YYXXZR/aZwfgx8x8/z6b9ORmiBPimaCMBt/x3WHScPbk29JgKtTfMDeM8FRc bj8A== X-Gm-Message-State: AOJu0Yx8KHvwwGuhJa068pt+LAsALoukHEdFrxgThGf87a2ruPr48scN QluckQ9XwEdtkFJ6fWcvlXe6EeeXcxcvwMiB1p197nkry9uFqg5sN7uloMbwz6zxf+IyIWoMZ2y ejBlosuJx0+WVO02mua9kNIyBx/z3o7A= X-Gm-Gg: ASbGnctpTjxXF120/n8vfv6ulsxoZb1rID8mkzsCUHUXYlrQUKxqlA7X9uNW+9Be1/8 ENP2CBzbf+BG5blgbdXRKrPZVRBuDwMCsujGTrxYq0Dsuz63E7fcDPVzo9WHNC7+0hNANRSngc+ MexiJ1Uew7EhYYjJJKDCiFIkgcHU1FFfKbDIYMQGzx8Fmq8aYX4hfK8wOh6J0z21q5l6QWTVKK0 Kl6CLoaCn7s0dFAY7OFZERw+QEbjT4UMfMls8rWQDSon23dDjQ= X-Google-Smtp-Source: AGHT+IHuOx/rY3QkjLMTAB37aJIAWqW0zX+EKtOJ6bJzLpNARlKPaJu4+56naMqTOtGOavvO5Gw1tSXR3FAR3xlOFc8= X-Received: by 2002:a05:6102:598e:b0:4fc:d0e5:23fe with SMTP id ada2fe7eead31-52b19e6ffd9mr5377994137.15.1756921889545; Wed, 03 Sep 2025 10:51:29 -0700 (PDT) MIME-Version: 1.0 References: <2aa85cf2-dfb1-474e-b190-0a96d7afeb2b@jakobs.com> In-Reply-To: <2aa85cf2-dfb1-474e-b190-0a96d7afeb2b@jakobs.com> From: Mauricio Fernandez Date: Wed, 3 Sep 2025 13:51:19 -0400 X-Gm-Features: Ac12FXyxmeoDYKMV2PtTXlXz8_cjpRpgKeLjcPH7EekV-eirFjp10IueKpnsOjE Message-ID: Subject: Re: Adding timestamp column To: Holger Jakobs , "David G. Johnston" Cc: pgsql-admin@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000001fe376063de941c1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000001fe376063de941c1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you Holger and David, the error was the missing clausule STORED The timecreated data type is Int8 King regards Mauricio Fern=C3=A1ndez El mi=C3=A9, 3 sept 2025 a las 13:46, Holger Jakobs () escribi=C3=B3: > 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=C3=A1ndez > > 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 > > > > --0000000000001fe376063de941c1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Thank you Holger and David, the error was the mis= sing clausule STORED

The timecreated data type is = Int8

King=C2=A0regards

Ma= uricio Fern=C3=A1ndez

El mi=C3=A9, 3 sept 2025 a las 13:46, Holger Jak= obs (<holger@jako= bs.com>) escribi=C3=B3:
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=C2=A0 a syntax=C2=A0error >
> alter table MDL_LOGSTORE_STANDARD_LOG
> =C2=A0 add column datecreated timestamp
> =C2=A0 generated always as ( timezone ('America/Santiago'::tex= t,
> to_timestamp(timecreated::double precision)));
>
> SQL Error [42601]: ERROR: syntax error at end of input
> =C2=A0 Position: 185
>
> I would appreciate some tips
>
> Thanks in advanced
>
> kind regards
>
> Mauricio Fern=C3=A1ndez

Instead of

alter table MDL_LOGSTORE_STANDARD_LOG
=C2=A0=C2=A0 add column datecreated timestamp
=C2=A0=C2=A0 generated always as ( timezone ('America/Santiago'::te= xt,
to_timestamp(timecreated::double precision)));

I would suggest

ALTER TABLE MDL_LOGSTORE_STANDARD_LOG
ADD COLUMN datecreated TIMESTAMP
=C2=A0=C2=A0 GENERATED ALWAYS AS (timecreated AT TIME ZONE 'America/San= tiago') STORED;

You didn't tell us the data type of the column timecreated. It should b= e
'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



--0000000000001fe376063de941c1--