postgresql/src/pl/plperl
Peter Eisentraut 83ea6c5402 Virtual generated columns
This adds a new variant of generated columns that are computed on read
(like a view, unlike the existing stored generated columns, which are
computed on write, like a materialized view).

The syntax for the column definition is

    ... GENERATED ALWAYS AS (...) VIRTUAL

and VIRTUAL is also optional.  VIRTUAL is the default rather than
STORED to match various other SQL products.  (The SQL standard makes
no specification about this, but it also doesn't know about VIRTUAL or
STORED.)  (Also, virtual views are the default, rather than
materialized views.)

Virtual generated columns are stored in tuples as null values.  (A
very early version of this patch had the ambition to not store them at
all.  But so much stuff breaks or gets confused if you have tuples
where a column in the middle is completely missing.  This is a
compromise, and it still saves space over being forced to use stored
generated columns.  If we ever find a way to improve this, a bit of
pg_upgrade cleverness could allow for upgrades to a newer scheme.)

The capabilities and restrictions of virtual generated columns are
mostly the same as for stored generated columns.  In some cases, this
patch keeps virtual generated columns more restricted than they might
technically need to be, to keep the two kinds consistent.  Some of
that could maybe be relaxed later after separate careful
considerations.

Some functionality that is currently not supported, but could possibly
be added as incremental features, some easier than others:

- index on or using a virtual column
- hence also no unique constraints on virtual columns
- extended statistics on virtual columns
- foreign-key constraints on virtual columns
- not-null constraints on virtual columns (check constraints are supported)
- ALTER TABLE / DROP EXPRESSION
- virtual column cannot have domain type
- virtual columns are not supported in logical replication

The tests in generated_virtual.sql have been copied over from
generated_stored.sql with the keyword replaced.  This way we can make
sure the behavior is mostly aligned, and the differences can be
visible.  Some tests for currently not supported features are
currently commented out.

Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Tested-by: Shlok Kyal <shlok.kyal.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/a368248e-69e4-40be-9c07-6c3b5880b0a6@eisentraut.org
2025-02-07 09:46:59 +01:00
..
expected Virtual generated columns 2025-02-07 09:46:59 +01:00
po Update copyright for 2025 2025-01-01 11:21:55 -05:00
sql Virtual generated columns 2025-02-07 09:46:59 +01:00
.gitignore Allow make check in PL directories 2011-02-15 06:52:12 +02:00
GNUmakefile Avoid bizarre meson behavior with backslashes in command arguments. 2024-11-11 12:20:08 -05:00
meson.build Update copyright for 2025 2025-01-01 11:21:55 -05:00
nls.mk Revert "Use wildcards instead of manually-maintained file lists in */nls.mk." 2022-07-13 14:29:10 -04:00
plc_perlboot.pl Update copyright for 2025 2025-01-01 11:21:55 -05:00
plc_trusted.pl Update copyright for 2025 2025-01-01 11:21:55 -05:00
plperl--1.0.sql Invent "trusted" extensions, and remove the pg_pltemplate catalog. 2020-01-29 18:42:43 -05:00
plperl.c Virtual generated columns 2025-02-07 09:46:59 +01:00
plperl.control Invent "trusted" extensions, and remove the pg_pltemplate catalog. 2020-01-29 18:42:43 -05:00
plperl.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
plperl_opmask.pl Update copyright for 2025 2025-01-01 11:21:55 -05:00
plperl_system.h Provide 64-bit ftruncate() and lseek() on Windows. 2025-01-09 15:00:58 +13:00
plperlu--1.0.sql Invent "trusted" extensions, and remove the pg_pltemplate catalog. 2020-01-29 18:42:43 -05:00
plperlu.control Create extension infrastructure for the core procedural languages. 2011-03-04 21:51:14 -05:00
ppport.h Remove HP-UX port. 2022-07-08 14:05:05 +12:00
README Stop generating plain-text INSTALL instructions. 2023-12-22 13:32:15 -05:00
SPI.xs Be more careful to avoid including system headers after perl.h 2022-08-27 14:45:18 +07:00
text2macro.pl Update copyright for 2025 2025-01-01 11:21:55 -05:00
Util.xs New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00

src/pl/plperl/README

PL/Perl allows you to write PostgreSQL functions and procedures in
Perl.  To include PL/Perl in the build use './configure --with-perl'.
To build from this directory use 'make all; make install'.  libperl
must have been built as a shared library, which is usually not the
case in standard installations.

Consult the PostgreSQL User's Guide for more information.