On Wed, 2026-12-02 at 09:10 -0600, Bruno Wolff III wrote:
> I was curious whether or not primary key could refer to a generated always 
> as column. I didn't find an answer under create table or section 5.4. 
> Maybe I missed it. It was easy enough to test and seems to work like I 
> guessed.
> (You can refer to it in a primary key iff it is stored.)
> It might be worth noting this somewhere in the documentation, if it 
> already isn't in there, someplace I missed.

That might be worth documenting; attached is a patch.

Yours,
Laurenz Albe
From a6511f544377320ac1c16b3a3a3e2601958de8be Mon Sep 17 00:00:00 2001
From: Laurenz Albe <[email protected]>
Date: Wed, 2 Dec 2026 19:12:07 +0100
Subject: [PATCH v1] Doc: virtual generated columns cannot occur in indexes

Author: Laurenz Albe <[email protected]>
Discussion: https://postgr.es/m/[email protected]
---
 doc/src/sgml/ddl.sgml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index d78d986756e..8ca8609cdc1 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -429,6 +429,12 @@ CREATE TABLE people (
       exist for stored generated columns.)
      </para>
     </listitem>
+    <listitem>
+     <para>
+      A virtual generated column cannot be used in an index definition, so it
+      also cannot be part of a primary key, unique or exclusion constraint.
+     </para>
+    <listitem>
     <listitem>
      <para>
       A generated column cannot have a column default or an identity definition.
-- 
2.56.1

Reply via email to