public inbox for [email protected]  
help / color / mirror / Atom feed
altering a column to to make it generated
3+ messages / 3 participants
[nested] [flat]

* altering a column to to make it generated
@ 2024-04-22 19:42  Celia McInnis <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Celia McInnis @ 2024-04-22 19:42 UTC (permalink / raw)
  To: pgsql-generallists.postgresql.org <[email protected]>

Can I alter a table column to now make it generated? I tried this
unsuccessfully:

create temp table tmp1 as select 15::numeric(6,1) as
distance,'24:30'::interval,0::numeric(7,3) as avgspd;
alter table tmp1 alter column avgspd type numeric(7,3) generated always as
((3600.*distance)/EXTRACT (EPOCH FROM rdrtime::interval)) STORED;
ERROR:  syntax error at or near "generated"
LINE 1: ... table tmp1 alter column avgspd type numeric(7,3) generated ...

I think that at least I have the right bracketing this time! :-)
                                                 ^


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

* Re: altering a column to to make it generated
@ 2024-04-22 19:45  David G. Johnston <[email protected]>
  parent: Celia McInnis <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: David G. Johnston @ 2024-04-22 19:45 UTC (permalink / raw)
  To: Celia McInnis <[email protected]>; +Cc: pgsql-generallists.postgresql.org <[email protected]>

On Mon, Apr 22, 2024 at 12:42 PM Celia McInnis <[email protected]>
wrote:

> Can I alter a table column to now make it generated? I tried this
> unsuccessfully:
>

I looked at all of the "alter table ... alter column" commands listed here:

https://www.postgresql.org/docs/current/sql-altertable.html

And none seem to involve the generated expression column.  So the answer is
no.

David J.


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

* Re: altering a column to to make it generated
@ 2024-04-22 20:11  Tom Lane <[email protected]>
  parent: David G. Johnston <[email protected]>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2024-04-22 20:11 UTC (permalink / raw)
  To: David G. Johnston <[email protected]>; +Cc: Celia McInnis <[email protected]>; pgsql-generallists.postgresql.org <[email protected]>

"David G. Johnston" <[email protected]> writes:
> On Mon, Apr 22, 2024 at 12:42 PM Celia McInnis <[email protected]>
> wrote:
>> Can I alter a table column to now make it generated? I tried this
>> unsuccessfully:

> I looked at all of the "alter table ... alter column" commands listed here:
> https://www.postgresql.org/docs/current/sql-altertable.html
> And none seem to involve the generated expression column.  So the answer is
> no.

I think what you'd need to do is drop the existing column
and then add a generated column.

			regards, tom lane






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


end of thread, other threads:[~2024-04-22 20:11 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-04-22 19:42 altering a column to to make it generated Celia McInnis <[email protected]>
2024-04-22 19:45 ` David G. Johnston <[email protected]>
2024-04-22 20:11   ` Tom Lane <[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