Skip to content

Commit 3607ec6

Browse files
author
Guilhem Charles
committed
add parameters aggregation to named queries docs
1 parent 1c695f5 commit 3607ec6

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎content/pages/named_queries.md‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,55 @@ the query's name. You can put quotes around arguments that include spaces.
5656
```
5757
\n user_by_name "Skelly McDermott"
5858
```
59+
60+
## Parameters Aggregation
61+
62+
Named queries also supports parameters aggregation via two placeholders.
63+
`$*` for raw aggregation and `$@` for string aggregation.
64+
The former use the raw value of aggregated parameters, the later will quote
65+
each aggregated value.
66+
67+
### Raw Aggregation
68+
```
69+
\ns users_by_age select * from users where id in ($*)
70+
```
71+
72+
When you call a named query with parameters, just add any (at least one)
73+
parameters after the query's name.
74+
75+
```
76+
\n users_by_age 42 1337
77+
```
78+
79+
### String Aggregation
80+
```
81+
\ns users_by_categories select * from users where category in ($@)
82+
```
83+
84+
When you call a named query with parameters, just add any (at least one)
85+
the parameters after the query's name.
86+
You can put quotes around arguments that include spaces.
87+
88+
```
89+
\n users_by_categories "home user" "mobile user" superuser
90+
```
91+
92+
## Combining Positional Parameters and Parameters Aggregation
93+
It is possible to combine both positional parameters and parameters aggregation.
94+
The positional parameters substitution takes place before the aggregation.
95+
Which means positional parameters can be placed after parameters aggregation
96+
in the query ; see example bellow.
97+
Please note that the positional parameters will not be part of the aggregation taking place afterwards!
98+
99+
```
100+
\ns users_by_categories_and_age select * from users where name in ($@) and age = $1
101+
```
102+
103+
```
104+
\n users_by_categories_and_age 42 "Skelly McDermott" "François Pignon"
105+
```
106+
107+
The query after substitution would be:
108+
```
109+
select * from users where name in ('Skelly McDermott', 'François Pignon') and age = 42
110+
```

0 commit comments

Comments
(0)