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 1rywB3-001AIL-2D for pgsql-general@arkaria.postgresql.org; Mon, 22 Apr 2024 16:05:57 +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 1rywB1-007epn-Kd for pgsql-general@arkaria.postgresql.org; Mon, 22 Apr 2024 16:05:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rywB1-007eT5-89 for pgsql-general@lists.postgresql.org; Mon, 22 Apr 2024 16:05:55 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rywAy-0046Or-Tl for pgsql-general@lists.postgresql.org; Mon, 22 Apr 2024 16:05:54 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-518a56cdc03so5591981e87.1 for ; Mon, 22 Apr 2024 09:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713801951; x=1714406751; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=Ym6kCDlCAs137PrxXxUalUFPl2Dtv2it8y/+xNSbtvo=; b=CSaCxUDr2iLn/NwIqQ8ZwCzvZi2oUUVkTyBs5yD5V0u52TSHq/r3zc/j2YOqwH3p5t HrPe/413EkQLGwEAlUVYLaLiafvqpo+JhunpCiEGFDb/Dhlwvfip43esOH1hS7IMeKiG +I7xBgv1/yF6qlAI1JRiiHnqJ7GOJdhNpLFEWj+wN8wHYOCwk3YZrOdQN34UP8VBOLq9 0eDtIzn4U0itBBRQXPLhSb5TH0msG4KVmbCZqJAO4wPBW1a6oUb5k7J3Ripsc0uVxuZe hMn7uSQ2MuQ9/2TeOtPhaL8KdfVbIUKX9xB4qAOeZl3MVVO1V5loWoiKRtWDz/pG41jz auRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713801951; x=1714406751; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Ym6kCDlCAs137PrxXxUalUFPl2Dtv2it8y/+xNSbtvo=; b=Sn81ggVKNpqzEDqKwuSHeEoIM6VPUQ3yGP8Xm4hmcuy49M3wHU+BsqhOPUZWrKDg/+ EEfsUDVNCjYxOFN5PppT2kM+d0KugMCW5kk9f+cROc2ae/ep+iJYX2dDwD1axv6N23WQ cirCDFngBHWRaXm4O5a3wbPvHRuMw6Wpl9Mohpnq0gjLR3cnta5WFyqQO2C/H2v7JXXT 4GKLuvEfj/J45bh1t5G52i2t4iGQEyPbigJZaZxA5j1ofBweGyQOC62Bd0yaD+2L1jrl rKpBc7N/JTFyJVEP94DskjLUhcB3vrwunQxVcVGhlLZOmCY0PDPCQZUWH10/x0YPnKZB ewng== X-Gm-Message-State: AOJu0YwRnQxjNtkyPx8XKysqqOhFS4leU05In2fGByp7c1uDQUVDy4T+ Th5EKkn8bq53Y1ptETIEqCsKoAo2RibWBYq7BXaMWa+8YG6/FgG7TeUXfMCdFi0paJIn8epSp1h 2QtOqRSBONMKtUgBl7WtoTFR2JuGwdnLP X-Google-Smtp-Source: AGHT+IGUfziSy6UhCg+El0dRrapSGXSXUds2ajVIuFck9ByZPo30A1G+k0R4j05XZL0HxHIMGNDuekmQBVr8w6llz20= X-Received: by 2002:a05:6512:110c:b0:51a:f571:bebb with SMTP id l12-20020a056512110c00b0051af571bebbmr4100037lfg.51.1713801950698; Mon, 22 Apr 2024 09:05:50 -0700 (PDT) MIME-Version: 1.0 From: Celia McInnis Date: Mon, 22 Apr 2024 12:05:39 -0400 Message-ID: Subject: adding a generated column to a table? To: "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="0000000000007ca7260616b19c6e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000007ca7260616b19c6e Content-Type: text/plain; charset="UTF-8" If I have a table containing a date field, say: create temporary table tmp1 as select now()::date as evtdate; SELECT 1 select DATE_PART('year', evtdate)::integer as year from tmp1; year ------ 2024 (1 row) Is there some way of doing something like the following?: alter table tmp1 add column year integer generated always as DATE_PART('year', evtdate)::integer STORED; ERROR: syntax error at or near "DATE_PART" LINE 1: ... tmp1 add column year integer generated always as DATE_PART(... --0000000000007ca7260616b19c6e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
If I have a table containing a date field,= say:
create temporary table tmp1 as select now()::date as evtdat= e;
SELECT 1

select DATE_PART('year', evtdate):= :integer as year from tmp1;
=C2=A0year
------
=C2=A02024
(1 ro= w)

Is there some way of doing something like the f= ollowing?:

alter table tmp1 add column year in= teger generated always as DATE_PART('year', evtdate)::integer STORE= D;
ERROR: =C2=A0syntax error at or near "DATE_PART"
LINE 1:= ... tmp1 add column year integer generated always as DATE_PART(...
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0
--0000000000007ca7260616b19c6e--