sql_funcs.yml 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. - type: Generic
  2. description: Generic functions can typically take arguments of any type.
  3. functions:
  4. - signature: CAST (cast_expr) -> T
  5. description: Value as type `T`
  6. url: /sql/functions/cast
  7. - signature: 'coalesce(x: T...) -> T?'
  8. description: First non-_NULL_ arg, or _NULL_ if all are _NULL_.
  9. - signature: 'greatest(x: T...) -> T?'
  10. description: The maximum argument, or _NULL_ if all are _NULL_.
  11. - signature: 'least(x: T...) -> T?'
  12. description: The minimum argument, or _NULL_ if all are _NULL_.
  13. - signature: 'nullif(x: T, y: T) -> T?'
  14. description: _NULL_ if `x == y`, else `x`.
  15. - type: Aggregate
  16. description: Aggregate functions take one or more of the same element type as arguments.
  17. functions:
  18. - signature: 'array_agg(x: T) -> T[]'
  19. description: Aggregate values (including nulls) as an array
  20. url: /sql/functions/array_agg
  21. - signature: 'avg(x: T) -> U'
  22. description: |
  23. Average of `T`'s values.
  24. Returns `numeric` if `x` is `int`, `double` if `x` is `real`, else returns
  25. same type as `x`.
  26. - signature: 'bool_and(x: T) -> T'
  27. description: _NULL_ if all values of `x` are _NULL_, otherwise true if all values of `x` are true, otherwise false.
  28. - signature: 'bool_or(x: T) -> T'
  29. description: _NULL_ if all values of `x` are _NULL_, otherwise true if any values of `x` are true, otherwise false.
  30. - signature: 'count(x: T) -> bigint'
  31. description: Number of non-_NULL_ inputs.
  32. - signature: jsonb_agg(expression) -> jsonb
  33. description: Aggregate values (including nulls) as a jsonb array
  34. url: /sql/functions/jsonb_agg
  35. - signature: jsonb_object_agg(keys, values) -> jsonb
  36. description: Aggregate keys and values (including nulls) as a jsonb object
  37. url: /sql/functions/jsonb_object_agg
  38. - signature: 'max(x: T) -> T'
  39. description: Maximum value among `T`.
  40. - signature: 'min(x: T) -> T'
  41. description: Minimum value among `T`.
  42. - signature: 'stddev(x: T) -> U'
  43. description: |
  44. Historical alias for `stddev_samp`. *(imprecise)*
  45. Returns `numeric` if `x` is `int`, `double` if `x` is `real`, else returns
  46. same type as `x`.
  47. - signature: 'stddev_pop(x: T) -> U'
  48. description: |
  49. Population standard deviation of `T`'s values. *(imprecise)*
  50. Returns `numeric` if `x` is `int`, `double` if `x` is `real`, else returns
  51. same type as `x`.
  52. - signature: 'stddev_samp(x: T) -> U'
  53. description: |
  54. Sample standard deviation of `T`'s values. *(imprecise)*
  55. Returns `numeric` if `x` is `int`, `double` if `x` is `real`, else returns
  56. same type as `x`.
  57. - signature: 'string_agg(value: text, delimiter: text) -> text'
  58. description: Concatenates the non-null input values into text. Each value after the first is preceded by the corresponding delimiter
  59. url: /sql/functions/string_agg
  60. - signature: 'sum(x: T) -> U'
  61. description: |
  62. Sum of `T`'s values
  63. Returns `bigint` if `x` is `int` or `smallint`, `numeric` if `x` is `bigint` or `uint8`,
  64. `uint8` if `x` is `uint4` or `uint2`, else returns same type as `x`.
  65. - signature: 'variance(x: T) -> U'
  66. description: |
  67. Historical alias for `var_samp`. *(imprecise)*
  68. Returns `numeric` if `x` is `int`, `double` if `x` is `real`, else returns
  69. same type as `x`.
  70. - signature: 'var_pop(x: T) -> U'
  71. description: |
  72. Population variance of `T`'s values. *(imprecise)*
  73. Returns `numeric` if `x` is `int`, `double` if `x` is `real`, else returns
  74. same type as `x`.
  75. - signature: 'var_samp(x: T) -> U'
  76. description: |
  77. Sample variance of `T`'s values. *(imprecise)*
  78. Returns `numeric` if `x` is `int`, `double` if `x` is `real`, else returns
  79. same type as `x`.
  80. - type: List
  81. description: List functions take [`list`](../types/list) arguments, and are [polymorphic](../types/list/#polymorphism).
  82. functions:
  83. - signature: 'list_agg(x: any) -> L'
  84. description: Aggregate values (including nulls) as a list
  85. url: /sql/functions/list_agg
  86. - signature: 'list_append(l: listany, e: listelementany) -> L'
  87. description: Appends `e` to `l`.
  88. - signature: 'list_cat(l1: listany, l2: listany) -> L'
  89. description: Concatenates `l1` and `l2`.
  90. - signature: 'list_length(l: listany) -> int'
  91. description: Return the number of elements in `l`.
  92. - signature: 'list_prepend(e: listelementany, l: listany) -> listany'
  93. description: Prepends `e` to `l`.
  94. - type: Map
  95. description: Map functions take [`map`](../types/map) arguments, and are [polymorphic](../types/#polymorphism).
  96. functions:
  97. - signature: 'map_length(m: mapany) -> int'
  98. description: Return the number of elements in `m`.
  99. - signature: 'map_build(kvs: list record(text, T)) -> map[text=>T]'
  100. description: |
  101. Builds a map from a list of records whose fields are two elements, the
  102. first of which is `text`. In the face of duplicate keys, `map_build` retains
  103. value from the record in the latest positition. This function is
  104. purpose-built to process [Kafka headers](/sql/create-source/kafka/#headers).
  105. version-added: v0.86
  106. - signature: 'map_agg(keys: text, values: T) -> map[text=>T]'
  107. description: Aggregate keys and values (including nulls) as a map
  108. url: /sql/functions/map_agg
  109. - type: Numbers
  110. description: Number functions take number-like arguments, e.g. [`int`](../types/int),
  111. [`float`](../types/float), [`numeric`](../types/numeric), unless otherwise specified.
  112. functions:
  113. - signature: 'abs(x: N) -> N'
  114. description: The absolute value of `x`.
  115. - signature: 'cbrt(x: double precision) -> double precision'
  116. description: The cube root of `x`.
  117. - signature: 'ceil(x: N) -> N'
  118. description: The smallest integer >= `x`.
  119. - signature: 'ceiling(x: N) -> N'
  120. description: "Alias of `ceil`."
  121. - signature: 'exp(x: N) -> N'
  122. description: Exponential of `x` (e raised to the given power)
  123. - signature: 'floor(x: N) -> N'
  124. description: The largest integer <= `x`.
  125. - signature: 'ln(x: double precision) -> double precision'
  126. description: Natural logarithm of `x`.
  127. - signature: 'ln(x: numeric) -> numeric'
  128. description: Natural logarithm of `x`.
  129. - signature: 'log(x: double precision) -> double precision'
  130. description: Base 10 logarithm of `x`.
  131. - signature: 'log(x: numeric) -> numeric'
  132. description: Base 10 logarithm of `x`.
  133. - signature: 'log10(x: double precision) -> double precision'
  134. description: Base 10 logarithm of `x`, same as `log`.
  135. - signature: 'log10(x: numeric) -> numeric'
  136. description: Base 10 logarithm of `x`, same as `log`.
  137. - signature: 'log(b: numeric, x: numeric) -> numeric'
  138. description: Base `b` logarithm of `x`.
  139. - signature: 'mod(x: N, y: N) -> N'
  140. description: "`x % y`"
  141. - signature: 'pow(x: double precision, y: double precision) -> double precision'
  142. description: "Alias of `power`."
  143. - signature: 'pow(x: numeric, y: numeric) -> numeric'
  144. description: "Alias of `power`."
  145. - signature: 'power(x: double precision, y: double precision) -> double precision'
  146. description: "`x` raised to the power of `y`."
  147. - signature: 'power(x: numeric, y: numeric) -> numeric'
  148. description: "`x` raised to the power of `y`."
  149. - signature: 'round(x: N) -> N'
  150. description: |
  151. `x` rounded to the nearest whole number.
  152. If `N` is `real` or `double precision`, rounds ties to the nearest even number.
  153. If `N` is `numeric`, rounds ties away from zero.
  154. - signature: 'round(x: numeric, y: int) -> numeric'
  155. description: "`x` rounded to `y` decimal places, while retaining the same
  156. [`numeric`](../types/numeric) scale; rounds ties away from zero."
  157. - signature: 'sqrt(x: numeric) -> numeric'
  158. description: The square root of `x`.
  159. - signature: 'sqrt(x: double precision) -> double precision'
  160. description: The square root of `x`.
  161. - signature: 'trunc(x: N) -> N'
  162. description: "`x` truncated toward zero to a whole number."
  163. - type: Trigonometric
  164. description: Trigonometric functions take and return `double precision` values.
  165. functions:
  166. - signature: 'cos(x: double precision) -> double precision'
  167. description: The cosine of `x`, with `x` in radians.
  168. - signature: 'acos(x: double precision) -> double precision'
  169. description: The inverse cosine of `x`, result in radians.
  170. - signature: 'cosh(x: double precision) -> double precision'
  171. description: The hyperbolic cosine of `x`, with `x` as a hyperbolic angle.
  172. - signature: 'acosh(x: double precision) -> double precision'
  173. description: The inverse hyperbolic cosine of `x`.
  174. - signature: 'cot(x: double precision) -> double precision'
  175. description: The cotangent of `x`, with `x` in radians.
  176. - signature: 'sin(x: double precision) -> double precision'
  177. description: The sine of `x`, with `x` in radians.
  178. - signature: 'asin(x: double precision) -> double precision'
  179. description: The inverse sine of `x`, result in radians.
  180. - signature: 'sinh(x: double precision) -> double precision'
  181. description: The hyperbolic sine of `x`, with `x` as a hyperbolic angle.
  182. - signature: 'asinh(x: double precision) -> double precision'
  183. description: The inverse hyperbolic sine of `x`.
  184. - signature: 'tan(x: double precision) -> double precision'
  185. description: The tangent of `x`, with `x` in radians.
  186. - signature: 'atan(x: double precision) -> double precision'
  187. description: The inverse tangent of `x`, result in radians.
  188. - signature: 'tanh(x: double precision) -> double precision'
  189. description: The hyperbolic tangent of `x`, with `x` as a hyperbolic angle.
  190. - signature: 'atanh(x: double precision) -> double precision'
  191. description: The inverse hyperbolic tangent of `x`.
  192. - signature: 'radians(x: double precision) -> double precision'
  193. description: Converts degrees to radians.
  194. - signature: 'degrees(x: double precision) -> double precision'
  195. description: Converts radians to degrees.
  196. - type: String
  197. functions:
  198. - signature: 'ascii(s: str) -> int'
  199. description: The ASCII value of `s`'s left-most character.
  200. - signature: 'btrim(s: str) -> str'
  201. description: Trim all spaces from both sides of `s`.
  202. - signature: 'btrim(s: str, c: str) -> str'
  203. description: Trim any character in `c` from both sides of `s`.
  204. - signature: 'bit_count(b: bytea) -> int'
  205. description: Returns the number of bits set in the bit string (aka _popcount_).
  206. - signature: 'bit_length(s: str) -> int'
  207. description: Number of bits in `s`.
  208. - signature: 'bit_length(b: bytea) -> int'
  209. description: Number of bits in `b`.
  210. - signature: 'char_length(s: str) -> int'
  211. description: Number of code points in `s`.
  212. - signature: 'chr(i: int) -> str'
  213. description: |
  214. Character with the given Unicode codepoint.
  215. Only supports codepoints that can be encoded in UTF-8.
  216. The NULL (0) character is not allowed.
  217. - signature: 'concat(f: any, r: any...) -> text'
  218. description: Concatenates the text representation of non-NULL arguments.
  219. - signature: 'concat_ws(sep: str, f: any, r: any...) -> text'
  220. description: Concatenates the text representation of non-NULL arguments from `f` and `r` separated by `sep`.
  221. - signature: 'convert_from(b: bytea, src_encoding: text) -> text'
  222. description: Convert data `b` from original encoding specified by `src_encoding` into `text`.
  223. - signature: 'decode(s: text, format: text) -> bytea'
  224. description: Decode `s` using the specified textual representation
  225. url: /sql/functions/encode
  226. - signature: 'encode(b: bytea, format: text) -> text'
  227. description: Encode `b` using the specified textual representation
  228. url: /sql/functions/encode
  229. - signature: 'get_bit(b: bytea, n: int) -> int'
  230. description: Return the `n`th bit from `b`, where the left-most bit in `b` is at the 0th position.
  231. - signature: 'get_byte(b: bytea, n: int) -> int'
  232. description: Return the `n`th byte from `b`, where the left-most byte in `b` is at the 0th position.
  233. - signature: 'constant_time_eq(a: bytea, b: bytea) -> bool'
  234. description: Returns `true` if the arrays are identical, otherwise returns `false`. The implementation mitigates timing attacks by making a best-effort attempt to execute in constant time if the arrays have the same length, regardless of their contents.
  235. - signature: 'constant_time_eq(a: text, b: text) -> bool'
  236. description: Returns `true` if the strings are identical, otherwise returns `false`. The implementation mitigates timing attacks by making a best-effort attempt to execute in constant time if the strings have the same length, regardless of their contents.
  237. - signature: 'initcap(a: text) -> text'
  238. description: |
  239. Returns `a` with the first character of every word in upper case and all
  240. other characters in lower case. Words are separated by non-alphanumeric
  241. characters.
  242. version-added: v0.97
  243. - signature: 'left(s: str, n: int) -> str'
  244. description: The first `n` characters of `s`. If `n` is negative, all but the last `|n|` characters of `s`.
  245. - signature: 'length(s: str) -> int'
  246. description: Number of code points in `s`.
  247. url: /sql/functions/length
  248. - signature: 'length(b: bytea) -> int'
  249. description: Number of bytes in `s`.
  250. url: /sql/functions/length
  251. - signature: 'length(s: bytea, encoding_name: str) -> int'
  252. description: Number of code points in `s` after encoding
  253. url: /sql/functions/length
  254. - signature: 'lower(s: str) -> str'
  255. description: Convert `s` to lowercase.
  256. - signature: 'lpad(s: str, len: int) -> str'
  257. description: "Prepend `s` with spaces up to length `len`,
  258. or right truncate if `len` is less than the length of `s`."
  259. - signature: 'lpad(s: str, len: int, p: str) -> str'
  260. description: "Prepend `s` with characters pulled from `p` up to length `len`,
  261. or right truncate if `len` is less than the length of `s`."
  262. - signature: 'ltrim(s: str) -> str'
  263. description: Trim all spaces from the left side of `s`.
  264. - signature: 'ltrim(s: str, c: str) -> str'
  265. description: Trim any character in `c` from the left side of `s`.
  266. - signature: 'octet_length(s: str) -> int'
  267. description: Number of bytes in `s`.
  268. - signature: 'octet_length(b: bytea) -> int'
  269. description: Number of bytes in `b`.
  270. - signature: 'parse_ident(ident: str[, strict_mode: bool]) -> str[]'
  271. description: |
  272. Given a qualified identifier like `a."b".c`, splits into an array of the
  273. constituent identifiers with quoting removed and escape sequences decoded.
  274. Extra characters after the last identifier are ignored unless the
  275. `strict_mode` parameter is `true` (defaults to `false`).
  276. - signature: 'position(sub: str IN s: str) -> int'
  277. description: The starting index of `sub` within `s` or `0` if `sub` is not a substring of `s`.
  278. - signature: 'regexp_match(haystack: str, needle: str [, flags: str]]) -> str[]'
  279. description: |
  280. Matches the regular expression `needle` against haystack, returning a
  281. string array that contains the value of each capture group specified in
  282. `needle`, in order. If `flags` is set to the string `i` matches
  283. case-insensitively.
  284. - signature: 'regexp_replace(source: str, pattern: str, replacement: str [, flags: str]]) -> str'
  285. description: |
  286. Replaces the first occurrence of `pattern` with `replacement` in `source`.
  287. No match will return `source` unchanged.
  288. If `flags` is set to `g`, all occurrences are replaced.
  289. If `flags` is set to `i`, matches case-insensitively.
  290. `$N` or `$name` in `replacement` can be used to match capture groups.
  291. `${N}` must be used to disambiguate capture group indexes from names if other characters follow `N`.
  292. A `$$` in `replacement` will write a literal `$`.
  293. See the [rust regex docs](https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace) for more details about replacement.
  294. - signature: "regexp_matches(haystack: str, needle: str [, flags: str]]) -> str[]"
  295. description: |
  296. Matches the regular expression `needle` against haystack, returning a
  297. string array that contains the value of each capture group specified in
  298. `needle`, in order. If `flags` is set to the string `i` matches
  299. case-insensitively. If `flags` is set to the string `g` all matches are
  300. returned, otherwise only the first match is returned. Without the `g`
  301. flag, the behavior is the same as `regexp_match`.
  302. - signature: 'regexp_split_to_array(text: str, pattern: str [, flags: str]]) -> str[]'
  303. description: |
  304. Splits `text` by the regular expression `pattern` into an array.
  305. If `flags` is set to `i`, matches case-insensitively.
  306. - signature: 'repeat(s: str, n: int) -> str'
  307. description: Replicate the string `n` times.
  308. - signature: 'replace(s: str, f: str, r: str) -> str'
  309. description: "`s` with all instances of `f` replaced with `r`."
  310. - signature: 'right(s: str, n: int) -> str'
  311. description: The last `n` characters of `s`. If `n` is negative, all but the first `|n|` characters of `s`.
  312. - signature: 'rtrim(s: str) -> str'
  313. description: Trim all spaces from the right side of `s`.
  314. - signature: 'rtrim(s: str, c: str) -> str'
  315. description: Trim any character in `c` from the right side of `s`.
  316. - signature: 'split_part(s: str, d: s, i: int) -> str'
  317. description: Split `s` on delimiter `d`. Return the `str` at index `i`, counting from 1.
  318. - signature: 'starts_with(s: str, prefix: str) -> bool'
  319. description: Report whether `s` starts with `prefix`.
  320. - signature: 'substring(s: str, start_pos: int) -> str'
  321. description: Substring of `s` starting at `start_pos`
  322. url: /sql/functions/substring
  323. - signature: 'substring(s: str, start_pos: int, l: int) -> str'
  324. description: Substring starting at `start_pos` of length `l`
  325. url: /sql/functions/substring
  326. - signature: "substring('s' [FROM 'start_pos']? [FOR 'l']?) -> str"
  327. description: Substring starting at `start_pos` of length `l`
  328. url: /sql/functions/substring
  329. - signature: "translate(s: str, from: str, to: str) -> str"
  330. description: |
  331. Any character in `s` that matches a character in `from` is replaced by the corresponding character in `to`.
  332. If `from` is longer than `to`, occurrences of the extra characters in `from` are removed.
  333. - signature: "trim([BOTH | LEADING | TRAILING]? ['c'? FROM]? 's') -> str"
  334. description: |
  335. Trims any character in `c` from `s` on the specified side.
  336. Defaults:
  337. &bull; Side: `BOTH`
  338. &bull; `'c'`: `' '` (space)
  339. - signature: 'try_parse_monotonic_iso8601_timestamp(s: str) -> timestamp'
  340. description: |
  341. Parses a specific subset of ISO8601 timestamps, returning `NULL` instead of
  342. error on failure: `YYYY-MM-DDThh:mm:ss.sssZ`
  343. url: /sql/functions/pushdown
  344. - signature: 'upper(s: str) -> str'
  345. description: Convert `s` to uppercase.
  346. - signature: 'reverse(s: str) -> str'
  347. description: Reverse the characters in `s`.
  348. - signature: 'string_to_array(s: str, delimiter: str [, null_string: str]) -> str[]'
  349. description: |
  350. Splits the string at occurrences of delimiter and returns a text array of
  351. the split segments.
  352. If `delimiter` is NULL, each character in the string will become a
  353. separate element in the array.
  354. If `delimiter` is an empty string, then the string is treated as a single
  355. field.
  356. If `null_string` is supplied and is not NULL, fields matching that string
  357. are replaced by NULL.
  358. For example: `string_to_array('xx~~yy~~zz', '~~', 'yy')` → `{xx,NULL,zz}`
  359. - type: Scalar
  360. description: Scalar functions take a list of scalar expressions
  361. functions:
  362. - signature: 'expression bool_op ALL(s: Scalars) -> bool'
  363. description: "`true` if applying [bool_op](#boolean-operators) to `expression` and every
  364. value of `s` evaluates to `true`."
  365. - signature: 'expression bool_op ANY(s: Scalars) -> bool'
  366. description: |
  367. `true` if applying [bool_op](#boolean-operators) to `expression` and any
  368. value of `s` evaluates to `true`. Avoid using in equi-join conditions as
  369. its use in the equi-join condition can lead to a significant increase in
  370. memory usage. See [idiomatic Materialize
  371. SQL](/transform-data/idiomatic-materialize-sql/any) for the alternative.
  372. - signature: 'expression IN(s: Scalars) -> bool'
  373. description: "`true` for each value in `expression` if it matches at least one
  374. element of `s`."
  375. - signature: 'expression NOT IN(s: Scalars) -> bool'
  376. description: "`true` for each value in `expression` if it does not match any elements
  377. of `s`."
  378. - signature: 'expression bool_op SOME(s: Scalars) -> bool'
  379. description: "`true` if applying [bool_op](#boolean-operators) to `expression` and any value
  380. of `s` evaluates to `true`."
  381. - type: Subquery
  382. description: Subquery functions take a query, e.g. [`SELECT`](/sql/select)
  383. functions:
  384. - signature: 'expression bool_op ALL(s: Query) -> bool'
  385. description: "`s` must return exactly one column; `true` if applying [bool_op](#boolean-operators)
  386. to `expression` and every value of `s` evaluates to `true`."
  387. - signature: 'expression bool_op ANY(s: Query) -> bool'
  388. description: "`s` must return exactly one column; `true` if applying [bool_op](#boolean-operators)
  389. to `expression` and any value of `s` evaluates to `true`."
  390. - signature: 'csv_extract(num_csv_col: int, col_name: string) -> col1: string, ... coln: string'
  391. description: Extracts separated values from a column containing a CSV file formatted as a string
  392. url: /sql/functions/csv_extract
  393. - signature: 'EXISTS(s: Query) -> bool'
  394. description: "`true` if `s` returns at least one row."
  395. - signature: 'expression IN(s: Query) -> bool'
  396. description: "`s` must return exactly one column; `true` for each value in `expression`
  397. if it matches at least one element of `s`."
  398. - signature: 'NOT EXISTS(s: Query) -> bool'
  399. description: "`true` if `s` returns zero rows."
  400. - signature: 'expression NOT IN(s: Query) -> bool'
  401. description: "`s` must return exactly one column; `true` for each value in `expression`
  402. if it does not match any elements of `s`."
  403. - signature: 'expression bool_op SOME(s: Query) -> bool'
  404. description: "`s` must return exactly one column; `true` if applying [bool_op](#boolean-operators)
  405. to `expression` and any value of `s` evaluates to `true`."
  406. - type: Date and time
  407. description: Time functions take or produce a time-like type, e.g. [`date`](../types/date),
  408. [`timestamp`](../types/timestamp), [`timestamp with time zone`](../types/timestamptz).
  409. functions:
  410. - signature: 'age(timestamp, timestamp) -> interval'
  411. description: 'Subtracts one timestamp from another, producing a "symbolic" result that uses years and months, rather than just days.'
  412. - signature: current_timestamp() -> timestamptz
  413. description: 'The `timestamp with time zone` representing when the query was executed.'
  414. unmaterializable: true
  415. - signature: 'date_bin(stride: interval, source: timestamp, origin: timestamp) -> timestamp'
  416. description: Align `source` with `origin` along `stride`
  417. url: /sql/functions/date-bin
  418. - signature: 'date_trunc(time_component: str, val: timestamp) -> timestamp'
  419. description: Largest `time_component` <= `val`
  420. url: /sql/functions/date-trunc
  421. - signature: 'date_trunc(time_component: str, val: interval) -> interval'
  422. description: Largest `time_component` <= `val`
  423. url: /sql/functions/date-trunc
  424. - signature: EXTRACT(extract_expr) -> numeric
  425. description: Specified time component from value
  426. url: /sql/functions/extract
  427. - signature: 'date_part(time_component: str, val: timestamp) -> float'
  428. description: Specified time component from value
  429. url: /sql/functions/date-part
  430. - signature: mz_now() -> mz_timestamp
  431. description: |
  432. The logical time at which a query executes. Used for temporal filters and query timestamp introspection
  433. url: /sql/functions/now_and_mz_now
  434. unmaterializable_unless_temporal_filter: true
  435. - signature: now() -> timestamptz
  436. description: 'The `timestamp with time zone` representing when the query was executed'
  437. url: /sql/functions/now_and_mz_now
  438. unmaterializable: true
  439. - signature: timestamp AT TIME ZONE zone -> timestamptz
  440. description: 'Converts `timestamp` to the specified time zone, expressed as an offset from UTC'
  441. url: /sql/functions/timezone-and-at-time-zone
  442. known_time_zone_limitation_cast: true
  443. - signature: timestamptz AT TIME ZONE zone -> timestamp
  444. description: 'Converts `timestamp with time zone` from UTC to the specified time zone, expressed as the local time'
  445. url: /sql/functions/timezone-and-at-time-zone
  446. known_time_zone_limitation_cast: true
  447. - signature: timezone(zone, timestamp) -> timestamptz
  448. description: 'Converts `timestamp` to specified time zone, expressed as an offset from UTC'
  449. url: /sql/functions/timezone-and-at-time-zone
  450. known_time_zone_limitation_cast: true
  451. - signature: timezone(zone, timestamptz) -> timestamp
  452. description: 'Converts `timestamp with time zone` from UTC to specified time zone, expressed as the local time'
  453. url: /sql/functions/timezone-and-at-time-zone
  454. known_time_zone_limitation_cast: true
  455. - signature: |-
  456. timezone_offset(zone: str, when: timestamptz) ->
  457. (abbrev: str, base_utc_offset: interval, dst_offset: interval)
  458. description: |
  459. Describes a time zone's offset from UTC at a specified moment.
  460. `zone` must be a valid IANA Time Zone Database identifier.
  461. `when` is a `timestamp with time zone` that specifies the moment at which to determine `zone`'s offset from UTC.
  462. `abbrev` is the abbreviation for `zone` that is in use at the specified moment (e.g., `EST` or `EDT`).
  463. `base_utc_offset` is the base offset from UTC at the specified moment (e.g., `-5 hours`). Positive offsets mean east of Greenwich; negative offsets mean west of Greenwich.
  464. `dst_offset` is the additional offset at the specified moment due to Daylight Saving Time rules (e.g., `1 hours`). If non-zero, Daylight Saving Time is in effect.
  465. - signature: 'to_timestamp(val: double precision) -> timestamptz'
  466. description: Converts Unix epoch (seconds since 00:00:00 UTC on January 1, 1970)
  467. to timestamp.
  468. - signature: 'to_char(val: timestamp, format: str)'
  469. description: Converts a timestamp into a string using the specified format
  470. url: /sql/functions/to_char
  471. - signature: 'justify_days(val: interval) -> interval'
  472. description: Adjust interval so 30-day time periods are represented as months
  473. url: /sql/functions/justify-days
  474. - signature: 'justify_hours(val: interval) -> interval'
  475. description: Adjust interval so 24-hour time periods are represented as days
  476. url: /sql/functions/justify-hours
  477. - signature: 'justify_interval(val: interval) -> interval'
  478. description: Adjust interval using justify_days and justify_hours, with additional sign adjustments
  479. url: /sql/functions/justify-interval
  480. - type: UUID
  481. functions:
  482. - signature: 'uuid_generate_v5(namespace: uuid, name: text) -> uuid'
  483. description: 'Generates a [version 5 UUID](https://www.rfc-editor.org/rfc/rfc4122#page-7) (SHA-1) in the given namespace using
  484. the specified input name.'
  485. - type: JSON
  486. functions:
  487. - signature: jsonb_agg(expression) -> jsonb
  488. description: Aggregate values (including nulls) as a jsonb array
  489. url: /sql/functions/jsonb_agg
  490. - signature: 'jsonb_array_elements(j: jsonb) -> Col<jsonb>'
  491. description: "`j`'s elements if `j` is an array"
  492. url: /sql/types/jsonb#jsonb_array_elements
  493. - signature: 'jsonb_array_elements_text(j: jsonb) -> Col<string>'
  494. description: "`j`'s elements if `j` is an array"
  495. url: /sql/types/jsonb#jsonb_array_elements_text
  496. - signature: 'jsonb_array_length(j: jsonb) -> int'
  497. description: Number of elements in `j`'s outermost array
  498. url: /sql/types/jsonb#jsonb_array_length
  499. - signature: 'jsonb_build_array(x: ...) -> jsonb'
  500. description: Output each element of `x` as a `jsonb` array. Elements can be of heterogenous
  501. types
  502. url: /sql/types/jsonb#jsonb_build_array
  503. - signature: 'jsonb_build_object(x: ...) -> jsonb'
  504. description: The elements of x as a `jsonb` object. The argument list alternates
  505. between keys and values
  506. url: /sql/types/jsonb#jsonb_build_object
  507. - signature: 'jsonb_each(j: jsonb) -> Col<(key: string, value: jsonb)>'
  508. description: "`j`'s outermost elements if `j` is an object"
  509. url: /sql/types/jsonb#jsonb_each
  510. - signature: 'jsonb_each_text(j: jsonb) -> Col<(key: string, value: string)>'
  511. description: "`j`'s outermost elements if `j` is an object"
  512. url: /sql/types/jsonb#jsonb_each_text
  513. - signature: jsonb_object_agg(keys, values) -> jsonb
  514. description: Aggregate keys and values (including nulls) as a `jsonb` object
  515. url: /sql/functions/jsonb_object_agg
  516. - signature: 'jsonb_object_keys(j: jsonb) -> Col<string>'
  517. description: "`j`'s outermost keys if `j` is an object"
  518. url: /sql/types/jsonb#jsonb_object_keys
  519. - signature: 'jsonb_pretty(j: jsonb) -> string'
  520. description: Pretty printed (i.e. indented) `j`
  521. url: /sql/types/jsonb#jsonb_pretty
  522. - signature: 'jsonb_typeof(j: jsonb) -> string'
  523. description: Type of `j`'s outermost value. One of `object`, `array`, `string`,
  524. `number`, `boolean`, and `null`
  525. url: /sql/types/jsonb#jsonb_typeof
  526. - signature: 'jsonb_strip_nulls(j: jsonb) -> jsonb'
  527. description: "`j` with all object fields with a value of `null` removed. Other
  528. `null` values remain"
  529. url: /sql/types/jsonb#jsonb_strip_nulls
  530. - signature: 'to_jsonb(v: T) -> jsonb'
  531. description: "`v` as `jsonb`"
  532. url: /sql/types/jsonb#to_jsonb
  533. - type: Table
  534. description: Table functions evaluate to a set of rows, rather than a single expression.
  535. functions:
  536. - signature: 'generate_series(start: int, stop: int) -> Col<int>'
  537. description: Generate all integer values between `start` and `stop`, inclusive.
  538. - signature: 'generate_series(start: int, stop: int, step: int) -> Col<int>'
  539. description: Generate all integer values between `start` and `stop`, inclusive, incrementing
  540. by `step` each time.
  541. - signature: 'generate_series(start: timestamp, stop: timestamp, step: interval) -> Col<timestamp>'
  542. description: Generate all timestamp values between `start` and `stop`, inclusive, incrementing
  543. by `step` each time.
  544. - signature: 'generate_subscripts(a: anyarray, dim: int) -> Col<int>'
  545. description: Generates a series comprising the valid subscripts of the `dim`'th dimension of the given array `a`.
  546. - signature: 'regexp_extract(regex: str, haystack: str) -> Col<string>'
  547. description: Values of the capture groups of `regex` as matched in `haystack`.
  548. - signature: 'regexp_split_to_table(text: str, pattern: str [, flags: str]]) -> Col<string>'
  549. description: |
  550. Splits `text` by the regular expression `pattern`.
  551. If `flags` is set to `i`, matches case-insensitively.
  552. - signature: 'unnest(a: anyarray)'
  553. description: Expands the array `a` into a set of rows.
  554. - signature: 'unnest(l: anylist)'
  555. description: Expands the list `l` into a set of rows.
  556. - signature: "unnest(m: anymap)"
  557. description: Expands the map `m` in a set of rows with the columns `key` and `value`.
  558. - type: Array
  559. functions:
  560. - signature: 'array_cat(a1: arrayany, a2: arrayany) -> arrayany'
  561. description: 'Concatenates `a1` and `a2`.'
  562. - signature: 'array_fill(anyelement, int[], [, int[]]) -> anyarray'
  563. description: 'Returns an array initialized with supplied value and dimensions, optionally with lower bounds other than 1.'
  564. - signature: 'array_length(a: arrayany, dim: bigint) -> int'
  565. description: 'Returns the length of the specified dimension of the array.'
  566. - signature: 'array_position(haystack: anycompatiblearray, needle: anycompatible) -> int'
  567. description: 'Returns the subscript of `needle` in `haystack`. Returns `null` if not found.'
  568. - signature: 'array_position(haystack: anycompatiblearray, needle: anycompatible, skip: int) -> int'
  569. description: 'Returns the subscript of `needle` in `haystack`, skipping the first `skip` elements. Returns `null` if not found.'
  570. - signature: 'array_to_string(a: anyarray, sep: text [, ifnull: text]) -> text'
  571. description: |
  572. Concatenates the elements of `array` together separated by `sep`.
  573. Null elements are omitted unless `ifnull` is non-null, in which case
  574. null elements are replaced with the value of `ifnull`.
  575. - signature: 'array_remove(a: anyarray, e: anyelement) -> anyarray'
  576. description: |
  577. Returns the array `a` without any elements equal to the given value `e`.
  578. The array must be one-dimensional. Comparisons are done using `IS NOT
  579. DISTINCT FROM semantics, so it is possible to remove NULLs.
  580. - type: Hash
  581. functions:
  582. - signature: 'crc32(data: bytea) -> uint32'
  583. description: |
  584. Computes the 32-bit cyclic redundancy check of the given bytea `data` using the IEEE 802.3 polynomial.
  585. version-added: v0.114
  586. - signature: 'crc32(data: text) -> uint32'
  587. description: |
  588. Computes the 32-bit cyclic redundancy check of the given text `data` using the IEEE 802.3 polynomial.
  589. version-added: v0.114
  590. - signature: 'digest(data: text, type: text) -> bytea'
  591. description: |
  592. Computes a binary hash of the given text `data` using the specified `type` algorithm.
  593. Supported hash algorithms are: `md5`, `sha1`, `sha224`, `sha256`, `sha384`, and `sha512`.
  594. - signature: 'digest(data: bytea, type: text) -> bytea'
  595. description: |
  596. Computes a binary hash of the given bytea `data` using the specified `type` algorithm.
  597. The supported hash algorithms are the same as for the text variant of this function.
  598. - signature: 'hmac(data: text, key: text, type: text) -> bytea'
  599. description: |
  600. Computes a hashed MAC of the given text `data` using the specified `key` and
  601. `type` algorithm. Supported hash algorithms are the same as for `digest`.
  602. - signature: 'hmac(data: bytea, key: bytea, type: text) -> bytea'
  603. description: |
  604. Computes a hashed MAC of the given bytea `data` using the specified `key` and
  605. `type` algorithm. The supported hash algorithms are the same as for `digest`.
  606. - signature: 'kafka_murmur2(data: bytea) -> integer'
  607. description: |
  608. Computes the Murmur2 hash of the given bytea `data` using the seed used by Kafka's default partitioner and with the high bit cleared.
  609. version-added: v0.114
  610. - signature: 'kafka_murmur2(data: text) -> integer'
  611. description: |
  612. Computes the Murmur2 hash of the given text `data` using the seed used by Kafka's default partitioner and with the high bit cleared.
  613. version-added: v0.114
  614. - signature: 'md5(data: bytea) -> text'
  615. description: |
  616. Computes the MD5 hash of the given bytea `data`.
  617. For PostgreSQL compatibility, returns a hex-encoded value of type `text` rather than `bytea`.
  618. - signature: 'seahash(data: bytea) -> u64'
  619. description: |
  620. Computes the [SeaHash](https://docs.rs/seahash) hash of the given bytea `data`.
  621. version-added: v0.114
  622. - signature: 'seahash(data: text) -> u64'
  623. description: |
  624. Computes the [SeaHash](https://docs.rs/seahash) hash of the given text `data`.
  625. version-added: v0.114
  626. - signature: 'sha224(data: bytea) -> bytea'
  627. description: |
  628. Computes the SHA-224 hash of the given bytea `data`.
  629. - signature: 'sha256(data: bytea) -> bytea'
  630. description: |
  631. Computes the SHA-256 hash of the given bytea `data`.
  632. - signature: 'sha384(data: bytea) -> bytea'
  633. description: |
  634. Computes the SHA-384 hash of the given bytea `data`.
  635. - signature: 'sha512(data: bytea) -> bytea'
  636. description: |
  637. Computes the SHA-512 hash of the given bytea `data`.
  638. - type: Window
  639. description: |
  640. {{< tip >}}
  641. For some window function query patterns, rewriting your query to not use
  642. window functions can yield better performance. See [Idiomatic Materialize SQL](/transform-data/idiomatic-materialize-sql/) for details.
  643. {{</ tip >}}
  644. Window functions compute values across sets of rows related to the current row.
  645. For example, you can use a window aggregation to smooth measurement data by computing the average of the last 5
  646. measurements before every row as follows:
  647. ```
  648. SELECT
  649. avg(measurement) OVER (ORDER BY time ROWS BETWEEN 4 PRECEDING AND CURRENT ROW)
  650. FROM measurements;
  651. ```
  652. Window functions always need an `OVER` clause. For the `OVER` clause, Materialize supports the same
  653. [syntax as
  654. PostgreSQL](https://www.postgresql.org/docs/current/tutorial-window.html),
  655. but supports only the following frame modes:
  656. - the `ROWS` frame mode.
  657. - the default frame, which is `RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT
  658. ROW`.
  659. {{< note >}}
  660. {{% idiomatic-sql/materialize-window-functions %}}
  661. See [Idiomatic Materialize SQL](/transform-data/idiomatic-materialize-sql/)
  662. for examples of rewriting window functions.
  663. {{</ note >}}
  664. In addition to the below window functions, you can use the `OVER` clause with any [aggregation function](#aggregate-functions)
  665. (e.g., `sum`, `avg`) as well. Using an aggregation with an `OVER` clause is called a _window aggregation_. A
  666. window aggregation computes the aggregate not on the groups specified by the `GROUP BY` clause, but on the frames
  667. specified inside the `OVER` clause. (Note that a window aggregation produces exactly one output value _for each input
  668. row_. This is different from a standard aggregation, which produces one output value for each _group_ specified by
  669. the `GROUP BY` clause.)
  670. functions:
  671. - signature: 'dense_rank() -> int'
  672. description: |
  673. Returns the rank of the current row within its partition without gaps, counting from 1.
  674. Rows that compare equal will have the same rank.
  675. - signature: 'first_value(value anycompatible) -> anyelement'
  676. description: |
  677. Returns `value` evaluated at the first row of the window frame. The default window frame is
  678. `RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW`.
  679. See also [Idiomatic Materialize SQL: First value](/transform-data/idiomatic-materialize-sql/first-value/).
  680. - signature: 'lag(value anycompatible [, offset integer [, default anycompatible ]]) -> int'
  681. description: |
  682. Returns `value` evaluated at the row that is `offset` rows before the current row within the partition;
  683. if there is no such row, instead returns `default` (which must be of a type compatible with `value`).
  684. If `offset` is `NULL`, `NULL` is returned instead.
  685. Both `offset` and `default` are evaluated with respect to the current row.
  686. If omitted, `offset` defaults to 1 and `default` to `NULL`.
  687. See also [Idiomatic Materialize SQL: Lag over](/transform-data/idiomatic-materialize-sql/lag/).
  688. - signature: 'last_value(value anycompatible) -> anyelement'
  689. description: |
  690. Returns `value` evaluated at the last row of the window frame. The default window frame is
  691. `RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW`.
  692. See also [Idiomatic Materialize SQL: Last
  693. value](/transform-data/idiomatic-materialize-sql/last-value/).
  694. - signature: 'lead(value anycompatible [, offset integer [, default anycompatible ]]) -> int'
  695. description: |
  696. Returns `value` evaluated at the row that is `offset` rows after the current row within the partition;
  697. if there is no such row, instead returns `default` (which must be of a type compatible with `value`).
  698. If `offset` is `NULL`, `NULL` is returned instead.
  699. Both `offset` and `default` are evaluated with respect to the current row.
  700. If omitted, `offset` defaults to 1 and `default` to `NULL`.
  701. See also [Idiomatic Materialize SQL: Lead
  702. over](/transform-data/idiomatic-materialize-sql/lead/).
  703. - signature: 'rank() -> int'
  704. description: |
  705. Returns the rank of the current row within its partition with gaps (counting from 1):
  706. rows that compare equal will have the same rank, and then the rank is incremented by the number of rows that
  707. compared equal.
  708. - signature: 'row_number() -> int'
  709. description: |
  710. Returns the number of the current row within its partition, counting from 1.
  711. Rows that compare equal will be ordered in an unspecified way.
  712. See also [Idiomatic Materialize SQL: Top-K](/transform-data/idiomatic-materialize-sql/top-k/).
  713. - type: System information
  714. description: Functions that return information about the system.
  715. functions:
  716. - signature: 'mz_environment_id() -> text'
  717. description: Returns a string containing a `uuid` uniquely identifying the Materialize environment.
  718. unmaterializable: true
  719. - signature: 'mz_uptime() -> interval'
  720. description: Returns the length of time that the materialized process has been running.
  721. unmaterializable: true
  722. - signature: 'mz_version() -> text'
  723. description: Returns the server's version information as a human-readable string.
  724. unmaterializable: true
  725. - signature: 'mz_version_num() -> int'
  726. description: Returns the server's version as an integer having the format `XXYYYZZ`, where `XX` is the major version, `YYY` is the minor version and `ZZ` is the patch version.
  727. unmaterializable: true
  728. - signature: 'current_database() -> text'
  729. description: |
  730. Returns the name of the current database.
  731. unmaterializable: true
  732. - signature: 'current_catalog() -> text'
  733. description: |
  734. Alias for `current_database`.
  735. unmaterializable: true
  736. version-added: v0.102
  737. - signature: 'current_user() -> text'
  738. description: |
  739. Returns the name of the user who executed the containing query.
  740. unmaterializable: true
  741. - signature: 'current_role() -> text'
  742. description: |
  743. Alias for `current_user`.
  744. unmaterializable: true
  745. version-added: v0.102
  746. - signature: 'user() -> text'
  747. description: |
  748. Alias for `current_user`.
  749. unmaterializable: true
  750. version-added: v0.102
  751. - signature: 'session_user() -> text'
  752. description: |
  753. Returns the name of the user who initiated the database connection.
  754. unmaterializable: true
  755. - signature: 'mz_row_size(expr: Record) -> int'
  756. description: Returns the number of bytes used to store a row.
  757. - type: PostgreSQL compatibility
  758. description: |
  759. Functions whose primary purpose is to facilitate compatibility with PostgreSQL tools.
  760. These functions may have suboptimal performance characteristics.
  761. functions:
  762. - signature: 'format_type(oid: int, typemod: int) -> text'
  763. description: Returns the canonical SQL name for the type specified by `oid` with `typemod` applied.
  764. - signature: 'current_schema() -> text'
  765. description: |
  766. Returns the name of the first non-implicit schema on the search path, or
  767. `NULL` if the search path is empty.
  768. unmaterializable: true
  769. - signature: 'current_schemas(include_implicit: bool) -> text[]'
  770. description: |
  771. Returns the names of the schemas on the search path.
  772. The `include_implicit` parameter controls whether implicit schemas like
  773. `mz_catalog` and `pg_catalog` are included in the output.
  774. unmaterializable: true
  775. - signature: 'current_setting(setting_name: text[, missing_ok: bool]) -> text'
  776. description: |
  777. Returns the value of the named setting or error if it does not exist.
  778. If `missing_ok` is true, return NULL if it does not exist.
  779. unmaterializable: true
  780. - signature: 'obj_description(oid: oid, catalog: text) -> text'
  781. description: Returns the comment for a database object specified by its `oid` and the
  782. name of the containing system catalog.
  783. - signature: 'col_description(oid: oid, column: int) -> text'
  784. description: Returns the comment for a table column, which is specified by the `oid` of
  785. its table and its column number.
  786. - signature: 'pg_backend_pid() -> int'
  787. description: Returns the internal connection ID.
  788. unmaterializable: true
  789. - signature: 'pg_cancel_backend(connection_id: int) -> bool'
  790. description: |
  791. Cancels an in-progress query on the specified connection ID.
  792. Returns whether the connection ID existed (not if it cancelled a query).
  793. side_effecting: true
  794. - signature: 'pg_column_size(expr: any) -> int'
  795. description: Returns the number of bytes used to store any individual data value.
  796. - signature: 'pg_size_pretty(expr: numeric) -> text'
  797. description: Converts a size in bytes into a human-readable format.
  798. - signature: 'pg_get_constraintdef(oid: oid[, pretty: bool]) -> text'
  799. description: |
  800. Returns the constraint definition for the given `oid`. Currently always
  801. returns NULL since constraints aren't supported.
  802. - signature: 'pg_get_indexdef(index: oid[, column: integer, pretty: bool]) -> text'
  803. description: |
  804. Reconstructs the creating command for an index. (This is a decompiled
  805. reconstruction, not the original text of the command.) If column is
  806. supplied and is not zero, only the definition of that column is reconstructed.
  807. - signature: 'pg_get_ruledef(rule_oid: oid[, pretty bool]) -> text'
  808. description: |
  809. Reconstructs the creating command for a rule. This function
  810. always returns NULL because Materialize does not support rules.
  811. - signature: 'pg_get_userbyid(role: oid) -> text'
  812. description: |
  813. Returns the role (user) name for the given `oid`. If no role matches the
  814. specified OID, the string `unknown (OID=oid)` is returned.
  815. - signature: 'pg_get_viewdef(view_name: text[, pretty: bool]) -> text'
  816. description: Returns the underlying SELECT command for the given view.
  817. - signature: 'pg_get_viewdef(view_oid: oid[, pretty: bool]) -> text'
  818. description: Returns the underlying SELECT command for the given view.
  819. - signature: 'pg_get_viewdef(view_oid: oid[, wrap_column: integer]) -> text'
  820. description: Returns the underlying SELECT command for the given view.
  821. - signature: 'pg_has_role([user: name or oid,] role: text or oid, privilege: text) -> bool'
  822. description: Alias for `has_role` for PostgreSQL compatibility.
  823. - signature: 'pg_is_in_recovery() -> bool'
  824. description: Returns if the a recovery is still in progress.
  825. - signature: 'pg_table_is_visible(relation: oid) -> boolean'
  826. description: Reports whether the relation with the specified OID is visible in the search path.
  827. - signature: 'pg_tablespace_location(tablespace: oid) -> text'
  828. description: Returns the path in the file system that the provided tablespace is on.
  829. - signature: 'pg_type_is_visible(relation: oid) -> boolean'
  830. description: Reports whether the type with the specified OID is visible in the search path.
  831. - signature: 'pg_function_is_visible(relation: oid) -> boolean'
  832. description: Reports whether the function with the specified OID is visible in the search path.
  833. - signature: 'pg_typeof(expr: any) -> text'
  834. description: Returns the type of its input argument as a string.
  835. - signature: 'pg_encoding_to_char(encoding_id: integer) -> text'
  836. description: PostgreSQL compatibility shim. Not intended for direct use.
  837. - signature: 'pg_postmaster_start_time() -> timestamptz'
  838. description: Returns the time when the server started.
  839. unmaterializable: true
  840. - signature: 'pg_relation_size(relation: regclass[, fork: text]) -> bigint'
  841. description: |
  842. Disk space used by the specified fork ('main', 'fsm', 'vm', or 'init')
  843. of the specified table or index. If no fork is specified, it defaults
  844. to 'main'. This function always returns -1 because Materialize does
  845. not store tables and indexes on local disk.
  846. - signature: 'pg_stat_get_numscans(oid: oid) -> bigint'
  847. description: |
  848. Number of sequential scans done when argument is a table,
  849. or number of index scans done when argument is an index.
  850. This function always returns -1 because Materialize does
  851. not collect statistics.
  852. - signature: 'version() -> text'
  853. description: Returns a PostgreSQL-compatible version string.
  854. unmaterializable: true
  855. - type: Access privilege inquiry
  856. description: |
  857. Functions that allow querying object access privileges. None of the following functions consider
  858. whether the provided role is a _superuser_ or not.
  859. functions:
  860. - signature: 'has_cluster_privilege([role: text or oid,] cluster: text, privilege: text) -> bool'
  861. description: |
  862. Reports whether the role with the specified role name or OID has the privilege on
  863. the cluster with the specified cluster name. If the role is omitted then
  864. the `current_role` is assumed.
  865. - signature: 'has_connection_privilege([role: text or oid,] connection: text or oid, privilege: text) -> bool'
  866. description: |
  867. Reports whether the role with the specified role name or OID has the privilege on
  868. the connection with the specified connection name or OID. If the role is omitted then
  869. the `current_role` is assumed.
  870. - signature: 'has_database_privilege([role: text or oid,] database: text or oid, privilege: text) -> bool'
  871. description: |
  872. Reports whether the role with the specified role name or OID has the privilege on
  873. the database with the specified database name or OID. If the role is omitted then
  874. the `current_role` is assumed.
  875. - signature: 'has_schema_privilege([role: text or oid,] schema: text or oid, privilege: text) -> bool'
  876. description: |
  877. Reports whether the role with the specified role name or OID has the privilege on
  878. the schema with the specified schema name or OID. If the role is omitted then
  879. the `current_role` is assumed.
  880. - signature: 'has_role([user: name or oid,] role: text or oid, privilege: text) -> bool'
  881. description: |
  882. Reports whether the `user` has the privilege for `role`. `privilege` can either be `MEMBER`
  883. or `USAGE`, however currently this value is ignored. The `PUBLIC` pseudo-role cannot be used
  884. for the `user` nor the `role`. If the `user` is omitted then the `current_role` is assumed.
  885. - signature: 'has_secret_privilege([role: text or oid,] secret: text or oid, privilege: text) -> bool'
  886. description: |
  887. Reports whether the role with the specified role name or OID has the privilege on
  888. the secret with the specified secret name or OID. If the role is omitted then
  889. the `current_role` is assumed.
  890. - signature: 'has_system_privilege([role: text or oid,] privilege: text) -> bool'
  891. description: |
  892. Reports whether the role with the specified role name or OID has the system privilege.
  893. If the role is omitted then the `current_role` is assumed.
  894. - signature: 'has_table_privilege([role: text or oid,] relation: text or oid, privilege: text) -> bool'
  895. description: |
  896. Reports whether the role with the specified role name or OID has the privilege on
  897. the relation with the specified relation name or OID. If the role is omitted then
  898. the `current_role` is assumed.
  899. - signature: 'has_type_privilege([role: text or oid,] type: text or oid, privilege: text) -> bool'
  900. description: |
  901. Reports whether the role with the specified role name or OID has the privilege on
  902. the type with the specified type name or OID. If the role is omitted then
  903. the `current_role` is assumed.
  904. - signature: 'mz_is_superuser() -> bool'
  905. description: Reports whether the `current_role` is a superuser.