-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy patharraytype.html
More file actions
109 lines (90 loc) · 2.3 KB
/
arraytype.html
File metadata and controls
109 lines (90 loc) · 2.3 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<html>
<head>
<title>Postgres Array | Ebean ORM</title>
<meta name="layout" content="_layout2/base-docs.html"/>
<meta name="bread1" content="Database platforms" href="/docs/database"/>
<meta name="bread2" content="Postgres" href="/docs/database/postgres"/>
<meta name="bread3" content="Array type" href="/docs/database/postgres/arraytype"/>
<#assign n0_docs="active">
<#assign n1_platforms="active">
<#assign n2_postgres="active">
<#assign arraytype="active">
</head>
<body>
<h2>Array type</h2>
<p>
We can use <code>@DbArray</code> to map a Set or List of String, UUID, Integer or Long.
</p>
<#include "/_common/lang-buttons.html">
<div class="code-java">
<pre content="java">
@Entity
public class Customer {
@Id
private long id;
private String name;
@DbArray
private Set<|String> tags = new LinkedHashSet<>();
// getters and setters
}
</pre>
</div>
<div class="code-kt">
<pre content="kotlin">
@Entity
class Customer(name: String) {
@Id
var id: Long = 0
var name: String = name
@DbArray
var tags = emptyMutableSet<>();
}
</pre>
</div>
<h3>DDL for Array types</h3>
<p>
In the above example the <em>tags</em> property maps to a <em>varchar[]</em>.
</p>
<pre content="sql">
create table customer (
id bigserial not null,
name varchar(255) not null,
registered date,
tags varchar[],
version bigint not null,
when_created timestamptz not null,
when_modified timestamptz not null,
constraint pk_customer primary key (id)
);
</pre>
<h3>Array contains expression</h3>
<p>
Commonly we want to use the <em>contains</em> expression.
</p>
<#include "/_common/lang-buttons.html">
<div class="code-java">
<pre content="java">
final List<|Customer> customers
= new QCustomer()
.tags.contains("BLUE")
.findList();
</pre>
</div>
<div class="code-kt">
<pre content="kotlin">
val customers
= QCustomer()
.tags.contains("BLUE")
.findList()
</pre>
</div>
<p>
The SQL for the above query is:
</p>
<pre content="sql">
select t0.id, t0.name, t0.registered, t0.tags, t0.version, t0.when_created, t0.when_modified
from customer t0
where t0.tags @> array[?]; --bind(BLUE)
</pre>
</body>
</html>