File: generated.out

package info (click to toggle)
pg-rewrite 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 348 kB
  • sloc: ansic: 3,132; sql: 199; makefile: 17; sh: 2
file content (68 lines) | stat: -rw-r--r-- 1,934 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- Generated columns - some meaningful combinations of source and destination
-- columns.
CREATE TABLE tab7(
        i int primary key,
	j int,
	k int generated always as (i + 1) virtual,
	l int generated always AS (i + 1) stored,
	m int generated always AS (i + 1) virtual);
CREATE TABLE tab7_new(
        i int primary key,
        -- Override the value copied from the source table.
        j int generated always AS (i - 1) stored,
	-- Check that the expression is evaluated correctly on the source
	-- table.
	k int,
	-- The same for stored expression.
	l int,
	-- Override the value computed on the source table.
	m int generated always as (i - 1) virtual);
INSERT INTO tab7(i, j) VALUES (1, 1);
SELECT rewrite_table('tab7', 'tab7_new', 'tab7_orig');
 rewrite_table 
---------------
 
(1 row)

SELECT * FROM tab7;
 i | j | k | l | m 
---+---+---+---+---
 1 | 0 | 2 | 2 | 0
(1 row)

CREATE EXTENSION pageinspect;
-- HEAP_HASNULL indicates that the value of 'm' hasn't been copied from the
-- source table.
SELECT raw_flags
FROM heap_page_items(get_raw_page('tab7', 0)),
LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2);
                      raw_flags                       
------------------------------------------------------
 {HEAP_HASNULL,HEAP_XMIN_COMMITTED,HEAP_XMAX_INVALID}
(1 row)

-- For PG < 18, test without VIRTUAL columns.
CREATE TABLE tab8(
        i int primary key,
        j int,
        k int generated always AS (i + 1) stored);
CREATE TABLE tab8_new(
        i int primary key,
        -- Override the value copied from the source table.
        j int generated always AS (i - 1) stored,
        -- Check that the expression is evaluated correctly on the source
        -- table.
        k int);
INSERT INTO tab8(i, j) VALUES (1, 1);
SELECT rewrite_table('tab8', 'tab8_new', 'tab8_orig');
 rewrite_table 
---------------
 
(1 row)

SELECT * FROM tab8;
 i | j | k 
---+---+---
 1 | 0 | 2
(1 row)