public inbox for [email protected]  
help / color / mirror / Atom feed
Adding timestamp column
4+ messages / 3 participants
[nested] [flat]

* Adding timestamp column
@ 2025-09-03 15:50 Mauricio Fernandez <[email protected]>
  2025-09-03 16:09 ` Re: Adding timestamp column David G. Johnston <[email protected]>
  2025-09-03 17:46 ` Re: Adding timestamp column Holger Jakobs <[email protected]>
  0 siblings, 2 replies; 4+ messages in thread

From: Mauricio Fernandez @ 2025-09-03 15:50 UTC (permalink / raw)
  To: Pgsql-admin <[email protected]>

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


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Adding timestamp column
  2025-09-03 15:50 Adding timestamp column Mauricio Fernandez <[email protected]>
@ 2025-09-03 16:09 ` David G. Johnston <[email protected]>
  1 sibling, 0 replies; 4+ messages in thread

From: David G. Johnston @ 2025-09-03 16:09 UTC (permalink / raw)
  To: Mauricio Fernandez <[email protected]>; +Cc: Pgsql-admin <[email protected]>

On Wednesday, September 3, 2025, Mauricio Fernandez <
[email protected]> wrote:
>
>
> 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
>
>
Unless you are experimenting with v18 the docs clearly indicate the keyword
“stored” is mandatory (since the implemented in 18 virtual is the default).

David J.


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Adding timestamp column
  2025-09-03 15:50 Adding timestamp column Mauricio Fernandez <[email protected]>
@ 2025-09-03 17:46 ` Holger Jakobs <[email protected]>
  2025-09-03 17:51   ` Re: Adding timestamp column Mauricio Fernandez <[email protected]>
  1 sibling, 1 reply; 4+ messages in thread

From: Holger Jakobs @ 2025-09-03 17:46 UTC (permalink / raw)
  To: [email protected]

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






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Adding timestamp column
  2025-09-03 15:50 Adding timestamp column Mauricio Fernandez <[email protected]>
  2025-09-03 17:46 ` Re: Adding timestamp column Holger Jakobs <[email protected]>
@ 2025-09-03 17:51   ` Mauricio Fernandez <[email protected]>
  0 siblings, 0 replies; 4+ messages in thread

From: Mauricio Fernandez @ 2025-09-03 17:51 UTC (permalink / raw)
  To: Holger Jakobs <[email protected]>; David G. Johnston <[email protected]>; +Cc: [email protected]

Thank you Holger and David, the error was the missing clausule STORED

The timecreated data type is Int8

King regards

Mauricio Fernández

El mié, 3 sept 2025 a las 13:46, Holger Jakobs (<[email protected]>)
escribió:

> 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
>
>
>
>


^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2025-09-03 17:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-09-03 15:50 Adding timestamp column Mauricio Fernandez <[email protected]>
2025-09-03 16:09 ` David G. Johnston <[email protected]>
2025-09-03 17:46 ` Holger Jakobs <[email protected]>
2025-09-03 17:51   ` Mauricio Fernandez <[email protected]>

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