Skip to main content

mz_catalog/builtin/
pg_catalog.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Built-in catalog items for the `pg_catalog` schema.
11
12use std::collections::BTreeMap;
13use std::sync::LazyLock;
14
15use mz_pgrepr::oid;
16use mz_repr::namespaces::PG_CATALOG_SCHEMA;
17use mz_repr::{RelationDesc, SqlScalarType};
18use mz_sql::catalog::{
19    CatalogType, CatalogTypeDetails, CatalogTypePgMetadata, NameReference, ObjectType,
20};
21use mz_sql::rbac;
22use mz_sql::session::user::MZ_SYSTEM_ROLE_ID;
23
24use super::{BuiltinType, BuiltinView, PUBLIC_SELECT};
25
26// Builtin definitions below. Ensure you add new builtins to the `BUILTINS` map.
27//
28// You SHOULD NOT delete a builtin. If you do, you will break any downstream
29// user objects that depended on the builtin.
30//
31// Builtins are loaded in dependency order, so a builtin must appear in `BUILTINS`
32// before any items it depends upon.
33//
34// WARNING: if you change the definition of an existing builtin item, you must
35// be careful to maintain backwards compatibility! Adding new columns is safe.
36// Removing a column, changing the name of a column, or changing the type of a
37// column is not safe, as persisted user views may depend upon that column.
38
39// The following types are the list of builtin data types available
40// in Materialize. This list is derived from the `pg_type` table in PostgreSQL.
41//
42// Builtin types cannot be created, updated, or deleted. Their OIDs
43// are static, unlike other objects, to match the type OIDs defined by Postgres.
44
45pub const TYPE_BOOL: BuiltinType<NameReference> = BuiltinType {
46    name: "bool",
47    schema: PG_CATALOG_SCHEMA,
48    oid: oid::TYPE_BOOL_OID,
49    details: CatalogTypeDetails {
50        typ: CatalogType::Bool,
51        array_id: None,
52        pg_metadata: Some(CatalogTypePgMetadata {
53            typinput_oid: 1242,
54            typreceive_oid: 2436,
55            typsend_oid: 2437,
56        }),
57    },
58};
59
60pub const TYPE_BYTEA: BuiltinType<NameReference> = BuiltinType {
61    name: "bytea",
62    schema: PG_CATALOG_SCHEMA,
63    oid: oid::TYPE_BYTEA_OID,
64    details: CatalogTypeDetails {
65        typ: CatalogType::Bytes,
66        array_id: None,
67        pg_metadata: Some(CatalogTypePgMetadata {
68            typinput_oid: 1244,
69            typreceive_oid: 2412,
70            typsend_oid: 2413,
71        }),
72    },
73};
74
75pub const TYPE_INT8: BuiltinType<NameReference> = BuiltinType {
76    name: "int8",
77    schema: PG_CATALOG_SCHEMA,
78    oid: oid::TYPE_INT8_OID,
79    details: CatalogTypeDetails {
80        typ: CatalogType::Int64,
81        array_id: None,
82        pg_metadata: Some(CatalogTypePgMetadata {
83            typinput_oid: 460,
84            typreceive_oid: 2408,
85            typsend_oid: 2409,
86        }),
87    },
88};
89
90pub const TYPE_INT4: BuiltinType<NameReference> = BuiltinType {
91    name: "int4",
92    schema: PG_CATALOG_SCHEMA,
93    oid: oid::TYPE_INT4_OID,
94    details: CatalogTypeDetails {
95        typ: CatalogType::Int32,
96        array_id: None,
97        pg_metadata: Some(CatalogTypePgMetadata {
98            typinput_oid: 42,
99            typreceive_oid: 2406,
100            typsend_oid: 2407,
101        }),
102    },
103};
104
105pub const TYPE_TEXT: BuiltinType<NameReference> = BuiltinType {
106    name: "text",
107    schema: PG_CATALOG_SCHEMA,
108    oid: oid::TYPE_TEXT_OID,
109    details: CatalogTypeDetails {
110        typ: CatalogType::String,
111        array_id: None,
112        pg_metadata: Some(CatalogTypePgMetadata {
113            typinput_oid: 46,
114            typreceive_oid: 2414,
115            typsend_oid: 2415,
116        }),
117    },
118};
119
120pub const TYPE_OID: BuiltinType<NameReference> = BuiltinType {
121    name: "oid",
122    schema: PG_CATALOG_SCHEMA,
123    oid: oid::TYPE_OID_OID,
124    details: CatalogTypeDetails {
125        typ: CatalogType::Oid,
126        array_id: None,
127        pg_metadata: Some(CatalogTypePgMetadata {
128            typinput_oid: 1798,
129            typreceive_oid: 2418,
130            typsend_oid: 2419,
131        }),
132    },
133};
134
135pub const TYPE_FLOAT4: BuiltinType<NameReference> = BuiltinType {
136    name: "float4",
137    schema: PG_CATALOG_SCHEMA,
138    oid: oid::TYPE_FLOAT4_OID,
139    details: CatalogTypeDetails {
140        typ: CatalogType::Float32,
141        array_id: None,
142        pg_metadata: Some(CatalogTypePgMetadata {
143            typinput_oid: 200,
144            typreceive_oid: 2424,
145            typsend_oid: 2425,
146        }),
147    },
148};
149
150pub const TYPE_FLOAT8: BuiltinType<NameReference> = BuiltinType {
151    name: "float8",
152    schema: PG_CATALOG_SCHEMA,
153    oid: oid::TYPE_FLOAT8_OID,
154    details: CatalogTypeDetails {
155        typ: CatalogType::Float64,
156        array_id: None,
157        pg_metadata: Some(CatalogTypePgMetadata {
158            typinput_oid: 214,
159            typreceive_oid: 2426,
160            typsend_oid: 2427,
161        }),
162    },
163};
164
165pub const TYPE_BOOL_ARRAY: BuiltinType<NameReference> = BuiltinType {
166    name: "_bool",
167    schema: PG_CATALOG_SCHEMA,
168    oid: oid::TYPE_BOOL_ARRAY_OID,
169    details: CatalogTypeDetails {
170        typ: CatalogType::Array {
171            element_reference: TYPE_BOOL.name,
172        },
173        array_id: None,
174        pg_metadata: Some(CatalogTypePgMetadata {
175            typinput_oid: 750,
176            typreceive_oid: 2400,
177            typsend_oid: 2401,
178        }),
179    },
180};
181
182pub const TYPE_BYTEA_ARRAY: BuiltinType<NameReference> = BuiltinType {
183    name: "_bytea",
184    schema: PG_CATALOG_SCHEMA,
185    oid: oid::TYPE_BYTEA_ARRAY_OID,
186    details: CatalogTypeDetails {
187        typ: CatalogType::Array {
188            element_reference: TYPE_BYTEA.name,
189        },
190        array_id: None,
191        pg_metadata: Some(CatalogTypePgMetadata {
192            typinput_oid: 750,
193            typreceive_oid: 2400,
194            typsend_oid: 2401,
195        }),
196    },
197};
198
199pub const TYPE_INT4_ARRAY: BuiltinType<NameReference> = BuiltinType {
200    name: "_int4",
201    schema: PG_CATALOG_SCHEMA,
202    oid: oid::TYPE_INT4_ARRAY_OID,
203    details: CatalogTypeDetails {
204        typ: CatalogType::Array {
205            element_reference: TYPE_INT4.name,
206        },
207        array_id: None,
208        pg_metadata: Some(CatalogTypePgMetadata {
209            typinput_oid: 750,
210            typreceive_oid: 2400,
211            typsend_oid: 2401,
212        }),
213    },
214};
215
216pub const TYPE_TEXT_ARRAY: BuiltinType<NameReference> = BuiltinType {
217    name: "_text",
218    schema: PG_CATALOG_SCHEMA,
219    oid: oid::TYPE_TEXT_ARRAY_OID,
220    details: CatalogTypeDetails {
221        typ: CatalogType::Array {
222            element_reference: TYPE_TEXT.name,
223        },
224        array_id: None,
225        pg_metadata: Some(CatalogTypePgMetadata {
226            typinput_oid: 750,
227            typreceive_oid: 2400,
228            typsend_oid: 2401,
229        }),
230    },
231};
232
233pub const TYPE_INT8_ARRAY: BuiltinType<NameReference> = BuiltinType {
234    name: "_int8",
235    schema: PG_CATALOG_SCHEMA,
236    oid: oid::TYPE_INT8_ARRAY_OID,
237    details: CatalogTypeDetails {
238        typ: CatalogType::Array {
239            element_reference: TYPE_INT8.name,
240        },
241        array_id: None,
242        pg_metadata: Some(CatalogTypePgMetadata {
243            typinput_oid: 750,
244            typreceive_oid: 2400,
245            typsend_oid: 2401,
246        }),
247    },
248};
249
250pub const TYPE_FLOAT4_ARRAY: BuiltinType<NameReference> = BuiltinType {
251    name: "_float4",
252    schema: PG_CATALOG_SCHEMA,
253    oid: oid::TYPE_FLOAT4_ARRAY_OID,
254    details: CatalogTypeDetails {
255        typ: CatalogType::Array {
256            element_reference: TYPE_FLOAT4.name,
257        },
258        array_id: None,
259        pg_metadata: Some(CatalogTypePgMetadata {
260            typinput_oid: 750,
261            typreceive_oid: 2400,
262            typsend_oid: 2401,
263        }),
264    },
265};
266
267pub const TYPE_FLOAT8_ARRAY: BuiltinType<NameReference> = BuiltinType {
268    name: "_float8",
269    schema: PG_CATALOG_SCHEMA,
270    oid: oid::TYPE_FLOAT8_ARRAY_OID,
271    details: CatalogTypeDetails {
272        typ: CatalogType::Array {
273            element_reference: TYPE_FLOAT8.name,
274        },
275        array_id: None,
276        pg_metadata: Some(CatalogTypePgMetadata {
277            typinput_oid: 750,
278            typreceive_oid: 2400,
279            typsend_oid: 2401,
280        }),
281    },
282};
283
284pub const TYPE_OID_ARRAY: BuiltinType<NameReference> = BuiltinType {
285    name: "_oid",
286    schema: PG_CATALOG_SCHEMA,
287    oid: oid::TYPE_OID_ARRAY_OID,
288    details: CatalogTypeDetails {
289        typ: CatalogType::Array {
290            element_reference: TYPE_OID.name,
291        },
292        array_id: None,
293        pg_metadata: Some(CatalogTypePgMetadata {
294            typinput_oid: 750,
295            typreceive_oid: 2400,
296            typsend_oid: 2401,
297        }),
298    },
299};
300
301pub const TYPE_DATE: BuiltinType<NameReference> = BuiltinType {
302    name: "date",
303    schema: PG_CATALOG_SCHEMA,
304    oid: oid::TYPE_DATE_OID,
305    details: CatalogTypeDetails {
306        typ: CatalogType::Date,
307        array_id: None,
308        pg_metadata: Some(CatalogTypePgMetadata {
309            typinput_oid: 1084,
310            typreceive_oid: 2468,
311            typsend_oid: 2469,
312        }),
313    },
314};
315
316pub const TYPE_TIME: BuiltinType<NameReference> = BuiltinType {
317    name: "time",
318    schema: PG_CATALOG_SCHEMA,
319    oid: oid::TYPE_TIME_OID,
320    details: CatalogTypeDetails {
321        typ: CatalogType::Time,
322        array_id: None,
323        pg_metadata: Some(CatalogTypePgMetadata {
324            typinput_oid: 1143,
325            typreceive_oid: 2470,
326            typsend_oid: 2471,
327        }),
328    },
329};
330
331pub const TYPE_TIMESTAMP: BuiltinType<NameReference> = BuiltinType {
332    name: "timestamp",
333    schema: PG_CATALOG_SCHEMA,
334    oid: oid::TYPE_TIMESTAMP_OID,
335    details: CatalogTypeDetails {
336        typ: CatalogType::Timestamp,
337        array_id: None,
338        pg_metadata: Some(CatalogTypePgMetadata {
339            typinput_oid: 1312,
340            typreceive_oid: 2474,
341            typsend_oid: 2475,
342        }),
343    },
344};
345
346pub const TYPE_TIMESTAMP_ARRAY: BuiltinType<NameReference> = BuiltinType {
347    name: "_timestamp",
348    schema: PG_CATALOG_SCHEMA,
349    oid: oid::TYPE_TIMESTAMP_ARRAY_OID,
350    details: CatalogTypeDetails {
351        typ: CatalogType::Array {
352            element_reference: TYPE_TIMESTAMP.name,
353        },
354        array_id: None,
355        pg_metadata: Some(CatalogTypePgMetadata {
356            typinput_oid: 750,
357            typreceive_oid: 2400,
358            typsend_oid: 2401,
359        }),
360    },
361};
362
363pub const TYPE_DATE_ARRAY: BuiltinType<NameReference> = BuiltinType {
364    name: "_date",
365    schema: PG_CATALOG_SCHEMA,
366    oid: oid::TYPE_DATE_ARRAY_OID,
367    details: CatalogTypeDetails {
368        typ: CatalogType::Array {
369            element_reference: TYPE_DATE.name,
370        },
371        array_id: None,
372        pg_metadata: Some(CatalogTypePgMetadata {
373            typinput_oid: 750,
374            typreceive_oid: 2400,
375            typsend_oid: 2401,
376        }),
377    },
378};
379
380pub const TYPE_TIME_ARRAY: BuiltinType<NameReference> = BuiltinType {
381    name: "_time",
382    schema: PG_CATALOG_SCHEMA,
383    oid: oid::TYPE_TIME_ARRAY_OID,
384    details: CatalogTypeDetails {
385        typ: CatalogType::Array {
386            element_reference: TYPE_TIME.name,
387        },
388        array_id: None,
389        pg_metadata: Some(CatalogTypePgMetadata {
390            typinput_oid: 750,
391            typreceive_oid: 2400,
392            typsend_oid: 2401,
393        }),
394    },
395};
396
397pub const TYPE_TIMESTAMPTZ: BuiltinType<NameReference> = BuiltinType {
398    name: "timestamptz",
399    schema: PG_CATALOG_SCHEMA,
400    oid: oid::TYPE_TIMESTAMPTZ_OID,
401    details: CatalogTypeDetails {
402        typ: CatalogType::TimestampTz,
403        array_id: None,
404        pg_metadata: Some(CatalogTypePgMetadata {
405            typinput_oid: 1150,
406            typreceive_oid: 2476,
407            typsend_oid: 2477,
408        }),
409    },
410};
411
412pub const TYPE_TIMESTAMPTZ_ARRAY: BuiltinType<NameReference> = BuiltinType {
413    name: "_timestamptz",
414    schema: PG_CATALOG_SCHEMA,
415    oid: oid::TYPE_TIMESTAMPTZ_ARRAY_OID,
416    details: CatalogTypeDetails {
417        typ: CatalogType::Array {
418            element_reference: TYPE_TIMESTAMPTZ.name,
419        },
420        array_id: None,
421        pg_metadata: Some(CatalogTypePgMetadata {
422            typinput_oid: 750,
423            typreceive_oid: 2400,
424            typsend_oid: 2401,
425        }),
426    },
427};
428
429pub const TYPE_INTERVAL: BuiltinType<NameReference> = BuiltinType {
430    name: "interval",
431    schema: PG_CATALOG_SCHEMA,
432    oid: oid::TYPE_INTERVAL_OID,
433    details: CatalogTypeDetails {
434        typ: CatalogType::Interval,
435        array_id: None,
436        pg_metadata: Some(CatalogTypePgMetadata {
437            typinput_oid: 1160,
438            typreceive_oid: 2478,
439            typsend_oid: 2479,
440        }),
441    },
442};
443
444pub const TYPE_INTERVAL_ARRAY: BuiltinType<NameReference> = BuiltinType {
445    name: "_interval",
446    schema: PG_CATALOG_SCHEMA,
447    oid: oid::TYPE_INTERVAL_ARRAY_OID,
448    details: CatalogTypeDetails {
449        typ: CatalogType::Array {
450            element_reference: TYPE_INTERVAL.name,
451        },
452        array_id: None,
453        pg_metadata: Some(CatalogTypePgMetadata {
454            typinput_oid: 750,
455            typreceive_oid: 2400,
456            typsend_oid: 2401,
457        }),
458    },
459};
460
461pub const TYPE_NAME: BuiltinType<NameReference> = BuiltinType {
462    name: "name",
463    schema: PG_CATALOG_SCHEMA,
464    oid: oid::TYPE_NAME_OID,
465    details: CatalogTypeDetails {
466        typ: CatalogType::PgLegacyName,
467        array_id: None,
468        pg_metadata: Some(CatalogTypePgMetadata {
469            typinput_oid: 34,
470            typreceive_oid: 2422,
471            typsend_oid: 2423,
472        }),
473    },
474};
475
476pub const TYPE_NAME_ARRAY: BuiltinType<NameReference> = BuiltinType {
477    name: "_name",
478    schema: PG_CATALOG_SCHEMA,
479    oid: oid::TYPE_NAME_ARRAY_OID,
480    details: CatalogTypeDetails {
481        typ: CatalogType::Array {
482            element_reference: TYPE_NAME.name,
483        },
484        array_id: None,
485        pg_metadata: Some(CatalogTypePgMetadata {
486            typinput_oid: 750,
487            typreceive_oid: 2400,
488            typsend_oid: 2401,
489        }),
490    },
491};
492
493pub const TYPE_NUMERIC: BuiltinType<NameReference> = BuiltinType {
494    name: "numeric",
495    schema: PG_CATALOG_SCHEMA,
496    oid: oid::TYPE_NUMERIC_OID,
497    details: CatalogTypeDetails {
498        typ: CatalogType::Numeric,
499        array_id: None,
500        pg_metadata: Some(CatalogTypePgMetadata {
501            typinput_oid: 1701,
502            typreceive_oid: 2460,
503            typsend_oid: 2461,
504        }),
505    },
506};
507
508pub const TYPE_NUMERIC_ARRAY: BuiltinType<NameReference> = BuiltinType {
509    name: "_numeric",
510    schema: PG_CATALOG_SCHEMA,
511    oid: oid::TYPE_NUMERIC_ARRAY_OID,
512    details: CatalogTypeDetails {
513        typ: CatalogType::Array {
514            element_reference: TYPE_NUMERIC.name,
515        },
516        array_id: None,
517        pg_metadata: Some(CatalogTypePgMetadata {
518            typinput_oid: 750,
519            typreceive_oid: 2400,
520            typsend_oid: 2401,
521        }),
522    },
523};
524
525pub const TYPE_RECORD: BuiltinType<NameReference> = BuiltinType {
526    name: "record",
527    schema: PG_CATALOG_SCHEMA,
528    oid: oid::TYPE_RECORD_OID,
529    details: CatalogTypeDetails {
530        typ: CatalogType::Pseudo,
531        array_id: None,
532        pg_metadata: Some(CatalogTypePgMetadata {
533            typinput_oid: 2290,
534            typreceive_oid: 2402,
535            typsend_oid: 2403,
536        }),
537    },
538};
539
540pub const TYPE_RECORD_ARRAY: BuiltinType<NameReference> = BuiltinType {
541    name: "_record",
542    schema: PG_CATALOG_SCHEMA,
543    oid: oid::TYPE_RECORD_ARRAY_OID,
544    details: CatalogTypeDetails {
545        typ: CatalogType::Array {
546            element_reference: TYPE_RECORD.name,
547        },
548        array_id: None,
549        pg_metadata: Some(CatalogTypePgMetadata {
550            typinput_oid: 750,
551            typreceive_oid: 2400,
552            typsend_oid: 2401,
553        }),
554    },
555};
556
557pub const TYPE_UUID: BuiltinType<NameReference> = BuiltinType {
558    name: "uuid",
559    schema: PG_CATALOG_SCHEMA,
560    oid: oid::TYPE_UUID_OID,
561    details: CatalogTypeDetails {
562        typ: CatalogType::Uuid,
563        array_id: None,
564        pg_metadata: Some(CatalogTypePgMetadata {
565            typinput_oid: 2952,
566            typreceive_oid: 2961,
567            typsend_oid: 2962,
568        }),
569    },
570};
571
572pub const TYPE_UUID_ARRAY: BuiltinType<NameReference> = BuiltinType {
573    name: "_uuid",
574    schema: PG_CATALOG_SCHEMA,
575    oid: oid::TYPE_UUID_ARRAY_OID,
576    details: CatalogTypeDetails {
577        typ: CatalogType::Array {
578            element_reference: TYPE_UUID.name,
579        },
580        array_id: None,
581        pg_metadata: Some(CatalogTypePgMetadata {
582            typinput_oid: 750,
583            typreceive_oid: 2400,
584            typsend_oid: 2401,
585        }),
586    },
587};
588
589pub const TYPE_JSONB: BuiltinType<NameReference> = BuiltinType {
590    name: "jsonb",
591    schema: PG_CATALOG_SCHEMA,
592    oid: oid::TYPE_JSONB_OID,
593    details: CatalogTypeDetails {
594        typ: CatalogType::Jsonb,
595        array_id: None,
596        pg_metadata: Some(CatalogTypePgMetadata {
597            typinput_oid: 3806,
598            typreceive_oid: 3805,
599            typsend_oid: 3803,
600        }),
601    },
602};
603
604pub const TYPE_JSONB_ARRAY: BuiltinType<NameReference> = BuiltinType {
605    name: "_jsonb",
606    schema: PG_CATALOG_SCHEMA,
607    oid: oid::TYPE_JSONB_ARRAY_OID,
608    details: CatalogTypeDetails {
609        typ: CatalogType::Array {
610            element_reference: TYPE_JSONB.name,
611        },
612        array_id: None,
613        pg_metadata: Some(CatalogTypePgMetadata {
614            typinput_oid: 750,
615            typreceive_oid: 2400,
616            typsend_oid: 2401,
617        }),
618    },
619};
620
621pub const TYPE_ANY: BuiltinType<NameReference> = BuiltinType {
622    name: "any",
623    schema: PG_CATALOG_SCHEMA,
624    oid: oid::TYPE_ANY_OID,
625    details: CatalogTypeDetails {
626        typ: CatalogType::Pseudo,
627        array_id: None,
628        pg_metadata: Some(CatalogTypePgMetadata {
629            typinput_oid: 2294,
630            typreceive_oid: 0,
631            typsend_oid: 0,
632        }),
633    },
634};
635
636pub const TYPE_ANYARRAY: BuiltinType<NameReference> = BuiltinType {
637    name: "anyarray",
638    schema: PG_CATALOG_SCHEMA,
639    oid: oid::TYPE_ANYARRAY_OID,
640    details: CatalogTypeDetails {
641        typ: CatalogType::Pseudo,
642        array_id: None,
643        pg_metadata: Some(CatalogTypePgMetadata {
644            typinput_oid: 2296,
645            typreceive_oid: 2502,
646            typsend_oid: 2503,
647        }),
648    },
649};
650
651pub const TYPE_ANYELEMENT: BuiltinType<NameReference> = BuiltinType {
652    name: "anyelement",
653    schema: PG_CATALOG_SCHEMA,
654    oid: oid::TYPE_ANYELEMENT_OID,
655    details: CatalogTypeDetails {
656        typ: CatalogType::Pseudo,
657        array_id: None,
658        pg_metadata: Some(CatalogTypePgMetadata {
659            typinput_oid: 2312,
660            typreceive_oid: 0,
661            typsend_oid: 0,
662        }),
663    },
664};
665
666pub const TYPE_ANYNONARRAY: BuiltinType<NameReference> = BuiltinType {
667    name: "anynonarray",
668    schema: PG_CATALOG_SCHEMA,
669    oid: oid::TYPE_ANYNONARRAY_OID,
670    details: CatalogTypeDetails {
671        typ: CatalogType::Pseudo,
672        array_id: None,
673        pg_metadata: Some(CatalogTypePgMetadata {
674            typinput_oid: 2777,
675            typreceive_oid: 0,
676            typsend_oid: 0,
677        }),
678    },
679};
680
681pub const TYPE_ANYRANGE: BuiltinType<NameReference> = BuiltinType {
682    name: "anyrange",
683    schema: PG_CATALOG_SCHEMA,
684    oid: oid::TYPE_ANYRANGE_OID,
685    details: CatalogTypeDetails {
686        typ: CatalogType::Pseudo,
687        array_id: None,
688        pg_metadata: Some(CatalogTypePgMetadata {
689            typinput_oid: 3832,
690            typreceive_oid: 0,
691            typsend_oid: 0,
692        }),
693    },
694};
695
696pub const TYPE_CHAR: BuiltinType<NameReference> = BuiltinType {
697    name: "char",
698    schema: PG_CATALOG_SCHEMA,
699    oid: oid::TYPE_CHAR_OID,
700    details: CatalogTypeDetails {
701        typ: CatalogType::PgLegacyChar,
702        array_id: None,
703        pg_metadata: Some(CatalogTypePgMetadata {
704            typinput_oid: 1245,
705            typreceive_oid: 2434,
706            typsend_oid: 2435,
707        }),
708    },
709};
710
711pub const TYPE_VARCHAR: BuiltinType<NameReference> = BuiltinType {
712    name: "varchar",
713    schema: PG_CATALOG_SCHEMA,
714    oid: oid::TYPE_VARCHAR_OID,
715    details: CatalogTypeDetails {
716        typ: CatalogType::VarChar,
717        array_id: None,
718        pg_metadata: Some(CatalogTypePgMetadata {
719            typinput_oid: 1046,
720            typreceive_oid: 2432,
721            typsend_oid: 2433,
722        }),
723    },
724};
725
726pub const TYPE_INT2: BuiltinType<NameReference> = BuiltinType {
727    name: "int2",
728    schema: PG_CATALOG_SCHEMA,
729    oid: oid::TYPE_INT2_OID,
730    details: CatalogTypeDetails {
731        typ: CatalogType::Int16,
732        array_id: None,
733        pg_metadata: Some(CatalogTypePgMetadata {
734            typinput_oid: 38,
735            typreceive_oid: 2404,
736            typsend_oid: 2405,
737        }),
738    },
739};
740
741pub const TYPE_INT2_ARRAY: BuiltinType<NameReference> = BuiltinType {
742    name: "_int2",
743    schema: PG_CATALOG_SCHEMA,
744    oid: oid::TYPE_INT2_ARRAY_OID,
745    details: CatalogTypeDetails {
746        typ: CatalogType::Array {
747            element_reference: TYPE_INT2.name,
748        },
749        array_id: None,
750        pg_metadata: Some(CatalogTypePgMetadata {
751            typinput_oid: 750,
752            typreceive_oid: 2400,
753            typsend_oid: 2401,
754        }),
755    },
756};
757
758pub const TYPE_BPCHAR: BuiltinType<NameReference> = BuiltinType {
759    name: "bpchar",
760    schema: PG_CATALOG_SCHEMA,
761    oid: oid::TYPE_BPCHAR_OID,
762    details: CatalogTypeDetails {
763        typ: CatalogType::Char,
764        array_id: None,
765        pg_metadata: Some(CatalogTypePgMetadata {
766            typinput_oid: 1044,
767            typreceive_oid: 2430,
768            typsend_oid: 2431,
769        }),
770    },
771};
772
773pub const TYPE_CHAR_ARRAY: BuiltinType<NameReference> = BuiltinType {
774    name: "_char",
775    schema: PG_CATALOG_SCHEMA,
776    oid: oid::TYPE_CHAR_ARRAY_OID,
777    details: CatalogTypeDetails {
778        typ: CatalogType::Array {
779            element_reference: TYPE_CHAR.name,
780        },
781        array_id: None,
782        pg_metadata: Some(CatalogTypePgMetadata {
783            typinput_oid: 750,
784            typreceive_oid: 2400,
785            typsend_oid: 2401,
786        }),
787    },
788};
789
790pub const TYPE_VARCHAR_ARRAY: BuiltinType<NameReference> = BuiltinType {
791    name: "_varchar",
792    schema: PG_CATALOG_SCHEMA,
793    oid: oid::TYPE_VARCHAR_ARRAY_OID,
794    details: CatalogTypeDetails {
795        typ: CatalogType::Array {
796            element_reference: TYPE_VARCHAR.name,
797        },
798        array_id: None,
799        pg_metadata: Some(CatalogTypePgMetadata {
800            typinput_oid: 750,
801            typreceive_oid: 2400,
802            typsend_oid: 2401,
803        }),
804    },
805};
806
807pub const TYPE_BPCHAR_ARRAY: BuiltinType<NameReference> = BuiltinType {
808    name: "_bpchar",
809    schema: PG_CATALOG_SCHEMA,
810    oid: oid::TYPE_BPCHAR_ARRAY_OID,
811    details: CatalogTypeDetails {
812        typ: CatalogType::Array {
813            element_reference: TYPE_BPCHAR.name,
814        },
815        array_id: None,
816        pg_metadata: Some(CatalogTypePgMetadata {
817            typinput_oid: 750,
818            typreceive_oid: 2400,
819            typsend_oid: 2401,
820        }),
821    },
822};
823
824pub const TYPE_REGPROC: BuiltinType<NameReference> = BuiltinType {
825    name: "regproc",
826    schema: PG_CATALOG_SCHEMA,
827    oid: oid::TYPE_REGPROC_OID,
828    details: CatalogTypeDetails {
829        typ: CatalogType::RegProc,
830        array_id: None,
831        pg_metadata: Some(CatalogTypePgMetadata {
832            typinput_oid: 44,
833            typreceive_oid: 2444,
834            typsend_oid: 2445,
835        }),
836    },
837};
838
839pub const TYPE_REGPROC_ARRAY: BuiltinType<NameReference> = BuiltinType {
840    name: "_regproc",
841    schema: PG_CATALOG_SCHEMA,
842    oid: oid::TYPE_REGPROC_ARRAY_OID,
843    details: CatalogTypeDetails {
844        typ: CatalogType::Array {
845            element_reference: TYPE_REGPROC.name,
846        },
847        array_id: None,
848        pg_metadata: Some(CatalogTypePgMetadata {
849            typinput_oid: 750,
850            typreceive_oid: 2400,
851            typsend_oid: 2401,
852        }),
853    },
854};
855
856pub const TYPE_REGTYPE: BuiltinType<NameReference> = BuiltinType {
857    name: "regtype",
858    schema: PG_CATALOG_SCHEMA,
859    oid: oid::TYPE_REGTYPE_OID,
860    details: CatalogTypeDetails {
861        typ: CatalogType::RegType,
862        array_id: None,
863        pg_metadata: Some(CatalogTypePgMetadata {
864            typinput_oid: 2220,
865            typreceive_oid: 2454,
866            typsend_oid: 2455,
867        }),
868    },
869};
870
871pub const TYPE_REGTYPE_ARRAY: BuiltinType<NameReference> = BuiltinType {
872    name: "_regtype",
873    schema: PG_CATALOG_SCHEMA,
874    oid: oid::TYPE_REGTYPE_ARRAY_OID,
875    details: CatalogTypeDetails {
876        typ: CatalogType::Array {
877            element_reference: TYPE_REGTYPE.name,
878        },
879        array_id: None,
880        pg_metadata: Some(CatalogTypePgMetadata {
881            typinput_oid: 750,
882            typreceive_oid: 2400,
883            typsend_oid: 2401,
884        }),
885    },
886};
887
888pub const TYPE_REGCLASS: BuiltinType<NameReference> = BuiltinType {
889    name: "regclass",
890    schema: PG_CATALOG_SCHEMA,
891    oid: oid::TYPE_REGCLASS_OID,
892    details: CatalogTypeDetails {
893        typ: CatalogType::RegClass,
894        array_id: None,
895        pg_metadata: Some(CatalogTypePgMetadata {
896            typinput_oid: 2218,
897            typreceive_oid: 2452,
898            typsend_oid: 2453,
899        }),
900    },
901};
902
903pub const TYPE_REGCLASS_ARRAY: BuiltinType<NameReference> = BuiltinType {
904    name: "_regclass",
905    schema: PG_CATALOG_SCHEMA,
906    oid: oid::TYPE_REGCLASS_ARRAY_OID,
907    details: CatalogTypeDetails {
908        typ: CatalogType::Array {
909            element_reference: TYPE_REGCLASS.name,
910        },
911        array_id: None,
912        pg_metadata: Some(CatalogTypePgMetadata {
913            typinput_oid: 750,
914            typreceive_oid: 2400,
915            typsend_oid: 2401,
916        }),
917    },
918};
919
920pub const TYPE_INT2_VECTOR: BuiltinType<NameReference> = BuiltinType {
921    name: "int2vector",
922    schema: PG_CATALOG_SCHEMA,
923    oid: oid::TYPE_INT2_VECTOR_OID,
924    details: CatalogTypeDetails {
925        typ: CatalogType::Int2Vector,
926        array_id: None,
927        pg_metadata: Some(CatalogTypePgMetadata {
928            typinput_oid: 40,
929            typreceive_oid: 2410,
930            typsend_oid: 2411,
931        }),
932    },
933};
934
935pub const TYPE_INT2_VECTOR_ARRAY: BuiltinType<NameReference> = BuiltinType {
936    name: "_int2vector",
937    schema: PG_CATALOG_SCHEMA,
938    oid: oid::TYPE_INT2_VECTOR_ARRAY_OID,
939    details: CatalogTypeDetails {
940        typ: CatalogType::Array {
941            element_reference: TYPE_INT2_VECTOR.name,
942        },
943        array_id: None,
944        pg_metadata: Some(CatalogTypePgMetadata {
945            typinput_oid: 750,
946            typreceive_oid: 2400,
947            typsend_oid: 2401,
948        }),
949    },
950};
951
952pub const TYPE_ANYCOMPATIBLE: BuiltinType<NameReference> = BuiltinType {
953    name: "anycompatible",
954    schema: PG_CATALOG_SCHEMA,
955    oid: oid::TYPE_ANYCOMPATIBLE_OID,
956    details: CatalogTypeDetails {
957        typ: CatalogType::Pseudo,
958        array_id: None,
959        pg_metadata: Some(CatalogTypePgMetadata {
960            typinput_oid: 5086,
961            typreceive_oid: 0,
962            typsend_oid: 0,
963        }),
964    },
965};
966
967pub const TYPE_ANYCOMPATIBLEARRAY: BuiltinType<NameReference> = BuiltinType {
968    name: "anycompatiblearray",
969    schema: PG_CATALOG_SCHEMA,
970    oid: oid::TYPE_ANYCOMPATIBLEARRAY_OID,
971    details: CatalogTypeDetails {
972        typ: CatalogType::Pseudo,
973        array_id: None,
974        pg_metadata: Some(CatalogTypePgMetadata {
975            typinput_oid: 5088,
976            typreceive_oid: 5090,
977            typsend_oid: 5091,
978        }),
979    },
980};
981
982pub const TYPE_ANYCOMPATIBLENONARRAY: BuiltinType<NameReference> = BuiltinType {
983    name: "anycompatiblenonarray",
984    schema: PG_CATALOG_SCHEMA,
985    oid: oid::TYPE_ANYCOMPATIBLENONARRAY_OID,
986    details: CatalogTypeDetails {
987        typ: CatalogType::Pseudo,
988        array_id: None,
989        pg_metadata: Some(CatalogTypePgMetadata {
990            typinput_oid: 5092,
991            typreceive_oid: 0,
992            typsend_oid: 0,
993        }),
994    },
995};
996
997pub const TYPE_ANYCOMPATIBLERANGE: BuiltinType<NameReference> = BuiltinType {
998    name: "anycompatiblerange",
999    schema: PG_CATALOG_SCHEMA,
1000    oid: oid::TYPE_ANYCOMPATIBLERANGE_OID,
1001    details: CatalogTypeDetails {
1002        typ: CatalogType::Pseudo,
1003        array_id: None,
1004        pg_metadata: Some(CatalogTypePgMetadata {
1005            typinput_oid: 5094,
1006            typreceive_oid: 0,
1007            typsend_oid: 0,
1008        }),
1009    },
1010};
1011
1012pub const TYPE_INT4_RANGE: BuiltinType<NameReference> = BuiltinType {
1013    name: "int4range",
1014    schema: PG_CATALOG_SCHEMA,
1015    oid: mz_pgrepr::oid::TYPE_INT4RANGE_OID,
1016    details: CatalogTypeDetails {
1017        typ: CatalogType::Range {
1018            element_reference: TYPE_INT4.name,
1019        },
1020        array_id: None,
1021        pg_metadata: Some(CatalogTypePgMetadata {
1022            typinput_oid: 3834,
1023            typreceive_oid: 3836,
1024            typsend_oid: 3837,
1025        }),
1026    },
1027};
1028
1029pub const TYPE_INT4_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1030    name: "_int4range",
1031    schema: PG_CATALOG_SCHEMA,
1032    oid: mz_pgrepr::oid::TYPE_INT4RANGE_ARRAY_OID,
1033    details: CatalogTypeDetails {
1034        typ: CatalogType::Array {
1035            element_reference: TYPE_INT4_RANGE.name,
1036        },
1037        array_id: None,
1038        pg_metadata: Some(CatalogTypePgMetadata {
1039            typinput_oid: 750,
1040            typreceive_oid: 2400,
1041            typsend_oid: 2401,
1042        }),
1043    },
1044};
1045
1046pub const TYPE_INT8_RANGE: BuiltinType<NameReference> = BuiltinType {
1047    name: "int8range",
1048    schema: PG_CATALOG_SCHEMA,
1049    oid: mz_pgrepr::oid::TYPE_INT8RANGE_OID,
1050    details: CatalogTypeDetails {
1051        typ: CatalogType::Range {
1052            element_reference: TYPE_INT8.name,
1053        },
1054        array_id: None,
1055        pg_metadata: Some(CatalogTypePgMetadata {
1056            typinput_oid: 3834,
1057            typreceive_oid: 3836,
1058            typsend_oid: 3837,
1059        }),
1060    },
1061};
1062
1063pub const TYPE_INT8_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1064    name: "_int8range",
1065    schema: PG_CATALOG_SCHEMA,
1066    oid: mz_pgrepr::oid::TYPE_INT8RANGE_ARRAY_OID,
1067    details: CatalogTypeDetails {
1068        typ: CatalogType::Array {
1069            element_reference: TYPE_INT8_RANGE.name,
1070        },
1071        array_id: None,
1072        pg_metadata: Some(CatalogTypePgMetadata {
1073            typinput_oid: 750,
1074            typreceive_oid: 2400,
1075            typsend_oid: 2401,
1076        }),
1077    },
1078};
1079
1080pub const TYPE_DATE_RANGE: BuiltinType<NameReference> = BuiltinType {
1081    name: "daterange",
1082    schema: PG_CATALOG_SCHEMA,
1083    oid: mz_pgrepr::oid::TYPE_DATERANGE_OID,
1084    details: CatalogTypeDetails {
1085        typ: CatalogType::Range {
1086            element_reference: TYPE_DATE.name,
1087        },
1088        array_id: None,
1089        pg_metadata: Some(CatalogTypePgMetadata {
1090            typinput_oid: 3834,
1091            typreceive_oid: 3836,
1092            typsend_oid: 3837,
1093        }),
1094    },
1095};
1096
1097pub const TYPE_DATE_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1098    name: "_daterange",
1099    schema: PG_CATALOG_SCHEMA,
1100    oid: mz_pgrepr::oid::TYPE_DATERANGE_ARRAY_OID,
1101    details: CatalogTypeDetails {
1102        typ: CatalogType::Array {
1103            element_reference: TYPE_DATE_RANGE.name,
1104        },
1105        array_id: None,
1106        pg_metadata: Some(CatalogTypePgMetadata {
1107            typinput_oid: 750,
1108            typreceive_oid: 2400,
1109            typsend_oid: 2401,
1110        }),
1111    },
1112};
1113
1114pub const TYPE_NUM_RANGE: BuiltinType<NameReference> = BuiltinType {
1115    name: "numrange",
1116    schema: PG_CATALOG_SCHEMA,
1117    oid: mz_pgrepr::oid::TYPE_NUMRANGE_OID,
1118    details: CatalogTypeDetails {
1119        typ: CatalogType::Range {
1120            element_reference: TYPE_NUMERIC.name,
1121        },
1122        array_id: None,
1123        pg_metadata: Some(CatalogTypePgMetadata {
1124            typinput_oid: 3834,
1125            typreceive_oid: 3836,
1126            typsend_oid: 3837,
1127        }),
1128    },
1129};
1130
1131pub const TYPE_NUM_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1132    name: "_numrange",
1133    schema: PG_CATALOG_SCHEMA,
1134    oid: mz_pgrepr::oid::TYPE_NUMRANGE_ARRAY_OID,
1135    details: CatalogTypeDetails {
1136        typ: CatalogType::Array {
1137            element_reference: TYPE_NUM_RANGE.name,
1138        },
1139        array_id: None,
1140        pg_metadata: Some(CatalogTypePgMetadata {
1141            typinput_oid: 750,
1142            typreceive_oid: 2400,
1143            typsend_oid: 2401,
1144        }),
1145    },
1146};
1147
1148pub const TYPE_TS_RANGE: BuiltinType<NameReference> = BuiltinType {
1149    name: "tsrange",
1150    schema: PG_CATALOG_SCHEMA,
1151    oid: mz_pgrepr::oid::TYPE_TSRANGE_OID,
1152    details: CatalogTypeDetails {
1153        typ: CatalogType::Range {
1154            element_reference: TYPE_TIMESTAMP.name,
1155        },
1156        array_id: None,
1157        pg_metadata: Some(CatalogTypePgMetadata {
1158            typinput_oid: 3834,
1159            typreceive_oid: 3836,
1160            typsend_oid: 3837,
1161        }),
1162    },
1163};
1164
1165pub const TYPE_TS_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1166    name: "_tsrange",
1167    schema: PG_CATALOG_SCHEMA,
1168    oid: mz_pgrepr::oid::TYPE_TSRANGE_ARRAY_OID,
1169    details: CatalogTypeDetails {
1170        typ: CatalogType::Array {
1171            element_reference: TYPE_TS_RANGE.name,
1172        },
1173        array_id: None,
1174        pg_metadata: Some(CatalogTypePgMetadata {
1175            typinput_oid: 750,
1176            typreceive_oid: 2400,
1177            typsend_oid: 2401,
1178        }),
1179    },
1180};
1181
1182pub const TYPE_TSTZ_RANGE: BuiltinType<NameReference> = BuiltinType {
1183    name: "tstzrange",
1184    schema: PG_CATALOG_SCHEMA,
1185    oid: mz_pgrepr::oid::TYPE_TSTZRANGE_OID,
1186    details: CatalogTypeDetails {
1187        typ: CatalogType::Range {
1188            element_reference: TYPE_TIMESTAMPTZ.name,
1189        },
1190        array_id: None,
1191        pg_metadata: Some(CatalogTypePgMetadata {
1192            typinput_oid: 3834,
1193            typreceive_oid: 3836,
1194            typsend_oid: 3837,
1195        }),
1196    },
1197};
1198
1199pub const TYPE_TSTZ_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1200    name: "_tstzrange",
1201    schema: PG_CATALOG_SCHEMA,
1202    oid: mz_pgrepr::oid::TYPE_TSTZRANGE_ARRAY_OID,
1203    details: CatalogTypeDetails {
1204        typ: CatalogType::Array {
1205            element_reference: TYPE_TSTZ_RANGE.name,
1206        },
1207        array_id: None,
1208        pg_metadata: Some(CatalogTypePgMetadata {
1209            typinput_oid: 750,
1210            typreceive_oid: 2400,
1211            typsend_oid: 2401,
1212        }),
1213    },
1214};
1215
1216pub const TYPE_ACL_ITEM: BuiltinType<NameReference> = BuiltinType {
1217    name: "aclitem",
1218    schema: PG_CATALOG_SCHEMA,
1219    oid: 1033,
1220    details: CatalogTypeDetails {
1221        typ: CatalogType::AclItem,
1222        array_id: None,
1223        pg_metadata: Some(CatalogTypePgMetadata {
1224            typinput_oid: 1031,
1225            typreceive_oid: 0,
1226            typsend_oid: 0,
1227        }),
1228    },
1229};
1230
1231pub const TYPE_ACL_ITEM_ARRAY: BuiltinType<NameReference> = BuiltinType {
1232    name: "_aclitem",
1233    schema: PG_CATALOG_SCHEMA,
1234    oid: 1034,
1235    details: CatalogTypeDetails {
1236        typ: CatalogType::Array {
1237            element_reference: TYPE_ACL_ITEM.name,
1238        },
1239        array_id: None,
1240        pg_metadata: Some(CatalogTypePgMetadata {
1241            typinput_oid: 750,
1242            typreceive_oid: 2400,
1243            typsend_oid: 2401,
1244        }),
1245    },
1246};
1247
1248pub const TYPE_INTERNAL: BuiltinType<NameReference> = BuiltinType {
1249    name: "internal",
1250    schema: PG_CATALOG_SCHEMA,
1251    oid: 2281,
1252    details: CatalogTypeDetails {
1253        typ: CatalogType::Pseudo,
1254        array_id: None,
1255        pg_metadata: Some(CatalogTypePgMetadata {
1256            typinput_oid: 2304,
1257            typreceive_oid: 0,
1258            typsend_oid: 0,
1259        }),
1260    },
1261};
1262
1263pub static PG_NAMESPACE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1264    name: "pg_namespace",
1265    schema: PG_CATALOG_SCHEMA,
1266    oid: oid::VIEW_PG_NAMESPACE_OID,
1267    desc: RelationDesc::builder()
1268        .with_column("oid", SqlScalarType::Oid.nullable(false))
1269        .with_column("nspname", SqlScalarType::String.nullable(false))
1270        .with_column("nspowner", SqlScalarType::Oid.nullable(false))
1271        .with_column(
1272            "nspacl",
1273            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
1274        )
1275        .finish(),
1276    column_comments: BTreeMap::new(),
1277    sql: "
1278SELECT
1279    oid, nspname, nspowner, nspacl
1280FROM mz_internal.pg_namespace_all_databases
1281WHERE database_name IS NULL OR database_name = pg_catalog.current_database();",
1282    access: vec![PUBLIC_SELECT],
1283    ontology: None,
1284});
1285
1286pub static PG_CLASS: LazyLock<BuiltinView> = LazyLock::new(|| {
1287    BuiltinView {
1288    name: "pg_class",
1289    schema: PG_CATALOG_SCHEMA,
1290    oid: oid::VIEW_PG_CLASS_OID,
1291    desc: RelationDesc::builder()
1292        .with_column("oid", SqlScalarType::Oid.nullable(false))
1293        .with_column("relname", SqlScalarType::String.nullable(false))
1294        .with_column("relnamespace", SqlScalarType::Oid.nullable(false))
1295        .with_column("reloftype", SqlScalarType::Oid.nullable(false))
1296        .with_column("relowner", SqlScalarType::Oid.nullable(false))
1297        .with_column("relam", SqlScalarType::Oid.nullable(false))
1298        .with_column("reltablespace", SqlScalarType::Oid.nullable(false))
1299        .with_column("relpages", SqlScalarType::Int32.nullable(false))
1300        .with_column("reltuples", SqlScalarType::Float32.nullable(false))
1301        .with_column("reltoastrelid", SqlScalarType::Oid.nullable(false))
1302        .with_column("relhasindex", SqlScalarType::Bool.nullable(false))
1303        .with_column("relpersistence", SqlScalarType::PgLegacyChar.nullable(false))
1304        .with_column("relkind", SqlScalarType::String.nullable(true))
1305        .with_column("relnatts", SqlScalarType::Int16.nullable(false))
1306        .with_column("relchecks", SqlScalarType::Int16.nullable(false))
1307        .with_column("relhasrules", SqlScalarType::Bool.nullable(false))
1308        .with_column("relhastriggers", SqlScalarType::Bool.nullable(false))
1309        .with_column("relhassubclass", SqlScalarType::Bool.nullable(false))
1310        .with_column("relrowsecurity", SqlScalarType::Bool.nullable(false))
1311        .with_column("relforcerowsecurity", SqlScalarType::Bool.nullable(false))
1312        .with_column("relreplident", SqlScalarType::PgLegacyChar.nullable(false))
1313        .with_column("relispartition", SqlScalarType::Bool.nullable(false))
1314        .with_column("relhasoids", SqlScalarType::Bool.nullable(false))
1315        .with_column(
1316            "reloptions",
1317            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
1318        )
1319        .finish(),
1320    column_comments: BTreeMap::new(),
1321    sql: "
1322SELECT
1323    oid, relname, relnamespace, reloftype, relowner, relam, reltablespace, relpages, reltuples, reltoastrelid,
1324    relhasindex, relpersistence, relkind, relnatts, relchecks, relhasrules, relhastriggers, relhassubclass,
1325    relrowsecurity, relforcerowsecurity, relreplident, relispartition, relhasoids, reloptions
1326FROM mz_internal.pg_class_all_databases
1327WHERE database_name IS NULL OR database_name = pg_catalog.current_database();
1328",
1329    access: vec![PUBLIC_SELECT],
1330    ontology: None,
1331}
1332});
1333
1334pub static PG_DEPEND: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1335    name: "pg_depend",
1336    schema: PG_CATALOG_SCHEMA,
1337    oid: oid::VIEW_PG_DEPEND_OID,
1338    desc: RelationDesc::builder()
1339        .with_column("classid", SqlScalarType::Oid.nullable(true))
1340        .with_column("objid", SqlScalarType::Oid.nullable(false))
1341        .with_column("objsubid", SqlScalarType::Int32.nullable(false))
1342        .with_column("refclassid", SqlScalarType::Oid.nullable(true))
1343        .with_column("refobjid", SqlScalarType::Oid.nullable(false))
1344        .with_column("refobjsubid", SqlScalarType::Int32.nullable(false))
1345        .with_column("deptype", SqlScalarType::PgLegacyChar.nullable(false))
1346        .finish(),
1347    column_comments: BTreeMap::new(),
1348    sql: "
1349WITH class_objects AS (
1350    SELECT
1351        CASE
1352            WHEN type = 'table' THEN 'pg_tables'::pg_catalog.regclass::pg_catalog.oid
1353            WHEN type = 'source' THEN 'pg_tables'::pg_catalog.regclass::pg_catalog.oid
1354            WHEN type = 'view' THEN 'pg_views'::pg_catalog.regclass::pg_catalog.oid
1355            WHEN type = 'materialized-view' THEN 'pg_matviews'::pg_catalog.regclass::pg_catalog.oid
1356        END classid,
1357        id,
1358        oid,
1359        schema_id
1360    FROM mz_catalog.mz_relations
1361    UNION ALL
1362    SELECT
1363        'pg_index'::pg_catalog.regclass::pg_catalog.oid AS classid,
1364        i.id,
1365        i.oid,
1366        r.schema_id
1367    FROM mz_catalog.mz_indexes i
1368    JOIN mz_catalog.mz_relations r ON i.on_id = r.id
1369),
1370
1371current_objects AS (
1372    SELECT class_objects.*
1373    FROM class_objects
1374    JOIN mz_catalog.mz_schemas ON mz_schemas.id = class_objects.schema_id
1375    LEFT JOIN mz_catalog.mz_databases d ON d.id = mz_schemas.database_id
1376    -- This filter is tricky, as it filters out not just objects outside the
1377    -- database, but *dependencies* on objects outside this database. It's not
1378    -- clear that this is the right choice, but because PostgreSQL doesn't
1379    -- support cross-database references, it's not clear that the other choice
1380    -- is better.
1381    WHERE mz_schemas.database_id IS NULL OR d.name = pg_catalog.current_database()
1382)
1383
1384SELECT
1385    objects.classid::pg_catalog.oid,
1386    objects.oid::pg_catalog.oid AS objid,
1387    0::pg_catalog.int4 AS objsubid,
1388    dependents.classid::pg_catalog.oid AS refclassid,
1389    dependents.oid::pg_catalog.oid AS refobjid,
1390    0::pg_catalog.int4 AS refobjsubid,
1391    'n'::pg_catalog.char AS deptype
1392FROM mz_internal.mz_object_dependencies
1393JOIN current_objects objects ON object_id = objects.id
1394JOIN current_objects dependents ON referenced_object_id = dependents.id",
1395    access: vec![PUBLIC_SELECT],
1396    ontology: None,
1397});
1398
1399pub static PG_DATABASE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1400    name: "pg_database",
1401    schema: PG_CATALOG_SCHEMA,
1402    oid: oid::VIEW_PG_DATABASE_OID,
1403    desc: RelationDesc::builder()
1404        .with_column("oid", SqlScalarType::Oid.nullable(false))
1405        .with_column("datname", SqlScalarType::String.nullable(false))
1406        .with_column("datdba", SqlScalarType::Oid.nullable(false))
1407        .with_column("encoding", SqlScalarType::Int32.nullable(false))
1408        .with_column("datistemplate", SqlScalarType::Bool.nullable(false))
1409        .with_column("datallowconn", SqlScalarType::Bool.nullable(false))
1410        .with_column("datcollate", SqlScalarType::String.nullable(false))
1411        .with_column("datctype", SqlScalarType::String.nullable(false))
1412        .with_column(
1413            "datacl",
1414            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
1415        )
1416        .with_key(vec![0])
1417        .finish(),
1418    column_comments: BTreeMap::new(),
1419    sql: "SELECT
1420    d.oid as oid,
1421    d.name as datname,
1422    role_owner.oid as datdba,
1423    6 as encoding,
1424    -- Materialize doesn't support database cloning.
1425    FALSE AS datistemplate,
1426    TRUE AS datallowconn,
1427    'C' as datcollate,
1428    'C' as datctype,
1429    NULL::pg_catalog.text[] as datacl
1430FROM mz_catalog.mz_databases d
1431JOIN mz_catalog.mz_roles role_owner ON role_owner.id = d.owner_id",
1432    access: vec![PUBLIC_SELECT],
1433    ontology: None,
1434});
1435
1436pub static PG_INDEX: LazyLock<BuiltinView> = LazyLock::new(|| {
1437    BuiltinView {
1438        name: "pg_index",
1439        schema: PG_CATALOG_SCHEMA,
1440        oid: oid::VIEW_PG_INDEX_OID,
1441        desc: RelationDesc::builder()
1442            .with_column("indexrelid", SqlScalarType::Oid.nullable(false))
1443            .with_column("indrelid", SqlScalarType::Oid.nullable(false))
1444            .with_column("indnatts", SqlScalarType::Int16.nullable(false))
1445            .with_column("indisunique", SqlScalarType::Bool.nullable(false))
1446            .with_column("indisprimary", SqlScalarType::Bool.nullable(false))
1447            .with_column("indimmediate", SqlScalarType::Bool.nullable(false))
1448            .with_column("indisclustered", SqlScalarType::Bool.nullable(false))
1449            .with_column("indisvalid", SqlScalarType::Bool.nullable(false))
1450            .with_column("indisreplident", SqlScalarType::Bool.nullable(false))
1451            .with_column("indkey", SqlScalarType::Int2Vector.nullable(false))
1452            .with_column("indoption", SqlScalarType::Int2Vector.nullable(false))
1453            .with_column("indexprs", SqlScalarType::String.nullable(true))
1454            .with_column("indpred", SqlScalarType::String.nullable(true))
1455            .with_key(vec![0, 1])
1456            .finish(),
1457        column_comments: BTreeMap::new(),
1458        sql: "SELECT
1459    mz_indexes.oid AS indexrelid,
1460    mz_relations.oid AS indrelid,
1461    count(mz_index_columns.index_position)::pg_catalog.int2 AS indnatts,
1462    -- MZ doesn't support creating unique indexes so indisunique is filled with false
1463    false::pg_catalog.bool AS indisunique,
1464    false::pg_catalog.bool AS indisprimary,
1465    -- MZ doesn't support unique indexes so indimmediate is filled with false
1466    false::pg_catalog.bool AS indimmediate,
1467    -- MZ doesn't support CLUSTER so indisclustered is filled with false
1468    false::pg_catalog.bool AS indisclustered,
1469    -- MZ never creates invalid indexes so indisvalid is filled with true
1470    true::pg_catalog.bool AS indisvalid,
1471    -- MZ doesn't support replication so indisreplident is filled with false
1472    false::pg_catalog.bool AS indisreplident,
1473    -- Return zero if the index attribute is not a simple column reference, column position otherwise
1474    pg_catalog.string_agg(coalesce(mz_index_columns.on_position::int8, 0)::pg_catalog.text, ' ' ORDER BY mz_index_columns.index_position::int8)::pg_catalog.int2vector AS indkey,
1475    -- MZ doesn't have per-column flags, so returning a 0 for each column in the index
1476    pg_catalog.string_agg('0', ' ')::pg_catalog.int2vector AS indoption,
1477    -- Index expressions are returned in MZ format
1478    CASE pg_catalog.string_agg(mz_index_columns.on_expression, ' ' ORDER BY mz_index_columns.index_position::int8)
1479    WHEN NULL THEN NULL
1480    ELSE '{' || pg_catalog.string_agg(mz_index_columns.on_expression, '}, {' ORDER BY mz_index_columns.index_position::int8) || '}'
1481    END AS indexprs,
1482    -- MZ doesn't support indexes with predicates
1483    NULL::pg_catalog.text AS indpred
1484FROM mz_catalog.mz_indexes
1485JOIN mz_catalog.mz_relations ON mz_indexes.on_id = mz_relations.id
1486JOIN mz_catalog.mz_index_columns ON mz_index_columns.index_id = mz_indexes.id
1487JOIN mz_catalog.mz_schemas ON mz_schemas.id = mz_relations.schema_id
1488LEFT JOIN mz_catalog.mz_databases d ON d.id = mz_schemas.database_id
1489WHERE mz_schemas.database_id IS NULL OR d.name = pg_catalog.current_database()
1490GROUP BY mz_indexes.oid, mz_relations.oid",
1491        access: vec![PUBLIC_SELECT],
1492        ontology: None,
1493    }
1494});
1495
1496pub static PG_INDEXES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1497    name: "pg_indexes",
1498    schema: PG_CATALOG_SCHEMA,
1499    oid: oid::VIEW_PG_INDEXES_OID,
1500    desc: RelationDesc::builder()
1501        .with_column("table_catalog", SqlScalarType::String.nullable(false))
1502        .with_column("schemaname", SqlScalarType::String.nullable(false))
1503        .with_column("tablename", SqlScalarType::String.nullable(false))
1504        .with_column("indexname", SqlScalarType::String.nullable(false))
1505        .with_column("tablespace", SqlScalarType::String.nullable(true))
1506        .with_column("indexdef", SqlScalarType::String.nullable(true))
1507        .finish(),
1508    column_comments: BTreeMap::new(),
1509    sql: "SELECT
1510    current_database() as table_catalog,
1511    s.name AS schemaname,
1512    r.name AS tablename,
1513    i.name AS indexname,
1514    NULL::text AS tablespace,
1515    -- TODO(jkosh44) Fill in with actual index definition.
1516    NULL::text AS indexdef
1517FROM mz_catalog.mz_indexes i
1518JOIN mz_catalog.mz_relations r ON i.on_id = r.id
1519JOIN mz_catalog.mz_schemas s ON s.id = r.schema_id
1520LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
1521WHERE s.database_id IS NULL OR d.name = current_database()",
1522    access: vec![PUBLIC_SELECT],
1523    ontology: None,
1524});
1525
1526/// Note: Databases, Roles, Clusters, Cluster Replicas, Secrets, and Connections are excluded from
1527/// this view for Postgres compatibility. Specifically, there is no classoid for these objects,
1528/// which is required for this view.
1529pub static PG_DESCRIPTION: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1530    name: "pg_description",
1531    schema: PG_CATALOG_SCHEMA,
1532    oid: oid::VIEW_PG_DESCRIPTION_OID,
1533    desc: RelationDesc::builder()
1534        .with_column("objoid", SqlScalarType::Oid.nullable(false))
1535        .with_column("classoid", SqlScalarType::Oid.nullable(true))
1536        .with_column("objsubid", SqlScalarType::Int32.nullable(false))
1537        .with_column("description", SqlScalarType::String.nullable(false))
1538        .finish(),
1539    column_comments: BTreeMap::new(),
1540    sql: "
1541SELECT
1542    objoid,
1543    classoid,
1544    objsubid,
1545    description
1546FROM
1547    mz_internal.pg_description_all_databases
1548WHERE
1549    (oid_database_name IS NULL OR oid_database_name = pg_catalog.current_database()) AND
1550    (class_database_name IS NULL OR class_database_name = pg_catalog.current_database());",
1551    access: vec![PUBLIC_SELECT],
1552    ontology: None,
1553});
1554
1555pub static PG_TYPE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1556    name: "pg_type",
1557    schema: PG_CATALOG_SCHEMA,
1558    oid: oid::VIEW_PG_TYPE_OID,
1559    desc: RelationDesc::builder()
1560        .with_column("oid", SqlScalarType::Oid.nullable(false))
1561        .with_column("typname", SqlScalarType::String.nullable(false))
1562        .with_column("typnamespace", SqlScalarType::Oid.nullable(false))
1563        .with_column("typowner", SqlScalarType::Oid.nullable(false))
1564        .with_column("typlen", SqlScalarType::Int16.nullable(true))
1565        .with_column("typtype", SqlScalarType::PgLegacyChar.nullable(false))
1566        .with_column("typcategory", SqlScalarType::PgLegacyChar.nullable(true))
1567        .with_column("typdelim", SqlScalarType::PgLegacyChar.nullable(false))
1568        .with_column("typrelid", SqlScalarType::Oid.nullable(false))
1569        .with_column("typelem", SqlScalarType::Oid.nullable(false))
1570        .with_column("typarray", SqlScalarType::Oid.nullable(false))
1571        .with_column("typinput", SqlScalarType::RegProc.nullable(true))
1572        // The underlying `mz_internal.pg_type_all_databases` keeps `typreceive`
1573        // as `oid` because it backs a builtin index, and resolving a `regproc` to
1574        // a name reads `current_database()`, which is unmaterializable.
1575        .with_column("typreceive", SqlScalarType::RegProc.nullable(false))
1576        .with_column("typnotnull", SqlScalarType::Bool.nullable(false))
1577        .with_column("typbasetype", SqlScalarType::Oid.nullable(false))
1578        .with_column("typtypmod", SqlScalarType::Int32.nullable(false))
1579        .with_column("typcollation", SqlScalarType::Oid.nullable(false))
1580        .with_column("typdefault", SqlScalarType::String.nullable(true))
1581        .with_column("typsend", SqlScalarType::RegProc.nullable(false))
1582        .finish(),
1583    column_comments: BTreeMap::new(),
1584    sql: "SELECT
1585    oid, typname, typnamespace, typowner, typlen, typtype, typcategory, typdelim, typrelid, typelem,
1586    typarray, typinput, typreceive::pg_catalog.regproc AS typreceive, typnotnull, typbasetype,
1587    typtypmod, typcollation, typdefault, typsend
1588FROM mz_internal.pg_type_all_databases
1589WHERE database_name IS NULL OR database_name = pg_catalog.current_database();",
1590    access: vec![PUBLIC_SELECT],
1591    ontology: None,
1592});
1593
1594/// <https://www.postgresql.org/docs/current/catalog-pg-attribute.html>
1595pub static PG_ATTRIBUTE: LazyLock<BuiltinView> = LazyLock::new(|| {
1596    BuiltinView {
1597        name: "pg_attribute",
1598        schema: PG_CATALOG_SCHEMA,
1599        oid: oid::VIEW_PG_ATTRIBUTE_OID,
1600        desc: RelationDesc::builder()
1601            .with_column("attrelid", SqlScalarType::Oid.nullable(false))
1602            .with_column("attname", SqlScalarType::String.nullable(false))
1603            .with_column("atttypid", SqlScalarType::Oid.nullable(false))
1604            .with_column("attlen", SqlScalarType::Int16.nullable(true))
1605            .with_column("attnum", SqlScalarType::Int16.nullable(false))
1606            .with_column("atttypmod", SqlScalarType::Int32.nullable(false))
1607            .with_column("attndims", SqlScalarType::Int16.nullable(false))
1608            .with_column("attnotnull", SqlScalarType::Bool.nullable(false))
1609            .with_column("atthasdef", SqlScalarType::Bool.nullable(false))
1610            .with_column("attidentity", SqlScalarType::PgLegacyChar.nullable(false))
1611            .with_column("attgenerated", SqlScalarType::PgLegacyChar.nullable(false))
1612            .with_column("attisdropped", SqlScalarType::Bool.nullable(false))
1613            .with_column("attcollation", SqlScalarType::Oid.nullable(false))
1614            .finish(),
1615        column_comments: BTreeMap::new(),
1616        sql: "
1617SELECT
1618    attrelid, attname, atttypid, attlen, attnum, atttypmod, attndims, attnotnull, atthasdef,
1619    attidentity, attgenerated, attisdropped, attcollation
1620FROM mz_internal.pg_attribute_all_databases
1621WHERE
1622  (database_name IS NULL OR database_name = pg_catalog.current_database()) AND
1623  (pg_type_database_name IS NULL OR pg_type_database_name = pg_catalog.current_database());",
1624        // Since this depends on pg_type, its id must be higher due to initialization
1625        // ordering.
1626        access: vec![PUBLIC_SELECT],
1627        ontology: None,
1628    }
1629});
1630
1631pub static PG_PROC: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1632    name: "pg_proc",
1633    schema: PG_CATALOG_SCHEMA,
1634    oid: oid::VIEW_PG_PROC_OID,
1635    desc: RelationDesc::builder()
1636        .with_column("oid", SqlScalarType::Oid.nullable(false))
1637        .with_column("proname", SqlScalarType::String.nullable(false))
1638        .with_column("pronamespace", SqlScalarType::Oid.nullable(false))
1639        .with_column("proowner", SqlScalarType::Oid.nullable(false))
1640        .with_column("proargdefaults", SqlScalarType::String.nullable(true))
1641        .with_column("prorettype", SqlScalarType::Oid.nullable(false))
1642        .finish(),
1643    column_comments: BTreeMap::new(),
1644    sql: "SELECT
1645    mz_functions.oid,
1646    mz_functions.name AS proname,
1647    mz_schemas.oid AS pronamespace,
1648    role_owner.oid AS proowner,
1649    NULL::pg_catalog.text AS proargdefaults,
1650    ret_type.oid AS prorettype
1651FROM mz_catalog.mz_functions
1652JOIN mz_catalog.mz_schemas ON mz_functions.schema_id = mz_schemas.id
1653LEFT JOIN mz_catalog.mz_databases d ON d.id = mz_schemas.database_id
1654JOIN mz_catalog.mz_types AS ret_type ON mz_functions.return_type_id = ret_type.id
1655JOIN mz_catalog.mz_roles role_owner ON role_owner.id = mz_functions.owner_id
1656WHERE mz_schemas.database_id IS NULL OR d.name = pg_catalog.current_database()",
1657    access: vec![PUBLIC_SELECT],
1658    ontology: None,
1659});
1660
1661pub static PG_OPERATOR: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1662    name: "pg_operator",
1663    schema: PG_CATALOG_SCHEMA,
1664    oid: oid::VIEW_PG_OPERATOR_OID,
1665    desc: RelationDesc::builder()
1666        .with_column("oid", SqlScalarType::Oid.nullable(false))
1667        .with_column("oprname", SqlScalarType::String.nullable(false))
1668        .with_column("oprresult", SqlScalarType::Oid.nullable(false))
1669        .with_column("oprleft", SqlScalarType::Oid.nullable(false))
1670        .with_column("oprright", SqlScalarType::Oid.nullable(false))
1671        .with_key(vec![0, 1, 2, 3, 4])
1672        .finish(),
1673    column_comments: BTreeMap::new(),
1674    sql: "SELECT
1675    mz_operators.oid,
1676    mz_operators.name AS oprname,
1677    ret_type.oid AS oprresult,
1678    left_type.oid as oprleft,
1679    right_type.oid as oprright
1680FROM mz_catalog.mz_operators
1681JOIN mz_catalog.mz_types AS ret_type ON mz_operators.return_type_id = ret_type.id
1682JOIN mz_catalog.mz_types AS left_type ON mz_operators.argument_type_ids[1] = left_type.id
1683JOIN mz_catalog.mz_types AS right_type ON mz_operators.argument_type_ids[2] = right_type.id
1684WHERE array_length(mz_operators.argument_type_ids, 1) = 2
1685UNION SELECT
1686    mz_operators.oid,
1687    mz_operators.name AS oprname,
1688    ret_type.oid AS oprresult,
1689    0 as oprleft,
1690    right_type.oid as oprright
1691FROM mz_catalog.mz_operators
1692JOIN mz_catalog.mz_types AS ret_type ON mz_operators.return_type_id = ret_type.id
1693JOIN mz_catalog.mz_types AS right_type ON mz_operators.argument_type_ids[1] = right_type.id
1694WHERE array_length(mz_operators.argument_type_ids, 1) = 1",
1695    access: vec![PUBLIC_SELECT],
1696    ontology: None,
1697});
1698
1699pub static PG_RANGE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1700    name: "pg_range",
1701    schema: PG_CATALOG_SCHEMA,
1702    oid: oid::VIEW_PG_RANGE_OID,
1703    desc: RelationDesc::builder()
1704        .with_column("rngtypid", SqlScalarType::Oid.nullable(false))
1705        .with_column("rngsubtype", SqlScalarType::Oid.nullable(false))
1706        .with_key(vec![])
1707        .finish(),
1708    column_comments: BTreeMap::new(),
1709    sql: "SELECT
1710    NULL::pg_catalog.oid AS rngtypid,
1711    NULL::pg_catalog.oid AS rngsubtype
1712WHERE false",
1713    access: vec![PUBLIC_SELECT],
1714    ontology: None,
1715});
1716
1717pub static PG_ENUM: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1718    name: "pg_enum",
1719    schema: PG_CATALOG_SCHEMA,
1720    oid: oid::VIEW_PG_ENUM_OID,
1721    desc: RelationDesc::builder()
1722        .with_column("oid", SqlScalarType::Oid.nullable(false))
1723        .with_column("enumtypid", SqlScalarType::Oid.nullable(false))
1724        .with_column("enumsortorder", SqlScalarType::Float32.nullable(false))
1725        .with_column("enumlabel", SqlScalarType::String.nullable(false))
1726        .with_key(vec![])
1727        .finish(),
1728    column_comments: BTreeMap::new(),
1729    sql: "SELECT
1730    NULL::pg_catalog.oid AS oid,
1731    NULL::pg_catalog.oid AS enumtypid,
1732    NULL::pg_catalog.float4 AS enumsortorder,
1733    NULL::pg_catalog.text AS enumlabel
1734WHERE false",
1735    access: vec![PUBLIC_SELECT],
1736    ontology: None,
1737});
1738
1739pub static PG_ATTRDEF: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1740    name: "pg_attrdef",
1741    schema: PG_CATALOG_SCHEMA,
1742    oid: oid::VIEW_PG_ATTRDEF_OID,
1743    desc: RelationDesc::builder()
1744        .with_column("oid", SqlScalarType::Oid.nullable(true))
1745        .with_column("adrelid", SqlScalarType::Oid.nullable(false))
1746        .with_column("adnum", SqlScalarType::Int64.nullable(false))
1747        .with_column("adbin", SqlScalarType::String.nullable(false))
1748        .with_column("adsrc", SqlScalarType::String.nullable(false))
1749        .finish(),
1750    column_comments: BTreeMap::new(),
1751    sql: "
1752SELECT
1753    pg_attrdef_all_databases.oid as oid,
1754    adrelid,
1755    adnum,
1756    adbin,
1757    adsrc
1758FROM mz_internal.pg_attrdef_all_databases
1759    JOIN mz_catalog.mz_databases d ON (d.id IS NULL OR d.name = pg_catalog.current_database());",
1760    access: vec![PUBLIC_SELECT],
1761    ontology: None,
1762});
1763
1764pub static PG_SETTINGS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1765    name: "pg_settings",
1766    schema: PG_CATALOG_SCHEMA,
1767    oid: oid::VIEW_PG_SETTINGS_OID,
1768    desc: RelationDesc::builder()
1769        .with_column("name", SqlScalarType::String.nullable(false))
1770        .with_column("setting", SqlScalarType::String.nullable(false))
1771        .with_key(vec![])
1772        .finish(),
1773    column_comments: BTreeMap::new(),
1774    sql: "SELECT
1775    name, setting
1776FROM (VALUES
1777    ('max_index_keys'::pg_catalog.text, '1000'::pg_catalog.text)
1778) AS _ (name, setting)",
1779    access: vec![PUBLIC_SELECT],
1780    ontology: None,
1781});
1782
1783pub static PG_AUTH_MEMBERS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1784    name: "pg_auth_members",
1785    schema: PG_CATALOG_SCHEMA,
1786    oid: oid::VIEW_PG_AUTH_MEMBERS_OID,
1787    desc: RelationDesc::builder()
1788        .with_column("roleid", SqlScalarType::Oid.nullable(false))
1789        .with_column("member", SqlScalarType::Oid.nullable(false))
1790        .with_column("grantor", SqlScalarType::Oid.nullable(false))
1791        .with_column("admin_option", SqlScalarType::Bool.nullable(false))
1792        .finish(),
1793    column_comments: BTreeMap::new(),
1794    sql: "SELECT
1795    role.oid AS roleid,
1796    member.oid AS member,
1797    grantor.oid AS grantor,
1798    -- Materialize hasn't implemented admin_option.
1799    false as admin_option
1800FROM mz_catalog.mz_role_members membership
1801JOIN mz_catalog.mz_roles role ON membership.role_id = role.id
1802JOIN mz_catalog.mz_roles member ON membership.member = member.id
1803JOIN mz_catalog.mz_roles grantor ON membership.grantor = grantor.id",
1804    access: vec![PUBLIC_SELECT],
1805    ontology: None,
1806});
1807
1808pub static PG_EVENT_TRIGGER: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1809    name: "pg_event_trigger",
1810    schema: PG_CATALOG_SCHEMA,
1811    oid: oid::VIEW_PG_EVENT_TRIGGER_OID,
1812    desc: RelationDesc::builder()
1813        .with_column("oid", SqlScalarType::Oid.nullable(false))
1814        .with_column("evtname", SqlScalarType::String.nullable(false))
1815        .with_column("evtevent", SqlScalarType::String.nullable(false))
1816        .with_column("evtowner", SqlScalarType::Oid.nullable(false))
1817        .with_column("evtfoid", SqlScalarType::Oid.nullable(false))
1818        .with_column("evtenabled", SqlScalarType::PgLegacyChar.nullable(false))
1819        .with_column(
1820            "evttags",
1821            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
1822        )
1823        .with_key(vec![])
1824        .finish(),
1825    column_comments: BTreeMap::new(),
1826    sql: "SELECT
1827        NULL::pg_catalog.oid AS oid,
1828        NULL::pg_catalog.text AS evtname,
1829        NULL::pg_catalog.text AS evtevent,
1830        NULL::pg_catalog.oid AS evtowner,
1831        NULL::pg_catalog.oid AS evtfoid,
1832        NULL::pg_catalog.char AS evtenabled,
1833        NULL::pg_catalog.text[] AS evttags
1834    WHERE false",
1835    access: vec![PUBLIC_SELECT],
1836    ontology: None,
1837});
1838
1839pub static PG_LANGUAGE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1840    name: "pg_language",
1841    schema: PG_CATALOG_SCHEMA,
1842    oid: oid::VIEW_PG_LANGUAGE_OID,
1843    desc: RelationDesc::builder()
1844        .with_column("oid", SqlScalarType::Oid.nullable(false))
1845        .with_column("lanname", SqlScalarType::String.nullable(false))
1846        .with_column("lanowner", SqlScalarType::Oid.nullable(false))
1847        .with_column("lanispl", SqlScalarType::Bool.nullable(false))
1848        .with_column("lanpltrusted", SqlScalarType::Bool.nullable(false))
1849        .with_column("lanplcallfoid", SqlScalarType::Oid.nullable(false))
1850        .with_column("laninline", SqlScalarType::Oid.nullable(false))
1851        .with_column("lanvalidator", SqlScalarType::Oid.nullable(false))
1852        .with_column(
1853            "lanacl",
1854            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
1855        )
1856        .with_key(vec![])
1857        .finish(),
1858    column_comments: BTreeMap::new(),
1859    sql: "SELECT
1860        NULL::pg_catalog.oid  AS oid,
1861        NULL::pg_catalog.text AS lanname,
1862        NULL::pg_catalog.oid  AS lanowner,
1863        NULL::pg_catalog.bool AS lanispl,
1864        NULL::pg_catalog.bool AS lanpltrusted,
1865        NULL::pg_catalog.oid  AS lanplcallfoid,
1866        NULL::pg_catalog.oid  AS laninline,
1867        NULL::pg_catalog.oid  AS lanvalidator,
1868        NULL::pg_catalog.text[] AS lanacl
1869    WHERE false",
1870    access: vec![PUBLIC_SELECT],
1871    ontology: None,
1872});
1873
1874pub static PG_SHDESCRIPTION: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1875    name: "pg_shdescription",
1876    schema: PG_CATALOG_SCHEMA,
1877    oid: oid::VIEW_PG_SHDESCRIPTION_OID,
1878    desc: RelationDesc::builder()
1879        .with_column("objoid", SqlScalarType::Oid.nullable(false))
1880        .with_column("classoid", SqlScalarType::Oid.nullable(false))
1881        .with_column("description", SqlScalarType::String.nullable(false))
1882        .with_key(vec![])
1883        .finish(),
1884    column_comments: BTreeMap::new(),
1885    sql: "SELECT
1886        NULL::pg_catalog.oid AS objoid,
1887        NULL::pg_catalog.oid AS classoid,
1888        NULL::pg_catalog.text AS description
1889    WHERE false",
1890    access: vec![PUBLIC_SELECT],
1891    ontology: None,
1892});
1893
1894pub static PG_TIMEZONE_ABBREVS: LazyLock<BuiltinView> = LazyLock::new(|| {
1895    BuiltinView {
1896        name: "pg_timezone_abbrevs",
1897        schema: PG_CATALOG_SCHEMA,
1898        oid: oid::VIEW_PG_TIMEZONE_ABBREVS_OID,
1899        desc: RelationDesc::builder()
1900            .with_column("abbrev", SqlScalarType::String.nullable(false))
1901            .with_column("utc_offset", SqlScalarType::Interval.nullable(true))
1902            .with_column("is_dst", SqlScalarType::Bool.nullable(true))
1903            .with_key(vec![0])
1904            .finish(),
1905        column_comments: BTreeMap::new(),
1906        sql: "SELECT
1907    abbreviation AS abbrev,
1908    COALESCE(utc_offset, timezone_offset(timezone_name, now()).base_utc_offset + timezone_offset(timezone_name, now()).dst_offset)
1909        AS utc_offset,
1910    COALESCE(dst, timezone_offset(timezone_name, now()).dst_offset <> INTERVAL '0')
1911        AS is_dst
1912FROM mz_catalog.mz_timezone_abbreviations",
1913        access: vec![PUBLIC_SELECT],
1914        ontology: None,
1915    }
1916});
1917
1918pub static PG_TIMEZONE_NAMES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1919    name: "pg_timezone_names",
1920    schema: PG_CATALOG_SCHEMA,
1921    oid: oid::VIEW_PG_TIMEZONE_NAMES_OID,
1922    desc: RelationDesc::builder()
1923        .with_column("name", SqlScalarType::String.nullable(false))
1924        .with_column("abbrev", SqlScalarType::String.nullable(true))
1925        .with_column("utc_offset", SqlScalarType::Interval.nullable(true))
1926        .with_column("is_dst", SqlScalarType::Bool.nullable(true))
1927        .with_key(vec![0])
1928        .finish(),
1929    column_comments: BTreeMap::new(),
1930    sql: "SELECT
1931    name,
1932    timezone_offset(name, now()).abbrev AS abbrev,
1933    timezone_offset(name, now()).base_utc_offset + timezone_offset(name, now()).dst_offset
1934        AS utc_offset,
1935    timezone_offset(name, now()).dst_offset <> INTERVAL '0'
1936        AS is_dst
1937FROM mz_catalog.mz_timezone_names",
1938    access: vec![PUBLIC_SELECT],
1939    ontology: None,
1940});
1941
1942// NOTE: If you add real data to this implementation, then please update
1943// the related `pg_` function implementations (like `pg_get_constraintdef`)
1944pub static PG_CONSTRAINT: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
1945    name: "pg_constraint",
1946    schema: PG_CATALOG_SCHEMA,
1947    oid: oid::VIEW_PG_CONSTRAINT_OID,
1948    desc: RelationDesc::builder()
1949        .with_column("oid", SqlScalarType::Oid.nullable(false))
1950        .with_column("conname", SqlScalarType::String.nullable(false))
1951        .with_column("connamespace", SqlScalarType::Oid.nullable(false))
1952        .with_column("contype", SqlScalarType::PgLegacyChar.nullable(false))
1953        .with_column("condeferrable", SqlScalarType::Bool.nullable(false))
1954        .with_column("condeferred", SqlScalarType::Bool.nullable(false))
1955        .with_column("convalidated", SqlScalarType::Bool.nullable(false))
1956        .with_column("conrelid", SqlScalarType::Oid.nullable(false))
1957        .with_column("contypid", SqlScalarType::Oid.nullable(false))
1958        .with_column("conindid", SqlScalarType::Oid.nullable(false))
1959        .with_column("conparentid", SqlScalarType::Oid.nullable(false))
1960        .with_column("confrelid", SqlScalarType::Oid.nullable(false))
1961        .with_column("confupdtype", SqlScalarType::PgLegacyChar.nullable(false))
1962        .with_column("confdeltype", SqlScalarType::PgLegacyChar.nullable(false))
1963        .with_column("confmatchtype", SqlScalarType::PgLegacyChar.nullable(false))
1964        .with_column("conislocal", SqlScalarType::Bool.nullable(false))
1965        .with_column("coninhcount", SqlScalarType::Int32.nullable(false))
1966        .with_column("connoinherit", SqlScalarType::Bool.nullable(false))
1967        .with_column(
1968            "conkey",
1969            SqlScalarType::Array(Box::new(SqlScalarType::Int16)).nullable(false),
1970        )
1971        .with_column(
1972            "confkey",
1973            SqlScalarType::Array(Box::new(SqlScalarType::Int16)).nullable(false),
1974        )
1975        .with_column(
1976            "conpfeqop",
1977            SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
1978        )
1979        .with_column(
1980            "conppeqop",
1981            SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
1982        )
1983        .with_column(
1984            "conffeqop",
1985            SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
1986        )
1987        .with_column(
1988            "conexclop",
1989            SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
1990        )
1991        .with_column("conbin", SqlScalarType::String.nullable(false))
1992        .with_key(vec![])
1993        .finish(),
1994    column_comments: BTreeMap::new(),
1995    sql: "SELECT
1996    NULL::pg_catalog.oid as oid,
1997    NULL::pg_catalog.text as conname,
1998    NULL::pg_catalog.oid as connamespace,
1999    NULL::pg_catalog.\"char\" as contype,
2000    NULL::pg_catalog.bool as condeferrable,
2001    NULL::pg_catalog.bool as condeferred,
2002    NULL::pg_catalog.bool as convalidated,
2003    NULL::pg_catalog.oid as conrelid,
2004    NULL::pg_catalog.oid as contypid,
2005    NULL::pg_catalog.oid as conindid,
2006    NULL::pg_catalog.oid as conparentid,
2007    NULL::pg_catalog.oid as confrelid,
2008    NULL::pg_catalog.\"char\" as confupdtype,
2009    NULL::pg_catalog.\"char\" as confdeltype,
2010    NULL::pg_catalog.\"char\" as confmatchtype,
2011    NULL::pg_catalog.bool as conislocal,
2012    NULL::pg_catalog.int4 as coninhcount,
2013    NULL::pg_catalog.bool as connoinherit,
2014    NULL::pg_catalog.int2[] as conkey,
2015    NULL::pg_catalog.int2[] as confkey,
2016    NULL::pg_catalog.oid[] as conpfeqop,
2017    NULL::pg_catalog.oid[] as conppeqop,
2018    NULL::pg_catalog.oid[] as conffeqop,
2019    NULL::pg_catalog.oid[] as conexclop,
2020    NULL::pg_catalog.text as conbin
2021WHERE false",
2022    access: vec![PUBLIC_SELECT],
2023    ontology: None,
2024});
2025
2026pub static PG_TABLES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2027    name: "pg_tables",
2028    schema: PG_CATALOG_SCHEMA,
2029    oid: oid::VIEW_PG_TABLES_OID,
2030    desc: RelationDesc::builder()
2031        .with_column("schemaname", SqlScalarType::String.nullable(true))
2032        .with_column("tablename", SqlScalarType::String.nullable(false))
2033        .with_column("tableowner", SqlScalarType::String.nullable(false))
2034        .finish(),
2035    column_comments: BTreeMap::new(),
2036    sql: "
2037SELECT n.nspname AS schemaname,
2038    c.relname AS tablename,
2039    pg_catalog.pg_get_userbyid(c.relowner) AS tableowner
2040FROM pg_catalog.pg_class c
2041LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
2042WHERE c.relkind IN ('r', 'p')",
2043    access: vec![PUBLIC_SELECT],
2044    ontology: None,
2045});
2046
2047pub static PG_TABLESPACE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2048    name: "pg_tablespace",
2049    schema: PG_CATALOG_SCHEMA,
2050    oid: oid::VIEW_PG_TABLESPACE_OID,
2051    desc: RelationDesc::builder()
2052        .with_column("oid", SqlScalarType::Oid.nullable(false))
2053        .with_column("spcname", SqlScalarType::String.nullable(false))
2054        .with_column("spcowner", SqlScalarType::Oid.nullable(true))
2055        .with_column(
2056            "spcacl",
2057            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
2058        )
2059        .with_column(
2060            "spcoptions",
2061            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
2062        )
2063        .with_key(vec![])
2064        .finish(),
2065    column_comments: BTreeMap::new(),
2066    sql: "
2067    SELECT oid, spcname, spcowner, spcacl, spcoptions
2068    FROM (
2069        VALUES (
2070            --These are the same defaults CockroachDB uses.
2071            0::pg_catalog.oid,
2072            'pg_default'::pg_catalog.text,
2073            NULL::pg_catalog.oid,
2074            NULL::pg_catalog.text[],
2075            NULL::pg_catalog.text[]
2076        )
2077    ) AS _ (oid, spcname, spcowner, spcacl, spcoptions)
2078",
2079    access: vec![PUBLIC_SELECT],
2080    ontology: None,
2081});
2082
2083pub static PG_ACCESS_METHODS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2084    name: "pg_am",
2085    schema: PG_CATALOG_SCHEMA,
2086    oid: oid::VIEW_PG_AM_OID,
2087    desc: RelationDesc::builder()
2088        .with_column("oid", SqlScalarType::Oid.nullable(false))
2089        .with_column("amname", SqlScalarType::String.nullable(false))
2090        .with_column("amhandler", SqlScalarType::RegProc.nullable(false))
2091        .with_column("amtype", SqlScalarType::PgLegacyChar.nullable(false))
2092        // NOTE: `amcanorder` was dropped from `pg_am` in PostgreSQL 9.6. Clients that
2093        // see our reported `server_version` of 9.5 query it, for example pgjdbc's
2094        // `DatabaseMetaData.getIndexInfo`.
2095        .with_column("amcanorder", SqlScalarType::Bool.nullable(false))
2096        .with_key(vec![])
2097        .finish(),
2098    column_comments: BTreeMap::new(),
2099    sql: "
2100SELECT NULL::pg_catalog.oid AS oid,
2101    NULL::pg_catalog.text AS amname,
2102    NULL::pg_catalog.regproc AS amhandler,
2103    NULL::pg_catalog.\"char\" AS amtype,
2104    NULL::pg_catalog.bool AS amcanorder
2105WHERE false",
2106    access: vec![PUBLIC_SELECT],
2107    ontology: None,
2108});
2109
2110pub static PG_ROLES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2111    name: "pg_roles",
2112    schema: PG_CATALOG_SCHEMA,
2113    oid: oid::VIEW_PG_ROLES_OID,
2114    desc: RelationDesc::builder()
2115        .with_column("rolname", SqlScalarType::String.nullable(false))
2116        .with_column("rolsuper", SqlScalarType::Bool.nullable(true))
2117        .with_column("rolinherit", SqlScalarType::Bool.nullable(false))
2118        .with_column("rolcreaterole", SqlScalarType::Bool.nullable(true))
2119        .with_column("rolcreatedb", SqlScalarType::Bool.nullable(true))
2120        .with_column("rolcanlogin", SqlScalarType::Bool.nullable(false))
2121        .with_column("rolreplication", SqlScalarType::Bool.nullable(false))
2122        .with_column("rolconnlimit", SqlScalarType::Int32.nullable(false))
2123        .with_column("rolpassword", SqlScalarType::String.nullable(false))
2124        .with_column(
2125            "rolvaliduntil",
2126            SqlScalarType::TimestampTz { precision: None }.nullable(true),
2127        )
2128        .with_column("rolbypassrls", SqlScalarType::Bool.nullable(false))
2129        .with_column(
2130            "rolconfig",
2131            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
2132        )
2133        .with_column("oid", SqlScalarType::Oid.nullable(false))
2134        .finish(),
2135    column_comments: BTreeMap::new(),
2136    sql: "SELECT
2137    rolname,
2138    rolsuper,
2139    rolinherit,
2140    rolcreaterole,
2141    rolcreatedb,
2142    COALESCE(rolcanlogin, false) AS rolcanlogin,
2143    rolreplication,
2144    rolconnlimit,
2145    '********' as rolpassword,
2146    rolvaliduntil,
2147    rolbypassrls,
2148    (
2149        SELECT array_agg(parameter_name || '=' || parameter_value)
2150        FROM mz_catalog.mz_role_parameters rp
2151        JOIN mz_catalog.mz_roles r ON r.id = rp.role_id
2152        WHERE ai.oid = r.oid
2153    ) AS rolconfig,
2154    oid
2155FROM pg_catalog.pg_authid ai",
2156    access: vec![PUBLIC_SELECT],
2157    ontology: None,
2158});
2159
2160pub static PG_USER: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2161    name: "pg_user",
2162    schema: PG_CATALOG_SCHEMA,
2163    oid: oid::VIEW_PG_USER_OID,
2164    desc: RelationDesc::builder()
2165        .with_column("usename", SqlScalarType::String.nullable(false))
2166        .with_column("usesysid", SqlScalarType::Oid.nullable(false))
2167        .with_column("usecreatedb", SqlScalarType::Bool.nullable(true))
2168        .with_column("usesuper", SqlScalarType::Bool.nullable(true))
2169        .with_column("userepl", SqlScalarType::Bool.nullable(false))
2170        .with_column("usebypassrls", SqlScalarType::Bool.nullable(false))
2171        .with_column("passwd", SqlScalarType::String.nullable(false))
2172        .with_column(
2173            "valuntil",
2174            SqlScalarType::TimestampTz { precision: None }.nullable(true),
2175        )
2176        .with_column(
2177            "useconfig",
2178            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
2179        )
2180        .finish(),
2181    column_comments: BTreeMap::new(),
2182    sql: "
2183SELECT
2184    rolname as usename,
2185    ai.oid as usesysid,
2186    rolcreatedb AS usecreatedb,
2187    rolsuper AS usesuper,
2188    rolreplication AS userepl,
2189    rolbypassrls AS usebypassrls,
2190    '********' as passwd,
2191    rolvaliduntil as valuntil,
2192    (
2193        SELECT array_agg(parameter_name || '=' || parameter_value)
2194        FROM mz_catalog.mz_role_parameters rp
2195        JOIN mz_catalog.mz_roles r ON r.id = rp.role_id
2196        WHERE ai.oid = r.oid
2197    ) AS useconfig
2198FROM pg_catalog.pg_authid ai
2199WHERE rolcanlogin",
2200    access: vec![PUBLIC_SELECT],
2201    ontology: None,
2202});
2203
2204pub static PG_VIEWS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2205    name: "pg_views",
2206    schema: PG_CATALOG_SCHEMA,
2207    oid: oid::VIEW_PG_VIEWS_OID,
2208    desc: RelationDesc::builder()
2209        .with_column("schemaname", SqlScalarType::String.nullable(true))
2210        .with_column("viewname", SqlScalarType::String.nullable(false))
2211        .with_column("viewowner", SqlScalarType::Oid.nullable(false))
2212        .with_column("definition", SqlScalarType::String.nullable(false))
2213        .finish(),
2214    column_comments: BTreeMap::new(),
2215    sql: "SELECT
2216    s.name AS schemaname,
2217    v.name AS viewname,
2218    role_owner.oid AS viewowner,
2219    v.definition AS definition
2220FROM mz_catalog.mz_views v
2221LEFT JOIN mz_catalog.mz_schemas s ON s.id = v.schema_id
2222LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
2223JOIN mz_catalog.mz_roles role_owner ON role_owner.id = v.owner_id
2224WHERE s.database_id IS NULL OR d.name = current_database()",
2225    access: vec![PUBLIC_SELECT],
2226    ontology: None,
2227});
2228
2229pub static PG_MATVIEWS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2230    name: "pg_matviews",
2231    schema: PG_CATALOG_SCHEMA,
2232    oid: oid::VIEW_PG_MATVIEWS_OID,
2233    desc: RelationDesc::builder()
2234        .with_column("schemaname", SqlScalarType::String.nullable(true))
2235        .with_column("matviewname", SqlScalarType::String.nullable(false))
2236        .with_column("matviewowner", SqlScalarType::Oid.nullable(false))
2237        .with_column("definition", SqlScalarType::String.nullable(false))
2238        .finish(),
2239    column_comments: BTreeMap::new(),
2240    sql: "SELECT
2241    s.name AS schemaname,
2242    m.name AS matviewname,
2243    role_owner.oid AS matviewowner,
2244    m.definition AS definition
2245FROM mz_catalog.mz_materialized_views m
2246LEFT JOIN mz_catalog.mz_schemas s ON s.id = m.schema_id
2247LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
2248JOIN mz_catalog.mz_roles role_owner ON role_owner.id = m.owner_id
2249WHERE s.database_id IS NULL OR d.name = current_database()",
2250    access: vec![PUBLIC_SELECT],
2251    ontology: None,
2252});
2253
2254// MZ doesn't support COLLATE so the table is filled with NULLs and made empty. pg_database hard
2255// codes a collation of 'C' for every database, so we could copy that here.
2256pub static PG_COLLATION: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2257    name: "pg_collation",
2258    schema: PG_CATALOG_SCHEMA,
2259    oid: oid::VIEW_PG_COLLATION_OID,
2260    desc: RelationDesc::builder()
2261        .with_column("oid", SqlScalarType::Oid.nullable(false))
2262        .with_column("collname", SqlScalarType::String.nullable(false))
2263        .with_column("collnamespace", SqlScalarType::Oid.nullable(false))
2264        .with_column("collowner", SqlScalarType::Oid.nullable(false))
2265        .with_column("collprovider", SqlScalarType::PgLegacyChar.nullable(false))
2266        .with_column("collisdeterministic", SqlScalarType::Bool.nullable(false))
2267        .with_column("collencoding", SqlScalarType::Int32.nullable(false))
2268        .with_column("collcollate", SqlScalarType::String.nullable(false))
2269        .with_column("collctype", SqlScalarType::String.nullable(false))
2270        .with_column("collversion", SqlScalarType::String.nullable(false))
2271        .with_key(vec![])
2272        .finish(),
2273    column_comments: BTreeMap::new(),
2274    sql: "
2275SELECT
2276    NULL::pg_catalog.oid AS oid,
2277    NULL::pg_catalog.text AS collname,
2278    NULL::pg_catalog.oid AS collnamespace,
2279    NULL::pg_catalog.oid AS collowner,
2280    NULL::pg_catalog.\"char\" AS collprovider,
2281    NULL::pg_catalog.bool AS collisdeterministic,
2282    NULL::pg_catalog.int4 AS collencoding,
2283    NULL::pg_catalog.text AS collcollate,
2284    NULL::pg_catalog.text AS collctype,
2285    NULL::pg_catalog.text AS collversion
2286WHERE false",
2287    access: vec![PUBLIC_SELECT],
2288    ontology: None,
2289});
2290
2291// MZ doesn't support row level security policies so the table is filled in with NULLs and made empty.
2292pub static PG_POLICY: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2293    name: "pg_policy",
2294    schema: PG_CATALOG_SCHEMA,
2295    oid: oid::VIEW_PG_POLICY_OID,
2296    desc: RelationDesc::builder()
2297        .with_column("oid", SqlScalarType::Oid.nullable(false))
2298        .with_column("polname", SqlScalarType::String.nullable(false))
2299        .with_column("polrelid", SqlScalarType::Oid.nullable(false))
2300        .with_column("polcmd", SqlScalarType::PgLegacyChar.nullable(false))
2301        .with_column("polpermissive", SqlScalarType::Bool.nullable(false))
2302        .with_column(
2303            "polroles",
2304            SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
2305        )
2306        .with_column("polqual", SqlScalarType::String.nullable(false))
2307        .with_column("polwithcheck", SqlScalarType::String.nullable(false))
2308        .with_key(vec![])
2309        .finish(),
2310    column_comments: BTreeMap::new(),
2311    sql: "
2312SELECT
2313    NULL::pg_catalog.oid AS oid,
2314    NULL::pg_catalog.text AS polname,
2315    NULL::pg_catalog.oid AS polrelid,
2316    NULL::pg_catalog.\"char\" AS polcmd,
2317    NULL::pg_catalog.bool AS polpermissive,
2318    NULL::pg_catalog.oid[] AS polroles,
2319    NULL::pg_catalog.text AS polqual,
2320    NULL::pg_catalog.text AS polwithcheck
2321WHERE false",
2322    access: vec![PUBLIC_SELECT],
2323    ontology: None,
2324});
2325
2326// MZ doesn't support table inheritance so the table is filled in with NULLs and made empty.
2327pub static PG_INHERITS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2328    name: "pg_inherits",
2329    schema: PG_CATALOG_SCHEMA,
2330    oid: oid::VIEW_PG_INHERITS_OID,
2331    desc: RelationDesc::builder()
2332        .with_column("inhrelid", SqlScalarType::Oid.nullable(false))
2333        .with_column("inhparent", SqlScalarType::Oid.nullable(false))
2334        .with_column("inhseqno", SqlScalarType::Int32.nullable(false))
2335        .with_column("inhdetachpending", SqlScalarType::Bool.nullable(false))
2336        .with_key(vec![])
2337        .finish(),
2338    column_comments: BTreeMap::new(),
2339    sql: "
2340SELECT
2341    NULL::pg_catalog.oid AS inhrelid,
2342    NULL::pg_catalog.oid AS inhparent,
2343    NULL::pg_catalog.int4 AS inhseqno,
2344    NULL::pg_catalog.bool AS inhdetachpending
2345WHERE false",
2346    access: vec![PUBLIC_SELECT],
2347    ontology: None,
2348});
2349
2350pub static PG_LOCKS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2351    name: "pg_locks",
2352    schema: PG_CATALOG_SCHEMA,
2353    oid: oid::VIEW_PG_LOCKS_OID,
2354    desc: RelationDesc::builder()
2355        .with_column("locktype", SqlScalarType::String.nullable(false))
2356        .with_column("database", SqlScalarType::Oid.nullable(false))
2357        .with_column("relation", SqlScalarType::Oid.nullable(false))
2358        .with_column("page", SqlScalarType::Int32.nullable(false))
2359        .with_column("tuple", SqlScalarType::Int16.nullable(false))
2360        .with_column("virtualxid", SqlScalarType::String.nullable(false))
2361        .with_column("transactionid", SqlScalarType::String.nullable(false))
2362        .with_column("classid", SqlScalarType::Oid.nullable(false))
2363        .with_column("objid", SqlScalarType::Oid.nullable(false))
2364        .with_column("objsubid", SqlScalarType::Int16.nullable(false))
2365        .with_column("virtualtransaction", SqlScalarType::String.nullable(false))
2366        .with_column("pid", SqlScalarType::Int32.nullable(false))
2367        .with_column("mode", SqlScalarType::String.nullable(false))
2368        .with_column("granted", SqlScalarType::Bool.nullable(false))
2369        .with_column("fastpath", SqlScalarType::Bool.nullable(false))
2370        .with_column(
2371            "waitstart",
2372            SqlScalarType::TimestampTz { precision: None }.nullable(false),
2373        )
2374        .with_key(vec![])
2375        .finish(),
2376    column_comments: BTreeMap::new(),
2377    sql: "
2378SELECT
2379-- While there exist locks in Materialize, we don't expose them, so all of these fields are NULL.
2380    NULL::pg_catalog.text AS locktype,
2381    NULL::pg_catalog.oid AS database,
2382    NULL::pg_catalog.oid AS relation,
2383    NULL::pg_catalog.int4 AS page,
2384    NULL::pg_catalog.int2 AS tuple,
2385    NULL::pg_catalog.text AS virtualxid,
2386    NULL::pg_catalog.text AS transactionid,
2387    NULL::pg_catalog.oid AS classid,
2388    NULL::pg_catalog.oid AS objid,
2389    NULL::pg_catalog.int2 AS objsubid,
2390    NULL::pg_catalog.text AS virtualtransaction,
2391    NULL::pg_catalog.int4 AS pid,
2392    NULL::pg_catalog.text AS mode,
2393    NULL::pg_catalog.bool AS granted,
2394    NULL::pg_catalog.bool AS fastpath,
2395    NULL::pg_catalog.timestamptz AS waitstart
2396WHERE false",
2397    access: vec![PUBLIC_SELECT],
2398    ontology: None,
2399});
2400
2401pub static PG_AUTHID: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2402    name: "pg_authid",
2403    schema: PG_CATALOG_SCHEMA,
2404    oid: oid::VIEW_PG_AUTHID_OID,
2405    desc: RelationDesc::builder()
2406        .with_column("oid", SqlScalarType::Oid.nullable(false))
2407        .with_column("rolname", SqlScalarType::String.nullable(false))
2408        .with_column("rolsuper", SqlScalarType::Bool.nullable(true))
2409        .with_column("rolinherit", SqlScalarType::Bool.nullable(false))
2410        .with_column("rolcreaterole", SqlScalarType::Bool.nullable(true))
2411        .with_column("rolcreatedb", SqlScalarType::Bool.nullable(true))
2412        .with_column("rolcanlogin", SqlScalarType::Bool.nullable(false))
2413        .with_column("rolreplication", SqlScalarType::Bool.nullable(false))
2414        .with_column("rolbypassrls", SqlScalarType::Bool.nullable(false))
2415        .with_column("rolconnlimit", SqlScalarType::Int32.nullable(false))
2416        .with_column("rolpassword", SqlScalarType::String.nullable(true))
2417        .with_column(
2418            "rolvaliduntil",
2419            SqlScalarType::TimestampTz { precision: None }.nullable(true),
2420        )
2421        .finish(),
2422    column_comments: BTreeMap::new(),
2423    // The `has_system_privilege` invocations for `rolcreaterole` and `rolcreatedb` get expanded
2424    // into very complex subqueries. If we put them into the SELECT clause directly, decorrelation
2425    // produces a very complex plan that the optimizer has a hard time dealing with. In particular,
2426    // the optimizer fails to reduce a query like `SELECT oid FROM pg_authid` to a simple lookup on
2427    // the `pg_authid_core` index and instead produces a large plan that contains a bunch of
2428    // expensive joins and arrangements.
2429    //
2430    // The proper fix is likely to implement `has_system_privileges` in Rust, but for now we work
2431    // around the issue by manually decorrelating `rolcreaterole` and `rolcreatedb`. Note that to
2432    // get the desired behavior we need to make sure that the join with `extra` doesn't change the
2433    // cardinality of `pg_authid_core` (otherwise it can never be optimized away). We ensure this
2434    // by:
2435    //  * using a `LEFT JOIN`, so the optimizer knows that left elements are never filtered
2436    //  * applying a `DISTINCT ON` to the CTE, so the optimizer knows that left elements are never
2437    //    duplicated
2438    sql: r#"
2439WITH extra AS (
2440    SELECT
2441        DISTINCT ON (oid)
2442        oid,
2443        mz_catalog.has_system_privilege(oid, 'CREATEROLE') AS rolcreaterole,
2444        mz_catalog.has_system_privilege(oid, 'CREATEDB') AS rolcreatedb
2445    FROM mz_internal.pg_authid_core
2446)
2447SELECT
2448    oid,
2449    rolname,
2450    rolsuper,
2451    rolinherit,
2452    extra.rolcreaterole,
2453    extra.rolcreatedb,
2454    rolcanlogin,
2455    rolreplication,
2456    rolbypassrls,
2457    rolconnlimit,
2458    rolpassword,
2459    rolvaliduntil
2460FROM mz_internal.pg_authid_core
2461LEFT JOIN extra USING (oid)"#,
2462    access: vec![rbac::owner_privilege(ObjectType::Table, MZ_SYSTEM_ROLE_ID)],
2463    ontology: None,
2464});
2465
2466pub static PG_AGGREGATE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2467    name: "pg_aggregate",
2468    schema: PG_CATALOG_SCHEMA,
2469    oid: oid::VIEW_PG_AGGREGATE_OID,
2470    desc: RelationDesc::builder()
2471        .with_column("aggfnoid", SqlScalarType::Oid.nullable(false))
2472        .with_column("aggkind", SqlScalarType::String.nullable(false))
2473        .with_column("aggnumdirectargs", SqlScalarType::Int16.nullable(false))
2474        .with_column("aggtransfn", SqlScalarType::RegProc.nullable(true))
2475        .with_column("aggfinalfn", SqlScalarType::RegProc.nullable(false))
2476        .with_column("aggcombinefn", SqlScalarType::RegProc.nullable(false))
2477        .with_column("aggserialfn", SqlScalarType::RegProc.nullable(false))
2478        .with_column("aggdeserialfn", SqlScalarType::RegProc.nullable(false))
2479        .with_column("aggmtransfn", SqlScalarType::RegProc.nullable(false))
2480        .with_column("aggminvtransfn", SqlScalarType::RegProc.nullable(false))
2481        .with_column("aggmfinalfn", SqlScalarType::RegProc.nullable(false))
2482        .with_column("aggfinalextra", SqlScalarType::Bool.nullable(false))
2483        .with_column("aggmfinalextra", SqlScalarType::Bool.nullable(false))
2484        .with_column("aggfinalmodify", SqlScalarType::PgLegacyChar.nullable(true))
2485        .with_column(
2486            "aggmfinalmodify",
2487            SqlScalarType::PgLegacyChar.nullable(true),
2488        )
2489        .with_column("aggsortop", SqlScalarType::Oid.nullable(false))
2490        .with_column("aggtranstype", SqlScalarType::Oid.nullable(true))
2491        .with_column("aggtransspace", SqlScalarType::Int32.nullable(true))
2492        .with_column("aggmtranstype", SqlScalarType::Oid.nullable(false))
2493        .with_column("aggmtransspace", SqlScalarType::Int32.nullable(true))
2494        .with_column("agginitval", SqlScalarType::String.nullable(true))
2495        .with_column("aggminitval", SqlScalarType::String.nullable(true))
2496        .finish(),
2497    column_comments: BTreeMap::new(),
2498    sql: "SELECT
2499    a.oid as aggfnoid,
2500    -- Currently Materialize only support 'normal' aggregate functions.
2501    a.agg_kind as aggkind,
2502    a.agg_num_direct_args as aggnumdirectargs,
2503    -- Materialize doesn't support these fields.
2504    NULL::pg_catalog.regproc as aggtransfn,
2505    '0'::pg_catalog.regproc as aggfinalfn,
2506    '0'::pg_catalog.regproc as aggcombinefn,
2507    '0'::pg_catalog.regproc as aggserialfn,
2508    '0'::pg_catalog.regproc as aggdeserialfn,
2509    '0'::pg_catalog.regproc as aggmtransfn,
2510    '0'::pg_catalog.regproc as aggminvtransfn,
2511    '0'::pg_catalog.regproc as aggmfinalfn,
2512    false as aggfinalextra,
2513    false as aggmfinalextra,
2514    NULL::pg_catalog.\"char\" AS aggfinalmodify,
2515    NULL::pg_catalog.\"char\" AS aggmfinalmodify,
2516    '0'::pg_catalog.oid as aggsortop,
2517    NULL::pg_catalog.oid as aggtranstype,
2518    NULL::pg_catalog.int4 as aggtransspace,
2519    '0'::pg_catalog.oid as aggmtranstype,
2520    NULL::pg_catalog.int4 as aggmtransspace,
2521    NULL::pg_catalog.text as agginitval,
2522    NULL::pg_catalog.text as aggminitval
2523FROM mz_internal.mz_aggregates a",
2524    access: vec![PUBLIC_SELECT],
2525    ontology: None,
2526});
2527
2528pub static PG_TRIGGER: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2529    name: "pg_trigger",
2530    schema: PG_CATALOG_SCHEMA,
2531    oid: oid::VIEW_PG_TRIGGER_OID,
2532    desc: RelationDesc::builder()
2533        .with_column("oid", SqlScalarType::Oid.nullable(false))
2534        .with_column("tgrelid", SqlScalarType::Oid.nullable(false))
2535        .with_column("tgparentid", SqlScalarType::Oid.nullable(false))
2536        .with_column("tgname", SqlScalarType::String.nullable(false))
2537        .with_column("tgfoid", SqlScalarType::Oid.nullable(false))
2538        .with_column("tgtype", SqlScalarType::Int16.nullable(false))
2539        .with_column("tgenabled", SqlScalarType::PgLegacyChar.nullable(false))
2540        .with_column("tgisinternal", SqlScalarType::Bool.nullable(false))
2541        .with_column("tgconstrrelid", SqlScalarType::Oid.nullable(false))
2542        .with_column("tgconstrindid", SqlScalarType::Oid.nullable(false))
2543        .with_column("tgconstraint", SqlScalarType::Oid.nullable(false))
2544        .with_column("tgdeferrable", SqlScalarType::Bool.nullable(false))
2545        .with_column("tginitdeferred", SqlScalarType::Bool.nullable(false))
2546        .with_column("tgnargs", SqlScalarType::Int16.nullable(false))
2547        .with_column("tgattr", SqlScalarType::Int2Vector.nullable(false))
2548        .with_column("tgargs", SqlScalarType::Bytes.nullable(false))
2549        .with_column("tgqual", SqlScalarType::String.nullable(false))
2550        .with_column("tgoldtable", SqlScalarType::String.nullable(false))
2551        .with_column("tgnewtable", SqlScalarType::String.nullable(false))
2552        .with_key(vec![])
2553        .finish(),
2554    column_comments: BTreeMap::new(),
2555    sql: "SELECT
2556    -- MZ doesn't support triggers so all of these fields are NULL.
2557    NULL::pg_catalog.oid AS oid,
2558    NULL::pg_catalog.oid AS tgrelid,
2559    NULL::pg_catalog.oid AS tgparentid,
2560    NULL::pg_catalog.text AS tgname,
2561    NULL::pg_catalog.oid AS tgfoid,
2562    NULL::pg_catalog.int2 AS tgtype,
2563    NULL::pg_catalog.\"char\" AS tgenabled,
2564    NULL::pg_catalog.bool AS tgisinternal,
2565    NULL::pg_catalog.oid AS tgconstrrelid,
2566    NULL::pg_catalog.oid AS tgconstrindid,
2567    NULL::pg_catalog.oid AS tgconstraint,
2568    NULL::pg_catalog.bool AS tgdeferrable,
2569    NULL::pg_catalog.bool AS tginitdeferred,
2570    NULL::pg_catalog.int2 AS tgnargs,
2571    NULL::pg_catalog.int2vector AS tgattr,
2572    NULL::pg_catalog.bytea AS tgargs,
2573    -- NOTE: The tgqual column is actually type `pg_node_tree` which we don't support. CockroachDB
2574    -- uses text as a placeholder, so we'll follow their lead here.
2575    NULL::pg_catalog.text AS tgqual,
2576    NULL::pg_catalog.text AS tgoldtable,
2577    NULL::pg_catalog.text AS tgnewtable
2578WHERE false
2579    ",
2580    access: vec![PUBLIC_SELECT],
2581    ontology: None,
2582});
2583
2584pub static PG_REWRITE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2585    name: "pg_rewrite",
2586    schema: PG_CATALOG_SCHEMA,
2587    oid: oid::VIEW_PG_REWRITE_OID,
2588    desc: RelationDesc::builder()
2589        .with_column("oid", SqlScalarType::Oid.nullable(false))
2590        .with_column("rulename", SqlScalarType::String.nullable(false))
2591        .with_column("ev_class", SqlScalarType::Oid.nullable(false))
2592        .with_column("ev_type", SqlScalarType::PgLegacyChar.nullable(false))
2593        .with_column("ev_enabled", SqlScalarType::PgLegacyChar.nullable(false))
2594        .with_column("is_instead", SqlScalarType::Bool.nullable(false))
2595        .with_column("ev_qual", SqlScalarType::String.nullable(false))
2596        .with_column("ev_action", SqlScalarType::String.nullable(false))
2597        .with_key(vec![])
2598        .finish(),
2599    column_comments: BTreeMap::new(),
2600    sql: "SELECT
2601    -- MZ doesn't support rewrite rules so all of these fields are NULL.
2602    NULL::pg_catalog.oid AS oid,
2603    NULL::pg_catalog.text AS rulename,
2604    NULL::pg_catalog.oid AS ev_class,
2605    NULL::pg_catalog.\"char\" AS ev_type,
2606    NULL::pg_catalog.\"char\" AS ev_enabled,
2607    NULL::pg_catalog.bool AS is_instead,
2608    -- NOTE: The ev_qual and ev_action columns are actually type `pg_node_tree` which we don't
2609    -- support. CockroachDB uses text as a placeholder, so we'll follow their lead here.
2610    NULL::pg_catalog.text AS ev_qual,
2611    NULL::pg_catalog.text AS ev_action
2612WHERE false
2613    ",
2614    access: vec![PUBLIC_SELECT],
2615    ontology: None,
2616});
2617
2618pub static PG_EXTENSION: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2619    name: "pg_extension",
2620    schema: PG_CATALOG_SCHEMA,
2621    oid: oid::VIEW_PG_EXTENSION_OID,
2622    desc: RelationDesc::builder()
2623        .with_column("oid", SqlScalarType::Oid.nullable(false))
2624        .with_column("extname", SqlScalarType::String.nullable(false))
2625        .with_column("extowner", SqlScalarType::Oid.nullable(false))
2626        .with_column("extnamespace", SqlScalarType::Oid.nullable(false))
2627        .with_column("extrelocatable", SqlScalarType::Bool.nullable(false))
2628        .with_column("extversion", SqlScalarType::String.nullable(false))
2629        .with_column(
2630            "extconfig",
2631            SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
2632        )
2633        .with_column(
2634            "extcondition",
2635            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
2636        )
2637        .with_key(vec![])
2638        .finish(),
2639    column_comments: BTreeMap::new(),
2640    sql: "SELECT
2641    -- MZ doesn't support extensions so all of these fields are NULL.
2642    NULL::pg_catalog.oid AS oid,
2643    NULL::pg_catalog.text AS extname,
2644    NULL::pg_catalog.oid AS extowner,
2645    NULL::pg_catalog.oid AS extnamespace,
2646    NULL::pg_catalog.bool AS extrelocatable,
2647    NULL::pg_catalog.text AS extversion,
2648    NULL::pg_catalog.oid[] AS extconfig,
2649    NULL::pg_catalog.text[] AS extcondition
2650WHERE false
2651    ",
2652    access: vec![PUBLIC_SELECT],
2653    ontology: None,
2654});