File: plpgsql_array.sql

package info (click to toggle)
libpg-query 15-4.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 28,320 kB
  • sloc: ansic: 163,581; sql: 69,531; ruby: 1,363; makefile: 247; cpp: 220
file content (79 lines) | stat: -rw-r--r-- 2,300 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
75
76
77
78
79
--
-- Tests for PL/pgSQL handling of array variables
--
-- We also check arrays of composites here, so this has some overlap
-- with the plpgsql_record tests.
--

create type complex as (r float8, i float8);
create type quadarray as (c1 complex[], c2 complex);

do $$ declare a int[];
begin a := array[1,2]; a[3] := 4; raise notice 'a = %', a; end$$;

do $$ declare a int[];
begin a[3] := 4; raise notice 'a = %', a; end$$;

do $$ declare a int[];
begin a[1][4] := 4; raise notice 'a = %', a; end$$;

do $$ declare a int[];
begin a[1] := 23::text; raise notice 'a = %', a; end$$;  -- lax typing

do $$ declare a int[];
begin a := array[1,2]; a[2:3] := array[3,4]; raise notice 'a = %', a; end$$;

do $$ declare a int[];
begin a := array[1,2]; a[2] := a[2] + 1; raise notice 'a = %', a; end$$;

do $$ declare a int[];
begin a[1:2] := array[3,4]; raise notice 'a = %', a; end$$;

do $$ declare a int[];
begin a[1:2] := 4; raise notice 'a = %', a; end$$;  -- error

do $$ declare a complex[];
begin a[1] := (1,2); a[1].i := 11; raise notice 'a = %', a; end$$;

do $$ declare a complex[];
begin a[1].i := 11; raise notice 'a = %, a[1].i = %', a, a[1].i; end$$;

-- perhaps this ought to work, but for now it doesn't:
do $$ declare a complex[];
begin a[1:2].i := array[11,12]; raise notice 'a = %', a; end$$;

do $$ declare a quadarray;
begin a.c1[1].i := 11; raise notice 'a = %, a.c1[1].i = %', a, a.c1[1].i; end$$;

do $$ declare a int[];
begin a := array_agg(x) from (values(1),(2),(3)) v(x); raise notice 'a = %', a; end$$;

create temp table onecol as select array[1,2] as f1;

do $$ declare a int[];
begin a := f1 from onecol; raise notice 'a = %', a; end$$;

do $$ declare a int[];
begin a := * from onecol for update; raise notice 'a = %', a; end$$;

-- error cases:

do $$ declare a int[];
begin a := from onecol; raise notice 'a = %', a; end$$;

do $$ declare a int[];
begin a := f1, f1 from onecol; raise notice 'a = %', a; end$$;

insert into onecol values(array[11]);

do $$ declare a int[];
begin a := f1 from onecol; raise notice 'a = %', a; end$$;

do $$ declare a int[];
begin a := f1 from onecol limit 1; raise notice 'a = %', a; end$$;

do $$ declare a real;
begin a[1] := 2; raise notice 'a = %', a; end$$;

do $$ declare a complex;
begin a.r[1] := 2; raise notice 'a = %', a; end$$;