File: sql_build.Rd

package info (click to toggle)
r-cran-dbplyr 2.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,376 kB
  • sloc: sh: 13; makefile: 2
file content (134 lines) | stat: -rw-r--r-- 3,462 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lazy-join-query.R, R/lazy-query.R,
%   R/lazy-select-query.R, R/lazy-set-op-query.R, R/query-join.R,
%   R/query-select.R, R/query-semi-join.R, R/query-set-op.R, R/sql-build.R
\name{lazy_multi_join_query}
\alias{lazy_multi_join_query}
\alias{lazy_semi_join_query}
\alias{lazy_query}
\alias{lazy_select_query}
\alias{lazy_set_op_query}
\alias{join_query}
\alias{select_query}
\alias{semi_join_query}
\alias{set_op_query}
\alias{sql_build}
\alias{sql_render}
\alias{sql_optimise}
\title{Build and render SQL from a sequence of lazy operations}
\usage{
lazy_multi_join_query(
  x,
  joins,
  table_names,
  vars,
  group_vars = op_grps(x),
  order_vars = op_sort(x),
  frame = op_frame(x),
  call = caller_env()
)

lazy_semi_join_query(
  x,
  y,
  vars,
  anti,
  by,
  na_matches = c("never", "na"),
  group_vars = op_grps(x),
  order_vars = op_sort(x),
  frame = op_frame(x),
  call = caller_env()
)

lazy_query(
  query_type,
  x,
  ...,
  group_vars = op_grps(x),
  order_vars = op_sort(x),
  frame = op_frame(x)
)

lazy_select_query(
  x,
  select = NULL,
  where = NULL,
  group_by = NULL,
  having = NULL,
  order_by = NULL,
  limit = NULL,
  distinct = FALSE,
  group_vars = NULL,
  order_vars = NULL,
  frame = NULL,
  select_operation = c("select", "mutate", "summarise"),
  message_summarise = NULL
)

lazy_set_op_query(x, y, type, all, call = caller_env())

join_query(
  x,
  y,
  vars,
  type = "inner",
  by = NULL,
  suffix = c(".x", ".y"),
  na_matches = FALSE
)

select_query(
  from,
  select = sql("*"),
  where = character(),
  group_by = character(),
  having = character(),
  window = character(),
  order_by = character(),
  limit = NULL,
  distinct = FALSE
)

semi_join_query(x, y, vars, anti = FALSE, by = NULL, na_matches = FALSE)

set_op_query(x, y, type, all = FALSE)

sql_build(op, con = NULL, ...)

sql_render(query, con = NULL, ..., subquery = FALSE, lvl = 0, cte = FALSE)

sql_optimise(x, con = NULL, ..., subquery = FALSE)
}
\arguments{
\item{...}{Other arguments passed on to the methods. Not currently used.}

\item{op}{A sequence of lazy operations}

\item{con}{A database connection. The default \code{NULL} uses a set of
rules that should be very similar to ANSI 92, and allows for testing
without an active database connection.}

\item{subquery}{Is this SQL going to be used in a subquery?
This is important because you can place a bare table name in a subquery
and  ORDER BY does not work in subqueries.}
}
\description{
\code{sql_build()} creates a \code{select_query} S3 object, that is rendered
to a SQL string by \code{sql_render()}. The output from \code{sql_build()} is
designed to be easy to test, as it's database agnostic, and has
a hierarchical structure. Outside of testing, however, you should
always call \code{sql_render()}.
}
\details{
\code{sql_build()} is generic over the lazy operations, \link{lazy_ops},
and generates an S3 object that represents the query. \code{sql_render()}
takes a query object and then calls a function that is generic
over the database. For example, \code{sql_build.op_mutate()} generates
a \code{select_query}, and \code{sql_render.select_query()} calls
\code{sql_select()}, which has different methods for different databases.
The default methods should generate ANSI 92 SQL where possible, so you
backends only need to override the methods if the backend is not ANSI
compliant.
}
\keyword{internal}