0

I have a table in my DB (PstgreSQL 14) that is auto-generated by another software. This table contains a t_stamp column stored as a BIGINT. I need to use this t_stampsomewhere else as a TIMESTAMP data type.

I thought about creating a generated column that would simply be the t_stamp column, casted to the right type :

ALTER TABLE myTable 
ADD COLUMN cpt_timestamp TIMESTAMP WITH TIME ZONE GENERATED ALWAYS AS to_timestamp(t_stamp/1000) STORED

And I get an error message :

ERROR:  syntax error at or near "to_timestamp"
LINE 2: ...tamp TIMESTAMP WITH TIME ZONE GENERATED ALWAYS AS to_timesta...
                                                             ^
SQL state: 42601
Character: 97

However, it works fine with a simple SELECT :

Select *, to_timestamp(t_stamp/1000) FROM my_table

Is it not possible to cast inside a generated query ?

Sim
  • 45
  • 1
  • 7

0 Answers0