2

Having a problem with this, trying to add a column which returns the year from a date column in postgresql 10: This is my SQL

ALTER TABLE stats ADD COLUMN year_ integer GENERATED ALWAYS AS (date_part('year', date)) STORED;

However, this returns a syntax error in the SQL window. I have looked up the online documentation and have no idea what is going wrong, also tried with the EXTRACT function and I keep on getting the same error of the sort

ERROR: syntax error at or near "(" LINE 1: ...tats ADD COLUMN year_ integer GENERATED ALWAYS AS (date_part...

  • generated columns have been introduced in Postgres 12, you can't use them in Postgres 10. You will have to upgrade if you really need them. –  Apr 29 '20 at 07:37
  • Oh thank you, this had me really confused. Syntax seemed simple enough – Mark Mukamutala Apr 29 '20 at 08:21

0 Answers0