diff --git a/doc/developer/sqllogictest.md b/doc/developer/sqllogictest.md index 96447344f4b0e..0097665460b67 100644 --- a/doc/developer/sqllogictest.md +++ b/doc/developer/sqllogictest.md @@ -190,6 +190,39 @@ Because the substitution is applied to actual output before both comparison and rewrite, the masked token is what gets recorded, so the file stays stable across runs. +### `user` extension + +The `user ` directive, from CockroachDB's logic tests, switches the +session user for all subsequent records. The role is created on first use and +its connection is cached. `user root` (and `user materialize`) switches back +to the default superuser. Roles created this way are dropped when the next +file starts. + +### CockroachDB dialect support + +The files in [test/sqllogictest/cockroach](/test/sqllogictest/cockroach) are +imported from CockroachDB (see the +[README](/test/sqllogictest/cockroach/README.md) for provenance). To run them +mostly unmodified, the runner handles some CockroachDB-isms: + +* A `query` without a `----` separator must succeed and return no rows. A + blank line only ends such a record when a new record (directive, comment, + or end of file) follows it, because hand-written files may contain blank + lines inside a query's SQL. +* A statement record containing multiple SQL commands executes them one at a + time, reporting the first error. +* A `CREATE TABLE` that fails to parse is retried with CockroachDB's inline + `INDEX`, `UNIQUE INDEX`, `INVERTED INDEX`, and `FAMILY` items stripped. + Constraints are kept. +* `SET` or `RESET` of a configuration parameter Materialize does not + recognize is a no-op success. +* `let $var` blocks are skipped, so records referencing the variable fail at + execution time. `skip_on_retry` is ignored. `statement notice` only checks + for success. The `retry` query option is ignored, `noticetrace` queries are + skipped entirely, and the `F` column type char is treated like `R`. +* An expected-error pattern that is not a valid regex never matches, failing + that record rather than aborting the whole run. + ### modes We have extended sqllogictest to have the concept of the "mode." There are two diff --git a/misc/python/materialize/cli/ci_closed_issues_detect.py b/misc/python/materialize/cli/ci_closed_issues_detect.py index a5e44bf8ab8da..5d821b266e27c 100644 --- a/misc/python/materialize/cli/ci_closed_issues_detect.py +++ b/misc/python/materialize/cli/ci_closed_issues_detect.py @@ -110,6 +110,7 @@ ( .*\.(svg|png|jpg|jpeg|avif|avro|ico|woff) | doc/developer/design/20230223_stabilize_with_mutually_recursive.md | \.(agents|claude)/skills/.* + | test/sqllogictest/cockroach/.* ) """, re.VERBOSE, diff --git a/src/sqllogictest/src/ast.rs b/src/sqllogictest/src/ast.rs index 587f87220ff76..47a52773290fd 100644 --- a/src/sqllogictest/src/ast.rs +++ b/src/sqllogictest/src/ast.rs @@ -145,6 +145,10 @@ pub enum Record<'a> { table_name: &'a str, tsv_path: &'a str, }, + /// A `user` directive. Switches the session user for subsequent records, + /// as in CockroachDB's logic tests. The role is created if it does not + /// exist yet. + User { location: Location, user: &'a str }, /// A `reset-server` directive ResetServer, /// A `replace` directive. Registers a regular-expression substitution that diff --git a/src/sqllogictest/src/parser.rs b/src/sqllogictest/src/parser.rs index 4e6fe16886ace..8ee9a21845d3b 100644 --- a/src/sqllogictest/src/parser.rs +++ b/src/sqllogictest/src/parser.rs @@ -133,7 +133,25 @@ impl<'a> Parser<'a> { "halt" => Ok(Record::Halt), // this is some cockroach-specific thing, we don't care - "subtest" | "user" | "kv-batch-size" => self.parse_record(), + "subtest" | "kv-batch-size" | "skip_on_retry" => self.parse_record(), + + // CockroachDB's `user` directive switches the session user for + // subsequent records. + "user" => Ok(Record::User { + location: self.location(), + user: words + .next() + .ok_or_else(|| anyhow!("user directive missing name"))?, + }), + + // CockroachDB's `let $var` binds the result of the following query + // to a variable that later records reference. We don't support the + // binding, so skip the directive and its query block. Records that + // reference the variable fail at execution time instead. + "let" => { + self.split_at(&DOUBLE_LINE_REGEX)?; + self.parse_record() + } "mode" => { self.mode = match words.next() { @@ -223,8 +241,17 @@ impl<'a> Parser<'a> { .map_err(|err| anyhow!("parsing count of rows affected: {}", err))?, ); } - Some("ok") | Some("OK") => (), Some("error") => expected_error = Some(parse_expected_error(first_line)), + // CockroachDB's `statement notice ` expects the statement + // to succeed and additionally emit a matching notice. We only + // check for success. + Some("notice") => (), + // An `ok` prefix accepts the typos present in files imported from + // CockroachDB (`oK`, `ok;`, `oko`), which CockroachDB's own + // lenient runner treats as plain `ok`. + Some(disposition) if disposition.to_lowercase().starts_with("ok") => (), + // A bare `statement` with no disposition expects success. + None => (), _ => bail!("invalid statement disposition: {}", first_line), }; let sql = self.split_at(&DOUBLE_LINE_REGEX)?; @@ -256,6 +283,7 @@ impl<'a> Parser<'a> { let mut sort = Sort::No; let mut check_column_names = false; let mut multiline = false; + let mut noticetrace = false; if let Some(options) = words.next() { for option in options.split(',') { match option { @@ -264,6 +292,13 @@ impl<'a> Parser<'a> { "valuesort" => sort = Sort::Value, "colnames" => check_column_names = true, "multiline" => multiline = true, + // CockroachDB re-runs `retry` queries until the output + // converges. We run them once, like any other query. + "retry" => (), + // CockroachDB `noticetrace` queries assert the emitted + // notices rather than rows. We can't observe notices, so + // the whole record is skipped below. + "noticetrace" => noticetrace = true, other => { if other.starts_with("partialsort") { // TODO(jamii) https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/logic.go#L153 @@ -285,6 +320,60 @@ impl<'a> Parser<'a> { static LINE_REGEX: LazyLock = LazyLock::new(|| Regex::new("\r?(\n|$)").unwrap()); static HASH_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"(\S+) values hashing to (\S+)").unwrap()); + // CockroachDB queries may omit the `----` separator entirely, in + // which case the query must succeed and return no rows. Detect this + // by checking whether the record ends before the next `----`, which + // otherwise belongs to a later record. A blank line only ends the + // record if what follows it starts a new record (directive, comment, + // or end of file): hand-written files contain blank lines inside a + // query's SQL, which CockroachDB's own files never do. + static RECORD_START_REGEX: LazyLock = LazyLock::new(|| { + Regex::new( + r"^(#|$|statement( |$)|query( |$)|simple( |$)|halt( |$)|mode |copy |user |subtest( |$)|let |skipif |onlyif |hash-threshold |reset-server( |$)|replace |kv-batch-size |skip_on_retry( |$))", + ) + .unwrap() + }); + let sep = QUERY_OUTPUT_REGEX.find(self.contents); + let end = DOUBLE_LINE_REGEX.find(self.contents); + let no_separator = match (&sep, &end) { + (Some(sep), Some(end)) if sep.start() < end.start() => false, + (_, Some(end)) => { + let mut rest = &self.contents[end.end()..]; + loop { + let line_end = rest.find('\n').map_or(rest.len(), |i| i + 1); + let line = rest[..line_end].trim(); + if line.is_empty() && line_end < rest.len() { + rest = &rest[line_end..]; + continue; + } + break RECORD_START_REGEX.is_match(line); + } + } + (_, None) => false, + }; + if no_separator { + let sql = self.split_at(&DOUBLE_LINE_REGEX)?; + if noticetrace { + return self.parse_record(); + } + return Ok(Record::Query { + sql, + output: Ok(QueryOutput { + types, + sort, + multiline, + label, + column_names: None, + mode: self.mode, + output: Output::Values(vec![]), + // An empty slice at the end of the SQL, so rewriting has + // an in-bounds position to work with. + output_str: &sql[sql.len()..], + }), + location, + }); + } + let sql = self.split_at(&QUERY_OUTPUT_REGEX)?; let mut output_str = self.split_at(if multiline { &EOF_REGEX @@ -292,6 +381,10 @@ impl<'a> Parser<'a> { &DOUBLE_LINE_REGEX })?; + if noticetrace { + return self.parse_record(); + } + // The `split_at(&QUERY_OUTPUT_REGEX)` stopped at the end of `----`, so `output_str` usually // starts with a newline, which is not actually part of the expected output. Strip off this // newline. @@ -494,6 +587,9 @@ fn parse_types(input: &str) -> Result, anyhow::Error> { 'T' => Type::Text, 'I' => Type::Integer, 'R' => Type::Real, + // CockroachDB uses `F` for floats and `R` for decimals. We + // don't distinguish the two. + 'F' => Type::Real, 'B' => Type::Bool, 'O' => Type::Oid, _ => bail!("Unexpected type char {} in: {}", char, input), @@ -536,3 +632,41 @@ pub fn regexp_strip_prefix<'a>(text: &'a str, regexp: &Regex) -> Option<&'a str> None => None, } } + +#[mz_ore::test] +fn test_parse_query_blank_lines_and_missing_separator() { + // A blank line inside a query's SQL does not end the record. + let file = "query I\nSELECT 1\n\nUNION ALL SELECT 2\n----\n1\n2\n\n"; + let records = Parser::new("f", file).parse_records().unwrap(); + assert_eq!(records.len(), 1); + match &records[0] { + Record::Query { sql, .. } => { + assert!(sql.contains("UNION ALL"), "sql: {sql}") + } + other => panic!("unexpected record: {other:?}"), + } + + // A query with no ---- separator expects zero rows, and the blank line + // ends the record when a new record follows. + let file = "query I\nSELECT 3\n\nstatement ok\nSELECT 4\n\n# comment\n\nquery I\nSELECT 5\n"; + let records = Parser::new("f", file).parse_records().unwrap(); + assert_eq!(records.len(), 3); + match &records[0] { + Record::Query { sql, output, .. } => { + assert_eq!(*sql, "SELECT 3"); + assert_eq!(output.as_ref().unwrap().output, Output::Values(vec![])); + } + other => panic!("unexpected record: {other:?}"), + } + + // No separator at end of file. + let file = "query I\nSELECT 6\n"; + let records = Parser::new("f", file).parse_records().unwrap(); + assert_eq!(records.len(), 1); + match &records[0] { + Record::Query { output, .. } => { + assert_eq!(output.as_ref().unwrap().output, Output::Values(vec![])); + } + other => panic!("unexpected record: {other:?}"), + } +} diff --git a/src/sqllogictest/src/runner.rs b/src/sqllogictest/src/runner.rs index a86b2caf09e29..8be0d81a1fb8d 100644 --- a/src/sqllogictest/src/runner.rs +++ b/src/sqllogictest/src/runner.rs @@ -472,6 +472,9 @@ pub struct RunnerInner<'a> { client: tokio_postgres::Client, system_client: tokio_postgres::Client, clients: BTreeMap, + /// The user set by the most recent `user` directive, if any. Records run + /// on that user's connection (cached in `clients`) instead of `client`. + active_user: Option, auto_index_tables: bool, auto_index_selects: bool, auto_transactions: bool, @@ -685,7 +688,7 @@ where T::from_sql_nullable(type_, value) } -fn format_datum(d: Slt, typ: &Type, mode: Mode, col: usize) -> String { +fn format_datum(d: Slt, typ: &Type, mode: Mode) -> String { match (typ, d.0) { (Type::Bool, Value::Bool(b)) => b.to_string(), @@ -770,10 +773,15 @@ fn format_datum(d: Slt, typ: &Type, mode: Mode, col: usize) -> String { (Type::Oid, Value::Oid(o)) => o.to_string(), - (_, d) => panic!( - "Don't know how to format {:?} as {:?} in column {}", - d, typ, col, - ), + // A mismatch between the declared column type and the value the query + // actually returned. Fall back to normal text encoding so the + // mismatch surfaces as an output diff rather than a panic that aborts + // the entire run. + (_, d) => { + let mut buf = BytesMut::new(); + d.encode_text(&mut buf); + String::from_utf8_lossy(&buf).into_owned() + } } } @@ -781,7 +789,7 @@ fn format_row(row: &Row, types: &[Type], mode: Mode) -> Vec { let mut formatted: Vec = vec![]; for i in 0..row.len() { let t: Option = row.get::>(i); - let t: Option = t.map(|d| format_datum(d, &types[i], mode, i)); + let t: Option = t.map(|d| format_datum(d, &types[i], mode)); formatted.push(match t { Some(t) => t, None => "NULL".into(), @@ -791,6 +799,87 @@ fn format_row(row: &Row, types: &[Type], mode: Mode) -> Vec { formatted } +/// Reports whether `err` matches the `expected_error` regex of a record. +/// +/// Expected errors in files imported from CockroachDB are not always valid +/// regexes. An invalid regex cannot match, so the record fails with the usual +/// mismatch outcome rather than aborting the entire run. +fn error_matches(expected_error: &str, err: &str) -> bool { + match Regex::new(expected_error) { + Ok(re) => re.is_match(err), + Err(_) => false, + } +} + +/// Removes CockroachDB-specific physical-layout items (`INDEX`, +/// `UNIQUE INDEX`, `INVERTED INDEX`, and `FAMILY` definitions) from the +/// column list of a `CREATE TABLE` statement. Constraints are kept, since +/// dropping them would change the statement's semantics. Returns `None` if +/// `sql` does not look like a `CREATE TABLE` statement. +fn strip_crdb_table_items(sql: &str) -> Option { + if !sql.trim_start().to_uppercase().starts_with("CREATE TABLE") { + return None; + } + let open = sql.find('(')?; + let mut depth = 1; + let mut in_string = false; + let mut in_ident = false; + let mut items: Vec<&str> = vec![]; + let mut item_start = open + 1; + let mut close = None; + for (i, c) in sql[open + 1..].char_indices() { + let i = open + 1 + i; + match c { + '\'' if !in_ident => in_string = !in_string, + '"' if !in_string => in_ident = !in_ident, + _ if in_string || in_ident => (), + '(' => depth += 1, + ')' => { + depth -= 1; + if depth == 0 { + close = Some(i); + break; + } + } + ',' if depth == 1 => { + items.push(&sql[item_start..i]); + item_start = i + 1; + } + _ => (), + } + } + let close = close?; + items.push(&sql[item_start..close]); + fn first_word(s: &str) -> String { + s.trim_start() + .chars() + .take_while(|c| c.is_ascii_alphanumeric() || *c == '_') + .collect::() + .to_uppercase() + } + let kept: Vec<&str> = items + .into_iter() + .filter(|item| { + let first = first_word(item); + let is_physical = match first.as_str() { + "INDEX" | "FAMILY" => true, + "UNIQUE" | "INVERTED" => { + let rest = &item.trim_start()[first.len()..]; + first_word(rest) == "INDEX" + } + _ => false, + }; + !is_physical + }) + .collect(); + Some(format!( + "{}{}{}", + &sql[..open + 1], + kept.join(","), + &sql[close..] + )) +} + impl<'a> Runner<'a> { pub async fn start(config: &'a RunConfig<'a>) -> Result, anyhow::Error> { let mut runner = Self { @@ -877,6 +966,7 @@ impl<'a> Runner<'a> { .batch_execute(sql!("DROP DATABASE {}", Sql::ident(name)).as_str()) .await?; } + inner .system_client .batch_execute("CREATE DATABASE materialize") @@ -971,6 +1061,26 @@ impl<'a> Runner<'a> { .await?; } + // Drop all user roles except the default one, so that roles created + // via the `user` directive or by the tests themselves do not leak + // into later files. Best-effort: a role that still owns objects (for + // example through default privileges) stays behind rather than + // failing the reset. + for row in inner + .system_client + .query( + "SELECT name FROM mz_roles WHERE id LIKE 'u%' AND name != 'materialize'", + &[], + ) + .await? + { + let name: &str = row.get("name"); + let _ = inner + .system_client + .batch_execute(sql!("DROP ROLE {}", Sql::ident(name)).as_str()) + .await; + } + // Grant initial privileges. inner .system_client @@ -1014,6 +1124,7 @@ impl<'a> Runner<'a> { .await .unwrap(); inner.clients = BTreeMap::new(); + inner.active_user = None; Ok(()) } @@ -1360,6 +1471,7 @@ impl<'a> RunnerInner<'a> { client, system_client, clients: BTreeMap::new(), + active_user: None, auto_index_tables: config.auto_index_tables, auto_index_selects: config.auto_index_selects, auto_transactions: config.auto_transactions, @@ -1390,6 +1502,70 @@ impl<'a> RunnerInner<'a> { Ok(()) } + /// The connection records run on: the `user` directive's connection when + /// one is active, the default connection otherwise. + fn active_client(&self) -> &tokio_postgres::Client { + match &self.active_user { + Some(user) => self + .clients + .get(user) + .expect("connection for the active user exists"), + None => &self.client, + } + } + + /// Handles a `user` directive: ensures the role exists, connects as it, + /// and makes it the active user. CockroachDB's `root` maps to the + /// default `materialize` user. + #[allow(clippy::disallowed_methods)] + async fn run_user<'r>( + &mut self, + user: &'r str, + location: &Location, + in_transaction: &mut bool, + ) -> Result, anyhow::Error> { + if self.auto_transactions && *in_transaction { + self.active_client().execute("COMMIT", &[]).await?; + *in_transaction = false; + } + if user == "root" || user == "materialize" { + self.active_user = None; + return Ok(Outcome::Success); + } + if !self.clients.contains_key(user) { + let create = sql!("CREATE ROLE {}", Sql::ident(user)); + if let Err(error) = self.system_client.batch_execute(create.as_str()).await { + if !error.to_string_with_causes().contains("already exists") { + return Ok(Outcome::Bail { + cause: Box::new(Outcome::PlanFailure { + error: anyhow!(error), + expected_error: None, + location: location.clone(), + }), + location: location.clone(), + }); + } + } + match connect(self.server_addr, Some(user), None).await { + Ok(client) => { + self.clients.insert(user.to_string(), client); + } + Err(error) => { + return Ok(Outcome::Bail { + cause: Box::new(Outcome::PlanFailure { + error: anyhow!(error), + expected_error: None, + location: location.clone(), + }), + location: location.clone(), + }); + } + } + } + self.active_user = Some(user.to_string()); + Ok(Outcome::Success) + } + #[allow(clippy::disallowed_methods)] async fn run_record<'r>( &mut self, @@ -1398,6 +1574,7 @@ impl<'a> RunnerInner<'a> { replacements: &[(Regex, String)], ) -> Result, anyhow::Error> { match &record { + Record::User { user, location } => self.run_user(user, location, in_transaction).await, Record::Statement { expected_error, rows_affected, @@ -1405,7 +1582,7 @@ impl<'a> RunnerInner<'a> { location, } => { if self.auto_transactions && *in_transaction { - self.client.execute("COMMIT", &[]).await?; + self.active_client().execute("COMMIT", &[]).await?; *in_transaction = false; } match self @@ -1416,7 +1593,7 @@ impl<'a> RunnerInner<'a> { if self.auto_index_tables { let additional = mutate(sql); for stmt in additional { - self.client.execute(&stmt, &[]).await?; + self.active_client().execute(&stmt, &[]).await?; } } Ok(Outcome::Success) @@ -1498,7 +1675,44 @@ impl<'a> RunnerInner<'a> { return Ok(Outcome::Success); } - match self.client.execute(sql, &[]).await { + // CockroachDB's logic tests frequently pack multiple commands into + // one statement record. The extended protocol used by `execute` + // rejects those, and Materialize restricts DDL inside the implicit + // transaction the simple protocol would wrap them in, so run each + // command separately and report the first error. This path cannot + // report an affected-row count, so records that assert one keep the + // single-command path (and fail if they contain multiple commands). + let commands = if expected_rows_affected.is_none() { + match mz_sql::parse::parse(sql) { + Ok(stmts) if stmts.len() > 1 => { + Some(stmts.iter().map(|s| s.sql.to_owned()).collect::>()) + } + Ok(_) => None, + // A statement Materialize cannot parse may be a CockroachDB + // `CREATE TABLE` with inline physical-layout items. Retry + // with those stripped, so the semantic records that follow + // can still run against the table. + Err(_) => strip_crdb_table_items(sql) + .filter(|stripped| mz_sql::parse::parse(stripped).is_ok()) + .map(|stripped| vec![stripped]), + } + } else { + None + }; + let result = match commands { + Some(commands) => { + let mut result = Ok(0); + for command in &commands { + if let Err(error) = self.active_client().execute(command, &[]).await { + result = Err(error); + break; + } + } + result + } + None => self.active_client().execute(sql, &[]).await, + }; + match result { Ok(actual) => { if let Some(expected_error) = expected_error { return Ok(Outcome::UnexpectedPlanSuccess { @@ -1523,7 +1737,7 @@ impl<'a> RunnerInner<'a> { } Err(error) => { if let Some(expected_error) = expected_error { - if Regex::new(expected_error)?.is_match(&error.to_string_with_causes()) { + if error_matches(expected_error, &error.to_string_with_causes()) { return Ok(Outcome::Success); } return Ok(Outcome::PlanFailure { @@ -1532,6 +1746,18 @@ impl<'a> RunnerInner<'a> { location, }); } + // CockroachDB tests configure many CockroachDB-specific + // session settings. Treat setting an unknown parameter as a + // no-op success so the records that follow still run. + static SET_STATEMENT_REGEX: LazyLock = + LazyLock::new(|| Regex::new("(?i)^(SET|RESET) ").unwrap()); + if SET_STATEMENT_REGEX.is_match(sql.trim_start()) + && error + .to_string_with_causes() + .contains("unrecognized configuration parameter") + { + return Ok(Outcome::Success); + } Ok(Outcome::PlanFailure { error: anyhow!(error), expected_error: None, @@ -1560,7 +1786,7 @@ impl<'a> RunnerInner<'a> { })); } Err(expected_error) => { - if Regex::new(expected_error)?.is_match(&e.to_string_with_causes()) { + if error_matches(expected_error, &e.to_string_with_causes()) { return Ok(PrepareQueryOutcome::Outcome(Outcome::Success)); } else { return Ok(PrepareQueryOutcome::Outcome(Outcome::ParseFailure { @@ -1571,10 +1797,17 @@ impl<'a> RunnerInner<'a> { } }, }; + // Query records in files imported from CockroachDB occasionally + // contain zero or multiple statements. Fail the record rather than + // the entire run. let statement = match &*statements { - [] => bail!("Got zero statements?"), [statement] => &statement.ast, - _ => bail!("Got multiple statements: {:?}", statements), + _ => { + return Ok(PrepareQueryOutcome::Outcome(Outcome::ParseFailure { + error: anyhow!("expected one statement, but got {}", statements.len()), + location, + })); + } }; let (is_select, num_attributes, has_as_of) = match statement { Statement::Select(stmt) => ( @@ -1589,13 +1822,13 @@ impl<'a> RunnerInner<'a> { Ok(_) => { if self.auto_transactions && !*in_transaction { // No ISOLATION LEVEL SERIALIZABLE because of database-issues#5323 - self.client.execute("BEGIN", &[]).await?; + self.active_client().execute("BEGIN", &[]).await?; *in_transaction = true; } } Err(_) => { if self.auto_transactions && *in_transaction { - self.client.execute("COMMIT", &[]).await?; + self.active_client().execute("COMMIT", &[]).await?; *in_transaction = false; } } @@ -1607,7 +1840,7 @@ impl<'a> RunnerInner<'a> { match statement { Statement::Show(..) => { if self.auto_transactions && *in_transaction { - self.client.execute("COMMIT", &[]).await?; + self.active_client().execute("COMMIT", &[]).await?; *in_transaction = false; } } @@ -1628,7 +1861,7 @@ impl<'a> RunnerInner<'a> { location: Location, replacements: &[(Regex, String)], ) -> Result, anyhow::Error> { - let rows = match self.client.query(sql, &[]).await { + let rows = match self.active_client().query(sql, &[]).await { Ok(rows) => rows, Err(error) => { let error_string = error.to_string_with_causes(); @@ -1649,7 +1882,7 @@ impl<'a> RunnerInner<'a> { } } Err(expected_error) => { - if Regex::new(expected_error)?.is_match(&error_string) { + if error_matches(expected_error, &error_string) { Ok(Outcome::Success) } else { Ok(Outcome::PlanFailure { @@ -1783,12 +2016,12 @@ impl<'a> RunnerInner<'a> { location: Location, ) -> Result>, anyhow::Error> { print_sql_if(self.stdout, sql, self.verbose); - let sql_result = self.client.execute(sql, &[]).await; + let sql_result = self.active_client().execute(sql, &[]).await; // Evaluate if we already reached an outcome or not. let tentative_outcome = if let Err(view_error) = sql_result { if let Err(expected_error) = output { - if Regex::new(expected_error)?.is_match(&view_error.to_string_with_causes()) { + if error_matches(expected_error, &view_error.to_string_with_causes()) { Some(Outcome::Success) } else { Some(Outcome::PlanFailure { @@ -1857,7 +2090,9 @@ impl<'a> RunnerInner<'a> { // Remember to clean up after ourselves by dropping the view. print_sql_if(self.stdout, drop_view.as_str(), self.verbose); - self.client.execute(drop_view.as_str(), &[]).await?; + self.active_client() + .execute(drop_view.as_str(), &[]) + .await?; Ok(view_outcome) } @@ -2124,6 +2359,9 @@ fn print_record(config: &RunConfig<'_>, record: &Record) { tsv_path ) } + Record::User { user, .. } => { + writeln!(config.stdout, "{}user {}", " ".repeat(PRINT_INDENT), user) + } Record::ResetServer => { writeln!(config.stdout, "{}reset-server", " ".repeat(PRINT_INDENT)) } @@ -3059,3 +3297,50 @@ fn test_mutate() { assert_eq!(expected, stmts, "sql: {sql}"); } } + +#[mz_ore::test] +fn test_strip_crdb_table_items() { + let cases = vec![ + ( + "CREATE TABLE t (a INT, INDEX foo (a), b INT)", + Some("CREATE TABLE t (a INT, b INT)"), + ), + ( + "CREATE TABLE t (a INT, INDEX(a))", + Some("CREATE TABLE t (a INT)"), + ), + ( + "CREATE TABLE t (a INT, UNIQUE INDEX foo (a), INVERTED INDEX bar (a))", + Some("CREATE TABLE t (a INT)"), + ), + ( + "CREATE TABLE t (k INT, v STRING, FAMILY \"primary\" (k, v))", + Some("CREATE TABLE t (k INT, v STRING)"), + ), + // Partial and expression indexes have nested clauses. + ( + "CREATE TABLE t (a INT, INDEX (a) WHERE a = 0, INDEX ((a + 1)))", + Some("CREATE TABLE t (a INT)"), + ), + // Constraints are kept. + ( + "CREATE TABLE t (a INT, UNIQUE (a), CHECK (a > 0))", + Some("CREATE TABLE t (a INT, UNIQUE (a), CHECK (a > 0))"), + ), + // Column names that merely start with a stripped keyword are kept. + ( + "CREATE TABLE t (index_col INT, \"index\" INT)", + Some("CREATE TABLE t (index_col INT, \"index\" INT)"), + ), + // Parens inside strings do not confuse the item splitter. + ( + "CREATE TABLE t (a TEXT DEFAULT 'a,(b', INDEX (a))", + Some("CREATE TABLE t (a TEXT DEFAULT 'a,(b')"), + ), + ("SELECT 1", None), + ]; + for (sql, expected) in cases { + let stripped = strip_crdb_table_items(sql); + assert_eq!(expected.map(|e| e.to_string()), stripped, "sql: {sql}"); + } +} diff --git a/test/sqllogictest/cockroach/README.md b/test/sqllogictest/cockroach/README.md index 92f79485e8ba6..a5e8bead5e7b0 100644 --- a/test/sqllogictest/cockroach/README.md +++ b/test/sqllogictest/cockroach/README.md @@ -9,11 +9,16 @@ Many CockroachDB tests are not applicable to Materialize. Tests that exercise CockroachDB internal concepts, like "ranges" and "zones", have been deleted outright. Tests that exercise features that we may support someday, like collations, have been retained, but the files are skipped with an unconditional -`halt` directive at the top. +`halt` directive at the top. Files that diverge from Materialize's behavior +partway through are cut short with a `halt` directive at the point of +divergence, so the prefix still runs. ## Legal details -The test files were retrieved on June 10, 2019 from: +The test files were retrieved in two batches. Each file's license header +records which batch it came from. + +The original batch was retrieved on June 10, 2019 from: > https://github.com/cockroachdb/cockroach/tree/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test @@ -22,6 +27,20 @@ decision to relicense CockroachDB under the Business Source License (BSL). (For more details about the BSL, see the blog post, ["Why We're Relicensing CockroachDB"][blog].) +The second batch was retrieved on July 6, 2026 from the commit tagged v23.1.0: + +> https://github.com/cockroachdb/cockroach/tree/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test + +CockroachDB v23.1 is licensed under BSL 1.1 with a Change Date of April 1, +2026 and a Change License of Apache 2.0 (see `licenses/BSL.txt` at that +commit). The retrieval date is after the Change Date, so the retrieved files +are governed by the Apache 2.0 license. + +Future refreshes have a limited window. CockroachDB v23.2 converts to Apache +2.0 on October 1, 2026, v24.1 on April 1, 2027, and v24.2 on October 1, 2027. +Releases from v24.3 onward use the CockroachDB Software License, which never +converts, so v24.2 is the last version that can ever be imported. + [blog]: https://www.cockroachlabs.com/blog/oss-relicensing-cockroachdb/ [slt]: https://www.sqlite.org/sqllogictest/doc/trunk/about.wiki -[slt-ext]: https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/logic.go +[slt-ext]: https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/logic.go diff --git a/test/sqllogictest/cockroach/alias_types.slt b/test/sqllogictest/cockroach/alias_types.slt index e250ee39bde24..c044cc1148b3d 100644 --- a/test/sqllogictest/cockroach/alias_types.slt +++ b/test/sqllogictest/cockroach/alias_types.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,19 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/alias_types +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/alias_types # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -# Not currently supporting these esoteric PostgreSQL-only types. -halt - statement ok CREATE TABLE aliases ( a OID, @@ -33,13 +33,8 @@ CREATE TABLE aliases ( query TT colnames SHOW CREATE TABLE aliases ---- -table_name create_statement -aliases CREATE TABLE aliases ( - a OID NULL, - b NAME NULL, - FAMILY "primary" (a, rowid), - FAMILY fam_1_b (b) -) +name create_sql +materialize.public.aliases CREATE␠TABLE␠materialize.public.aliases␠(a␠pg_catalog.oid,␠b␠pg_catalog.name); statement ok INSERT INTO aliases VALUES (100, 'abc') @@ -47,14 +42,15 @@ INSERT INTO aliases VALUES (100, 'abc') statement ok INSERT INTO aliases VALUES (2, 'def') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO aliases VALUES ('bool'::REGTYPE, ('ghi':::STRING)::NAME) query OT SELECT a, b FROM aliases ORDER BY a ---- -2 def -16 ghi +2 def 100 abc query TT @@ -66,14 +62,12 @@ query T SELECT b || 'cat' FROM aliases ORDER BY a ---- defcat -ghicat abccat query T SELECT reverse(b) FROM aliases ORDER BY a ---- fed -ihg cba query I @@ -81,4 +75,3 @@ SELECT length(b::BYTES) FROM aliases ORDER BY a ---- 3 3 -3 diff --git a/test/sqllogictest/cockroach/alter_column_type.slt b/test/sqllogictest/cockroach/alter_column_type.slt deleted file mode 100644 index 287efc64da28f..0000000000000 --- a/test/sqllogictest/cockroach/alter_column_type.slt +++ /dev/null @@ -1,187 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/alter_column_type -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -# A basic sanity check to demonstrate column type changes. -subtest SanityCheck - -statement ok -CREATE TABLE t (s STRING, sl STRING(5), t TIME, ts TIMESTAMP) - -statement ok -SET TIME ZONE 'Europe/Amsterdam' - -statement ok -INSERT INTO t VALUES ('some string', 'short', TIME '20:16:27', '2018-05-23 20:16:27.658082') - -query TTTT -SELECT * FROM t ----- -some string short 0000-01-01 20:16:27 +0000 UTC 2018-05-23 20:16:27.658082 +0000 +0000 - -# Not using TIMETZ until materialize#26074 and materialize#25224 are resolved. -statement ok -ALTER TABLE t ALTER s TYPE BYTES, ALTER sl TYPE STRING(6), ALTER ts TYPE TIMESTAMPTZ - -query TTBTTTB colnames -SHOW COLUMNS FROM t ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -s BYTES true NULL · {} false -sl STRING(6) true NULL · {} false -t TIME true NULL · {} false -ts TIMESTAMPTZ true NULL · {} false -rowid INT8 false unique_rowid() · {primary} true - -query TTTT -SELECT * FROM t ----- -some string short 0000-01-01 20:16:27 +0000 UTC 2018-05-23 22:16:27.658082 +0200 +0200 - -statement ok -DROP TABLE t - - -# Demonstrate manual flow for non-trivial column change -subtest ManualGeneralChange - -statement ok -CREATE TABLE t (a INT PRIMARY KEY, b STRING) - -statement ok -CREATE INDEX idx ON t (b) - -statement ok -INSERT INTO t VALUES (1, '01'), (2, '002'), (3, '0003') - -query IT colnames -SELECT * from t ORDER BY b DESC ----- -a b -1 01 -2 002 -3 0003 - -statement ok -ALTER TABLE t ADD COLUMN i INT as (b::INT) STORED - -statement ok -CREATE INDEX idx2 ON t (i) - -statement ok -ALTER TABLE t ALTER COLUMN i DROP STORED, DROP COLUMN b CASCADE - -query TT colnames -show create table t ----- -table_name create_statement -t CREATE TABLE t ( - a INT8 NOT NULL, - i INT8 NULL, - CONSTRAINT "primary" PRIMARY KEY (a ASC), - INDEX idx2 (i ASC), - FAMILY "primary" (a, i) -) - -statement ok -ALTER TABLE t RENAME COLUMN i TO b - -statement ok -ALTER INDEX idx2 RENAME TO idx - -query II colnames -SELECT * from t ORDER BY b DESC ----- -a b -3 3 -2 2 -1 1 - -statement ok -DROP TABLE t CASCADE - - -# Demonstrate that we can change to an alias of a type -subtest ChangeVisibleColumnType - -statement ok -CREATE TABLE t (a INT) - -query TTBTTTB colnames -SHOW COLUMNS FROM t ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -a INT8 true NULL · {} false -rowid INT8 false unique_rowid() · {primary} true - -statement ok -ALTER TABLE t ALTER a TYPE INTEGER - -query TTBTTTB colnames -SHOW COLUMNS FROM t ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -a INT8 true NULL · {} false -rowid INT8 false unique_rowid() · {primary} true - -statement ok -DROP TABLE t - - -# Verify error handling when a bad COLLATE is used -subtest BadStringLocale - -statement ok -CREATE TABLE t (s STRING) - -statement error pq: invalid locale bad_locale -ALTER TABLE t ALTER s TYPE STRING COLLATE bad_locale - -statement ok -DROP TABLE t - - -# Verify error handling when a silly COLLATE is used -subtest BadCollateOnNotString - -statement ok -CREATE TABLE t (i INT) - -statement error pq: COLLATE can only be used with string types -ALTER TABLE t ALTER i TYPE INT COLLATE nope - -statement ok -DROP TABLE t - - -# Verify that making a no-op change is ok -subtest NoOpColumnChange - -statement ok -CREATE TABLE t (s STRING) - -statement ok -ALTER TABLE t ALTER s TYPE STRING - -statement ok -DROP TABLE t diff --git a/test/sqllogictest/cockroach/alter_database_convert_to_schema.slt b/test/sqllogictest/cockroach/alter_database_convert_to_schema.slt new file mode 100644 index 0000000000000..2d45ab7f5963f --- /dev/null +++ b/test/sqllogictest/cockroach/alter_database_convert_to_schema.slt @@ -0,0 +1,34 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/alter_database_convert_to_schema +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE DATABASE parent; +USE parent; +CREATE DATABASE pgdatabase; +USE test; + +statement error Expected OWNER, found identifier "convert" +ALTER DATABASE parent CONVERT TO SCHEMA WITH PARENT pgdatabase diff --git a/test/sqllogictest/cockroach/alter_database_owner.slt b/test/sqllogictest/cockroach/alter_database_owner.slt new file mode 100644 index 0000000000000..7c1bd5d68291f --- /dev/null +++ b/test/sqllogictest/cockroach/alter_database_owner.slt @@ -0,0 +1,131 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/alter_database_owner +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE DATABASE d; +CREATE USER testuser2 + +# Ensure user must exist for set owner. +statement error unknown role 'fake_user' +ALTER DATABASE d OWNER TO fake_user + +# Not supported by Materialize. +onlyif cockroach +# Superusers can alter owner to any user. +statement ok +ALTER DATABASE d OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DATABASE d OWNER TO root + +# Other users must be owner to alter the owner. +user testuser + +statement error unknown database 'd' +ALTER DATABASE d OWNER TO testuser + +# other users must be owner to alter the owner to the current owner again +statement error unknown role 'root' +ALTER DATABASE d OWNER TO root + +# Non-superusers also must be a member of the new owning role. +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DATABASE d OWNER TO testuser + +user testuser + +statement error unknown role 'testuser2' +ALTER DATABASE d OWNER TO testuser2 + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT testuser2 TO testuser + +user testuser + +statement error unknown role 'testuser2' +ALTER DATABASE d OWNER TO testuser2 + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER USER testuser CREATEDB + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DATABASE d OWNER TO testuser2 + +query T +SELECT r.rolname FROM pg_database d JOIN pg_roles r ON d.datdba = r.oid WHERE d.datname = 'd'; +---- + + +# Test that a user can reassign the owner from one role to another if they are +# a member of both roles, even if those roles are not members of each other. +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE ROLE a; +CREATE ROLE b; +GRANT a, b TO testuser; +ALTER DATABASE d OWNER TO a + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DATABASE d OWNER TO b + +query T +SELECT r.rolname FROM pg_database d JOIN pg_roles r ON d.datdba = r.oid WHERE d.datname = 'd'; +---- + + +user root + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #62012 +statement ok +CREATE DATABASE "order"; +ALTER DATABASE "order" OWNER TO testuser diff --git a/test/sqllogictest/cockroach/alter_default_privileges_for_all_roles.slt b/test/sqllogictest/cockroach/alter_default_privileges_for_all_roles.slt new file mode 100644 index 0000000000000..91ac3020fbc36 --- /dev/null +++ b/test/sqllogictest/cockroach/alter_default_privileges_for_all_roles.slt @@ -0,0 +1,228 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/alter_default_privileges_for_all_roles +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT SELECT ON TABLES TO testuser + +statement ok +CREATE TABLE t() + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON t +---- +database_name schema_name table_name grantee privilege_type is_grantable +test public t admin ALL true +test public t root ALL true +test public t testuser SELECT false + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES GRANT CREATE ON TABLES TO testuser + +statement ok +CREATE TABLE t2() + +# Not supported by Materialize. +onlyif cockroach +# Taking the union of default privileges defined on ALL ROLES and testuser +# testuser should have CREATE and SELECT on the table. +query TTTTTB colnames +SHOW GRANTS ON t2 +---- +database_name schema_name table_name grantee privilege_type is_grantable +test public t2 admin ALL true +test public t2 root ALL true +test public t2 testuser CREATE false +test public t2 testuser SELECT false + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES REVOKE SELECT ON TABLES FROM testuser + +statement ok +CREATE TABLE t3() + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON t3 +---- +database_name schema_name table_name grantee privilege_type is_grantable +test public t3 admin ALL true +test public t3 root ALL true +test public t3 testuser CREATE false + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT CREATE ON TABLES TO testuser + +statement ok +CREATE TABLE t4() + +# Not supported by Materialize. +onlyif cockroach +# CREATE is defined as a default privilege when the table is created by +# ALL ROLES and root. +query TTTTTB colnames +SHOW GRANTS ON t4 +---- +database_name schema_name table_name grantee privilege_type is_grantable +test public t4 admin ALL true +test public t4 root ALL true +test public t4 testuser CREATE false + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT CREATE ON TABLES TO testuser, testuser2 + +statement ok +CREATE TABLE t5() + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON t5 +---- +database_name schema_name table_name grantee privilege_type is_grantable +test public t5 admin ALL true +test public t5 root ALL true +test public t5 testuser CREATE false +test public t5 testuser2 CREATE false + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT ALL ON TABLES TO testuser, testuser2 + +statement ok +CREATE TABLE t6() + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON t6 +---- +database_name schema_name table_name grantee privilege_type is_grantable +test public t6 admin ALL true +test public t6 root ALL true +test public t6 testuser ALL false +test public t6 testuser2 ALL false + +# Not supported by Materialize. +onlyif cockroach +# Revoking from the target role should not affect the default privileges +# defined on ALL ROLES. +statement ok +ALTER DEFAULT PRIVILEGES REVOKE ALL ON TABLES FROM testuser, testuser2 + +statement ok +CREATE TABLE t7() + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON t7 +---- +database_name schema_name table_name grantee privilege_type is_grantable +test public t7 admin ALL true +test public t7 root ALL true +test public t7 testuser ALL false +test public t7 testuser2 ALL false + +user testuser + +# Must be an admin to alter default privileges for all roles. +statement error permission denied to ALTER DEFAULT PRIVILEGES FOR ALL ROLES +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT SELECT ON TABLES TO testuser + +user root + +# Not supported by Materialize. +onlyif cockroach +# Ensure default privileges can be defined for all roles on schemas, types +# and sequences. +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT ALL ON SEQUENCES TO testuser, testuser2; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT ALL ON SCHEMAS TO testuser, testuser2; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT ALL ON TYPES TO testuser, testuser2; + +statement ok +CREATE SCHEMA s + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW GRANTS ON SCHEMA s +---- +database_name schema_name grantee privilege_type is_grantable +test s admin ALL true +test s root ALL true +test s testuser ALL false +test s testuser2 ALL false + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE seq + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON seq +---- +database_name schema_name table_name grantee privilege_type is_grantable +test public seq admin ALL true +test public seq root ALL true +test public seq testuser ALL false +test public seq testuser2 ALL false + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE typ AS ENUM() + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON TYPE typ +---- +database_name schema_name type_name grantee privilege_type is_grantable +test public typ admin ALL true +test public typ public USAGE false +test public typ root ALL true +test public typ testuser ALL false +test public typ testuser2 ALL false diff --git a/test/sqllogictest/cockroach/alter_default_privileges_for_schema.slt b/test/sqllogictest/cockroach/alter_default_privileges_for_schema.slt new file mode 100644 index 0000000000000..c30b51f9fbaff --- /dev/null +++ b/test/sqllogictest/cockroach/alter_default_privileges_for_schema.slt @@ -0,0 +1,244 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/alter_default_privileges_for_schema +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE DATABASE d; +GRANT CREATE ON DATABASE d TO testuser + +# By default, testuser should have ALL privileges on a schema it creates. +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE d; + +# Not supported by Materialize. +onlyif cockroach +# The public schema is special and has hard-coded privileges for the public role. +# When https://github.com/cockroachdb/cockroach/issues/70266 is resolved, +# the public role will no longer have CREATE privilege. +query TTTTB colnames +SHOW GRANTS ON SCHEMA public +---- +database_name schema_name grantee privilege_type is_grantable +d public admin ALL true +d public public CREATE false +d public public USAGE false +d public root ALL true + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA testuser_s; + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW GRANTS ON SCHEMA testuser_s; +---- +database_name schema_name grantee privilege_type is_grantable +d testuser_s admin ALL true +d testuser_s root ALL true +d testuser_s testuser ALL true + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES REVOKE ALL ON SCHEMAS FROM testuser; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA testuser_s2; + +# Not supported by Materialize. +onlyif cockroach +# Note that CREATE is still present for testuser due to our current inheritance +# behavior. +# TODO(richardjcai): Remove this when we remove our current inheritance logic. +query TTTTB colnames +SHOW GRANTS ON SCHEMA testuser_s2 +---- +database_name schema_name grantee privilege_type is_grantable +d testuser_s2 admin ALL true +d testuser_s2 root ALL true +d testuser_s2 testuser ALL true + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE test; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES GRANT ALL ON SCHEMAS TO testuser, testuser2 + +statement ok +CREATE SCHEMA s + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW GRANTS ON SCHEMA s +---- +database_name schema_name grantee privilege_type is_grantable +test s admin ALL true +test s root ALL true +test s testuser ALL false +test s testuser2 ALL false + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES REVOKE USAGE ON SCHEMAS FROM testuser, testuser2 + +statement ok +CREATE SCHEMA s2 + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW GRANTS ON SCHEMA s2 +---- +database_name schema_name grantee privilege_type is_grantable +test s2 admin ALL true +test s2 root ALL true +test s2 testuser CREATE false +test s2 testuser2 CREATE false + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES REVOKE ALL ON SCHEMAS FROM testuser, testuser2 + +statement ok +CREATE SCHEMA s3 + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW GRANTS ON SCHEMA s3 +---- +database_name schema_name grantee privilege_type is_grantable +test s3 admin ALL true +test s3 root ALL true + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON DATABASE d TO testuser + +# Record disabled, not supported by Materialize: +user testuser +# statement ok +# USE d + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE testuser REVOKE ALL ON SCHEMAS FROM testuser, testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA s4 + +# Not supported by Materialize. +onlyif cockroach +# testuser still has CREATE due to "inheriting" it from the parent database. +query TTTTB colnames +SHOW GRANTS ON SCHEMA s4 +---- +database_name schema_name grantee privilege_type is_grantable +d s4 admin ALL true +d s4 root ALL true +d s4 testuser ALL true + +# Record disabled, not supported by Materialize: +user root +# statement ok +# USE d + +# Not supported by Materialize. +onlyif cockroach +# root must be a member of testuser to ALTER DEFAULT PRIVILEGES FOR ROLE testuser. +statement ok +GRANT testuser TO root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE testuser REVOKE ALL ON SCHEMAS FROM testuser, testuser2 + +# Record disabled, not supported by Materialize: +user testuser +# statement ok +# USE d + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA s5 + +# Not supported by Materialize. +onlyif cockroach +# testuser still has CREATE due to "inheriting" it from the parent database. +query TTTTB colnames +SHOW GRANTS ON SCHEMA s5 +---- +database_name schema_name grantee privilege_type is_grantable +d s5 admin ALL true +d s5 root ALL true +d s5 testuser ALL true + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES GRANT ALL ON SCHEMAS TO testuser, testuser2 + +user root + +statement ok +CREATE SCHEMA s_72322 + +# Not supported by Materialize. +onlyif cockroach +# When root creates the table, testuser and testuser2 should not get privileges. +query TTTTB colnames +SHOW GRANTS ON SCHEMA s_72322 +---- +database_name schema_name grantee privilege_type is_grantable +d s_72322 admin ALL true +d s_72322 root ALL true diff --git a/test/sqllogictest/cockroach/alter_role_set.slt b/test/sqllogictest/cockroach/alter_role_set.slt new file mode 100644 index 0000000000000..1ca3b35e98dce --- /dev/null +++ b/test/sqllogictest/cockroach/alter_role_set.slt @@ -0,0 +1,396 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/alter_role_set +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE ROLE test_set_role; +CREATE DATABASE test_set_db + +# Not supported by Materialize. +onlyif cockroach +query OTT +SELECT database_id, role_name, settings FROM system.database_role_settings +---- + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE test_set_role SET application_name = 'a'; +ALTER ROLE test_set_role IN DATABASE test_set_db SET application_name = 'b'; +ALTER ROLE ALL IN DATABASE test_set_db SET application_name = 'c'; +ALTER ROLE ALL SET application_name = 'd'; +ALTER ROLE test_set_role SET custom_option.setting = 'e' + +# Not supported by Materialize. +onlyif cockroach +# Verify that the defaults were stored. +query OTT colnames +SELECT database_id, role_name, settings FROM system.database_role_settings ORDER BY 1, 2 +---- +database_id role_name settings +0 · {application_name=d} +0 test_set_role {application_name=a,custom_option.setting=e} +106 · {application_name=c} +106 test_set_role {application_name=b} + +# Not supported by Materialize. +onlyif cockroach +# Defaults should be in pg_catalog too. +query OOTTT colnames +SELECT setdatabase, setrole, d.datname, r.rolname, setconfig +FROM pg_catalog.pg_db_role_setting +LEFT JOIN pg_catalog.pg_database d ON setdatabase = d.oid +LEFT JOIN pg_catalog.pg_roles r ON setrole = r.oid +ORDER BY 1, 2 +---- +setdatabase setrole datname rolname setconfig +0 0 NULL NULL {application_name=d} +0 265380634 NULL test_set_role {application_name=a,custom_option.setting=e} +106 0 test_set_db NULL {application_name=c} +106 265380634 test_set_db test_set_role {application_name=b} + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE test_set_role SET backslash_quote = 'safe_encoding' + +# Not supported by Materialize. +onlyif cockroach +# Verify that a new setting was added in the array. +query T +SELECT settings FROM system.database_role_settings +WHERE database_id = 0 AND role_name = 'test_set_role' +---- +{application_name=a,custom_option.setting=e,backslash_quote=safe_encoding} + +statement ok +ALTER ROLE test_set_role SET application_name = 'f' + +# Not supported by Materialize. +onlyif cockroach +# Verify that the existing setting was updated in the array. +query T +SELECT settings FROM system.database_role_settings +WHERE database_id = 0 AND role_name = 'test_set_role' +---- +{custom_option.setting=e,backslash_quote=safe_encoding,application_name=f} + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE test_set_role SET serial_normalization = 'sql_sequence'; +ALTER ROLE test_set_role RESET application_name + +# Not supported by Materialize. +onlyif cockroach +# Verify that the existing setting was removed from the array. +query T +SELECT settings FROM system.database_role_settings +WHERE database_id = 0 AND role_name = 'test_set_role' +---- +{custom_option.setting=e,backslash_quote=safe_encoding,serial_normalization=sql_sequence} + +# Resetting something that isn't there anymore is fine. +statement ok +ALTER ROLE test_set_role RESET application_name + +# Setting for a role that does not exist should error +statement error unknown role 'fake_role' +ALTER ROLE fake_role SET application_name = 'e'; + +# Not supported by Materialize. +onlyif cockroach +# Setting for a role that does not exist works with IF EXISTS, +statement ok +ALTER ROLE IF EXISTS fake_role SET application_name = 'e'; + +# Setting for a database that does not exist should error. +statement error Expected end of statement, found EXISTS +ALTER ROLE IF EXISTS fake_role IN DATABASE fake_database SET application_name = 'e'; + +# Test setting a variable that does not exist. +statement error unrecognized configuration parameter "potato" +ALTER ROLE test_set_role SET potato = 'potato' + +# Not supported by Materialize. +onlyif cockroach +# Test *resetting* a variable that does not exist; it should work +statement ok +ALTER ROLE test_set_role RESET potato; +ALTER ROLE test_set_role SET potato TO DEFAULT; + +# Test setting a variable to an invalid value. +statement error unrecognized configuration parameter "serial_normalization" +ALTER ROLE test_set_role SET serial_normalization = 'potato' + +# Test setting a compat-only variable to an invalid value. +statement error unrecognized configuration parameter "backslash_quote" +ALTER ROLE test_set_role SET backslash_quote = 'off' + +# Not supported by Materialize. +onlyif cockroach +# Test a setting that does not have a `Set` function defined. +statement error parameter "integer_datetimes" cannot be changed +ALTER ROLE test_set_role SET integer_datetimes = 'on' + +# Not supported by Materialize. +onlyif cockroach +# Test a setting that does not have a `Set` function defined, but does have +# `RuntimeSet` defined. +statement error parameter "transaction_isolation" cannot be changed +ALTER ROLE test_set_role SET transaction_isolation = 'serializable' + +# Not supported by Materialize. +onlyif cockroach +# Verify that the `database` and `role` variables cannot be set. +statement error parameter "database" cannot be changed +ALTER ROLE test_set_role SET database = 'd' + +statement error unrecognized configuration parameter "role" +ALTER ROLE test_set_role SET role = 'd' + +# Test setting with a name of "". +statement error zero\-length delimited identifier +ALTER ROLE test_set_role SET "" = 'foo' + +query T +SELECT current_user() +---- +materialize + +# Verify that the admin role can't be edited, even as root. +statement error unknown role 'admin' +ALTER ROLE admin SET application_name = 'g' + +# Verify that the root user can't be edited, even as root. +statement error unknown role 'root' +ALTER ROLE root SET application_name = 'g' + +# Verify that the public role can't be edited. +statement error role name "public" is reserved +ALTER ROLE public SET application_name = 'g' + +# Verify that the "" role can't be edited. +statement error zero\-length delimited identifier +ALTER ROLE "" SET application_name = 'g' + +# Not supported by Materialize. +onlyif cockroach +# Verify that root is allowed to edit some other role that has ADMIN. +statement ok +CREATE ROLE other_admin; +GRANT admin TO other_admin; +ALTER ROLE other_admin SET application_name = 'g'; +ALTER ROLE other_admin RESET application_name + +user testuser + +# Not supported by Materialize. +onlyif cockroach +# Verify that testuser can't edit their own defaults. +statement error pq: ALTER ROLE ... SET requires MODIFYCLUSTERSETTING, MODIFYSQLCLUSTERSETTING or CREATEROLE +ALTER ROLE testuser RESET application_name + +# Verify users with MODIFYCLUSTERSETTING can ALTER ROLE SET +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT SYSTEM MODIFYCLUSTERSETTING TO testuser + +user testuser + +statement ok +ALTER ROLE testuser RESET application_name + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE SYSTEM MODIFYCLUSTERSETTING FROM testuser + +# Not supported by Materialize. +onlyif cockroach +# Verify users with MODIFYSQLCLUSTERSETTING can ALTER ROLE SET +statement ok +GRANT SYSTEM MODIFYSQLCLUSTERSETTING TO testuser + +user testuser + +statement ok +ALTER ROLE testuser RESET application_name + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE SYSTEM MODIFYSQLCLUSTERSETTING FROM testuser + + +# Not supported by Materialize. +onlyif cockroach +# Verify users with the MODIFYCLUSTERSETTING role option can also ALTER ROLE SET +statement ok +ALTER ROLE testuser with MODIFYCLUSTERSETTING + +user testuser + +statement ok +ALTER ROLE testuser RESET application_name + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE testuser WITH NOMODIFYCLUSTERSETTING + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE testuser WITH CREATEROLE + +user testuser + +# Now that testuser has CREATEROLE, it can edit itself. +statement ok +ALTER ROLE testuser RESET application_name + +# Not supported by Materialize. +onlyif cockroach +# Now that testuser has CREATEROLE, it can also edit test_set_role. +statement ok +ALTER ROLE test_set_role RESET application_name + +# However, even with CREATEROLE, testuser cannot do RESET ALL. +statement error Expected end of statement, found IN +ALTER ROLE ALL IN DATABASE test_set_db RESET application_name + +# Verify that testuser can't edit an ADMIN, even after getting CREATEROLE. +statement error unknown role 'other_admin' +ALTER ROLE other_admin SET application_name = 'abc' + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE ALL RESET ALL + +# Not supported by Materialize. +onlyif cockroach +# Verify that defaults were removed for (db_id=0, role_name="") but nothing else. +query OTT colnames +SELECT database_id, role_name, settings FROM system.database_role_settings ORDER BY 1, 2 +---- +database_id role_name settings +0 test_set_role {custom_option.setting=e,backslash_quote=safe_encoding,serial_normalization=sql_sequence} +106 · {application_name=c} +106 test_set_role {application_name=b} + +statement ok +DROP DATABASE test_set_db + +# Not supported by Materialize. +onlyif cockroach +# Verify that the defaults were removed for the dropped database. +query OTT colnames +SELECT database_id, role_name, settings FROM system.database_role_settings ORDER BY 1, 2 +---- +database_id role_name settings +0 test_set_role {custom_option.setting=e,backslash_quote=safe_encoding,serial_normalization=sql_sequence} + +statement ok +DROP ROLE test_set_role + +# Not supported by Materialize. +onlyif cockroach +# Verify that the defaults were removed for the dropped role. +query OTT colnames +SELECT database_id, role_name, settings FROM system.database_role_settings ORDER BY 1, 2 +---- +database_id role_name settings + +# Regression test for the special "tracing" variable. +query error unknown role 'all' +ALTER ROLE ALL SET tracing = 'off' + +# Test that no-op alter role set command is actually no-op (i.e. does not perform schema change) +subtest no_op_alter_role_set + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE user roach + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE roach SET timezone = 'America/New_York' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE roach SET use_declarative_schema_changer = 'off' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE roach SET statement_timeout = '10s' + +# Remember the current table version for `system.database_role_settings`. +let $database_role_setttings_version +SELECT crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor)->'table'->>'version' FROM system.descriptor WHERE id = 'system.public.database_role_settings'::REGCLASS + +# Not supported by Materialize. +onlyif cockroach +# Issue a bunch no-op alter role set commands +statement ok +ALTER ROLE roach SET timezone = 'America/New_York' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE roach SET use_declarative_schema_changer = 'off' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE roach SET statement_timeout = '10s' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER ROLE roach RESET search_path + +# Not supported by Materialize. +onlyif cockroach +# Check that the above no-op 'ALTER ROLE ... SET/RESET ...' commands did not incur schema change on +# the 'database_role_settings' table by asserting its version remains unchanged. +query B +SELECT crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor)->'table'->>'version' = $database_role_setttings_version::STRING FROM system.descriptor WHERE id = 'system.public.database_role_settings'::REGCLASS +---- +true diff --git a/test/sqllogictest/cockroach/alter_schema_owner.slt b/test/sqllogictest/cockroach/alter_schema_owner.slt new file mode 100644 index 0000000000000..d63226962257a --- /dev/null +++ b/test/sqllogictest/cockroach/alter_schema_owner.slt @@ -0,0 +1,118 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/alter_schema_owner +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA s; +CREATE USER testuser2 + +# Not supported by Materialize. +onlyif cockroach +# Superusers can alter owner to any user. +statement ok +ALTER SCHEMA s OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SCHEMA s OWNER TO root + +# Other users must be owner to alter the owner. +user testuser + +statement error unknown schema 's' +ALTER SCHEMA s OWNER TO testuser + +# other users must be owner to alter the owner to the current owner again +statement error unknown role 'root' +ALTER SCHEMA s OWNER TO root + +# Non-superusers also must be a member of the new owning role. +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SCHEMA s OWNER TO testuser + +user testuser + +statement error unknown role 'testuser2' +ALTER SCHEMA s OWNER TO testuser2 + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT testuser2 TO testuser + +user testuser + +statement error unknown role 'testuser2' +ALTER SCHEMA s OWNER TO testuser2 + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON DATABASE test TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SCHEMA s OWNER TO testuser2 + +query T +SELECT pg_get_userbyid(nspowner) FROM pg_namespace WHERE nspname = 's'; +---- + + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SCHEMA s OWNER TO CURRENT_USER + +query T +SELECT pg_get_userbyid(nspowner) FROM pg_namespace WHERE nspname = 's'; +---- + + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SCHEMA s OWNER TO testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SCHEMA s OWNER TO SESSION_USER + +query T +SELECT pg_get_userbyid(nspowner) FROM pg_namespace WHERE nspname = 's'; +---- diff --git a/test/sqllogictest/cockroach/alter_sequence_owner.slt b/test/sqllogictest/cockroach/alter_sequence_owner.slt new file mode 100644 index 0000000000000..01d4f369a39b2 --- /dev/null +++ b/test/sqllogictest/cockroach/alter_sequence_owner.slt @@ -0,0 +1,107 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/alter_sequence_owner +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA s; +CREATE SEQUENCE seq; +CREATE SEQUENCE s.seq; +CREATE USER testuser2 + +# Ensure user must exist for set owner. +statement error Expected one of TABLE or VIEW or MATERIALIZED or SOURCE or SINK or INDEX or TYPE or ROLE or USER or CLUSTER or SECRET or CONNECTION or DATABASE or SCHEMA or FUNCTION or NETWORK, found identifier "sequence" +ALTER SEQUENCE seq OWNER TO fake_user + +# Not supported by Materialize. +onlyif cockroach +# Superusers can alter owner to any user which has CREATE privileges on the +# parent schema. This succeeds since all users have CREATE on the public schema +# by default. +statement ok +ALTER SEQUENCE seq OWNER TO testuser + +statement error Expected one of TABLE or VIEW or MATERIALIZED or SOURCE or SINK or INDEX or TYPE or ROLE or USER or CLUSTER or SECRET or CONNECTION or DATABASE or SCHEMA or FUNCTION or NETWORK, found identifier "sequence" +ALTER SEQUENCE s.seq OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +# ALTER SEQUENCE IF EXISTS OWNER succeeds if the sequence does not exist. +statement ok +ALTER SEQUENCE IF EXISTS does_not_exist OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON SCHEMA s TO testuser, testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE seq OWNER TO root + +# ALTER VIEW cannot be used for sequences. +statement error unknown role 'testuser' +ALTER VIEW seq OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SEQUENCE seq OWNER TO testuser; +ALTER SEQUENCE s.seq OWNER TO testuser; +ALTER SEQUENCE seq OWNER TO root; +ALTER SEQUENCE s.seq OWNER TO root; + +# Other users must be owner to alter the owner. +user testuser + +statement error Expected one of TABLE or VIEW or MATERIALIZED or SOURCE or SINK or INDEX or TYPE or ROLE or USER or CLUSTER or SECRET or CONNECTION or DATABASE or SCHEMA or FUNCTION or NETWORK, found identifier "sequence" +ALTER SEQUENCE seq OWNER TO testuser2 + +# Non-superusers also must be a member of the new owning role. +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SEQUENCE seq OWNER TO testuser + +user testuser + +statement error Expected one of TABLE or VIEW or MATERIALIZED or SOURCE or SINK or INDEX or TYPE or ROLE or USER or CLUSTER or SECRET or CONNECTION or DATABASE or SCHEMA or FUNCTION or NETWORK, found identifier "sequence" +ALTER SEQUENCE seq OWNER TO testuser2 + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT testuser2 TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SEQUENCE seq OWNER TO testuser2 diff --git a/test/sqllogictest/cockroach/alter_table.slt b/test/sqllogictest/cockroach/alter_table.slt deleted file mode 100644 index 63b787d04f6e9..0000000000000 --- a/test/sqllogictest/cockroach/alter_table.slt +++ /dev/null @@ -1,929 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/alter_table -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -statement ok -CREATE TABLE other (b INT PRIMARY KEY) - -statement ok -INSERT INTO other VALUES (9) - -statement ok -CREATE TABLE t (a INT PRIMARY KEY CHECK(a > 0), f INT REFERENCES other, INDEX (f)) - -statement ok -INSERT INTO t VALUES (1, 9) - -statement error syntax error at or near "*" -ALTER TABLE t RENAME TO t.* - -statement ok -ALTER TABLE t ADD b INT - -query TTBTTTB colnames -SHOW COLUMNS FROM t ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -a INT8 false NULL · {primary,t_f_idx} false -f INT8 true NULL · {t_f_idx} false -b INT8 true NULL · {} false - -statement ok -ALTER TABLE t ADD CONSTRAINT foo UNIQUE (b) - -query TTTTRT -SELECT job_type, description, user_name, status, fraction_completed, error -FROM crdb_internal.jobs -WHERE job_type = 'SCHEMA CHANGE' -ORDER BY created DESC -LIMIT 1 ----- -SCHEMA CHANGE ALTER TABLE test.public.t ADD CONSTRAINT foo UNIQUE (b) root succeeded 1 · - -statement error duplicate constraint name: "foo" -ALTER TABLE t ADD CONSTRAINT foo UNIQUE (b) - -statement error multiple primary keys for table "t" are not allowed -ALTER TABLE t ADD CONSTRAINT bar PRIMARY KEY (b) - -query TTBITTBB colnames -SHOW INDEXES ON t ----- -table_name index_name non_unique seq_in_index column_name direction storing implicit -t primary false 1 a ASC false false -t t_f_idx true 1 f ASC false false -t t_f_idx true 2 a ASC false true -t foo false 1 b ASC false false -t foo false 2 a ASC false true - -query III -SELECT * FROM t ----- -1 9 NULL - -statement ok -ALTER TABLE t ADD c INT - -statement ok -INSERT INTO t VALUES (2, 9, 1, 1), (3, 9, 2, 1) - -statement error pgcode 23505 violates unique constraint "bar" -ALTER TABLE t ADD CONSTRAINT bar UNIQUE (c) - -# Test that rollback was successful -query TTTTTR -SELECT job_type, regexp_replace(description, 'JOB \d+', 'JOB ...'), user_name, status, running_status, fraction_completed::decimal(10,2) -FROM crdb_internal.jobs -WHERE job_type = 'SCHEMA CHANGE' -ORDER BY created DESC -LIMIT 2 ----- -SCHEMA CHANGE ROLL BACK JOB ...: ALTER TABLE test.public.t ADD CONSTRAINT bar UNIQUE (c) root running waiting for GC TTL 0.00 -SCHEMA CHANGE ALTER TABLE test.public.t ADD CONSTRAINT bar UNIQUE (c) root failed NULL 0.00 - -query IIII colnames,rowsort -SELECT * FROM t ----- -a f b c -1 9 NULL NULL -2 9 1 1 -3 9 2 1 - -query TTTTB colnames -SHOW CONSTRAINTS FROM t ----- -table_name constraint_name constraint_type details validated -t check_a CHECK CHECK (a > 0) true -t fk_f_ref_other FOREIGN KEY FOREIGN KEY (f) REFERENCES other (b) true -t foo UNIQUE UNIQUE (b ASC) true -t primary PRIMARY KEY PRIMARY KEY (a ASC) true - -statement error CHECK -INSERT INTO t (a, f) VALUES (-2, 9) - -statement ok -ALTER TABLE t DROP CONSTRAINT check_a - -statement ok -INSERT INTO t (a, f) VALUES (-2, 9) - -statement error validation of CHECK "a > 0" failed on row: a=-2, f=9, b=NULL, c=NULL -ALTER TABLE t ADD CONSTRAINT check_a CHECK (a > 0) - -statement ok -DELETE FROM t WHERE a = -2 - -statement ok -ALTER TABLE t ADD CONSTRAINT check_a CHECK (a > 0) - -statement error CHECK -INSERT INTO t (a) VALUES (-3) - -query TTTTB -SHOW CONSTRAINTS FROM t ----- -t check_a CHECK CHECK (a > 0) true -t fk_f_ref_other FOREIGN KEY FOREIGN KEY (f) REFERENCES other (b) true -t foo UNIQUE UNIQUE (b ASC) true -t primary PRIMARY KEY PRIMARY KEY (a ASC) true - -statement error duplicate constraint name -ALTER TABLE t ADD CONSTRAINT check_a CHECK (a > 0) - -statement error duplicate constraint name -ALTER TABLE t ADD CONSTRAINT fk_f_ref_other FOREIGN KEY (a) REFERENCES other (b) - -# added constraints with generated names avoid name collisions. -statement ok -ALTER TABLE t ADD CHECK (a > 0) - -query TTTTB -SHOW CONSTRAINTS FROM t ----- -t check_a CHECK CHECK (a > 0) true -t check_a1 CHECK CHECK (a > 0) true -t fk_f_ref_other FOREIGN KEY FOREIGN KEY (f) REFERENCES other (b) true -t foo UNIQUE UNIQUE (b ASC) true -t primary PRIMARY KEY PRIMARY KEY (a ASC) true - -statement error constraint "typo" does not exist -ALTER TABLE t VALIDATE CONSTRAINT typo - -# TODO(erik): re-enable test when unvalidated checks can be added -#statement error validation of CHECK "a > 0" failed on row: a=-2, f=9, b=NULL, c=NULL -#ALTER TABLE t VALIDATE CONSTRAINT check_a - -#statement ok -#DELETE FROM t WHERE a = -2 - -statement ok -ALTER TABLE t VALIDATE CONSTRAINT check_a - -query TTTTB -SHOW CONSTRAINTS FROM t ----- -t check_a CHECK CHECK (a > 0) true -t check_a1 CHECK CHECK (a > 0) true -t fk_f_ref_other FOREIGN KEY FOREIGN KEY (f) REFERENCES other (b) true -t foo UNIQUE UNIQUE (b ASC) true -t primary PRIMARY KEY PRIMARY KEY (a ASC) true - -statement ok -ALTER TABLE t DROP CONSTRAINT check_a, DROP CONSTRAINT check_a1 - -statement error pgcode 42703 column "d" does not exist -ALTER TABLE t DROP d - -statement ok -ALTER TABLE t DROP IF EXISTS d - -statement error column "a" is referenced by the primary key -ALTER TABLE t DROP a - -statement error constraint "bar" does not exist -ALTER TABLE t DROP CONSTRAINT bar - -statement ok -ALTER TABLE t DROP CONSTRAINT IF EXISTS bar - -statement error cannot drop UNIQUE constraint \"foo\" using ALTER TABLE DROP CONSTRAINT, use DROP INDEX CASCADE instead -ALTER TABLE t DROP CONSTRAINT foo - -statement ok -DROP INDEX foo CASCADE - -query TTTTTRT -SELECT job_type, description, user_name, status, running_status, fraction_completed, error -FROM crdb_internal.jobs -WHERE job_type = 'SCHEMA CHANGE' -ORDER BY created DESC -LIMIT 1 ----- -SCHEMA CHANGE DROP INDEX test.public.t@foo CASCADE root running waiting for GC TTL 0 · - -query TTBITTBB colnames -SHOW INDEXES ON t ----- -table_name index_name non_unique seq_in_index column_name direction storing implicit -t primary false 1 a ASC false false -t t_f_idx true 1 f ASC false false -t t_f_idx true 2 a ASC false true - -statement ok -ALTER TABLE t DROP b, DROP c - -query II rowsort -SELECT * FROM t ----- -1 9 -2 9 -3 9 - -statement ok -ALTER TABLE t ADD d INT UNIQUE - -statement ok -INSERT INTO t VALUES (4, 9, 1) - -statement error duplicate key value \(d\)=\(1\) violates unique constraint \"t_d_key\" -INSERT INTO t VALUES (5, 9, 1) - -# Add a column with no default value -statement ok -ALTER TABLE t ADD COLUMN x DECIMAL - -# Add a non NULL column with a default value -statement ok -ALTER TABLE t ADD COLUMN y DECIMAL NOT NULL DEFAULT (DECIMAL '1.3') - -statement error could not parse "1-3" as type decimal -ALTER TABLE t ADD COLUMN p DECIMAL NOT NULL DEFAULT (DECIMAL '1-3') - -# Add a non NULL column with no default value -statement error pgcode 23502 null value in column \"q\" violates not-null constraint -ALTER TABLE t ADD COLUMN q DECIMAL NOT NULL - -statement ok -ALTER TABLE t ADD COLUMN z DECIMAL DEFAULT (DECIMAL '1.4') - -statement ok -INSERT INTO t VALUES (11, 9, 12, DECIMAL '1.0') - -statement ok -INSERT INTO t (a, d) VALUES (13, 14) - -statement ok -INSERT INTO t (a, d, y) VALUES (21, 22, DECIMAL '1.0') - -statement ok -INSERT INTO t (a, d) VALUES (23, 24) - -statement error foreign key -INSERT INTO t VALUES (31, 7, 32) - -statement error in use as a foreign key constraint -DROP INDEX t@t_f_idx - -statement ok -ALTER TABLE t DROP CONSTRAINT fk_f_ref_other - -statement ok -INSERT INTO t VALUES (31, 7, 32) - -statement ok -INSERT INTO t (a, d, x, y, z) VALUES (33, 34, DECIMAL '2.0', DECIMAL '2.1', DECIMAL '2.2') - -statement ok -DROP INDEX t@t_f_idx - -query TTTTTRT -SELECT job_type, description, user_name, status, running_status, fraction_completed, error -FROM crdb_internal.jobs -WHERE job_type = 'SCHEMA CHANGE' -ORDER BY created DESC -LIMIT 1 ----- -SCHEMA CHANGE DROP INDEX test.public.t@t_f_idx root running waiting for GC TTL 0 · - -statement ok -ALTER TABLE t DROP COLUMN f - -query IITTT colnames,rowsort -SELECT * FROM t ----- -a d x y z -1 NULL NULL 1.3 1.4 -2 NULL NULL 1.3 1.4 -3 NULL NULL 1.3 1.4 -4 1 NULL 1.3 1.4 -11 12 1.0 1.3 1.4 -13 14 NULL 1.3 1.4 -21 22 NULL 1.0 1.4 -23 24 NULL 1.3 1.4 -31 32 NULL 1.3 1.4 -33 34 2.0 2.1 2.2 - -statement ok -ALTER TABLE t DROP COLUMN d - -statement ok -ALTER TABLE t ADD COLUMN e INT; ALTER TABLE t ADD COLUMN d INT - -statement ok -CREATE VIEW v AS SELECT x, y FROM t WHERE e > 5 - -statement error cannot drop column "x" because view "v" depends on it -ALTER TABLE t DROP COLUMN x - -statement error cannot drop column "y" because view "v" depends on it -ALTER TABLE t DROP COLUMN y - -statement error cannot drop column "e" because view "v" depends on it -ALTER TABLE t DROP COLUMN e - -# TODO(knz): this statement should succeed after cockroach#17269 is fixed. -statement error cannot drop column "d" because view "v" depends on it -ALTER TABLE t DROP COLUMN d - -# TODO(knz): remove the following once the test above succeeds. -statement ok -ALTER TABLE t DROP COLUMN d CASCADE - -statement ok -ALTER TABLE t DROP COLUMN e CASCADE - -statement ok -ALTER TABLE t ADD COLUMN e INT - -statement ok -CREATE VIEW v AS SELECT x, y FROM t WHERE e > 5 - -statement ok -ALTER TABLE t DROP COLUMN IF EXISTS q - -statement error cannot drop column "e" because view "v" depends on it -ALTER TABLE t DROP COLUMN IF EXISTS e - -statement ok -ALTER TABLE t DROP COLUMN IF EXISTS e CASCADE - -statement ok -ALTER TABLE t ADD COLUMN g INT UNIQUE - -statement ok -CREATE TABLE o (gf INT REFERENCES t (g), h INT, i INT, INDEX ii (i) STORING(h)) - -statement error "t_g_key" is referenced by foreign key from table "o" -ALTER TABLE t DROP COLUMN g - -statement ok -ALTER TABLE t DROP COLUMN g CASCADE - -statement error column "h" is referenced by existing index "ii" -ALTER TABLE o DROP COLUMN h - -statement ok -ALTER TABLE o DROP COLUMN h CASCADE - -statement ok -ALTER TABLE t ADD f INT CHECK (f > 1) - -statement ok -ALTER TABLE t ADD g INT DEFAULT 1 CHECK (g > 0) - -statement ok -ALTER TABLE t ADD h INT CHECK (h > 0) CHECK (h < 10) UNIQUE - -statement error pq: validation of CHECK "i < 0" failed on row:.* i=1 -ALTER TABLE t ADD i INT DEFAULT 1 CHECK (i < 0) - -statement error pq: validation of CHECK "i < g" failed on row:.* g=1.* i=1 -ALTER TABLE t ADD i INT DEFAULT 1 CHECK (i < g) - -statement error pq: validation of CHECK "i > 0" failed on row:.* g=1.* i=0 -ALTER TABLE t ADD i INT AS (g - 1) STORED CHECK (i > 0) - -statement error adding a REFERENCES constraint while also adding a column via ALTER not supported -ALTER TABLE t ADD f INT UNIQUE REFERENCES other - -query TTTTB -SHOW CONSTRAINTS FROM t ----- -t check_f CHECK CHECK (f > 1) true -t check_g CHECK CHECK (g > 0) true -t check_h CHECK CHECK (h > 0) true -t check_h1 CHECK CHECK (h < 10) true -t primary PRIMARY KEY PRIMARY KEY (a ASC) true -t t_h_key UNIQUE UNIQUE (h ASC) true - -statement ok -DROP TABLE t - -# Test that more than one column with constraints can be added in the same -# statement. The constraints added here are on columns that are new and both -# columns and constraints run through the schema change process together. - -statement ok -CREATE TABLE t (a INT PRIMARY KEY) - -statement ok -INSERT INTO t VALUES (1) - -# Check references column added in same statement -statement ok -ALTER TABLE t ADD b INT DEFAULT 1, ADD c INT DEFAULT 2 CHECK (c > b) - -statement ok -ALTER TABLE t ADD d INT UNIQUE, ADD e INT UNIQUE, ADD f INT - -# Check references column added in same statement -statement error pq: validation of CHECK "g = h" failed on row:.* g=3.* h=2 -ALTER TABLE t ADD g INT DEFAULT 3, ADD h INT DEFAULT 2 CHECK (g = h) - -# Multiple unique columns can be added, followed by other commands (cockroach#35011) -statement ok -ALTER TABLE t ADD COLUMN u INT UNIQUE, ADD COLUMN v INT UNIQUE, ADD CONSTRAINT ck CHECK (a > 0); - -query TTTTB -SHOW CONSTRAINTS FROM t ----- -t check_c_b CHECK CHECK (c > b) true -t ck CHECK CHECK (a > 0) true -t primary PRIMARY KEY PRIMARY KEY (a ASC) true -t t_d_key UNIQUE UNIQUE (d ASC) true -t t_e_key UNIQUE UNIQUE (e ASC) true -t t_u_key UNIQUE UNIQUE (u ASC) true -t t_v_key UNIQUE UNIQUE (v ASC) true - -statement ok -DROP TABLE t - -# Subsequent operations succeed because the table is empty -statement ok -CREATE TABLE tt (a INT PRIMARY KEY) - -statement ok -ALTER TABLE tt ADD COLUMN q DECIMAL NOT NULL - -statement ok -ALTER table tt ADD COLUMN r DECIMAL - -# Ensure that a UNIQUE NOT NULL COLUMN can be added when there is no data in -# the table. -statement ok -ALTER TABLE tt ADD COLUMN s DECIMAL UNIQUE NOT NULL - -statement ok -ALTER TABLE tt ADD t DECIMAL UNIQUE DEFAULT 4.0 - -query TTBTTTB colnames -SHOW COLUMNS FROM tt ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -a INT8 false NULL · {primary,tt_s_key,tt_t_key} false -q DECIMAL false NULL · {} false -r DECIMAL true NULL · {} false -s DECIMAL false NULL · {tt_s_key} false -t DECIMAL true 4.0:::DECIMAL · {tt_t_key} false - -# Default values can be added and changed after table creation. -statement ok -CREATE TABLE add_default (a int primary key, b int not null) - -statement error null value in column "b" violates not-null constraint -INSERT INTO add_default (a) VALUES (1) - -statement ok -ALTER TABLE add_default ALTER COLUMN b SET DEFAULT 42 - -statement ok -INSERT INTO add_default (a) VALUES (2) - -statement ok -ALTER TABLE add_default ALTER COLUMN b SET DEFAULT 10 - -statement ok -INSERT INTO add_default (a) VALUES (3) - -statement error could not parse "foo" as type int -ALTER TABLE add_default ALTER COLUMN b SET DEFAULT 'foo' - -statement error variable sub-expressions are not allowed in DEFAULT -ALTER TABLE add_default ALTER COLUMN b SET DEFAULT c - -statement error variable sub-expressions are not allowed in DEFAULT -ALTER TABLE add_default ALTER COLUMN b SET DEFAULT (SELECT 1) - -statement ok -ALTER TABLE add_default ALTER COLUMN b DROP DEFAULT - -statement error null value in column "b" violates not-null constraint -INSERT INTO add_default (a) VALUES (4) - -statement ok -ALTER TABLE add_default ALTER COLUMN b SET DEFAULT NULL - -statement error null value in column "b" violates not-null constraint -INSERT INTO add_default (a) VALUES (4) - -# Each row gets the default value from the time it was inserted. -query II rowsort -SELECT * FROM add_default ----- -2 42 -3 10 - -statement ok -ALTER TABLE add_default ALTER b DROP NOT NULL - -statement ok -INSERT INTO add_default (a) VALUES (5) - -query II -SELECT * from add_default WHERE a=5 ----- -5 NULL - -# Add a column with a default current_timestamp() -statement ok -ALTER TABLE add_default ADD COLUMN c TIMESTAMP DEFAULT current_timestamp() - -query II rowsort -SELECT a,b FROM add_default WHERE current_timestamp > c AND current_timestamp() - c < interval '10s' ----- -2 42 -3 10 -5 NULL - -# Add a column with a default transaction_timestamp() -statement ok -ALTER TABLE add_default ADD COLUMN d TIMESTAMP DEFAULT transaction_timestamp() - -query II rowsort -SELECT a,b FROM add_default WHERE d > c AND d - c < interval '10s' ----- -2 42 -3 10 -5 NULL - -# Add a column with a default statement_timestamp() -statement ok -ALTER TABLE add_default ADD COLUMN e TIMESTAMP DEFAULT statement_timestamp() - -query II rowsort -SELECT a,b FROM add_default WHERE e > d AND e - d < interval '10s' ----- -2 42 -3 10 -5 NULL - -# Add a column with a null-default statement_timestamp() -statement ok -ALTER TABLE add_default ADD COLUMN f TIMESTAMP DEFAULT NULL - -query IIS rowsort -SELECT a,b,f FROM add_default ----- -2 42 NULL -3 10 NULL -5 NULL NULL - -# Adding a unique column to an existing table with data with a default value -# is illegal -statement error pgcode 23505 violates unique constraint \"add_default_g_key\" -ALTER TABLE add_default ADD g INT UNIQUE DEFAULT 1 - -# various default evaluation errors - -statement ok -CREATE SEQUENCE initial_seq - -statement error cannot backfill such sequence operation -ALTER TABLE add_default ADD g INT DEFAULT nextval('initial_seq') - -statement error cannot backfill such evaluated expression -ALTER TABLE add_default ADD g OID DEFAULT 'foo'::regclass::oid - -statement error cannot access virtual schema in anonymous database -ALTER TABLE add_default ADD g INT DEFAULT 'foo'::regtype::INT - -subtest 26422 - -statement ok -BEGIN - -statement ok -ALTER TABLE add_default ADD fee FLOAT NOT NULL DEFAULT 2.99 - -statement ok -ALTER TABLE add_default ALTER COLUMN fee DROP DEFAULT - -statement error pgcode XXA00 null value in column "fee" violates not-null constraint -COMMIT - -statement error pgcode 42703 column "fee" does not exist -ALTER TABLE add_default DROP fee - -# Multiple columns can be added at once with heterogeneous DEFAULT usage -statement ok -CREATE TABLE d (a INT PRIMARY KEY) - -statement ok -INSERT INTO d VALUES (1), (2) - -statement ok -ALTER TABLE d ADD COLUMN c INT, ADD COLUMN b INT DEFAULT 7 - -statement ok -INSERT INTO d (a, c) VALUES (3, 4) - -query III rowsort -SELECT * FROM d ----- -1 NULL 7 -2 NULL 7 -3 4 7 - -# Test privileges. - -statement ok -CREATE TABLE privs (a INT PRIMARY KEY, b INT) - -statement ok -INSERT INTO privs VALUES (1) - -user testuser - -query T -SHOW DATABASE ----- -test - -statement error user testuser does not have CREATE privilege on relation privs -ALTER TABLE privs ADD c INT - -statement error user testuser does not have CREATE privilege on relation privs -ALTER TABLE privs ADD CONSTRAINT foo UNIQUE (b) - -user root - -query TTBTTTB colnames -SHOW COLUMNS FROM privs ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -a INT8 false NULL · {primary} false -b INT8 true NULL · {} false - -statement ok -GRANT CREATE ON privs TO testuser - -user testuser - -statement ok -ALTER TABLE privs ADD c INT - -statement ok -ALTER TABLE privs ADD CONSTRAINT foo UNIQUE (b) - -query TTBTTTB colnames -SHOW COLUMNS FROM privs ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -a INT8 false NULL · {primary,foo} false -b INT8 true NULL · {foo} false -c INT8 true NULL · {} false - -statement error pgcode 42P01 relation "nonexistent" does not exist -ALTER TABLE nonexistent SPLIT AT VALUES (42) - -statement error pgcode 42P01 relation "nonexistent" does not exist -ALTER INDEX nonexistent@noindex SPLIT AT VALUES (42) - -statement error pgcode 42P01 relation "nonexistent" does not exist -ALTER TABLE nonexistent UNSPLIT AT VALUES (42) - -statement error pgcode 42P01 relation "nonexistent" does not exist -ALTER INDEX nonexistent@noindex UNSPLIT AT VALUES (42) - -user root - -statement ok -CREATE VIEW privsview AS SELECT a,b,c FROM privs - -statement error pgcode 42809 "privsview" is not a table -ALTER TABLE privsview ADD d INT - -statement error pgcode 42809 "privsview" is not a table -ALTER TABLE privsview SPLIT AT VALUES (42) - -statement error pgcode 42809 "privsview" is not a table -ALTER TABLE privsview UNSPLIT AT VALUES (42) - -# Verify that impure defaults are evaluated separately on each row -# (database-issues#4105) -statement ok -CREATE TABLE impure (x INT); INSERT INTO impure(x) VALUES (1), (2), (3); - -statement ok -ALTER TABLE impure ADD COLUMN a INT DEFAULT unique_rowid(); - -query I -SELECT count(distinct a) FROM impure ----- -3 - -# No orphaned schema change jobs. -query I -SELECT count(*) FROM crdb_internal.jobs -WHERE job_type = 'SCHEMA CHANGE' AND status = 'pending' OR status = 'started' ----- -0 - -# Verify that ALTER TABLE statements are rolled back properly when a DEFAULT expression returns -# an error. - -statement ok -CREATE TABLE default_err_test (foo text) - -statement ok -INSERT INTO default_err_test VALUES ('foo'), ('bar'), ('baz') - -statement error some_msg -ALTER TABLE default_err_test ADD COLUMN id int DEFAULT crdb_internal.force_error('foo', 'some_msg') - -query T -SELECT * from default_err_test ORDER BY foo ----- -bar -baz -foo - -# Create a table with a computed column that we'll de-compute -statement ok -CREATE TABLE decomputed_column (a INT PRIMARY KEY, b INT AS ( a + 1 ) STORED) - -statement ok -INSERT INTO decomputed_column VALUES (1), (2) - -statement error cannot write directly to computed column -INSERT INTO decomputed_column VALUES (3, NULL), (4, 99) - -statement ok -ALTER TABLE decomputed_column ALTER COLUMN b DROP STORED - -statement error pq: column "a" is not a computed column -ALTER TABLE decomputed_column ALTER COLUMN a DROP STORED - -statement error pq: column "b" is not a computed column -ALTER TABLE decomputed_column ALTER COLUMN b DROP STORED - -# Verify that the computation is dropped and that we can mutate the column -statement ok -INSERT INTO decomputed_column VALUES (3, NULL), (4, 99) - -query II -select a, b from decomputed_column order by a ----- -1 2 -2 3 -3 NULL -4 99 - -query TT -show create table decomputed_column ----- -decomputed_column CREATE TABLE decomputed_column ( - a INT8 NOT NULL, - b INT8 NULL, - CONSTRAINT "primary" PRIMARY KEY (a ASC), - FAMILY "primary" (a, b) -) - -# Test for https://github.com/cockroachdb/cockroach/issues/26483 -# We try to create a unique column on an un-indexable type. -statement ok -CREATE TABLE b26483() - -statement error unimplemented: column c is of type int\[\] and thus is not indexable -ALTER TABLE b26483 ADD COLUMN c INT[] UNIQUE - -# As above, but performed in a transaction -statement ok -BEGIN - -statement ok -CREATE TABLE b26483_tx() - -statement ok -ALTER TABLE b26483_tx ADD COLUMN c INT[] - -statement error unimplemented: column c is of type int\[\] and thus is not indexable -CREATE INDEX on b26483_tx (c) - -statement ok -ROLLBACK - -# Verify that auditing can be enabled by root, and cannot be disabled by non-root. - -statement ok -CREATE TABLE audit(x INT); ALTER TABLE audit EXPERIMENTAL_AUDIT SET READ WRITE; - -# The user must be able to issue ALTER for this test to be meaningful. -statement ok -GRANT CREATE ON audit TO testuser - -user testuser - -# Check the user can indeed change the table -statement ok -ALTER TABLE audit ADD COLUMN y INT - -# But not the audit settings. -statement error change auditing settings on a table -ALTER TABLE audit EXPERIMENTAL_AUDIT SET OFF; - -user root - -# Check column backfill in the presence of fks -subtest 27402 - -statement ok -CREATE TABLE users ( - id INT NOT NULL, - city STRING NOT NULL, - name STRING NULL, - CONSTRAINT "primary" PRIMARY KEY (city ASC, id ASC) -) - -statement ok -CREATE TABLE vehicles ( - id INT NOT NULL, - city STRING NOT NULL, - type STRING NULL, - owner_id INT NULL, - mycol STRING NULL, - CONSTRAINT "primary" PRIMARY KEY (city ASC, id ASC), - INDEX vehicles_auto_index_fk_city_ref_users (city ASC, owner_id ASC) -) - -statement ok -CREATE TABLE rides ( - id INT NOT NULL, - city STRING NOT NULL, - vehicle_city STRING NULL, - rider_id INT NULL, - vehicle_id INT NULL, - CONSTRAINT "primary" PRIMARY KEY (city ASC, id ASC), - INDEX rides_auto_index_fk_city_ref_users (city ASC, rider_id ASC), - INDEX rides_auto_index_fk_vehicle_city_ref_vehicles (vehicle_city ASC, vehicle_id ASC), - CONSTRAINT check_vehicle_city_city CHECK (vehicle_city = city) -) - -statement ok -ALTER TABLE vehicles ADD CONSTRAINT fk_city_ref_users FOREIGN KEY (city, owner_id) REFERENCES users (city, id) - -statement ok -ALTER TABLE rides ADD CONSTRAINT fk_city_ref_users FOREIGN KEY (city, rider_id) REFERENCES users (city, id) - -statement ok -ALTER TABLE rides ADD CONSTRAINT fk_vehicle_city_ref_vehicles FOREIGN KEY (vehicle_city, vehicle_id) REFERENCES vehicles (city, id) - - -statement ok -INSERT INTO users VALUES (10, 'lagos', 'chimamanda') - -statement ok -INSERT INTO vehicles VALUES (100, 'lagos', 'toyota', 10, 'mycol') - -statement ok -INSERT INTO rides VALUES (567, 'lagos', 'lagos', 10, 100) - -statement ok -ALTER TABLE vehicles DROP COLUMN mycol; - -# check that adding a reference on a column still being backfilled fails. -# fix through cockroach#32917 - -statement ok -CREATE TABLE t32917 (a INT PRIMARY KEY) - -statement ok -INSERT INTO t32917 VALUES (1), (2), (3) - -statement ok -CREATE TABLE t32917_2 (b INT PRIMARY KEY) - -statement ok -INSERT INTO t32917_2 VALUES (1), (2), (3) - -statement ok -BEGIN - -statement ok -ALTER TABLE t32917_2 ADD c INT UNIQUE DEFAULT 4 - -statement error adding a REFERENCES constraint while the column is being added not supported -ALTER TABLE t32917_2 ADD CONSTRAINT fk_c_a FOREIGN KEY (c) references t32917 (a) - -statement ok -ROLLBACK diff --git a/test/sqllogictest/cockroach/alter_table_owner.slt b/test/sqllogictest/cockroach/alter_table_owner.slt new file mode 100644 index 0000000000000..cd52814c5455e --- /dev/null +++ b/test/sqllogictest/cockroach/alter_table_owner.slt @@ -0,0 +1,107 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/alter_table_owner +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA s; +CREATE TABLE t (); +CREATE TABLE s.t (); +CREATE USER testuser2 + +# Ensure user must exist for set owner. +statement error unknown role 'fake_user' +ALTER TABLE t OWNER TO fake_user + +# Not supported by Materialize. +onlyif cockroach +# Superusers can alter owner to any user which has CREATE privileges on the +# parent schema. This succeeds since all users have CREATE on the public schema +# by default. +statement ok +ALTER TABLE t OWNER TO testuser + +statement error unknown role 'testuser' +ALTER TABLE s.t OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +# ALTER TABLE IF EXISTS OWNER succeeds if the table does not exist. +statement ok +ALTER TABLE IF EXISTS does_not_exist OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON SCHEMA s TO testuser, testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE s.t OWNER TO testuser; +ALTER TABLE t OWNER TO root; +ALTER TABLE s.t OWNER TO root + +# Other users must be owner to alter the owner. +user testuser + +statement error unknown role 'testuser2' +ALTER TABLE t OWNER TO testuser2 + +# other users must be owner to alter the owner to the current owner again +statement error unknown role 'root' +ALTER TABLE t OWNER TO root + +# Non-superusers also must be a member of the new owning role. +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t OWNER TO testuser + +user testuser + +statement error unknown role 'testuser2' +ALTER TABLE t OWNER TO testuser2 + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT testuser2 TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t OWNER TO testuser2 + +user root + +query T +SELECT tableowner FROM pg_tables WHERE schemaname = 'public' AND tablename = 't' +---- diff --git a/test/sqllogictest/cockroach/alter_type_owner.slt b/test/sqllogictest/cockroach/alter_type_owner.slt new file mode 100644 index 0000000000000..6952d51a0a45e --- /dev/null +++ b/test/sqllogictest/cockroach/alter_type_owner.slt @@ -0,0 +1,135 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/alter_type_owner +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA s; +CREATE TYPE s.typ AS ENUM (); +CREATE USER testuser2 + +# Ensure user must exist for set owner. +statement error unknown role 'fake_user' +ALTER TYPE s.typ OWNER TO fake_user + +# Superusers can alter owner to any user which has CREATE privileges on the +# parent schema. +statement error unknown role 'testuser' +ALTER TYPE s.typ OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE, USAGE ON SCHEMA s TO testuser, testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TYPE s.typ OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TYPE s.typ OWNER TO root + +# Other users must be owner to alter the owner. +user testuser + +statement error unknown schema 's' +ALTER TYPE s.typ OWNER TO testuser + +# other users must be owner to alter the owner to the current owner again +statement error unknown role 'root' +ALTER TYPE s.typ OWNER TO root + +# Non-superusers also must be a member of the new owning role. +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TYPE s.typ OWNER TO testuser + +user testuser + +statement error unknown role 'testuser2' +ALTER TYPE s.typ OWNER TO testuser2 + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT testuser2 TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TYPE s.typ OWNER TO testuser2 + +# Ensure testuser2 is owner. +user root + +query T +SELECT pg_get_userbyid(typowner) FROM pg_type WHERE typname = 'typ'; +---- + + +# Ensure admins who don't have explicit CREATE privilege on a schema can +# still become the owner. +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON DATABASE test TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA s2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE s2.typ AS ENUM () + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT root TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +# This should succeed despite root not having explicit CREATE privilege on s2. +statement ok +ALTER TYPE s2.typ OWNER TO root diff --git a/test/sqllogictest/cockroach/alter_view_owner.slt b/test/sqllogictest/cockroach/alter_view_owner.slt new file mode 100644 index 0000000000000..4b742c8a9d845 --- /dev/null +++ b/test/sqllogictest/cockroach/alter_view_owner.slt @@ -0,0 +1,151 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/alter_view_owner +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA s; +CREATE VIEW vx AS SELECT 1; +CREATE VIEW s.vx AS SELECT 1; +CREATE MATERIALIZED VIEW mvx AS SELECT 1; +CREATE USER testuser2 + +# Ensure user must exist for set owner. +statement error unknown role 'fake_user' +ALTER VIEW vx OWNER TO fake_user + +# Not supported by Materialize. +onlyif cockroach +# Superusers can alter owner to any user which has CREATE privileges on the +# parent schema. This succeeds since all users have CREATE on the public schema +# by default. +statement ok +ALTER VIEW vx OWNER TO testuser + +statement error unknown role 'testuser' +ALTER VIEW s.vx OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +# ALTER VIEW IF EXISTS OWNER succeeds if the view does not exist. +statement ok +ALTER VIEW IF EXISTS does_not_exist OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON SCHEMA s TO testuser, testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE vx OWNER TO root + +# Not supported by Materialize. +onlyif cockroach +# ALTER TABLE can be used for materialized views. +statement ok +ALTER TABLE mvx OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE mvx OWNER TO root + +# ALTER SEQUENCE cannot be used for views. +statement error Expected one of TABLE or VIEW or MATERIALIZED or SOURCE or SINK or INDEX or TYPE or ROLE or USER or CLUSTER or SECRET or CONNECTION or DATABASE or SCHEMA or FUNCTION or NETWORK, found identifier "sequence" +ALTER SEQUENCE vx OWNER TO testuser + +# MATERIALIZED keyword can only be present for materialized views. +statement error unknown role 'testuser' +ALTER MATERIALIZED VIEW vx OWNER TO testuser; + +# MATERIALIZED keyword must be present to change the owner of materialized views. +statement error unknown role 'testuser' +ALTER VIEW mvx OWNER TO testuser; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER VIEW vx OWNER TO testuser; +ALTER MATERIALIZED VIEW mvx OWNER TO testuser; +ALTER VIEW s.vx OWNER TO testuser; +ALTER VIEW vx OWNER TO root; +ALTER MATERIALIZED VIEW mvx OWNER TO root; +ALTER VIEW s.vx OWNER TO root; + +# Other users must be owner to alter the owner. +user testuser + +statement error unknown role 'testuser2' +ALTER VIEW vx OWNER TO testuser2 + +statement error unknown role 'testuser2' +ALTER MATERIALIZED VIEW mvx OWNER TO testuser2 + +# Non-superusers also must be a member of the new owning role. +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER VIEW vx OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER MATERIALIZED VIEW mvx OWNER TO testuser + +user testuser + +statement error unknown role 'testuser2' +ALTER VIEW vx OWNER TO testuser2 + +statement error unknown role 'testuser2' +ALTER MATERIALIZED VIEW mvx OWNER TO testuser2 + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT testuser2 TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER VIEW vx OWNER TO testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER MATERIALIZED VIEW mvx OWNER TO testuser2 + +user root + +query T +SELECT viewowner FROM pg_views WHERE schemaname = 'public' AND viewname = 'vx' +---- diff --git a/test/sqllogictest/cockroach/and_or.slt b/test/sqllogictest/cockroach/and_or.slt new file mode 100644 index 0000000000000..418796faf2bef --- /dev/null +++ b/test/sqllogictest/cockroach/and_or.slt @@ -0,0 +1,66 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/and_or +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +DROP TABLE IF EXISTS t; CREATE TABLE t (k INT PRIMARY KEY, a INT, b INT) + +statement ok +INSERT INTO t VALUES (1, NULL, NULL), (2, NULL, 1), (3, 1, NULL), (4, 2, 0), (5, 3, 3) + +# Test AND short-circuiting projection logic (check that the right side is not +# evaluated when the left side is false). +query B +SELECT a <> 2 AND 3 / b = 1 FROM t ORDER BY k +---- +NULL +false +NULL +false +true + +# Test AND short-circuiting selection logic (check that the right side is not +# evaluated when the left side is false). +query I +SELECT a FROM t WHERE a <> 2 AND 3 / b = 1 ORDER BY k +---- +3 + +# Test OR short-circuiting projection logic (check that the right side is not +# evaluated when the left side is true). +query B +SELECT a = 2 OR 3 / b = 1 FROM t ORDER BY k +---- +NULL +NULL +NULL +true +true + +# Test OR short-circuiting selection logic (check that the right side is not +# evaluated when the left side is true). +query I +SELECT a FROM t WHERE a = 2 OR 3 / b = 1 ORDER BY k +---- +2 +3 diff --git a/test/sqllogictest/cockroach/array.slt b/test/sqllogictest/cockroach/array.slt deleted file mode 100644 index 6123500e98461..0000000000000 --- a/test/sqllogictest/cockroach/array.slt +++ /dev/null @@ -1,1322 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/array -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -# pg arrays must preserve control characters when converted to string, -# but their direct representation as string does not escape the -# control characters. In order for the test file to remain valid -# printable UTF-8, we double-escape the representations below. - -# TODO: Support bytea -#statement ok -#SET bytea_output = escape - -# array construction - -query error cannot determine type of empty array -SELECT ARRAY[] - -query T -SELECT ARRAY[1, 2, 3] ----- -{1,2,3} - -statement ok -CREATE TABLE k ( - k INT PRIMARY KEY -) - -statement ok -INSERT INTO k VALUES (1), (2), (3), (4), (5) - -query T rowsort -SELECT ARRAY[k] FROM k ----- -{1} -{2} -{3} -{4} -{5} - -query error expected 1 to be of type bool, found type int -SELECT ARRAY['a', true, 1] - -query T -SELECT ARRAY['a,', 'b{', 'c}', 'd', 'e f'] ----- -{"a,","b{","c}",d,"e f"} - -query T -SELECT ARRAY['1}'::BYTES] ----- -{"\\x317d"} - -# TODO(jordan): cockroach#16487 -# query T -# SELECT ARRAY[e'g\x10h'] -# ---- -# {g\x10h} - -query TTTTTTT -SELECT '', 'NULL', 'Null', 'null', NULL, '"', e'\'' ----- -· NULL Null null NULL " ' - -query T -SELECT ARRAY['', 'NULL', 'Null', 'null', NULL, '"', e'\''] ----- -{"","NULL","Null","null",NULL,"\"",'} - -query T -SELECT NULL::INT[] ----- -NULL - -query TTTT -SELECT - ARRAY[NULL]::STRING[], - ARRAY[NULL]::INT[], - ARRAY[NULL]::FLOAT[], - ARRAY[NULL]::TIMESTAMP[] ----- -{NULL} {NULL} {NULL} {NULL} - -query BB -SELECT NULL::INT[] IS DISTINCT FROM NULL, ARRAY[1,2,3] IS DISTINCT FROM NULL ----- -false true - -# materialize#19821 - -query T -SELECT ARRAY['one', 'two', 'fünf'] ----- -{one,two,fünf} - -query T -SELECT ARRAY[e'\n', e'g\x10h']::STRING::BYTES::STRING ----- -{"\012",g\020h} - -query T -SELECT ARRAY['foo', 'bar'] ----- -{foo,bar} - -# array construction from subqueries - -query T -SELECT ARRAY(SELECT 3 WHERE false) ----- -{} - -statement ok -SELECT ARRAY(SELECT 3 WHERE false) FROM k - -query T -SELECT ARRAY(SELECT 3) ----- -{3} - -query T -SELECT ARRAY(VALUES (1),(2),(1)) ----- -{1,2,1} - -statement error arrays cannot have arrays as element type -SELECT ARRAY(VALUES (ARRAY[1])) - -query T -SELECT ARRAY(VALUES ('a'),('b'),('c')) ----- -{a,b,c} - - -# TODO(justin): uncomment when cockroach#32715 is fixed. -# query T -# SELECT ARRAY(SELECT (1,2)) -# ---- -# {"(1,2)"} - -query error subquery must return only one column, found 2 -SELECT ARRAY(SELECT 1, 2) - -query T -SELECT ARRAY[]:::int[] ----- -{} - -# casting strings to arrays - -query T -SELECT '{1,2,3}'::INT[] ----- -{1,2,3} - -query T -SELECT '{hello,"hello"}'::STRING[] ----- -{hello,hello} - -query T -SELECT e'{he\\\\llo}'::STRING[] ----- -{"he\\llo"} - -query T -SELECT '{"abc\nxyz"}'::STRING[] ----- -{abcnxyz} - -query T -SELECT '{hello}'::VARCHAR(2)[] ----- -{he} - -# array casting - -query T -SELECT ARRAY['foo']::STRING ----- -{foo} - -query T -SELECT ARRAY[e'foo\nbar']::STRING::BYTES::STRING ----- -{"foo\012bar"} - -query TTTTTT -SELECT - ARRAY[e'foo\000bar']::STRING::BYTES::STRING, - ARRAY[e'foo\001bar']::STRING::BYTES::STRING, - ARRAY[e'foo\002bar']::STRING::BYTES::STRING, - ARRAY[e'foo\030bar']::STRING::BYTES::STRING, - ARRAY[e'foo\034bar']::STRING::BYTES::STRING, - ARRAY[e'foo\100bar']::STRING::BYTES::STRING ----- -{foo\000bar} {foo\001bar} {foo\002bar} {foo\030bar} {foo\034bar} {foo@bar} - -query T -SELECT ARRAY[1,2,3]::INT[] ----- -{1,2,3} - -query error invalid cast: int[] -> UUID[] -SELECT ARRAY[1,2,3]::UUID[] - -query error invalid cast: inet[] -> INT[] -SELECT ARRAY['8.8.8.8'::INET, '8.8.4.4'::INET]::INT[] - -query T -SELECT ARRAY[1,2,3]::TEXT[] ----- -{1,2,3} - -query T -SELECT ARRAY[1,2,3]::INT2VECTOR ----- -{1,2,3} - -# array subscript access - -query T -SELECT ARRAY['a', 'b', 'c'][-1] ----- -NULL - -query T -SELECT ARRAY['a', 'b', 'c'][0] ----- -NULL - -query T -SELECT (ARRAY['a', 'b', 'c'])[2] ----- -b - -query T -SELECT ARRAY['a', 'b', 'c'][2] ----- -b - -query T -SELECT ARRAY['a', 'b', 'c'][4] ----- -NULL - -query T -SELECT ARRAY['a', 'b', 'c'][1.5 + 1.5] ----- -c - -query I -SELECT ARRAY[1, 2, 3][-1] ----- -NULL - -query I -SELECT ARRAY[1, 2, 3][0] ----- -NULL - -query I -SELECT ARRAY[1, 2, 3][2] ----- -2 - -query I -SELECT ARRAY[1, 2, 3][4] ----- -NULL - -query I -SELECT ARRAY[1, 2, 3][1.5 + 1.5] ----- -3 - -query error unimplemented: multidimensional indexing -SELECT ARRAY['a', 'b', 'c'][4][2] - -query error incompatible ARRAY subscript type: decimal -SELECT ARRAY['a', 'b', 'c'][3.5] - -query error could not parse "abc" as type int -SELECT ARRAY['a', 'b', 'c']['abc'] - -query error cannot subscript type integer because it is not an array -SELECT (123)[2] - -# array slicing - -query error unimplemented: ARRAY slicing -SELECT ARRAY['a', 'b', 'c'][:] - -query error unimplemented: ARRAY slicing -SELECT ARRAY['a', 'b', 'c'][1:] - -query error unimplemented: ARRAY slicing -SELECT ARRAY['a', 'b', 'c'][1:2] - -query error unimplemented: ARRAY slicing -SELECT ARRAY['a', 'b', 'c'][:2] - -query error unimplemented: ARRAY slicing -SELECT ARRAY['a', 'b', 'c'][2:1] - -# other forms of indirection - -# From a column name. -query T -SELECT a[1] FROM (SELECT ARRAY['a','b','c'] AS a) ----- -a - -# From a column ordinal. -query T -SELECT @1[1] FROM (SELECT ARRAY['a','b','c'] AS a) ----- -a - -# From a parenthetized expression. -query I -SELECT (ARRAY(VALUES (1),(2),(1)))[2] ----- -2 - -# From an ArrayFlatten expression - ARRAY(subquery)[...] -query I -SELECT ARRAY(VALUES (1),(2),(1))[2] ----- -2 - -# From a single-column subquery converted to a single datum. -query I -SELECT ((SELECT ARRAY[1, 2, 3]))[3] ----- -3 - -# From a subquery. -query T -SELECT (SELECT ARRAY['a', 'b', 'c'])[3] ----- -c - -query T -SELECT ARRAY(SELECT generate_series(1,10) ORDER BY 1 DESC) ----- -{10,9,8,7,6,5,4,3,2,1} - -statement ok -CREATE TABLE z ( - x INT PRIMARY KEY, - y INT -) - -statement ok -INSERT INTO z VALUES (1, 5), (2, 4), (3, 3), (4, 2), (5, 1) - -query T -SELECT ARRAY(SELECT x FROM z ORDER BY y) ----- -{5,4,3,2,1} - -# From a function call expression. -query T -SELECT current_schemas(true)[1] ----- -pg_catalog - -# From a CASE sub-expression. -query I -SELECT (CASE 1 = 1 WHEN true THEN ARRAY[1,2] ELSE ARRAY[2,3] END)[1] ----- -1 - -# From a tuple. -query error cannot subscript type tuple{int, int, int} because it is not an array -SELECT (1,2,3)[1] - -query error cannot subscript type tuple{int, int, int} because it is not an array -SELECT ROW (1,2,3)[1] - -# Ensure grouping by an array column works - -statement ok -SELECT conkey FROM pg_catalog.pg_constraint GROUP BY conkey - -statement ok -SELECT indkey[0] FROM pg_catalog.pg_index - -# Verify serialization of array in expression (with distsql). -statement ok -CREATE TABLE t (k INT) - -statement ok -INSERT INTO t VALUES (1), (2), (3), (4), (5) - -query I rowsort -SELECT k FROM t WHERE k = ANY ARRAY[2,4] ----- -2 -4 - -query I rowsort -SELECT k FROM t WHERE k > ANY ARRAY[2,4] ----- -3 -4 -5 - -query I -SELECT k FROM t WHERE k < ALL ARRAY[2,4] ----- -1 - -# Undocumented - bounds should be allowed, as in Postgres -statement ok -CREATE TABLE boundedtable (b INT[10], c INT ARRAY[10]) - -statement ok -DROP TABLE boundedtable - -# Creating multidimensional arrays should be disallowed. -statement error unimplemented.*\nHINT.*32552 -CREATE TABLE badtable (b INT[][]) - -# Nested arrays should be disallowed - -query error unimplemented: arrays cannot have arrays as element type.*\nHINT.*32552 -SELECT ARRAY[ARRAY[1,2,3]] - -# The postgres-compat aliases should be disallowed. -# INT2VECTOR is deprecated in Postgres. - -query error VECTOR column types are unsupported -CREATE TABLE badtable (b INT2VECTOR) - -# Using an array as a primary key should be disallowed. materialize#17154 - -statement error column b is of type int\[\] and thus is not indexable -CREATE TABLE badtable (b INT[] PRIMARY KEY) - -# Indexing an array column should be disallowed. materialize#17154 - -statement error column b is of type int\[\] and thus is not indexable -CREATE TABLE a (b INT[] UNIQUE) - - -# Regression test for database-issues#5547 - -statement ok -CREATE TABLE ident (x INT) - -query T -SELECT ARRAY[ROW()] FROM ident ----- - -statement error column b is of type int\[\] and thus is not indexable -CREATE TABLE a ( - b INT[], - CONSTRAINT c UNIQUE (b) -) - -statement error column b is of type int\[\] and thus is not indexable -CREATE TABLE a ( - b INT[], - INDEX c (b) -) - -statement ok -CREATE TABLE a (b INT ARRAY) - -query TT -SHOW CREATE TABLE a ----- -a CREATE TABLE a ( - b INT8[] NULL, - FAMILY "primary" (b, rowid) - ) - -statement ok -DROP TABLE a - -statement ok -CREATE TABLE a (b INT[], c INT[]) - -statement error column b is of type int\[\] and thus is not indexable -CREATE INDEX idx ON a (b) - -statement error the following columns are not indexable due to their type: b \(type int\[\]\), c \(type int\[\]\) -CREATE INDEX idx ON a (b, c) - -statement ok -DROP TABLE a - -# Int array columns. - -statement ok -CREATE TABLE a (b INT[]) - -statement ok -INSERT INTO a VALUES (ARRAY[1,2,3]) - -query T -SELECT b FROM a ----- -{1,2,3} - -statement ok -DELETE FROM a - -statement ok -INSERT INTO a VALUES (NULL) - -query T -SELECT b FROM a ----- -NULL - -statement ok -DELETE FROM a - -statement ok -INSERT INTO a VALUES (ARRAY[]) - -query T -SELECT b FROM a ----- -{} - -statement ok -DELETE FROM a; - -# Make sure arrays originating from ARRAY_AGG work as expected. - -statement ok -INSERT INTO a (SELECT array_agg(generate_series) from generate_series(1,3)) - -query T -SELECT * FROM a ----- -{1,2,3} - -query TT -SHOW CREATE TABLE a ----- -a CREATE TABLE a ( - b INT8[] NULL, - FAMILY "primary" (b, rowid) - ) - -statement error could not parse "foo" as type int -INSERT INTO a VALUES (ARRAY['foo']) - -statement error could not parse "foo" as type int -INSERT INTO a VALUES (ARRAY[1, 'foo']) - -statement ok -DELETE FROM a - -statement ok -INSERT INTO a VALUES (ARRAY[1,2,3]), (ARRAY[4,5]), (ARRAY[6]) - -query I -SELECT b[1] FROM a ORDER BY b[1] ----- -1 -4 -6 - -query I -SELECT b[2] FROM a ORDER BY b[1] ----- -2 -5 -NULL - -# NULL values - -statement ok -DELETE FROM a - -statement ok -INSERT INTO a VALUES (ARRAY[NULL::INT]), (ARRAY[NULL::INT, 1]), (ARRAY[1, NULL::INT]), (ARRAY[NULL::INT, NULL::INT]) - -query T rowsort -SELECT * FROM a ----- -{NULL} -{NULL,1} -{1,NULL} -{NULL,NULL} - -statement ok -DELETE FROM a - -# Test with arrays bigger than 8 elements so the NULL bitmap has to be larger than a byte - -statement ok -INSERT INTO a VALUES (ARRAY[1,2,3,4,5,6,7,8,NULL::INT]) - -query T -SELECT * FROM a ----- -{1,2,3,4,5,6,7,8,NULL} - -statement ok -DROP TABLE a - -# Ensure that additional type info stays when used as an array. - -statement ok -CREATE TABLE a (b SMALLINT[]) - -query TT -SHOW CREATE TABLE a ----- -a CREATE TABLE a ( - b INT2[] NULL, - FAMILY "primary" (b, rowid) -) - -statement error integer out of range for type int2 \(column "b"\) -INSERT INTO a VALUES (ARRAY[100000]) - -statement ok -DROP TABLE a - -# String array columns. - -statement ok -CREATE TABLE a (b STRING[]) - -statement ok -INSERT INTO a VALUES (ARRAY['foo', 'bar', 'baz']) - -query T -SELECT b FROM a ----- -{foo,bar,baz} - -statement ok -UPDATE a SET b = ARRAY[] - -query T -SELECT b FROM a ----- -{} - -# Test NULLs with strings - -statement ok -DELETE FROM a - -statement ok -INSERT INTO a VALUES (ARRAY[NULL::STRING, NULL::STRING, NULL::STRING, NULL::STRING, NULL::STRING, NULL::STRING, 'G']) - -query T -SELECT * FROM a ----- -{NULL,NULL,NULL,NULL,NULL,NULL,G} - -statement ok -DROP TABLE a - -# Bool array columns. - -statement ok -CREATE TABLE a (b BOOL[]) - -statement ok -INSERT INTO a VALUES (ARRAY[]), (ARRAY[TRUE]), (ARRAY[FALSE]), (ARRAY[TRUE, TRUE]), (ARRAY[FALSE, TRUE]) - -query T rowsort -SELECT b FROM a ----- -{} -{t} -{f} -{t,t} -{f,t} - -statement ok -DROP TABLE a - -# Float array columns. - -statement ok -CREATE TABLE a (b FLOAT[]) - -statement ok -INSERT INTO a VALUES (ARRAY[1.1, 2.2, 3.3]) - -query T -SELECT b FROM a ----- -{1.1,2.2,3.3} - -statement ok -DROP TABLE a - -# Decimal array columns. - -statement ok -CREATE TABLE a (b DECIMAL[]) - -statement ok -INSERT INTO a VALUES (ARRAY[1.1, 2.2, 3.3]) - -query T -SELECT b FROM a ----- -{1.1,2.2,3.3} - -statement ok -DROP TABLE a - -# Bytes array columns. - -statement ok -CREATE TABLE a (b BYTES[]) - -statement ok -INSERT INTO a VALUES (ARRAY['foo','bar','baz']) - -query T -SELECT b FROM a ----- -{"\\x666f6f","\\x626172","\\x62617a"} - -statement ok -DROP TABLE a - -# Date array columns. - -statement ok -CREATE TABLE a (b DATE[]) - -statement ok -INSERT INTO a VALUES (ARRAY[current_date]) - -query I -SELECT count(b) FROM a ----- -1 - -statement ok -DROP TABLE a - -# Timestamp array columns. - -statement ok -CREATE TABLE a (b TIMESTAMP[]) - -statement ok -INSERT INTO a VALUES (ARRAY[now()]) - -query I -SELECT count(b) FROM a ----- -1 - -statement ok -DROP TABLE a - -# Interval array columns. - -statement ok -CREATE TABLE a (b INTERVAL[]) - -statement ok -INSERT INTO a VALUES (ARRAY['1-2'::interval]) - -query T -SELECT b FROM a ----- -{"1 year 2 mons"} - -statement ok -DROP TABLE a - -# UUID array columns. - -statement ok -CREATE TABLE a (b UUID[]) - -statement ok -INSERT INTO a VALUES (ARRAY[uuid_v4()::uuid]) - -query I -SELECT count(b) FROM a ----- -1 - -statement ok -DROP TABLE a - -# OID array columns. - -statement ok -CREATE TABLE a (b OID[]) - -statement ok -INSERT INTO a VALUES (ARRAY[1]) - -query T -SELECT b FROM a ----- -{1} - -statement ok -DROP TABLE a - -# Collated string array columns. - -statement ok -CREATE TABLE a (b STRING[] COLLATE en) - -statement ok -INSERT INTO a VALUES (ARRAY['hello' COLLATE en]), (ARRAY['goodbye' COLLATE en]) - -query T rowsort -SELECT * FROM a ----- -{hello} -{goodbye} - -statement error value type collatedstring{fr}\[\] doesn't match type collatedstring{en}\[\] of column "b" -INSERT INTO a VALUES (ARRAY['hello' COLLATE fr]) - -statement ok -DROP TABLE a - -query T -SELECT * FROM unnest(ARRAY['a', 'B']) ORDER BY UNNEST; ----- -B -a - -query T -SELECT * FROM unnest(ARRAY['a' COLLATE en, 'B' COLLATE en]) ORDER BY UNNEST; ----- -a -B - -# TODO(justin): type system limitation -statement error unsupported binary operator -SELECT ARRAY['foo' COLLATE en] || ARRAY['bar' COLLATE en] - -statement error unsupported binary operator -SELECT ARRAY['foo' COLLATE en] || 'bar' COLLATE en - -statement ok -CREATE TABLE a (b STRING[]) - -statement ok -INSERT INTO a VALUES (ARRAY['foo']) - -statement error value type collatedstring{en}\[\] doesn't match type text\[\] of column "b" -INSERT INTO a VALUES (ARRAY['foo' COLLATE en]) - -statement ok -DROP TABLE a - -# Array operators - -# Element append - -query T -SELECT ARRAY['a','b','c'] || 'd' ----- -{a,b,c,d} - -query T -SELECT ARRAY[1,2,3] || 4 ----- -{1,2,3,4} - -query T -SELECT NULL::INT[] || 4 ----- -{4} - -query T -SELECT 4 || NULL::INT[] ----- -{4} - -query T -SELECT ARRAY[1,2,3] || NULL::INT ----- -{1,2,3,NULL} - -query T -SELECT NULL::INT[] || NULL::INT ----- -{NULL} - -query T -SELECT NULL::INT || ARRAY[1,2,3] ----- -{NULL,1,2,3} - -query TT -SELECT NULL::INT || NULL::INT[], NULL::INT[] || NULL::INT ----- -{NULL} {NULL} - -query T -SELECT 1 || ARRAY[2,3,4] ----- -{1,2,3,4} - -# This is a departure from Postgres' behavior. -# In Postgres, ARRAY[1,2,3] || NULL = ARRAY[1,2,3]. - -query T -SELECT ARRAY[1,2,3] || NULL ----- -{1,2,3} - -query T -SELECT NULL || ARRAY[1,2,3] ----- -{1,2,3} - -# This test is here because its typechecking is related to the above - -query TT -SELECT NULL || 'asdf', 'asdf' || NULL ----- -NULL NULL - -statement ok -CREATE TABLE a (b INT[]) - -# Ensure arrays appended to still encode properly. - -statement ok -INSERT INTO a VALUES (ARRAY[]) - -statement ok -UPDATE a SET b = b || 1 - -statement ok -UPDATE a SET b = b || 2 - -statement ok -UPDATE a SET b = b || 3 - -statement ok -UPDATE a SET b = b || 4 - -query T -SELECT b FROM a ----- -{1,2,3,4} - -statement ok -UPDATE a SET b = NULL::INT || b || NULL::INT - -query T -SELECT b FROM a ----- -{NULL,1,2,3,4,NULL} - -# Array append - -query T -SELECT ARRAY[1,2,3] || ARRAY[4,5,6] ----- -{1,2,3,4,5,6} - -query T -SELECT ARRAY['a','b','c'] || ARRAY['d','e','f'] ----- -{a,b,c,d,e,f} - -query T -SELECT ARRAY[1,2,3] || NULL::INT[] ----- -{1,2,3} - -query T -SELECT NULL::INT[] || ARRAY[4,5,6] ----- -{4,5,6} - -query T -SELECT NULL::INT[] || NULL::INT[] ----- -NULL - -# Array equality - -query B -SELECT ARRAY[1,2,3] = ARRAY[1,2,3] ----- -true - -query B -SELECT ARRAY[1,2,4] = ARRAY[1,2,3] ----- -false - -query B -SELECT ARRAY[1,2,3] != ARRAY[1,2,3] ----- -false - -query B -SELECT ARRAY[1,2,4] != ARRAY[1,2,3] ----- -true - -query B -SELECT ARRAY[1,2,4] = NULL ----- -NULL - -# This behavior is surprising (one might expect that the result would be -# NULL), but it's how Postgres behaves. -query B -SELECT ARRAY[1,2,NULL] = ARRAY[1,2,3] ----- -false - -# ARRAY_APPEND function - -query TT -SELECT array_append(ARRAY[1,2,3], 4), array_append(ARRAY[1,2,3], NULL::INT) ----- -{1,2,3,4} {1,2,3,NULL} - -query TT -SELECT array_append(NULL::INT[], 4), array_append(NULL::INT[], NULL::INT) ----- -{4} {NULL} - -# ARRAY_PREPEND function - -query TT -SELECT array_prepend(4, ARRAY[1,2,3]), array_prepend(NULL::INT, ARRAY[1,2,3]) ----- -{4,1,2,3} {NULL,1,2,3} - -query TT -SELECT array_prepend(4, NULL::INT[]), array_prepend(NULL::INT, NULL::INT[]) ----- -{4} {NULL} - -# ARRAY_CAT function - -query TT -SELECT array_cat(ARRAY[1,2,3], ARRAY[4,5,6]), array_cat(ARRAY[1,2,3], NULL::INT[]) ----- -{1,2,3,4,5,6} {1,2,3} - -query TT -SELECT array_cat(NULL::INT[], ARRAY[4,5,6]), array_cat(NULL::INT[], NULL::INT[]) ----- -{4,5,6} NULL - -# ARRAY_REMOVE function - -query T -SELECT array_remove(ARRAY[1,2,3,2], 2) ----- -{1,3} - -query T -SELECT array_remove(ARRAY[1,2,3,NULL::INT], NULL::INT) ----- -{1,2,3} - -query T -SELECT array_remove(NULL::INT[], NULL::INT) ----- -NULL - -# ARRAY_REPLACE function - -query T -SELECT array_replace(ARRAY[1,2,5,4], 5, 3) ----- -{1,2,3,4} - -query TT -SELECT array_replace(ARRAY[1,2,NULL,4], NULL::INT, 3), array_replace(NULL::INT[], 5, 3) ----- -{1,2,3,4} NULL - -# ARRAY_POSITION function - -query I -SELECT array_position(ARRAY['sun','mon','tue','wed','thu','fri','sat','mon'], 'mon') ----- -2 - -query I -SELECT array_position(ARRAY['sun','mon','tue','wed','thu','fri','sat','mon'], 'abc') ----- -NULL - -query I -SELECT array_position(NULL::STRING[], 'abc') ----- -NULL - -# ARRAY_POSITIONS function - -query TT -SELECT array_positions(ARRAY['A','A','B','A'], 'A'), array_positions(ARRAY['A','A','B','A'], 'C') ----- -{1,2,4} {} - -query T -SELECT array_positions(NULL::STRING[], 'A') ----- -NULL - -query T -SELECT string_to_array('axbxc', 'x') ----- -{a,b,c} - -query T -SELECT string_to_array('~a~~b~c', '~') ----- -{"",a,"",b,c} - -query T -SELECT string_to_array('~foo~~bar~baz', '~', 'bar') ----- -{"",foo,"",NULL,baz} - -query T -SELECT string_to_array('xx~^~yy~^~zz', '~^~', 'yy') ----- -{xx,NULL,zz} - -query T -SELECT string_to_array('foo', '') ----- -{foo} - -query T -SELECT string_to_array('', '') ----- -{} - -query T -SELECT string_to_array('', 'foo') ----- -{} - -query T -SELECT string_to_array('a', NULL) ----- -{a} - -query T -SELECT string_to_array(NULL, 'a') ----- -NULL - -query T -SELECT string_to_array(NULL, 'a', 'b') ----- -NULL - -query T -SELECT string_to_array('a', 'foo', NULL) ----- -{a} - -query T -SELECT string_to_array('foofoofoofoo', 'foo', 'foo') ----- -{"","","","",""} - -# Regression test for materialize#23429. - -statement ok -CREATE TABLE x (a STRING[], b INT[]) - -statement ok -UPDATE x SET a = ARRAY[], b = ARRAY[] - - -# Github Issue 24175: Regression test for error when using ANY with UUID array. -statement ok -CREATE TABLE documents (shared_users UUID[]); - -statement ok -INSERT INTO documents -VALUES - (ARRAY[]), - (ARRAY['3ae3560e-d771-4b63-affb-47e8d7853680'::UUID, - '6CC1B5C1-FE4F-417D-96BD-AFD1FEEEC34F'::UUID]), - (ARRAY['C6F8286C-3A41-4D7E-A4F4-3234B7A57BA9'::UUID]) - -query T -SELECT * -FROM documents -WHERE '3ae3560e-d771-4b63-affb-47e8d7853680'::UUID = ANY (documents.shared_users); ----- -{3ae3560e-d771-4b63-affb-47e8d7853680,6cc1b5c1-fe4f-417d-96bd-afd1feeec34f} - -statement ok -CREATE TABLE u (x INT) - -statement ok -INSERT INTO u VALUES (1), (2) - -statement ok -CREATE TABLE v (y INT[]) - -statement ok -INSERT INTO v VALUES (ARRAY[1, 2]) - -# Regression test for cockroach#30191. Ensure ArrayFlatten returns correct type. -query T -SELECT * FROM v WHERE y = ARRAY(SELECT x FROM u ORDER BY x); ----- -{1,2} - -# Regression test for cockroach#34439. Ensure that empty arrays are interned correctly. -query B -SELECT ARRAY[''] = ARRAY[] FROM (VALUES (1)) WHERE ARRAY[B''] != ARRAY[] ----- -false - -subtest 36477 - -statement ok -CREATE TABLE array_single_family (a INT PRIMARY KEY, b INT[], FAMILY fam0(a), FAMILY fam1(b)) - -statement ok -INSERT INTO array_single_family VALUES(0,ARRAY[]) - -statement ok -INSERT INTO array_single_family VALUES(1,ARRAY[1]) - -statement ok -INSERT INTO array_single_family VALUES(2,ARRAY[1,2]) - -statement ok -INSERT INTO array_single_family VALUES(3,ARRAY[1,2,NULL]) - -statement ok -INSERT INTO array_single_family VALUES(4,ARRAY[NULL,2,3]) - -statement ok -INSERT INTO array_single_family VALUES(5,ARRAY[1,NULL,3]) - -statement ok -INSERT INTO array_single_family VALUES(6,ARRAY[NULL::INT]) - -statement ok -INSERT INTO array_single_family VALUES(7,ARRAY[NULL::INT,NULL::INT]) - -statement ok -INSERT INTO array_single_family VALUES(8,ARRAY[NULL::INT,NULL::INT,NULL::INT]) - -query IT colnames -SELECT a, b FROM array_single_family ORDER BY a ----- -a b -0 {} -1 {1} -2 {1,2} -3 {1,2,NULL} -4 {NULL,2,3} -5 {1,NULL,3} -6 {NULL} -7 {NULL,NULL} -8 {NULL,NULL,NULL} - -statement ok -DROP TABLE array_single_family - -query TT -SELECT ARRAY[]::int[], ARRAY[]:::int[] ----- -{} {} - -subtest 37544 - -query T -SELECT - col_1 -FROM - ( - VALUES - (ARRAY[]::INT8[]), - (ARRAY[]::INT8[]) - ) - AS tab_1 (col_1) -GROUP BY - tab_1.col_1 ----- -{} diff --git a/test/sqllogictest/cockroach/as_of.slt b/test/sqllogictest/cockroach/as_of.slt index 9425296feb011..a31be2e03c622 100644 --- a/test/sqllogictest/cockroach/as_of.slt +++ b/test/sqllogictest/cockroach/as_of.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,88 +9,190 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/as_of +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/as_of # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach -# Unlikely to support the SELECT ... AS OF SYSTEM TIME syntax exactly. -halt - statement ok CREATE TABLE t (i INT) statement ok INSERT INTO t VALUES (2) +# Not supported by Materialize. +onlyif cockroach # Verify strings can be parsed as intervals. query I SELECT * FROM t AS OF SYSTEM TIME '-1us' ---- 2 +# Not supported by Materialize. +onlyif cockroach # Verify a forced interval type works. query I SELECT * FROM t AS OF SYSTEM TIME INTERVAL '-1us' ---- 2 +# Not supported by Materialize. +onlyif cockroach # Verify that we can use computed expressions. query I -SELECT * FROM t AS OF SYSTEM TIME -( ('1000' || 'us')::INTERVAL ) +SELECT * FROM t AS OF SYSTEM TIME -( parse_interval('1000' || 'us') ) ---- 2 -statement error pq: AS OF SYSTEM TIME: only constant expressions or experimental_follower_read_timestamp are allowed +statement error Expected end of statement, found TIME SELECT * FROM t AS OF SYSTEM TIME cluster_logical_timestamp() -statement error pq: subqueries are not allowed in AS OF SYSTEM TIME +statement error Expected end of statement, found TIME SELECT * FROM t AS OF SYSTEM TIME (SELECT '-1h'::INTERVAL) -statement error pq: relation "t" does not exist +statement error pgcode 3D000 Expected end of statement, found TIME SELECT * FROM t AS OF SYSTEM TIME '-1h' -statement error pq: experimental_follower_read_timestamp\(\): experimental_follower_read_timestamp is only available in ccl distribution -SELECT * FROM t AS OF SYSTEM TIME experimental_follower_read_timestamp() +query T noticetrace +SELECT pg_sleep(5) -- we need to sleep so that the 4.8s elapses and the SELECT * FROM t returns something. +---- + +# Notices print twice -- once during planning and once during execution. +# There's no nice way of reducing this to once without some hacks -- so left as is. +skipif config 3node-tenant-default-configs +query T noticetrace +SELECT * FROM t AS OF SYSTEM TIME follower_read_timestamp() +---- +NOTICE: follower reads disabled because you are running a non-CCL distribution +NOTICE: follower reads disabled because you are running a non-CCL distribution -statement error pq: unknown signature: experimental_follower_read_timestamp\(string\) \(desired \) -SELECT * FROM t AS OF SYSTEM TIME experimental_follower_read_timestamp('boom') +statement error Expected end of statement, found TIME +SELECT * FROM t AS OF SYSTEM TIME follower_read_timestamp('boom') -statement error pq: AS OF SYSTEM TIME: only constant expressions or experimental_follower_read_timestamp are allowed +statement error Expected end of statement, found TIME SELECT * FROM t AS OF SYSTEM TIME now() -statement error cannot specify timestamp in the future +statement error Expected end of statement, found TIME SELECT * FROM t AS OF SYSTEM TIME '10s' +statement error Expected end of statement, found TIME +SELECT * FROM t AS OF SYSTEM TIME interval '1 microsecond' + # Verify that the TxnTimestamp used to generate now() and current_timestamp() is # set to the historical timestamp. +# Not supported by Materialize. +onlyif cockroach query T SELECT * FROM (SELECT now()) AS OF SYSTEM TIME '2018-01-01' ---- 2018-01-01 00:00:00 +0000 UTC +# Verify that timezones are not truncated + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM (SELECT now()) AS OF SYSTEM TIME '2018-01-01 00:00:00-1:00' +---- +2018-01-01 01:00:00 +0000 UTC + # Verify that zero intervals indistinguishable from zero cause an error. -statement error pq: AS OF SYSTEM TIME: interval value '0.1us' too small, must be <= -1µs +statement error Expected end of statement, found TIME SELECT * FROM t AS OF SYSTEM TIME '0.1us' -statement error pq: AS OF SYSTEM TIME: interval value '0,0' too small, must be <= -1µs -SELECT * FROM t AS OF SYSTEM TIME '0,0' +statement error Expected end of statement, found TIME +SELECT * FROM t AS OF SYSTEM TIME '0-0' -statement error pq: AS OF SYSTEM TIME: interval value '0.000000000,0' too small, must be <= -1µs -SELECT * FROM t AS OF SYSTEM TIME '0.000000000,0' - -statement error pq: AS OF SYSTEM TIME: interval value '-0.1us' too small, must be <= -1µs +statement error Expected end of statement, found TIME SELECT * FROM t AS OF SYSTEM TIME '-0.1us' -statement error pq: AS OF SYSTEM TIME: zero timestamp is invalid +statement error Expected end of statement, found TIME SELECT * FROM t AS OF SYSTEM TIME '0' + +# Not supported by Materialize. +onlyif cockroach +# Verify we can explain a statement that has AS OF. +statement ok +EXPLAIN SELECT * FROM t AS OF SYSTEM TIME '-1us' + +skipif config 3node-tenant-default-configs +# Regression test for out of bounds error during the type-checking of AOST with +# a placeholder (#56488). +statement error Expected end of statement, found TIME +SELECT * FROM t AS OF SYSTEM TIME $1 + +skipif config 3node-tenant-default-configs +statement error pgcode XXC01 function "with_min_timestamp" does not exist +SELECT with_min_timestamp('2020-01-15 15:16:17') + +skipif config 3node-tenant-default-configs +statement error pgcode XXC01 function "with_min_timestamp" does not exist +SELECT with_min_timestamp(statement_timestamp()) + +skipif config 3node-tenant-default-configs +statement error pgcode XXC01 function "with_max_staleness" does not exist +SELECT with_max_staleness('1s') + +skipif config 3node-tenant-default-configs +statement error pgcode XXC01 Expected end of statement, found TIME +SELECT * FROM t AS OF SYSTEM TIME with_min_timestamp('2020-01-15 15:16:17') + +skipif config 3node-tenant-default-configs +statement error pgcode XXC01 Expected end of statement, found TIME +SELECT * FROM t AS OF SYSTEM TIME with_min_timestamp(statement_timestamp()) + +skipif config 3node-tenant-default-configs +statement error pgcode XXC01 Expected end of statement, found TIME +SELECT * FROM t AS OF SYSTEM TIME with_max_staleness('1s'::interval) + +statement ok +BEGIN + +statement ok +SELECT * from t + +statement error Expected transaction mode, found AS +SET TRANSACTION AS OF system time '-1s' + +statement ok +ROLLBACK + +statement ok +BEGIN + +statement ok +INSERT INTO t VALUES(1) + +statement error Expected transaction mode, found AS +SET TRANSACTION AS OF system time '-1s' + +statement ok +ROLLBACK + +# Verify that an expression that requires normalization does not result in an +# internal error. +statement error Expected end of statement, found TIME +SELECT * FROM t AS OF SYSTEM TIME ('' BETWEEN '' AND '') + +# Check that AOST in multi-stmt implicit transaction has the proper error. +statement error Expected end of statement, found TIME +insert into t values(1); select * from t as of system time '-1s'; + +statement error Expected end of statement, found TIME +select * from t as of system time '-1s'; select * from t as of system time '-2s'; + +# Not supported by Materialize. +onlyif cockroach +# Specifying the AOST in the first statement (and no others) is allowed. +statement ok +select * from t as of system time '-1s'; select * from t; diff --git a/test/sqllogictest/cockroach/bit.slt b/test/sqllogictest/cockroach/bit.slt index 9c4a89de92db6..f0beb9c25fd60 100644 --- a/test/sqllogictest/cockroach/bit.slt +++ b/test/sqllogictest/cockroach/bit.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,19 +9,21 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/bit +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/bit # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach +# Not supported by Materialize. +onlyif cockroach query TTT SELECT B'1000101'::BIT(4)::STRING, B'1000101'::BIT(4), @@ -29,64 +31,81 @@ SELECT B'1000101'::BIT(4)::STRING, ---- 1000 1000 1000101 - +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE bits(a BIT, b BIT(4), c VARBIT, d VARBIT(4)) +CREATE TABLE bits ( + a BIT, b BIT(4), c VARBIT, d VARBIT(4), + FAMILY "primary" (a, b, c, d, rowid) +) +# Not supported by Materialize. +onlyif cockroach query TT colnames SHOW CREATE TABLE bits ---- table_name create_statement -bits CREATE TABLE bits ( - a BIT NULL, - b BIT(4) NULL, - c VARBIT NULL, - d VARBIT(4) NULL, - FAMILY "primary" (a, b, c, d, rowid) -) +bits CREATE TABLE public.bits ( + a BIT NULL, + b BIT(4) NULL, + c VARBIT NULL, + d VARBIT(4) NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT bits_pkey PRIMARY KEY (rowid ASC) + ) subtest bit_fixed1 +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO bits(a) VALUES (B'1'), (B'0'); -statement error bit string length 0 does not match type BIT +statement error unknown catalog item 'bits' INSERT INTO bits(a) VALUES (B'') -statement error bit string length 4 does not match type BIT +statement error unknown catalog item 'bits' INSERT INTO bits(a) VALUES (B'1110') subtest bit_fixed4 +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO bits(b) VALUES (B'0000'), (B'1001'); -statement error bit string length 0 does not match type BIT\(4\) +statement error unknown catalog item 'bits' INSERT INTO bits(b) VALUES (B'') -statement error bit string length 3 does not match type BIT\(4\) +statement error unknown catalog item 'bits' INSERT INTO bits(b) VALUES (B'111') -statement error bit string length 9 does not match type BIT\(4\) +statement error unknown catalog item 'bits' INSERT INTO bits(b) VALUES (B'111000111') subtest bit_varying_unlimited +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO bits(c) VALUES (B'1'), (B'0'), (B''), (B'1110'), (B'0101010101010101001101010101010101010101010101010101010101010101010010101') -- more than 64 bits subtest bit_varying_limited +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO bits(d) VALUES (B'1'), (B'0'), (B''), (B'1110') -statement error bit string length 73 too large for type VARBIT\(4\) +statement error unknown catalog item 'bits' INSERT INTO bits(d) VALUES (B'0101010101010101001101010101010101010101010101010101010101010101010010101') -- more than 64 bits subtest results +# Not supported by Materialize. +onlyif cockroach query TITITITI colnames SELECT a, length(a::STRING) an, b, length(b::STRING) bn, @@ -112,12 +131,18 @@ NULL NULL 1001 4 NULL subtest bit_arith +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO bits(b) VALUES (B'0110'), (B'0011') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO bits(c) VALUES (B'1010'), (B'11') +# Not supported by Materialize. +onlyif cockroach # Shifts always truncate/pad to the bit array size. query TTTTTTT colnames SELECT x.b, @@ -137,6 +162,8 @@ b l0 r0 lm1 r1 rm11 l1 0110 0110 0110 0011 0011 1100 1100 1001 1001 1001 0100 0100 0010 0010 +# Not supported by Materialize. +onlyif cockroach # Concat works on mixed bit arrays. query TTTT rowsort SELECT x.b, y.c, x.b || y.c, y.c || x.b FROM bits x, bits y WHERE x.b IS NOT NULL AND length(y.c::string) < 5 @@ -166,6 +193,8 @@ SELECT x.b, y.c, x.b || y.c, y.c || x.b FROM bits x, bits y WHERE x.b IS NOT NUL 0011 1010 00111010 10100011 0011 11 001111 110011 +# Not supported by Materialize. +onlyif cockroach query TT rowsort SELECT x.b, ~x.b AS comp FROM bits x WHERE b IS NOT NULL ---- @@ -174,15 +203,21 @@ SELECT x.b, ~x.b AS comp FROM bits x WHERE b IS NOT NULL 0110 1001 0011 1100 +# Not supported by Materialize. +onlyif cockroach statement ok DELETE FROM bits; INSERT INTO bits(c) VALUES (B'0'), (B'1') +# Not supported by Materialize. +onlyif cockroach query TT rowsort SELECT x.c, ~x.c AS comp FROM bits x ---- 0 1 1 0 +# Not supported by Materialize. +onlyif cockroach query TTTTT rowsort SELECT x.c AS v1, y.c AS v2, x.c & y.c AS "and", @@ -197,6 +232,8 @@ FROM bits x, bits y subtest bit_ordering +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE obits(x VARBIT); INSERT INTO obits(x) VALUES @@ -215,6 +252,8 @@ CREATE TABLE obits(x VARBIT); (B'01001001010101'), (B'11001001010101') +# Not supported by Materialize. +onlyif cockroach # Check unindexed ordering. query T SELECT * FROM obits ORDER BY x @@ -234,10 +273,14 @@ SELECT * FROM obits ORDER BY x 11 11001001010101 +# Not supported by Materialize. +onlyif cockroach # Check indexed ordering. statement ok CREATE INDEX obits_idx ON obits(x) +# Not supported by Materialize. +onlyif cockroach query T SELECT * FROM obits@obits_idx ORDER BY x ---- @@ -258,12 +301,16 @@ SELECT * FROM obits@obits_idx ORDER BY x subtest bit_arrays +# Not supported by Materialize. +onlyif cockroach query TT colnames SELECT ARRAY[B'101011'] AS a, '{111001}'::VARBIT[] AS b ---- a b {101011} {111001} +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE obitsa(x VARBIT(20)[]); INSERT INTO obitsa(x) VALUES @@ -283,14 +330,19 @@ CREATE TABLE obitsa(x VARBIT(20)[]); (ARRAY[B'01', B'01001001010101']), (ARRAY[B'01', B'11001001010101']) +# Not supported by Materialize. +onlyif cockroach query T SELECT create_statement FROM [SHOW CREATE obitsa] ---- -CREATE TABLE obitsa ( - x VARBIT(20)[] NULL, - FAMILY "primary" (x, rowid) +CREATE TABLE public.obitsa ( + x VARBIT(20)[] NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT obitsa_pkey PRIMARY KEY (rowid ASC) ) +# Not supported by Materialize. +onlyif cockroach # Check unindexed ordering. query T rowsort SELECT * FROM obitsa @@ -310,3 +362,47 @@ SELECT * FROM obitsa {01,1001001010101} {01,01001001010101} {01,11001001010101} + +subtest bit_conversions + +# Invalid digit in constant literal. +statement error type "b" does not exist +SELECT B'AB'::BIT(8) + +# Invalid digit in cast conversion from string. +statement error type "bit" does not exist +SELECT 'AB'::BIT(8) + +# Not supported by Materialize. +onlyif cockroach +# Conversion from string. +query T +SELECT '10101011'::STRING::BIT(8) +---- +10101011 + +# Invalid digit in hex cast conversion from string. +statement error type "bit" does not exist +SELECT 'xZZ'::BIT(8) + +# Not supported by Materialize. +onlyif cockroach +# Conversion from string. +query TT +SELECT 'xAb'::STRING::BIT(8), 'XaB'::STRING::BIT(8) +---- +10101011 10101011 + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT BIT(4) '1101', BIT(1) '1010' +---- +1101 1 + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT VARBIT(4) '1101', VARBIT(2) '1001' +---- +1101 10 diff --git a/test/sqllogictest/cockroach/builtin_function.slt b/test/sqllogictest/cockroach/builtin_function.slt index a5f29bdea3266..abc9ebf31c3fe 100644 --- a/test/sqllogictest/cockroach/builtin_function.slt +++ b/test/sqllogictest/cockroach/builtin_function.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,20 +9,20 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/builtin_function +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/builtin_function # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 +# tenant-capability-override-opt: can_check_consistency=true statement ok CREATE TABLE foo (a int) @@ -30,18 +30,25 @@ CREATE TABLE foo (a int) statement ok INSERT INTO foo (a) VALUES (1) -query error unknown function: foo.bar +query error unknown schema 'foo' SELECT foo.bar() -query error unknown function: defaults +query error function "pg_catalog\.defaults" does not exist +SELECT pg_catalog.defaults() + +query error function "defaults" does not exist SELECT defaults() +# Not supported by Materialize. +onlyif cockroach query II colnames SELECT length('roach7'), length(b'roach77') ---- length length 6 7 +# Not supported by Materialize. +onlyif cockroach query IIIIII SELECT length('Hello, 世界'), length(b'Hello, 世界'), char_length('Hello, 世界'), char_length(b'Hello, 世界'), @@ -49,14 +56,18 @@ SELECT length('Hello, 世界'), length(b'Hello, 世界'), ---- 9 13 9 13 9 13 -statement error unknown signature: length\(int\) +statement error function length\(integer\) does not exist SELECT length(23) +# Not supported by Materialize. +onlyif cockroach query III SELECT octet_length('Hello'), octet_length('世界'), octet_length(b'世界') ---- 5 6 6 +# Not supported by Materialize. +onlyif cockroach query III SELECT bit_length('Hello'), bit_length('世界'), bit_length(b'世界') ---- @@ -69,13 +80,17 @@ SELECT quote_ident('abc'), quote_ident('ab.c'), quote_ident('ab"c'), quote_ident quote_ident('bigint'), -- col name keyword quote_ident('alter') -- unreserved keyword ---- -abc "ab.c" "ab""c" 世界 "array" "family" "bigint" alter +abc "ab.c" "ab""c" "世界" "array" family bigint alter +# Not supported by Materialize. +onlyif cockroach query TTTT SELECT quote_literal('abc'), quote_literal('ab''c'), quote_literal('ab"c'), quote_literal(e'ab\nc') ---- 'abc' e'ab\'c' 'ab"c' e'ab\nc' +# Not supported by Materialize. +onlyif cockroach query TTTTTTTT SELECT quote_literal(123::string), quote_nullable(123::string), @@ -85,14 +100,18 @@ SELECT ---- '123' '123' '123' '123' 'true' 'true' '123.3' '123.3' +# Not supported by Materialize. +onlyif cockroach query TTTTTT SELECT quote_literal('1d'::interval), quote_nullable('1d'::interval), quote_literal('2018-06-11 12:13:14'::timestamp), quote_nullable('2018-06-11 12:13:14'::timestamp), quote_literal('2018-06-11'::date), quote_nullable('2018-06-11'::date) ---- -'1 day' '1 day' '2018-06-11 12:13:14+00:00' '2018-06-11 12:13:14+00:00' '2018-06-11' '2018-06-11' +'1 day' '1 day' '2018-06-11 12:13:14' '2018-06-11 12:13:14' '2018-06-11' '2018-06-11' +# Not supported by Materialize. +onlyif cockroach query TTBB SELECT quote_literal(null::int), quote_nullable(null::int), @@ -102,22 +121,25 @@ NULL NULL true false # Check that quote_literal is properly sensitive to bytea_output. +# Not supported by Materialize. +onlyif cockroach query TT SELECT quote_literal(b'abc'), quote_nullable(b'abc') ---- e'\\x616263' e'\\x616263' -# TODO: Support bytea -#statement ok -#SET bytea_output = 'escape' -# -#query TT -#SELECT quote_literal(b'abc'), quote_nullable(b'abc') -#---- -#'abc' 'abc' -# -#statement ok -#RESET bytea_output +statement ok +SET bytea_output = 'escape' + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT quote_literal(b'abc'), quote_nullable(b'abc') +---- +'abc' 'abc' + +statement ok +RESET bytea_output query T colnames SELECT upper('roacH7') @@ -125,7 +147,24 @@ SELECT upper('roacH7') upper ROACH7 -statement error unknown signature: upper\(decimal\) +# Not supported by Materialize. +onlyif cockroach +query T +SELECT unaccent(str) FROM ( VALUES + ('no_special_CHARACTERS1!'), + ('Żółć'), + ('⃞h̀ELLO`̀́⃞'), + ('Softhyphen­separator'), + ('some ̂thing') +) tbl(str) +---- +no_special_CHARACTERS1! +Zolc +hELLO` +Softhyphen-separator +something + +statement error function upper\(numeric\) does not exist SELECT upper(2.2) query T colnames @@ -134,15 +173,19 @@ SELECT lower('RoacH7') lower roach7 -statement error unknown signature: lower\(int\) +statement error function lower\(integer\) does not exist SELECT lower(32) +# Not supported by Materialize. +onlyif cockroach # Multiplying by zero so the result is deterministic. query R SELECT random() * 0.0 ---- 0 +# Not supported by Materialize. +onlyif cockroach # Concatenating 'empty' because the empty string doesn't work in these tests. query T SELECT concat() || 'empty' @@ -154,6 +197,8 @@ SELECT concat('RoacH', NULL) ---- RoacH +# Not supported by Materialize. +onlyif cockroach statement error unknown signature: concat\(string, bool, decimal, bool\) SELECT concat('RoacH', false, 64.532, TRUE) @@ -177,6 +222,8 @@ SELECT substring('RoacH' from 2 for 3) ---- oac +# Not supported by Materialize. +onlyif cockroach query T SELECT substring('RoacH' for 3 from 2) ---- @@ -217,9 +264,11 @@ SELECT substr('12345', -2, 77) ---- 12345 -statement error substr\(\): negative substring length -1 not allowed +statement error negative substring length not allowed SELECT substr('12345', 2, -1) +# Not supported by Materialize. +onlyif cockroach query T SELECT substr('string', 4827075662841736053, 5123273972570225659) || 'empty' ---- @@ -230,28 +279,173 @@ SELECT substring('12345' for 3) ---- 123 +# Not supported by Materialize. +onlyif cockroach query T SELECT substring('foobar' from 'o.b') ---- oob +# Not supported by Materialize. +onlyif cockroach query T SELECT substring('f(oabaroob' from '\(o(.)b') ---- a +# Not supported by Materialize. +onlyif cockroach query T SELECT substring('f(oabaroob' from '+(o(.)b' for '+') ---- a -query error substring\(\): error parsing regexp: missing closing \): `\\\\\(o\(.\)b` +query error invalid input syntax for type integer: invalid digit found in string: "\\\(o\(\.\)b" SELECT substring('f(oabaroob' from '\(o(.)b' for '+') +# Not supported by Materialize. +onlyif cockroach query error unknown signature: substring\(\) SELECT substring() -query error unknown signature: concat_ws\(\) +# Adding testcases for substring against bit array. + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT substring(B'11110000', 0), substring(B'11110000', -1), substring(B'11110000', 5) +---- +11110000 11110000 0000 + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT substring(B'11110000', 8), substring(B'11110000', 10), substring(B'', 0) +---- +0 · · + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT substring('11100011'::bit(8), 4), substring('11100011'::bit(6), 4), substring(B'', 0, 1) +---- +00011 000 · + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT substring(B'11110000', 0, 4), substring(B'11110000', -1, 4), substring(B'11110000', 5, 10) +---- +111 11 0000 + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT substring(B'11110000', 8, 1), substring(B'11110000', 8, 0), substring(B'11110000', 10, 5) +---- +0 · · + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT substring('11100011'::bit(10), 4, 10), substring('11100011'::bit(8), 1, 8) +---- +0001100 11100011 + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT substring(B'10001000' FOR 4 FROM 0), substring(B'10001000' FROM 0 FOR 4), substring(B'10001000' FOR 4) +---- +100 100 1000 + +query error type "bit" does not exist +SELECT substring('11100011'::bit(10), 4, -1) + +# Adding testcases for substring against byte array. + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT substring(b'abc', 0), substring(b'\x61\x62\x63', -1) +---- +abc abc + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT substring(b'abc', 3), substring(b'abc', 5) +---- +c · + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT substring('abc'::bytea, 0) +---- +abc + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT substring(b'\x61\x62\x63', 0, 4), substring(b'abc', -1, 4) +---- +abc ab + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT substring(b'abc', 3, 1), substring(b'abc', 3, 0), substring(b'abc', 4, 3) +---- +c · · + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT substring('abc'::bytea, 0, 4) +---- +abc + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT substring(b'abc' FOR 3 FROM 1), substring(b'abc' FROM 1 FOR 3), substring(b'abc' FOR 3) +---- +abc abc abc + +query error function substring\(bytea, integer, integer\) does not exist +SELECT substring('11100011'::bytea, 4, -1) + +# Not supported by Materialize. +onlyif cockroach +query TTTTT +SELECT + encode(substring(decode('ff0001', 'hex'), 1), 'hex'), + encode(substring(decode('ff0001', 'hex'), 1, 1), 'hex'), + encode(substring(decode('ff0001', 'hex'), 1, 7), 'hex'), + encode(substring(decode('ff0001', 'hex'), 2), 'hex'), + encode(substring(decode('ff0001', 'hex'), 4), 'hex') +---- +ff0001 ff ff0001 0001 · + +# Not supported by Materialize. +onlyif cockroach +query TTTTTTTTTT +SELECT + encode(substring(decode('5c0001', 'hex'), 1), 'hex'), + encode(substring(decode('aa5c0001', 'hex'), 1), 'hex'), + encode(substring(decode('aa5c0001', 'hex'), 2), 'hex'), + encode(substring(decode('aa5c1a1a1a1a0001', 'hex'), 2), 'hex'), + encode(substring(decode('5c0001', 'hex'), 1, 1), 'hex'), + encode(substring(decode('aa5c0001', 'hex'), 1, 2), 'hex'), + encode(substring(decode('aa5c0001', 'hex'), 2, 2), 'hex'), + encode(substring(decode('aa5c1a1a1a1a0001', 'hex'), 2, 2), 'hex'), + encode(substring(decode('5c0001', 'hex'), 1), 'escape'), + encode(substring(decode('aa5c0001', 'hex'), 2, 1), 'escape') +---- +5c0001 aa5c0001 5c0001 5c1a1a1a1a0001 5c aa5c 5c00 5c1a \\\000\001 \\ + +query error function concat_ws\(\) does not exist SELECT concat_ws() query T @@ -269,6 +463,8 @@ SELECT concat_ws(',', 'abcde', '2') ---- abcde,2 +# Not supported by Materialize. +onlyif cockroach statement error unknown signature: concat_ws\(string, string, int, unknown, int\) SELECT concat_ws(',', 'abcde', 2, NULL, 22) @@ -287,11 +483,11 @@ SELECT repeat('Pg', -1) || 'empty' ---- empty -statement error pq: repeat\(\): requested length too large +statement error function repeat\(unknown, bigint\) does not exist SELECT repeat('s', 9223372036854775807) -# Regression for database-issues#5638. -statement error pq: repeat\(\): requested length too large +# Regression for #19035. +statement error "6978072892806141784" integer out of range SELECT repeat('1234567890'::string, 6978072892806141784::int) query I @@ -304,6 +500,8 @@ select ascii('禅') ---- 31109 +# Not supported by Materialize. +onlyif cockroach query error ascii\(\): the input string must not be empty select ascii('') @@ -322,7 +520,7 @@ select chr(31109) ---- 禅 -query error chr\(\): input value must be >= 0 +query error requested character too large for encoding: \-1 SELECT chr(-1) query T @@ -330,27 +528,43 @@ SELECT md5('abc') ---- 900150983cd24fb0d6963f7d28e17f72 +# Not supported by Materialize. +onlyif cockroach query T SELECT sha1('abc') ---- a9993e364706816aba3e25717850c26c9cd0d89d +query T +SELECT sha224('abc') +---- +[35, 9, 125, 34, 52, 5, 216, 34, 134, 66, 164, 119, 189, 162, 85, 179, 42, 173, 188, 228, 189, 160, 179, 247, 227, 108, 157, 167] + query T SELECT sha256('abc') ---- -ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad +[186, 120, 22, 191, 143, 1, 207, 234, 65, 65, 64, 222, 93, 174, 34, 35, 176, 3, 97, 163, 150, 23, 122, 156, 180, 16, 255, 97, 242, 0, 21, 173] + +query T +SELECT sha384('abc') +---- +[203, 0, 117, 63, 69, 163, 94, 139, 181, 160, 61, 105, 154, 198, 80, 7, 39, 44, 50, 171, 14, 222, 209, 99, 26, 139, 96, 90, 67, 255, 91, 237, 128, 134, 7, 43, 161, 231, 204, 35, 88, 186, 236, 161, 52, 200, 37, 167] +# Not supported by Materialize. +onlyif cockroach query IIII SELECT fnv32('abc'), fnv32a('abc'), fnv64('abc'), fnv64a('abc') ---- 1134309195 440920331 -2820157060406071861 -1792535898324117685 +# Not supported by Materialize. +onlyif cockroach query II SELECT crc32ieee('abc'), crc32c('abc') ---- 891568578 910901175 -# Regression tests for materialize#29754 +# Regression tests for #29754 query T SELECT md5(NULL::STRING) ---- @@ -361,31 +575,57 @@ SELECT md5('') ---- d41d8cd98f00b204e9800998ecf8427e +# Not supported by Materialize. +onlyif cockroach query T SELECT md5(NULL::STRING, NULL::STRING) ---- NULL +# Not supported by Materialize. +onlyif cockroach query T SELECT sha1(NULL::STRING) ---- NULL +# Not supported by Materialize. +onlyif cockroach +query T +SELECT sha224(NULL::STRING) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach query T SELECT sha256(NULL::STRING) ---- NULL +# Not supported by Materialize. +onlyif cockroach +query T +SELECT sha384(NULL::STRING) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach query T SELECT sha512(NULL::STRING, NULL::STRING) ---- NULL +# Not supported by Materialize. +onlyif cockroach query T SELECT fnv32(NULL::STRING) ---- NULL +# Not supported by Materialize. +onlyif cockroach query T SELECT to_hex(2147483647) ---- @@ -406,6 +646,41 @@ SELECT strpos('💩high', 'ig') ---- 3 +# Not supported by Materialize. +onlyif cockroach +query III +SELECT strpos(B'00001111', B'1111'), strpos(B'', B''), strpos(B'0000111', B'1111') +---- +5 1 0 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT strpos('000001'::varbit, '1'::varbit) +---- +6 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT position(B'100' in B'100101') +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT strpos(b'\x61\145aabc', b'abc'), strpos(b'', b''), strpos(b'ttt\x61\x61c', b'abc') +---- +4 1 0 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT position('\x616263'::bytea in 'abc'::bytea) +---- +1 + query I SELECT position('ig' in 'high') ---- @@ -416,49 +691,69 @@ SELECT position('a' in 'high') ---- 0 +# Not supported by Materialize. +onlyif cockroach query error unknown signature: strpos\(\) SELECT position() +# Not supported by Materialize. +onlyif cockroach query T SELECT overlay('123456789' placing 'xxxx' from 3) ---- 12xxxx789 +# Not supported by Materialize. +onlyif cockroach query T SELECT overlay('123456789' placing 'xxxx' from 3 for 2) ---- 12xxxx56789 +# Not supported by Materialize. +onlyif cockroach query T SELECT overlay('123456789' placing 'xxxx' from 3 for 6) ---- 12xxxx9 +# Not supported by Materialize. +onlyif cockroach query T SELECT overlay('123456789' placing 'xxxx' from 15 for 6) ---- 123456789xxxx +# Not supported by Materialize. +onlyif cockroach query T SELECT overlay('123456789' placing 'xxxx' from 3 for 10) ---- 12xxxx +# Not supported by Materialize. +onlyif cockroach query T SELECT overlay('123456789' placing 'xxxx' from 3 for -1) ---- 12xxxx23456789 +# Not supported by Materialize. +onlyif cockroach query T SELECT overlay('123456789' placing 'xxxx' from 3 for -8) ---- 12xxxx123456789 +# Not supported by Materialize. +onlyif cockroach query T SELECT overlay('💩123456789' placing 'xxxxÂ' from 3 for 3) ---- 💩1xxxxÂ56789 +# Not supported by Materialize. +onlyif cockroach query error non-positive substring length not allowed: -1 SELECT overlay('123456789' placing 'xxxx' from -1 for 6) @@ -548,11 +843,15 @@ SELECT initcap('THOMAS') ---- Thomas +# Not supported by Materialize. +onlyif cockroach query T SELECT left('💩abcde'::bytes, 2) ---- [240 159] +# Not supported by Materialize. +onlyif cockroach query T SELECT right('abcde💩'::bytes, 2) ---- @@ -578,7 +877,7 @@ SELECT abs(NULL) ---- NULL -query error abs\(\): abs of min integer value \(-9223372036854775808\) not defined +query error "\-9223372036854775808" bigint out of range SELECT abs(-9223372036854775808) query I @@ -586,6 +885,8 @@ SELECT abs(-9223372036854775807) ---- 9223372036854775807 +# Not supported by Materialize. +onlyif cockroach query B SELECT abs(sin(pi())) < 1e-12 ---- @@ -593,31 +894,39 @@ true subtest standard_float_digits +# Not supported by Materialize. +onlyif cockroach query RR SELECT acos(-0.5), round(acos(0.5), 15) ---- -2.0943951023932 1.0471975511966 +2.0943951023931957 1.047197551196598 query RR SELECT cot(-0.5), cot(0.5) ---- --1.83048772171245 1.83048772171245 +-1.830487721712452 1.830487721712452 +# Not supported by Materialize. +onlyif cockroach query RRR SELECT asin(-0.5), asin(0.5), asin(1.5) ---- --0.523598775598299 0.523598775598299 NaN +-0.5235987755982989 0.5235987755982989 NaN query RR SELECT atan(-0.5), atan(0.5) ---- --0.463647609000806 0.463647609000806 +-0.4636476090008061 0.4636476090008061 +# Not supported by Materialize. +onlyif cockroach query RR SELECT atan2(-10.0, 5.0), atan2(10.0, 5.0) ---- --1.10714871779409 1.10714871779409 +-1.1071487177940904 1.1071487177940904 +# Not supported by Materialize. +onlyif cockroach query RRR SELECT cbrt(-1.0::float), round(cbrt(27.0::float), 15), cbrt(19.3::decimal) ---- @@ -632,23 +941,25 @@ SELECT ceil(-0.5::float), ceil(0.5::float), ceiling(0.5::float), ceil(0.1::decim query RR SELECT cos(-0.5), cos(0.5) ---- -0.877582561890373 0.877582561890373 +0.8775825618903728 0.8775825618903728 query RRR SELECT sin(-1.0), sin(0.0), sin(1.0) ---- --0.841470984807897 0 0.841470984807897 +-0.8414709848078965 0 0.8414709848078965 query RR SELECT degrees(-0.5), degrees(0.5) ---- --28.6478897565412 28.6478897565412 +-28.64788975654116 28.64788975654116 subtest extra_float_digits_3 statement ok SET extra_float_digits = 3 +# Not supported by Materialize. +onlyif cockroach query RR SELECT acos(-0.5), round(acos(0.5), 15) ---- @@ -659,6 +970,8 @@ SELECT cot(-0.5), cot(0.5) ---- -1.830487721712452 1.830487721712452 +# Not supported by Materialize. +onlyif cockroach query RRR SELECT asin(-0.5), asin(0.5), asin(1.5) ---- @@ -669,11 +982,15 @@ SELECT atan(-0.5), atan(0.5) ---- -0.4636476090008061 0.4636476090008061 +# Not supported by Materialize. +onlyif cockroach query RR SELECT atan2(-10.0, 5.0), atan2(10.0, 5.0) ---- -1.1071487177940904 1.1071487177940904 +# Not supported by Materialize. +onlyif cockroach query RRR SELECT cbrt(-1.0::float), round(cbrt(27.0::float), 15), cbrt(19.3::decimal) ---- @@ -704,22 +1021,28 @@ SET extra_float_digits = 0 subtest other_tests +# Not supported by Materialize. +onlyif cockroach query IIII SELECT div(-1::int, 2::int), div(1::int, 2::int), div(9::int, 4::int), div(-9::int, 4::int) ---- 0 0 2 -2 +# Not supported by Materialize. +onlyif cockroach query RRRRRR SELECT div(-1.0::float, 2.0), div(1.0::float, 2.0), div(9.0::float, 4.0), div(-9.0::float, 4.0), div(1.0::float, 0.0), div(1111.0::decimal, 9.44) ---- -0 0 2 -2 +Inf 117 -query error div\(\): division by zero +query error function "div" does not exist SELECT div(1.0::decimal, 0.0::decimal) -query error div\(\): division by zero +query error function "div" does not exist SELECT div(1::int, 0::int) +# Not supported by Materialize. +onlyif cockroach # math.Exp(1.0) returns different results on amd64 vs arm64. # Round to make this test consistent across archs. # See https://github.com/golang/go/issues/20319. @@ -728,7 +1051,7 @@ SELECT exp(-1.0::float), round(exp(1.0::float), 13), exp(2.0::decimal) ---- 0.367879441171442 2.718281828459 7.3890560989306502272 -query error exp\(\): overflow +query error "1E2000" is out of range for type numeric: exceeds maximum precision 39 SELECT exp(1e2000::decimal) query RRR @@ -736,33 +1059,63 @@ SELECT floor(-1.5::float), floor(1.5::float), floor(9.123456789::decimal) ---- -2 1 9 +# Not supported by Materialize. +onlyif cockroach query BBBBBB SELECT 1::FLOAT IS NAN, 1::FLOAT IS NOT NAN, isnan(1::FLOAT), 'NaN'::FLOAT IS NAN, 'NaN'::FLOAT IS NOT NAN, isnan('NaN'::FLOAT) ---- false true false true false true +# Not supported by Materialize. +onlyif cockroach query RRR SELECT ln(-2.0::float), ln(2.0::float), ln(2.5::decimal) ---- NaN 0.693147180559945 0.91629073187415506518 -query error cannot take logarithm of a negative number +query error function ln is not defined for negative numbers SELECT ln(-100.000::decimal) -query error cannot take logarithm of zero +query error function ln is not defined for zero SELECT ln(0::decimal) query RR SELECT log(10.0::float), log(100.000::decimal) ---- -1 2.0000000000000000000 +1 2 + +# Not supported by Materialize. +onlyif cockroach +query R +SELECT log(2.0::float, 4.0::float) +---- +2 + +query R +SELECT log(2.0::decimal, 4.0::decimal) +---- +2 + +query error function log\(double precision, double precision\) does not exist +SELECT log(2.0::float, -10.0::float) + +query error function log\(double precision, double precision\) does not exist +SELECT log(2.0::float, 0.0::float) + +query error function log is not defined for negative numbers +SELECT log(2.0::decimal, -10.0::decimal) -query error cannot take logarithm of a negative number +query error function log is not defined for zero +SELECT log(2.0::decimal, 0.0::decimal) + +query error function log10 is not defined for negative numbers SELECT log(-100.000::decimal) -query error cannot take logarithm of zero +query error function log10 is not defined for zero SELECT log(0::decimal) +# Not supported by Materialize. +onlyif cockroach query RRIR SELECT mod(5.0::float, 2.0), mod(1.0::float, 0.0), mod(5, 2), mod(19.3::decimal, 2) ---- @@ -771,10 +1124,10 @@ SELECT mod(5.0::float, 2.0), mod(1.0::float, 0.0), mod(5, 2), mod(19.3::decimal, # mod returns the same results as PostgreSQL 9.4.4 # in tests below (except for the error message). -query error mod\(\): zero modulus +query error division by zero SELECT mod(5, 0) -query error mod\(\): zero modulus +query error division by zero SELECT mod(5::decimal, 0::decimal) query II @@ -819,26 +1172,36 @@ SELECT mod(9223372036854775807, 4) # div and mod are a logical pair +# Not supported by Materialize. +onlyif cockroach query R SELECT div(9.0::float, 2.0) * 2.0 + mod(9.0::float, 2.0) ---- 9 +# Not supported by Materialize. +onlyif cockroach query R SELECT div(9.0::float, -2.0) * -2.0 + mod(9.0::float, -2.0) ---- 9 +# Not supported by Materialize. +onlyif cockroach query R SELECT div(-9.0::float, 2.0) * 2.0 + mod(-9.0::float, 2.0) ---- -9 +# Not supported by Materialize. +onlyif cockroach query R SELECT div(-9.0::float, -2.0) * -2.0 + mod(-9.0::float, -2.0) ---- -9 +# Not supported by Materialize. +onlyif cockroach query R SELECT pi() ---- @@ -849,6 +1212,8 @@ SELECT pow(-2::int, 3::int), pow(2::int, 3::int) ---- -8 8 +# Not supported by Materialize. +onlyif cockroach statement error integer out of range SELECT pow(2::int, -3::int) @@ -857,9 +1222,11 @@ SELECT pow(0::int, 3::int), pow(3::int, 0::int), pow(-3::int, 0::int) ---- 0 1 1 -statement error integer out of range +statement error zero raised to a negative power is undefined SELECT pow(0::int, -3::int) +# Not supported by Materialize. +onlyif cockroach # TODO(mjibson): This uses the decimal implementation internally, which # returns NaN, hence the below error. However postgres returns 1 for this, # which we should probably match. @@ -869,18 +1236,24 @@ SELECT pow(0::int, 0::int) query RRR SELECT pow(-3.0::float, 2.0), power(3.0::float, 2.0), pow(5.0::decimal, 2.0) ---- -9 9 25.00 +9 9 25 +# Not supported by Materialize. +onlyif cockroach query R SELECT pow(CAST (pi() AS DECIMAL), DECIMAL '2.0') ---- 9.8696044010893571205 +# Not supported by Materialize. +onlyif cockroach query R SELECT power(0::decimal, -1) ---- Infinity +# Not supported by Materialize. +onlyif cockroach # TODO(mjibson): Postgres returns an error for this. query R SELECT power(-1, -.1) @@ -890,23 +1263,31 @@ NaN query RR SELECT radians(-45.0), radians(45.0) ---- --0.785398163397448 0.785398163397448 +-0.7853981633974483 0.7853981633974483 +# Not supported by Materialize. +onlyif cockroach query R SELECT round(123.456::float, -2438602134409251682) ---- NaN +# Not supported by Materialize. +onlyif cockroach query RRR SELECT round(4.2::float, 0), round(4.2::float, 10), round(4.22222222::decimal, 3) ---- 4 4.2 4.222 +# Not supported by Materialize. +onlyif cockroach query R SELECT round(1e-308::float, 324) ---- 1e-308 +# Not supported by Materialize. +onlyif cockroach # round to nearest even query RRRR SELECT round(-2.5::float, 0), round(-1.5::float, 0), round(1.5::float, 0), round(2.5::float, 0) @@ -918,6 +1299,8 @@ SELECT round(-2.5::float), round(-1.5::float), round(-0.0::float), round(0.0::fl ---- -2 -2 -0 0 2 2 +# Not supported by Materialize. +onlyif cockroach # some edge cases: denormal, 0.5-epsilon, 0.5+epsilon, 1 bit fractions, 1 bit fraction rounding to 0 bit fraction, large integer query RRRRRRR SELECT round(1.390671161567e-309::float), round(0.49999999999999994::float), round(0.5000000000000001::float), round(2251799813685249.5::float), round(2251799813685250.5::float), round(4503599627370495.5::float), round(4503599627370497::float) @@ -935,7 +1318,7 @@ SELECT round(-2.5::decimal, 0), round(-1.5::decimal, 0), round(1.5::decimal, 0), query RRRRR SELECT round(-2.5::decimal, 3), round(-1.5::decimal, 3), round(0.0::decimal, 3), round(1.5::decimal, 3), round(2.5::decimal, 3) ---- --2.500 -1.500 0.000 1.500 2.500 +-2.5 -1.5 0 1.5 2.5 query RRRRR SELECT round(-2.5::decimal), round(-1.5::decimal), round(0.0::decimal), round(1.5::decimal), round(2.5::decimal) @@ -955,21 +1338,29 @@ SELECT round(-2.123456789, 5), round(2.123456789, 5), round(2.123456789012345678 ---- -2.12346 2.12346 2.12345678901235 +# Not supported by Materialize. +onlyif cockroach query RR SELECT round(-1.7976931348623157e+308::float, 1), round(1.7976931348623157e+308::float, 1) ---- -1.7976931348623157e+308 1.7976931348623157e+308 +# Not supported by Materialize. +onlyif cockroach query RR SELECT round(-1.7976931348623157e+308::float, -303), round(1.7976931348623157e+308::float, -303) ---- -1.79769e+308 1.79769e+308 +# Not supported by Materialize. +onlyif cockroach query RR SELECT round(-1.23456789e+308::float, -308), round(1.23456789e+308::float, -308) ---- -1e+308 1e+308 +# Not supported by Materialize. +onlyif cockroach query RRRR SELECT 1.234567890123456789::float, round(1.234567890123456789::float, 15), round(1.234567890123456789::float, 16), round(1.234567890123456789::float, 17) ---- @@ -988,21 +1379,29 @@ SELECT round(-2.123456789, 5), round(2.123456789, 5), round(2.123456789012345678 ---- -2.12346 2.12346 2.12345678901235 +# Not supported by Materialize. +onlyif cockroach query RR SELECT round(-1.7976931348623157e+308::float, 1), round(1.7976931348623157e+308::float, 1) ---- -1.79769313e+308 1.79769313e+308 +# Not supported by Materialize. +onlyif cockroach query RR SELECT round(-1.7976931348623157e+308::float, -303), round(1.7976931348623157e+308::float, -303) ---- -1.79769e+308 1.79769e+308 +# Not supported by Materialize. +onlyif cockroach query RR SELECT round(-1.23456789e+308::float, -308), round(1.23456789e+308::float, -308) ---- -1e+308 1e+308 +# Not supported by Materialize. +onlyif cockroach query RRRR SELECT 1.234567890123456789::float, round(1.234567890123456789::float, 15), round(1.234567890123456789::float, 16), round(1.234567890123456789::float, 17) ---- @@ -1013,33 +1412,43 @@ SET extra_float_digits = 0 subtest more_round_tests +# Not supported by Materialize. +onlyif cockroach query RR SELECT round(-1.7976931348623157e-308::float, 1), round(1.7976931348623157e-308::float, 1) ---- -0 0 +# Not supported by Materialize. +onlyif cockroach query RRR SELECT round(123.456::float, -1), round(123.456::float, -2), round(123.456::float, -3) ---- 120 100 0 -query RRRR -SELECT round(123.456::decimal, -1), round(123.456::decimal, -2), round(123.456::decimal, -3), round(123.456::decimal, -200) +query RRRRR +SELECT round(123.456::decimal, -1), round(123.456::decimal, -2), round(123.456::decimal, -3), round(123.456::decimal, -200), round(-0.1::decimal) ---- -1.2E+2 1E+2 0E+3 0E+200 +120 100 0 0 0 +# Not supported by Materialize. +onlyif cockroach query RRRR SELECT round('nan'::decimal), round('nan'::decimal, 1), round('nan'::float), round('nan'::float, 1) ---- NaN NaN NaN NaN +# Not supported by Materialize. +onlyif cockroach # Match postgres float round for inf. query RRRR SELECT round('inf'::float), round('inf'::float, 1), round('-inf'::float), round('-inf'::float, 1) ---- +Inf +Inf -Inf -Inf +# Not supported by Materialize. +onlyif cockroach # But decimal round (which isn't supported at all in postgres because # postgres doesn't support NaN or Inf for its decimals) conforms to # the GDA spec. @@ -1048,6 +1457,8 @@ SELECT round('inf'::decimal) ---- NaN +# Not supported by Materialize. +onlyif cockroach query R SELECT round(1::decimal, 3000) ---- @@ -1055,11 +1466,15 @@ NaN subtest more_tests +# Not supported by Materialize. +onlyif cockroach query III SELECT sign(-2), sign(0), sign(2) ---- -1 0 1 +# Not supported by Materialize. +onlyif cockroach query RRRR SELECT sign(-2.0), sign(-0.0), sign(0.0), sign(2.0) ---- @@ -1068,7 +1483,7 @@ SELECT sign(-2.0), sign(-0.0), sign(0.0), sign(2.0) query RR SELECT sqrt(4.0::float), sqrt(9.0::decimal) ---- -2 3 +2 3 query error cannot take square root of a negative number SELECT sqrt(-1.0::float) @@ -1076,6 +1491,8 @@ SELECT sqrt(-1.0::float) query error cannot take square root of a negative number SELECT sqrt(-1.0::decimal) +# Not supported by Materialize. +onlyif cockroach query RRR SELECT round(tan(-5.0), 14), tan(0.0), round(tan(5.0), 14) ---- @@ -1086,6 +1503,25 @@ SELECT trunc(-0.0), trunc(0.0), trunc(1.9), trunc(19.5678::decimal) ---- 0 0 1 19 +# Not supported by Materialize. +onlyif cockroach +query RRRRRRR +WITH v(x) AS + (VALUES('0'::numeric),('1'::numeric),('-1'::numeric),('4.2'::numeric), + ('-7.777'::numeric),('9127.777'::numeric),('inf'::numeric),('-inf'::numeric),('nan'::numeric)) +SELECT x, trunc(x), trunc(x,1), trunc(x,2), trunc(x,0), trunc(x,-1), trunc(x,-2) +FROM v +---- +0 0 0.0 0.00 0 0 0 +1 1 1.0 1.00 1 0 0 +-1 -1 -1.0 -1.00 -1 0 0 +4.2 4 4.2 4.20 4 0 0 +-7.777 -7 -7.7 -7.77 -7 0 0 +9127.777 9127 9127.7 9127.77 9127 9.12E+3 9.1E+3 +Infinity Infinity Infinity Infinity Infinity Infinity Infinity +-Infinity -Infinity -Infinity -Infinity -Infinity -Infinity -Infinity +NaN NaN NaN NaN NaN NaN NaN + query T SELECT translate('Techonthenet.com', 'e.to', '456') ---- @@ -1106,26 +1542,36 @@ SELECT translate('a‰ÒÁ', 'aÒ', '∏p') ---- ∏‰pÁ +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_extract('foobar', 'o.b') ---- oob +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_extract('foobar', 'o(.)b') ---- o +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_extract('foobar', '(o(.)b)') ---- oob +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_extract('foabaroob', 'o(.)b') ---- a +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_extract('foobar', 'o.x') ---- @@ -1144,31 +1590,36 @@ fooXX query T SELECT regexp_replace('foobarbaz', 'b(..)', E'X\\1Y', 'g') ---- -fooXarYXazY +fooX\1YX\1Y query T SELECT regexp_replace('foobarbaz', 'b(.)(.)', E'X\\2\\1\\3Y', 'g') ---- -fooXraYXzaY +fooX\2\1\3YX\2\1\3Y query T SELECT regexp_replace(E'fooBa\nrbaz', 'b(..)', E'X\\&Y', 'gi') ---- -fooXBa -YrXbazY +fooX\&YrX\&Y +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_replace(E'fooBa\nrbaz', 'b(..)', E'X\\&Y', 'gmi') ---- fooBa rXbazY +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_replace(E'fooBar\nbaz', 'b(..)$', E'X\\&Y', 'gpi') ---- fooBar XbazY +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_replace(E'fooBar\nbaz', 'b(..)$', E'X\\&Y', 'gwi') ---- @@ -1180,15 +1631,16 @@ SELECT regexp_replace('foobarbaz', 'nope', 'NO') ---- foobarbaz -query error regexp_replace\(\): invalid regexp flag: 'z' +query error invalid regular expression flag: z SELECT regexp_replace(E'fooBar\nbaz', 'b(..)$', E'X\\&Y', 'z') query T SELECT regexp_replace(E'Foo\nFoo', '^(foo)', 'BAR', 'i') ---- -BAR -Foo +BAR⏎Foo +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_replace(e'DOGGIE\ndog \nDOG', '^d.+', 'CAT', 's') ---- @@ -1196,6 +1648,8 @@ DOGGIE dog DOG +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_replace(e'DOGGIE\ndog \nDOG', '^d.+', 'CAT', 'n'); ---- @@ -1203,6 +1657,8 @@ DOGGIE CAT DOG +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_replace(e'DOGGIE\ndog \nDOG', '^D.+', 'CAT', 'p') ---- @@ -1210,48 +1666,80 @@ CAT dog DOG +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_replace(e'DOGGIE\ndog \nDOG', '^d.+', 'CAT', 'w') ---- DOGGIE CAT +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_replace('abc', 'b', e'\n', 'w') ---- a c +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_replace('abc\', 'b', 'a', 'w') ---- aac\ +# Not supported by Materialize. +onlyif cockroach query T SELECT regexp_replace('abc', 'c', 'a\', 'w') ---- aba\ -# database-issues#5644 +# #19046 query T SELECT regexp_replace('ReRe','R(e)','1\\1','g'); ---- -1\11\1 +1\\11\\1 + +# Regression test for #51289. +query T +SELECT regexp_replace('TIMESTAMP(6)', '.*(\((\d+)\))?.*', '\2') +---- +\2 + +query T +SELECT regexp_replace('TIMESTAMP(6)', '.*(\((\d+)\)).*', '\2') +---- +\2 +query T +SELECT regexp_replace('TIMESTAMP(6)', '.*(\((\d+)\)?).*', '\2') +---- +\2 + +# Not supported by Materialize. +onlyif cockroach query B SELECT unique_rowid() < unique_rowid() ---- true +# Not supported by Materialize. +onlyif cockroach query BI SELECT uuid_v4() != uuid_v4(), length(uuid_v4()) ---- true 16 -query error syntax error at or near.* +# Not supported by Materialize. +onlyif cockroach +query error at or near.*: syntax error SELECT greatest() -query error syntax error at or near.* +# Not supported by Materialize. +onlyif cockroach +query error at or near.*: syntax error SELECT least() query I @@ -1429,37 +1917,41 @@ true true false false query I SELECT strpos(version(), 'CockroachDB') ---- -1 +0 -# Don't panic during incorrect use of * (materialize#7727) -query error pq: cos\(\): cannot use "\*" in this context +# Don't panic during incorrect use of * (#7727) +query error unknown schema 'system' SELECT cos(*) FROM system.namespace -# Don't panic with invalid names (database-issues#2461) -query error cannot use "nonexistent.\*" without a FROM clause +# Don't panic with invalid names (#8045) +query error column "nonexistent" does not exist SELECT TRIM(TRAILING nonexistent.*[1]) -query error rtrim\(\): cannot subscript type tuple +query error cannot subscript type record\(x: integer\) SELECT TRIM(TRAILING foo.*[1]) FROM (VALUES (1)) AS foo(x) -# Don't panic with invalid names (database-issues#2460) -query error cannot use "nonexistent.\*" without a FROM clause +# Not supported by Materialize. +onlyif cockroach +# Don't panic with invalid names (#8044) +query error no data source matches pattern: nonexistent.\* SELECT OVERLAY(nonexistent.* PLACING 'string' FROM 'string') +# Not supported by Materialize. +onlyif cockroach query error unknown signature SELECT OVERLAY(foo.* PLACING 'string' FROM 'string') FROM (VALUES (1)) AS foo(x) -# Don't panic with invalid names (database-issues#2455) -query error cannot use "nonexistent.\*" without a FROM clause +# Don't panic with invalid names (#8023) +query error column "nonexistent" does not exist SELECT nonexistent.* IS NOT TRUE -query error unsupported comparison operator: IS DISTINCT FROM +query error SELECT clause must have type boolean, not type record\(x: integer\) SELECT foo.* IS NOT TRUE FROM (VALUES (1)) AS foo(x) query T SELECT current_schemas(true) ---- -{pg_catalog,public} +{mz_catalog,pg_catalog,public} query T SELECT current_schemas(false) @@ -1471,8 +1963,8 @@ SELECT current_schemas(false) query T SELECT current_schemas(x) FROM (VALUES (true), (false)) AS t(x); ---- -{pg_catalog,public} {public} +{mz_catalog,pg_catalog,public} statement ok SET search_path=test,pg_catalog @@ -1480,7 +1972,7 @@ SET search_path=test,pg_catalog query T SELECT current_schemas(true) ---- -{pg_catalog} +{mz_catalog,pg_catalog} query T SELECT current_schemas(false) @@ -1490,13 +1982,13 @@ SELECT current_schemas(false) statement ok RESET search_path -query error pq: unknown signature: current_schemas() +query error function current_schemas\(\) does not exist SELECT current_schemas() query T SELECT current_schemas(NULL::bool) ---- -NULL +{public} query B SELECT 'public' = ANY (current_schemas(true)) @@ -1537,6 +2029,53 @@ SELECT current_schema() ---- public +query B +SELECT pg_catalog.pg_function_is_visible((select 'pg_table_is_visible'::regproc)) +---- +true + +query B +SELECT pg_catalog.pg_function_is_visible(0) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +# COLLATION FOR returns a locale name for a collated string +# but for a not collated string 'default' locale name is a Postgres compatible behavior: +# https://www.postgresql.org/docs/10/functions-info.html#FUNCTIONS-INFO-CATALOG-TABLE +query T +SELECT COLLATION FOR ('foo') +---- +"default" + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT COLLATION FOR ('foo' COLLATE "de_DE"); +---- +"de_DE" + +statement error Expected end of statement, found left parenthesis +SELECT COLLATION FOR (1); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_collation_for ('foo') +---- +"default" + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_collation_for ('foo' COLLATE "de_DE"); +---- +"de_DE" + +statement error function "pg_collation_for" does not exist +SELECT pg_collation_for(1); + query I SELECT array_length(ARRAY['a', 'b'], 1) ---- @@ -1557,6 +2096,27 @@ SELECT array_length(ARRAY['a'], 2) ---- NULL +# Not supported by Materialize. +onlyif cockroach +query I +SELECT cardinality(ARRAY['a', 'b']) +---- +2 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT cardinality(ARRAY[]:::int[]) +---- +0 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT cardinality(NULL:::int[]) +---- +NULL + query I SELECT array_lower(ARRAY['a', 'b'], 1) ---- @@ -1597,16 +2157,22 @@ SELECT array_upper(ARRAY['a'], 2) ---- NULL +# Not supported by Materialize. +onlyif cockroach query I SELECT array_length(ARRAY[]:::int[], 1) ---- NULL +# Not supported by Materialize. +onlyif cockroach query I SELECT array_lower(ARRAY[]:::int[], 1) ---- NULL +# Not supported by Materialize. +onlyif cockroach query I SELECT array_upper(ARRAY[]:::int[], 1) ---- @@ -1637,6 +2203,8 @@ SELECT encode('abc', 'hex'), decode('616263', 'hex') ---- 616263 abc +# Not supported by Materialize. +onlyif cockroach query T SELECT encode(e'123\000456', 'escape') ---- @@ -1662,53 +2230,95 @@ SELECT decode('padded1=', 'base64')::STRING ---- \xa5a75d79dd -query error illegal base64 data at input byte 4 +query error invalid base64 end sequence SELECT decode('invalid', 'base64') -query error only 'hex', 'escape', and 'base64' formats are supported for encode\(\) +query error invalid encoding name 'fake' SELECT encode('abc', 'fake') -query error only 'hex', 'escape', and 'base64' formats are supported for decode\(\) +query error invalid encoding name 'fake' SELECT decode('abc', 'fake') +# Not supported by Materialize. +onlyif cockroach query T SELECT from_ip(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x01\x02\x03\x04') ---- 1.2.3.4 +# Not supported by Materialize. +onlyif cockroach query T SELECT from_ip(to_ip('1.2.3.4')) ---- 1.2.3.4 +# Not supported by Materialize. +onlyif cockroach # net.IP.String() always gives us the most succinct form of ipv6 query T select from_ip(to_ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334')) ---- 2001:db8:85a3::8a2e:370:7334 -query error pq: unknown signature: to_ip() +query error function "to_ip" does not exist SELECT to_ip() -query error pq: from_ip\(\): zero length IP +query error function "from_ip" does not exist SELECT from_ip(b'') -query error pq: to_ip\(\): invalid IP format: '' +query error function "to_ip" does not exist SELECT to_ip('') -query error pq: to_ip\(\): invalid IP format: 'asdf' +query error function "to_ip" does not exist select to_ip('asdf') query R select ln(4.0786335175292462e+34::decimal) ---- -79.693655171940461633 +79.6936551719404616326118419422821569713 +# Not supported by Materialize. +onlyif cockroach query IB -SELECT length(gen_random_uuid()::BYTES), gen_random_uuid() = gen_random_uuid() +SELECT length(gen_random_ulid()::BYTES), gen_random_ulid() = gen_random_ulid() ---- 16 false +# Not supported by Materialize. +onlyif cockroach +query TTTT +SELECT uuid_to_ulid('0178951c-b665-30a7-19a2-a18999834858'), + ulid_to_uuid('01F2AHSDK562KHK8N1H6CR6J2R'), + ulid_to_uuid(uuid_to_ulid('0178951c-b665-30a7-19a2-a18999834858')), + uuid_to_ulid(ulid_to_uuid('01F2AHSDK562KHK8N1H6CR6J2R')) +---- +01F2AHSDK562KHK8N1H6CR6J2R 0178951c-b665-30a7-19a2-a18999834858 0178951c-b665-30a7-19a2-a18999834858 01F2AHSDK562KHK8N1H6CR6J2R + +let $ulid1 +SELECT gen_random_ulid() + +# Not supported by Materialize. +onlyif cockroach +# Proper sorting of ULIDs inside the same millisecond is not guaranteed, we need this to enforce correct behavior. +statement ok +SELECT pg_sleep(0.001) + +let $ulid2 +SELECT gen_random_ulid() + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT '$ulid1' < '$ulid2', + '$ulid1' > '$ulid2', + uuid_to_ulid('$ulid1') < uuid_to_ulid('$ulid2'), + uuid_to_ulid('$ulid1') > uuid_to_ulid('$ulid2') +---- +true false true false + +# Not supported by Materialize. +onlyif cockroach query TTTTTT SELECT to_uuid('63616665-6630-3064-6465-616462656566'), to_uuid('{63616665-6630-3064-6465-616462656566}'), @@ -1724,23 +2334,27 @@ cafef00ddeadbeef cafef00ddeadbeef 63616665-6630-3064-6465-616462656566 -query error uuid: incorrect UUID length +query error function "to_uuid" does not exist SELECT to_uuid('63616665-6630-3064-6465') -query error uuid: incorrect UUID length +query error function "to_uuid" does not exist SELECT to_uuid('63616665-6630-3064-6465-616462656566-123') -query error uuid: incorrect UUID format +query error function "to_uuid" does not exist SELECT to_uuid('6361666512-6630-3064-6465-616462656566') -query error uuid: UUID must be exactly 16 bytes long, got 4 bytes +query error function "from_uuid" does not exist SELECT from_uuid(b'f00d') +# Not supported by Materialize. +onlyif cockroach query T SELECT pg_catalog.pg_typeof(sign(1:::decimal)) ---- -decimal +numeric +# Not supported by Materialize. +onlyif cockroach query T VALUES (pg_typeof(1:::int)), (pg_typeof('a':::string)), @@ -1752,97 +2366,67 @@ VALUES (pg_typeof(1:::int)), (pg_typeof(b'a':::bytes)), (pg_typeof(array[1,2,3])) ---- -int -string -bool +bigint +text +boolean unknown interval date -timestamptz -bytes -int[] - -# TODO(def-): Reenable after database-issues#6599 is fixed -# query T -# VALUES (format_type('anyelement'::regtype, -1)), -# (format_type('bit'::regtype, -1)), -# (format_type('bool'::regtype, -1)), -# (format_type('bytea'::regtype, -1)), -# (format_type('char'::regtype, -1)), -# (format_type('date'::regtype, -1)), -# (format_type('decimal'::regtype, -1)), -# (format_type('float'::regtype, -1)), -# (format_type('float4'::regtype, -1)), -# (format_type('interval'::regtype, -1)), -# (format_type('numeric'::regtype, -1)), -# (format_type('oid'::regtype, -1)), -# (format_type('oidvector'::regtype, -1)), -# (format_type('inet'::regtype, -1)), -# (format_type('int'::regtype, -1)), -# (format_type('int4'::regtype, -1)), -# (format_type('int2'::regtype, -1)), -# (format_type('int2vector'::regtype, -1)), -# (format_type('interval'::regtype, -1)), -# (format_type('json'::regtype, -1)), -# (format_type('name'::regtype, -1)), -# (format_type('regclass'::regtype, -1)), -# (format_type('regnamespace'::regtype, -1)), -# (format_type('regproc'::regtype, -1)), -# (format_type('regprocedure'::regtype, -1)), -# (format_type('regtype'::regtype, -1)), -# (format_type('string'::regtype, -1)), -# (format_type('time'::regtype, -1)), -# (format_type('timestamp'::regtype, -1)), -# (format_type('timestamptz'::regtype, -1)), -# (format_type('record'::regtype, -1)), -# (format_type('uuid'::regtype, -1)), -# (format_type('unknown'::regtype, -1)), -# (format_type('varbit'::regtype, -1)), -# (format_type('varchar'::regtype, -1)), -# (format_type('int[]'::regtype, -1)), -# (format_type('int2[]'::regtype, -1)), -# (format_type('string[]'::regtype, -1)), -# (format_type('varchar[]'::regtype, -1)) -# ---- -# anyelement -# bit -# boolean -# bytea -# character -# date -# numeric -# double precision -# real -# interval -# numeric -# oid -# oidvector -# inet -# bigint -# integer -# smallint -# int2vector -# interval -# jsonb -# name -# regclass -# regnamespace -# regproc -# regprocedure -# regtype -# text -# time without time zone -# timestamp without time zone -# timestamp with time zone -# record -# uuid -# unknown -# bit varying -# character varying -# bigint[] -# smallint[] -# text[] -# character varying[] +timestamp with time zone +bytea +bigint[] + +# SQL-492 (https://linear.app/materializeinc/issue/SQL-492), root cause CLU-159 +# (https://linear.app/materializeinc/issue/CLU-159): format_type expands to a +# large expression, and constant-folding it across many VALUES rows exceeds the +# optimizer's recursion limit. PG evaluates all 44 rows and returns the formatted +# type names (anyelement, bit, boolean, bytea, bpchar, "char", date, numeric, +# double precision, real, interval, numeric, oid, oidvector, inet, ...). +query error exceeded recursion limit of 2048 +VALUES (format_type('anyelement'::regtype, -1)), + (format_type('bit'::regtype, -1)), + (format_type('bool'::regtype, -1)), + (format_type('bytea'::regtype, -1)), + (format_type('char'::regtype, -1)), + (format_type('"char"'::regtype, -1)), + (format_type('date'::regtype, -1)), + (format_type('decimal'::regtype, -1)), + (format_type('float'::regtype, -1)), + (format_type('float4'::regtype, -1)), + (format_type('interval'::regtype, -1)), + (format_type('numeric'::regtype, -1)), + (format_type('oid'::regtype, -1)), + (format_type('oidvector'::regtype, -1)), + (format_type('inet'::regtype, -1)), + (format_type('int'::regtype, -1)), + (format_type('int4'::regtype, -1)), + (format_type('int2'::regtype, -1)), + (format_type('int2vector'::regtype, -1)), + (format_type('interval'::regtype, -1)), + (format_type('json'::regtype, -1)), + (format_type('name'::regtype, -1)), + (format_type('regclass'::regtype, -1)), + (format_type('regnamespace'::regtype, -1)), + (format_type('regproc'::regtype, -1)), + (format_type('regprocedure'::regtype, -1)), + (format_type('regrole'::regtype, -1)), + (format_type('regtype'::regtype, -1)), + (format_type('string'::regtype, -1)), + (format_type('time'::regtype, -1)), + (format_type('timestamp'::regtype, -1)), + (format_type('timestamptz'::regtype, -1)), + (format_type('record'::regtype, -1)), + (format_type('uuid'::regtype, -1)), + (format_type('unknown'::regtype, -1)), + (format_type('varbit'::regtype, -1)), + (format_type('varchar'::regtype, -1)), + (format_type('void'::regtype, -1)), + (format_type('int[]'::regtype, -1)), + (format_type('int2[]'::regtype, -1)), + (format_type('string[]'::regtype, -1)), + (format_type('varchar[]'::regtype, -1)), + (format_type('pg_catalog.int4'::regtype, -1)), + (format_type('pg_catalog.int2'::regtype, -1)) query T VALUES (format_type('anyelement'::regtype, NULL)), @@ -1855,15 +2439,15 @@ VALUES (format_type('anyelement'::regtype, NULL)), (format_type('timestamptz'::regtype, NULL)), (format_type('record'::regtype, NULL)) ---- -anyelement -boolean -bytea date +bytea +record +boolean numeric interval -timestamp without time zone +anyelement timestamp with time zone -record +timestamp without time zone query T SELECT format_type(oid, -1) FROM pg_type WHERE typname='text' LIMIT 1 @@ -1890,25 +2474,22 @@ SELECT format_type(oid, -1) FROM pg_type WHERE typname='_text' LIMIT 1 ---- text[] -query T -SELECT pg_catalog.pg_get_expr('abc', 1); ----- -abc - -query T -SELECT pg_catalog.pg_get_expr('abc', 1, true); ----- -abc +# Ensure each type can be formatted. +statement ok +SELECT format_type(oid, NULL) FROM pg_type +# Not supported by Materialize. +onlyif cockroach +# Ensure that implicit record types for virtual tables can be formatted. query T -SELECT pg_catalog.pg_get_expr('abc', 1, false); +select format_type('pg_namespace'::regtype, null); ---- -abc +pg_namespace query T SELECT pg_catalog.pg_get_userbyid((SELECT oid FROM pg_roles WHERE rolname='root')) ---- -root +NULL query T SELECT pg_catalog.pg_get_userbyid(20) @@ -1920,13 +2501,37 @@ SELECT pg_catalog.pg_get_indexdef(0) ---- NULL +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE testenum AS ENUM ('foo', 'bar', 'baz') + +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE test.pg_indexdef_test (a INT, UNIQUE INDEX pg_indexdef_idx (a ASC), INDEX other (a DESC)) +CREATE TABLE test.pg_indexdef_test ( + a INT, + e testenum, + UNIQUE INDEX pg_indexdef_idx (a ASC), + INDEX pg_indexdef_partial_idx (a) WHERE a > 0, + INDEX pg_indexdef_partial_enum_idx (a) WHERE e IN ('foo', 'bar'), + INDEX other (a DESC) +) query T SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_idx')) ---- -CREATE UNIQUE INDEX pg_indexdef_idx ON test.public.pg_indexdef_test (a ASC) +NULL + +query T +SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_partial_idx')) +---- +NULL + +query T +SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_partial_enum_idx')) +---- +NULL query T SELECT pg_catalog.pg_get_indexdef(0, 0, true) @@ -1936,52 +2541,63 @@ NULL query T SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_idx'), 0, true) ---- -CREATE UNIQUE INDEX pg_indexdef_idx ON test.public.pg_indexdef_test (a ASC) +NULL +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE test.pg_indexdef_test_cols (a INT, b INT, UNIQUE INDEX pg_indexdef_cols_idx (a ASC, b DESC), INDEX other (a DESC)) query T SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 0, true) ---- -CREATE UNIQUE INDEX pg_indexdef_cols_idx ON test.public.pg_indexdef_test_cols (a ASC, b DESC) +NULL query T SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 1, true) ---- -a +NULL query T SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 2, false) ---- -b +NULL +# The empty string should be returned for index 3. Previously, there was a bug +# where this would return the primary key column name, since the primary key +# is stored in the index. query T SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 3, false) ---- -rowid +NULL query I SELECT length(pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 4, false)) ---- -0 +NULL query I SELECT length(pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), -1, false)) ---- -0 +NULL query T SELECT pg_catalog.pg_get_viewdef(0) ---- NULL +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE test.pg_viewdef_test (a int, b int, c int) +# Not supported by Materialize. +onlyif cockroach statement ok CREATE VIEW test.pg_viewdef_view AS SELECT a, b FROM test.pg_viewdef_test +# Not supported by Materialize. +onlyif cockroach query T SELECT pg_catalog.pg_get_viewdef('pg_viewdef_view'::regclass::oid) ---- @@ -1997,33 +2613,55 @@ SELECT pg_catalog.pg_get_viewdef(0, false) ---- NULL +# Not supported by Materialize. +onlyif cockroach query T SELECT pg_catalog.pg_get_viewdef('pg_viewdef_view'::regclass::oid, true) ---- SELECT a, b FROM test.public.pg_viewdef_test +# Not supported by Materialize. +onlyif cockroach query T SELECT pg_catalog.pg_get_viewdef('pg_viewdef_view'::regclass::oid, false) ---- SELECT a, b FROM test.public.pg_viewdef_test +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE MATERIALIZED VIEW test.pg_viewdef_mview AS SELECT b, a FROM test.pg_viewdef_test + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_catalog.pg_get_viewdef('pg_viewdef_mview'::regclass::oid) +---- +SELECT b, a FROM test.public.pg_viewdef_test + +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE test.pg_constraintdef_test ( a int, b int unique, c int check (c > a), + d string, + UNIQUE INDEX (a) WHERE d = 'foo', FOREIGN KEY(a) REFERENCES test.pg_indexdef_test(a) ON DELETE CASCADE -) +); +ALTER TABLE test.pg_constraintdef_test ADD CONSTRAINT c CHECK (c > 0) NOT VALID; +ALTER TABLE test.pg_constraintdef_test ADD CONSTRAINT fk FOREIGN KEY (c) REFERENCES test.pg_indexdef_test(a) NOT VALID; query T rowsort SELECT pg_catalog.pg_get_constraintdef(oid) FROM pg_catalog.pg_constraint WHERE conrelid='pg_constraintdef_test'::regclass ---- -FOREIGN KEY (a) REFERENCES pg_indexdef_test (a) ON DELETE CASCADE -CHECK (c > a) -UNIQUE (b ASC) + +# Not supported by Materialize. +onlyif cockroach # These functions always return NULL since we don't support comments on vtable columns and databases. query TT SELECT col_description('pg_class'::regclass::oid, 2), @@ -2031,6 +2669,8 @@ SELECT col_description('pg_class'::regclass::oid, 2), ---- NULL NULL +# Not supported by Materialize. +onlyif cockroach # vtable comments are supported query TT SELECT regexp_replace(obj_description('pg_class'::regclass::oid), e' .*', '') AS comment1, @@ -2048,6 +2688,8 @@ COMMENT ON TABLE t IS 'waa' statement ok COMMENT ON COLUMN t.x IS 'woo' +# Not supported by Materialize. +onlyif cockroach query TTTT SELECT obj_description('t'::regclass::oid), obj_description('t'::regclass::oid, 'pg_class'), @@ -2056,17 +2698,23 @@ SELECT obj_description('t'::regclass::oid), ---- waa waa NULL woo +# Not supported by Materialize. +onlyif cockroach statement ok COMMENT ON DATABASE test is 'foo' +# Not supported by Materialize. +onlyif cockroach query TTTT -SELECT shobj_description((select oid from pg_database where datname = 'materialize')::oid, 'pg_database'), +SELECT shobj_description((select oid from pg_database where datname = 'defaultdb')::oid, 'pg_database'), shobj_description((select oid from pg_database where datname = 'test')::oid, 'pg_database'), shobj_description((select oid from pg_database where datname = 'notexist')::oid, 'pg_database'), shobj_description((select oid from pg_database where datname = 'test')::oid, 'notexist') ---- NULL foo NULL NULL +# Not supported by Materialize. +onlyif cockroach # Ensure that shobj_ and obj_description don't return the opposite type of # comments. query TT @@ -2081,19 +2729,36 @@ SELECT pg_catalog.length('hello') ---- 5 -query OOO -SELECT oid(3), oid(0), oid(12023948723) +# Not supported by Materialize. +onlyif cockroach +# -2147483648 is MinInt32. +# 4294967295 is MaxUint32. +query OOOOO +SELECT oid(3), oid(0), (-1)::oid, (-2147483648)::oid, (4294967295)::oid ---- -3 0 12023948723 +3 0 4294967295 2147483648 4294967295 + +# -2147483649 is (MinInt32 - 1). +query error function "oid" does not exist +SELECT oid(-2147483649) + +# 4294967296 is (MaxUint32 + 1). +query error function "oid" does not exist +SELECT oid(4294967296) +# Not supported by Materialize. +onlyif cockroach query T -SELECT to_english(i) FROM (VALUES (1), (13), (617), (-2)) AS a(i) +SELECT to_english(i) FROM (VALUES (1), (13), (617), (-2), (-9223372036854775808)) AS a(i) ---- one one-three six-one-seven minus-two +minus-nine-two-two-three-three-seven-two-zero-three-six-eight-five-four-seven-seven-five-eight-zero-eight +# Not supported by Materialize. +onlyif cockroach # Do some basic sanity checking of the variadic hash functions. query BBBBBBBBB SELECT @@ -2109,6 +2774,8 @@ SELECT ---- true false true false true false true true true +# Not supported by Materialize. +onlyif cockroach # The hash functions should be stable, so verify that the following hashes # don't change. query T @@ -2131,7 +2798,7 @@ be09b235155bae6cb96b94ce4645260937e856ac3907d710850256e6351f50b428f948a7af339374 f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7 95bce0fdbcf48ba9c944dae46238d89bbd6df696a0d0b7cc8fc16eeabd30c03d6d2506cfcce81de320b37bc677df1bd045ac9231b43ae11807773db3909d1220 b2d173023893f71caadf7cb2f9557355462570de2c9c971b9cfa5494936e28df8e13d0db4d550aab66d5e7a002f678ddb02def092c069ce473cf5fb293953986 -960b0fed9378be1e9adefd91e1be6ac9c1de7208008dfec438ff845135727bebea0f7458a5181079f61288176e0168cfea501b900c3e495b3ab9bbe4d372486d +17ecb6d43868f7502f588817661f5edb85b8e408d304ffbdeddd6b1abbec00dc5dda907b930356f1a031be368ea053626af59a9e74fbe55cf9cb7855acfd5f17 d82c4eb5261cb9c8aa9855edd67d1bd10482f41529858d925094d173fa662aa91ff39bc5b188615273484021dfb16fd8284cf684ccf0fc795be3aa2fc1e6c181 # We only support one encoding, UTF8, which is hardcoded to id 6 just like in @@ -2141,6 +2808,8 @@ SELECT pg_catalog.pg_encoding_to_char(6), pg_catalog.pg_encoding_to_char(7) ---- UTF8 NULL +# Not supported by Materialize. +onlyif cockroach # TODO(jordan): Restore this to original form by removing FROM # clause once issue 32876 is fixed. query TITI @@ -2153,23 +2822,27 @@ WHERE relname = 'pg_constraint' query TTTT SELECT quote_ident('foo'), quote_ident('select'), quote_ident('int8'), quote_ident('numeric') ---- -foo "select" int8 "numeric" +foo "select" int8 numeric +# Not supported by Materialize. +onlyif cockroach query TT SELECT lpad('abc', 5, 'xy'), rpad('abc', 5, 'xy') ---- xyabc abcxy +# Not supported by Materialize. +onlyif cockroach query TT SELECT lpad('abc', 5, ''), rpad('abc', 5, '') ---- abc abc -query error requested length too large +query error function lpad\(unknown, bigint\) does not exist SELECT lpad('abc', 100000000000000) -query error requested length too large +query error function "rpad" does not exist SELECT rpad('abc', 100000000000000) query TT @@ -2182,76 +2855,1840 @@ SELECT array_to_string(ARRAY['a', 'b,', 'c'], NULL), array_to_string(ARRAY['a', ---- NULL afoob,foozerpfooc -query error could not determine polymorphic type because input has type unknown -SELECT array_to_string(NULL, ',') +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT array_to_string(NULL, ','), array_to_string(NULL, 'foo', 'zerp') +---- +NULL NULL -query error could not determine polymorphic type because input has type unknown -SELECT array_to_string(NULL, 'foo', 'zerp') +# Builtin array_to_string should recursively search nested arrays. +query T +SELECT array_to_string(ARRAY[ARRAY[ARRAY[5,6], ARRAY[2,3]], ARRAY[ARRAY[7,8], ARRAY[4,44]]], ' '); +---- +5 6 2 3 7 8 4 44 -subtest pg_is_in_recovery +# Not supported by Materialize. +onlyif cockroach +# Builtin array_to_string should recursively search nested arrays. +query T +SELECT array_to_string(ARRAY[(SELECT ARRAY[1,2]::int2vector)],' '); +---- +1 2 -query B colnames -SELECT pg_is_in_recovery() +# Not supported by Materialize. +onlyif cockroach +# Examples from https://www.postgresql.org/docs/9.3/functions-string.html#FUNCTIONS-STRING-FORMAT +query T +SELECT format('Hello %s', 'World') ---- -pg_is_in_recovery -false +Hello World -subtest pg_is_xlog_replay_paused +# Not supported by Materialize. +onlyif cockroach +query T +SELECT format('INSERT INTO %I VALUES(%L)', 'locations', 'C:\Program Files') +---- +INSERT INTO locations VALUES(e'C:\\Program Files') -query B colnames -SELECT pg_is_xlog_replay_paused() +# Not supported by Materialize. +onlyif cockroach +query T +SELECT format('|%10s|', 'foo') ---- -pg_is_xlog_replay_paused -false +| foo| +# Not supported by Materialize. +onlyif cockroach query T -SELECT pg_catalog.pg_client_encoding() +SELECT format('|%-10s|', 'foo') ---- -UTF8 +|foo | -subtest check_consistency +# Not supported by Materialize. +onlyif cockroach +query T +SELECT format('|%*s|', 10, 'foo') +---- +| foo| + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT format('|%*s|', -10, 'foo') +---- +|foo | + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT format('|%-*s|', 10, 'foo') +---- +|foo | + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT format('|%-*s|', -10, 'foo') +---- +|foo | + +# Not supported by Materialize. +onlyif cockroach +# Escaping $ into \x24 only needed in testlogic or prepared statements +query T +SELECT format(E'Testing %3\x24s, %2\x24s, %1\x24s', 'one', 'two', 'three') +---- +Testing three, two, one + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT format(E'Testing %3\x24s, %2\x24s, %s', 'one', 'two', 'three') +---- +Testing three, two, three + +# Not supported by Materialize. +onlyif cockroach +query error pq: format\(\): error parsing format string: not enough arguments +SELECT format(E'%2\x24s','foo'); + +subtest pg_is_in_recovery + +query B colnames +SELECT pg_is_in_recovery() +---- +pg_is_in_recovery +false + +subtest pg_is_xlog_replay_paused + +# Not supported by Materialize. +onlyif cockroach +query B colnames +SELECT pg_is_xlog_replay_paused() +---- +pg_is_xlog_replay_paused +false + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_catalog.pg_client_encoding() +---- +UTF8 + +subtest width_bucket + +# Not supported by Materialize. +onlyif cockroach +# Tests for width_bucket builtin +query I +SELECT width_bucket(8.0, 2.0, 3.0, 5) +---- +6 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT width_bucket(5.35, 0.024, 10.06, 5) +---- +3 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT width_bucket(7, 3, 11, 5) +---- +3 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT width_bucket(now(), array['yesterday', 'today', 'tomorrow']::timestamptz[]) +---- +2 + +query error function "width_bucket" does not exist +SELECT width_bucket(1, array['a', 'h', 'l', 'z']); + +# Not supported by Materialize. +onlyif cockroach +# Regression for #40623 +query I +SELECT width_bucket(1, array[]::int[]); +---- +0 + +# Not supported by Materialize. +onlyif cockroach +# Sanity check pg_type_is_visible. +query BBB +SELECT pg_type_is_visible('int'::regtype), pg_type_is_visible(NULL), pg_type_is_visible(99999) +---- +true NULL NULL + +# Not supported by Materialize. +onlyif cockroach +# Sanity check pg_get_function_arguments. +query T +SELECT pg_get_function_arguments('convert_from'::regproc::oid) +---- +bytea, text + +# Not supported by Materialize. +onlyif cockroach +# This produces an empty string in Postgres too. +query T +SELECT pg_get_function_arguments('version'::regproc::oid) +---- +· + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_get_function_arguments('array_length'::regproc) +---- +anyarray, int8 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_get_function_arguments((select oid from pg_proc where proname='variance' and proargtypes[0] = 'int'::regtype)) +---- +int8 + +# Not supported by Materialize. +onlyif cockroach +# Sanity check pg_get_function_identity_arguments. +query T +SELECT pg_get_function_identity_arguments('convert_from'::regproc::oid) +---- +bytea, text + +# Not supported by Materialize. +onlyif cockroach +# This produces an empty string in Postgres too. +query T +SELECT pg_get_function_identity_arguments('version'::regproc::oid) +---- +· + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_get_function_identity_arguments('array_length'::regproc) +---- +anyarray, int8 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_get_function_identity_arguments((select oid from pg_proc where proname='variance' and proargtypes[0] = 'int'::regtype)) +---- +int8 + +# Sanity check pg_get_function_result. + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_get_function_result('array_length'::regproc) +---- +int8 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_get_function_result((select oid from pg_proc where proname='variance' and proargtypes[0] = 'int'::regtype)) +---- +numeric + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_get_function_result('pg_sleep'::regproc) +---- +bool + +# Note in Postgres <= 9.5, returns SETOF anyelement. +query error function "pg_get_function_result" does not exist +SELECT pg_get_function_result('unnest'::regproc); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT CASE WHEN true THEN (1, 2) ELSE NULL END +---- +(1,2) + +query B +SELECT (1, 2) IN ((2, 3), NULL, (1, 2)) +---- +true + +query B +SELECT (1, 2) IN ((2, 3), NULL) +---- +NULL + +# Test for regression in hex functions. +subtest regression_41707 + +# Not supported by Materialize. +onlyif cockroach +# The int8 casts make it match postgres behavior - unfortunately, we do not default to int4. +query TTTTTTT +select to_hex(-2147483649), to_hex(-2147483648::int8), to_hex(-1::int8), to_hex(0), to_hex(1), to_hex(2147483647), to_hex(2147483648) +---- +ffffffff7fffffff ffffffff80000000 ffffffffffffffff 0 1 7fffffff 80000000 + +# Not supported by Materialize. +onlyif cockroach +query T +select to_hex(E'\\047\\134'::bytea) +---- +275c + +# Not supported by Materialize. +onlyif cockroach +query T +select to_hex('abc') +---- +616263 + +# Test for timezone builtin. +subtest timezone_test + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE -3 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT timezone('UTC+6', '1970-01-01 01:00') +---- +1969-12-31 22:00:00 +0000 +0000 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT timezone('UTC+6', '1970-01-01 01:00'::time) +---- +0000-01-01 22:00:00 -0600 -0600 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT timezone('UTC+6', '1970-01-01 01:00'::timetz) +---- +0000-01-01 22:00:00 -0600 -0600 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT timezone('UTC+6', '1970-01-01 01:00'::timestamp) +---- +1970-01-01 04:00:00 -0300 -0300 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT timezone('UTC+6', '1970-01-01 01:00'::timestamptz) +---- +1969-12-31 22:00:00 +0000 +0000 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE +0 + +subtest getdatabaseencoding + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT getdatabaseencoding() +---- +UTF8 + +subtest get_byte + +query I +SELECT get_byte('Th\000omas'::BYTEA, 4) +---- +109 + +query error index 10 out of valid range, 0\.\.2 +SELECT get_byte('abc'::BYTEA, 10) + +query error index \-10 out of valid range, 0\.\.2 +SELECT get_byte('abc'::BYTEA, -10) + +subtest set_byte + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT set_byte('Th\000omas'::BYTEA, 2, 64) +---- +Th@omas + +# Not supported by Materialize. +onlyif cockroach +# A substitute value that's larger than 8 bit will be truncated. +query T +SELECT set_byte('Th\000omas'::BYTEA, 2, 16448) +---- +Th@omas + +query error function "set_byte" does not exist +SELECT set_byte('abc'::BYTEA, 10, 123) + +query error function "set_byte" does not exist +SELECT set_byte('abc'::BYTEA, -10, 123) + +subtest get_bit + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT get_bit(B'100101110101', 3) UNION SELECT get_bit(B'100101110101', 2) +---- +1 +0 + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT get_bit('000000'::varbit, 5) UNION SELECT get_bit('1111111'::varbit, 5) +---- +1 +0 + +query error type "b" does not exist +SELECT get_bit(B'10110', 10) + +query error type "b" does not exist +SELECT get_bit(B'', 0); + +query II +SELECT i, get_bit('\x11'::BYTEA, i) FROM generate_series(0, 7) i ORDER BY i; +---- +0 1 +1 0 +2 0 +3 0 +4 1 +5 0 +6 0 +7 0 + +query II rowsort +SELECT i, get_bit('\x11ef'::BYTEA, i) FROM generate_series(0, 15) i ORDER BY i; +---- +0 1 +1 0 +2 0 +3 0 +4 1 +5 0 +6 0 +7 0 +8 1 +9 1 +10 1 +11 1 +12 0 +13 1 +14 1 +15 1 + +query error type "b" does not exist +SELECT get_bit(b'\x61', 8) + +query error type "b" does not exist +SELECT get_bit(b'', 0) + +subtest set_bit + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT set_bit(B'1101010', 0, 0) UNION SELECT set_bit(B'1101010', 2, 1) +---- +0101010 +1111010 + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT set_bit('000000'::varbit, 5, 1) UNION SELECT set_bit('111111'::varbit, 5, 0) +---- +000001 +111110 + +query error function "set_bit" does not exist +SELECT set_bit(B'1101010', 10, 1) + +query error function "set_bit" does not exist +SELECT set_bit(B'1001010', 0, 2) + +query error function "set_bit" does not exist +SELECT set_bit(B'', 0, 1) + +# Not supported by Materialize. +onlyif cockroach +query IT +SELECT i, encode(set_bit('\x00'::BYTEA, i, 1), 'hex') FROM generate_series(0, 7) i ORDER BY i +---- +0 01 +1 02 +2 04 +3 08 +4 10 +5 20 +6 40 +7 80 + +# Not supported by Materialize. +onlyif cockroach +query IT +SELECT i, encode(set_bit('\x0000'::bytea, i, 1), 'hex') FROM generate_series(0, 15) i ORDER BY i +---- +0 0100 +1 0200 +2 0400 +3 0800 +4 1000 +5 2000 +6 4000 +7 8000 +8 0001 +9 0002 +10 0004 +11 0008 +12 0010 +13 0020 +14 0040 +15 0080 + +query error function "set_bit" does not exist +SELECT set_bit(b'ac', 16, 0) + +query error function "set_bit" does not exist +SELECT set_bit(b'', 0, 1) + +query error function "set_bit" does not exist +SELECT set_bit(b'\145\x6C\l', 0, 2) + +subtest num_nulls_test + +statement ok +CREATE TABLE nulls_test(a INT, b STRING) + +statement ok +INSERT INTO nulls_test VALUES(1, 'foo'), (1, NULL), (NULL, 'foo'), (NULL, NULL) + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT num_nulls(a, b), num_nonnulls(a, b) FROM nulls_test +---- +0 2 +1 1 +1 1 +2 0 + +subtest pb_to_json + +# Not supported by Materialize. +onlyif cockroach +query T +select crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor)->'database'->>'name' from system.descriptor where id=1 +---- +system + +# Not supported by Materialize. +onlyif cockroach +query T +select crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor, true, true)->'database'->>'name' from system.descriptor where id=1 +---- +system + +query error unknown schema 'crdb_internal' +select crdb_internal.pb_to_json('cockroach.sql.sqlbase.descriptor', descriptor)->'database'->>'name' from system.descriptor where id=1 + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT (SELECT * FROM [SHOW crdb_version]) = version() +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +select crdb_internal.json_to_pb('cockroach.sql.sqlbase.Descriptor', crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor)) = descriptor from system.descriptor where id = 1 +---- +true + +query error unknown schema 'crdb_internal' +select crdb_internal.json_to_pb('cockroach.sql.sqlbase.Descriptor', crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor, true, true)) = descriptor from system.descriptor where id = 1 + +subtest regexp_split + +query T +SELECT regexp_split_to_table('3aa0AAa1', 'a+') +---- +1 +3 +0AA + +query T +SELECT regexp_split_to_table('3aa0AAa1', 'a+', 'i') +---- +0 +1 +3 + +query T +SELECT regexp_split_to_array('3aa0AAa1', 'a+') +---- +{3,0AA,1} + +query T +SELECT regexp_split_to_array('3aaa0AAa1', 'a+', 'i') +---- +{3,0,1} + +subtest crdb_internal.trace_id + +# switch users -- this one has no permissions so expect errors +user testuser + +query error unknown schema 'crdb_internal' +SELECT * FROM crdb_internal.trace_id() + +user root + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT count(*) = 1 FROM crdb_internal.trace_id() +---- +true + +subtest crdb_internal.payloads_for_span + +# switch users -- this one has no permissions so expect errors +user testuser + +query error unknown schema 'crdb_internal' +SELECT * FROM crdb_internal.payloads_for_span(0) + +user root + +# Not supported by Materialize. +onlyif cockroach +query TT colnames +SELECT * FROM crdb_internal.payloads_for_span(0) +WHERE false +---- +payload_type payload_jsonb + +subtest crdb_internal.payloads_for_trace + +# switch users -- this one has no permissions so expect errors +user testuser + +query error unknown schema 'crdb_internal' +SELECT * FROM crdb_internal.payloads_for_span(0) + +user root + +# Not supported by Materialize. +onlyif cockroach +query TTT colnames +SELECT * FROM crdb_internal.payloads_for_trace(0) +WHERE false +---- +span_id payload_type payload_jsonb + +# switch users -- this one has no permissions so expect errors +user testuser + +query error unknown schema 'crdb_internal' +SELECT * FROM crdb_internal.set_trace_verbose(0, false) + +user root + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT * FROM crdb_internal.set_trace_verbose(0, false) +WHERE false +---- + +# Not supported by Materialize. +onlyif cockroach +# set timezone to something other then UTC +statement ok +SET timezone = 'Europe/Berlin' + +query T +select generate_series('2021-07-05'::timestamptz, '2021-07-06'::timestamptz, '1day'::interval) +---- +2021-07-05 00:00:00+00 +2021-07-06 00:00:00+00 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE +0 + +# Not supported by Materialize. +onlyif cockroach +statement ok +set timezone = 'Europe/Bucharest'; + +# the following two queries should provide the same output +query T +select '2020-10-25 00:00'::TIMESTAMPTZ + (i::text || ' hour')::interval from generate_series(0, 24) AS g(i); +---- +2020-10-25 16:00:00+00 +2020-10-25 08:00:00+00 +2020-10-25 00:00:00+00 +2020-10-26 00:00:00+00 +2020-10-25 05:00:00+00 +2020-10-25 21:00:00+00 +2020-10-25 13:00:00+00 +2020-10-25 18:00:00+00 +2020-10-25 10:00:00+00 +2020-10-25 02:00:00+00 +2020-10-25 23:00:00+00 +2020-10-25 15:00:00+00 +2020-10-25 07:00:00+00 +2020-10-25 12:00:00+00 +2020-10-25 04:00:00+00 +2020-10-25 20:00:00+00 +2020-10-25 01:00:00+00 +2020-10-25 17:00:00+00 +2020-10-25 09:00:00+00 +2020-10-25 22:00:00+00 +2020-10-25 14:00:00+00 +2020-10-25 06:00:00+00 +2020-10-25 19:00:00+00 +2020-10-25 11:00:00+00 +2020-10-25 03:00:00+00 + +query T +select generate_series('2020-10-25 00:00'::TIMESTAMPTZ, '2020-10-25 23:00'::TIMESTAMPTZ, '1 hour'); +---- +2020-10-25 16:00:00+00 +2020-10-25 08:00:00+00 +2020-10-25 00:00:00+00 +2020-10-25 05:00:00+00 +2020-10-25 21:00:00+00 +2020-10-25 13:00:00+00 +2020-10-25 18:00:00+00 +2020-10-25 10:00:00+00 +2020-10-25 02:00:00+00 +2020-10-25 23:00:00+00 +2020-10-25 15:00:00+00 +2020-10-25 07:00:00+00 +2020-10-25 12:00:00+00 +2020-10-25 04:00:00+00 +2020-10-25 20:00:00+00 +2020-10-25 01:00:00+00 +2020-10-25 17:00:00+00 +2020-10-25 09:00:00+00 +2020-10-25 22:00:00+00 +2020-10-25 14:00:00+00 +2020-10-25 06:00:00+00 +2020-10-25 19:00:00+00 +2020-10-25 11:00:00+00 +2020-10-25 03:00:00+00 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE +0 + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'AAA'::text ~ similar_escape('(ACTIVE|CLOSED|PENDING)'::text, NULL::text) +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'ACTIVE'::text ~ similar_escape('(ACTIVE|CLOSED|PENDING)'::text, NULL::text) +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'ACTIVE'::text ~ similar_escape(NULL::text, NULL::text) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'AAA'::text ~ similar_to_escape('(ACTIVE|CLOSED|PENDING)'::text, NULL::text) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'ACTIVE'::text ~ similar_to_escape('(ACTIVE|CLOSED|PENDING)'::text, NULL::text) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'ACTIVE'::text ~ similar_to_escape('(ACTIVE|CLOSED|PENDING)'::text) +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'AAA'::text ~ similar_to_escape('(ACTIVE|CLOSED|PENDING)'::text) +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'ACTIVE'::text ~ similar_to_escape(NULL::text) +---- +NULL + +subtest password_hash + +# Need to escapes the dollar signs since the testlogic language gives them special meaning. + +query error pgcode 42601 unknown schema 'crdb_internal' +SELECT crdb_internal.check_password_hash_format(('CRDB-BCRYPT$'||'3a$'||'10$'||'vcmoIBvgeHjgScVHWRMWI.Z3v03WMixAw2bBS6qZihljSUuwi88Yq')::bytes) + +query error pgcode 42601 unknown schema 'crdb_internal' +SELECT crdb_internal.check_password_hash_format(('CRDB-BCRYPT$'||'2a$'||'10$'||'vcmoIBvgeHjgScVHWRMWI.Z3v0')::bytes) + +query error pgcode 42601 unknown schema 'crdb_internal' +SELECT crdb_internal.check_password_hash_format(('CRDB-BCRYPT$'||'2a$'||'01$'||'vcmoIBvgeHjgScVHWRMWI.Z3v03WMixAw2bBS6qZihljSUuwi88Yq')::bytes) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.check_password_hash_format(('CRDB-BCRYPT$'||'2a$'||'10$'||'vcmoIBvgeHjgScVHWRMWI.Z3v03WMixAw2bBS6qZihljSUuwi88Yq')::bytes) +---- +crdb-bcrypt + +# Not supported by Materialize. +onlyif cockroach +# Legacy format, only recognized for parsing, not for storing passwords. +query T +SELECT crdb_internal.check_password_hash_format('md5aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') +---- +md5 + +# Not supported by Materialize. +onlyif cockroach +# Not yet supported for storing passwords, but recognized on input. +query T +SELECT crdb_internal.check_password_hash_format(('SCRAM-SHA-256$'||'4096:B5VaTCvCLDzZxSYL829oVA==$'||'3Ako3mNxNtdsaSOJl0Av3i6vyV2OiSP9Ly7famdFSbw=:d7BfSmrtjwbF74mSoOhQiDSpoIvlakXKdpBNb3Meunc=')::bytes) +---- +scram-sha-256 + +subtest session_revival_token + +user host-cluster-root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TENANT ALL SET CLUSTER SETTING server.user_login.session_revival_token.enabled = true + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER parentuser; +GRANT parentuser TO testuser + +skipif config 3node-tenant-default-configs +statement error unknown schema 'crdb_internal' +select crdb_internal.create_session_revival_token() + +onlyif config 3node-tenant +statement error cannot create token for root user +select crdb_internal.create_session_revival_token() + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE token_payload(algorithm STRING, "expiresAt" TIMESTAMPTZ, "issuedAt" TIMESTAMPTZ, "user" STRING) + +# Not supported by Materialize. +onlyif cockroach +# Make sure the token is generated for testuser, not parentuser. +statement ok +SET ROLE parentuser + +# create_session_revival_token requires tenant-signing certs, so it only works +# in 3node-tenant. +onlyif config 3node-tenant +query TTBBBB +WITH + a AS (SELECT crdb_internal.create_session_revival_token() AS token), + b AS ( + SELECT + crdb_internal.pb_to_json( + 'cockroach.sql.sessiondatapb.SessionRevivalToken', + a.token + ) AS json_token + FROM a + ), + c AS ( + SELECT + (json_populate_record( + NULL::token_payload, + crdb_internal.pb_to_json( + 'cockroach.sql.sessiondatapb.SessionRevivalToken.Payload', + decode(b.json_token->>'payload', 'base64'), + true + ) + )).* + FROM b + ) +SELECT + algorithm, + "user", + "expiresAt" > now(), + "expiresAt" < (now() + INTERVAL '11 minutes'), + "expiresAt" > "issuedAt", + crdb_internal.validate_session_revival_token(a.token) +FROM + c, a +---- +Ed25519 testuser true true true true + +user host-cluster-root + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TENANT ALL SET CLUSTER SETTING server.user_login.session_revival_token.enabled = false + +user root + +# Not supported by Materialize. +onlyif cockroach +# test OVERLAPS expression +query B +SELECT overlaps( +TIMESTAMP '2000-01-01 00:00:00', +TIMESTAMP '2000-01-01 01:00:00', +TIMESTAMP '2000-01-01 00:30:00', +TIMESTAMP '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMP '2000-01-01 01:00:00', +TIMESTAMP '2000-01-01 00:00:00', +TIMESTAMP '2000-01-01 00:30:00', +TIMESTAMP '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMP '2000-01-01 00:00:00', +TIMESTAMP '2000-01-01 00:15:00', +TIMESTAMP '2000-01-01 00:30:00', +TIMESTAMP '2000-01-01 01:30:00'); +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMP '2000-01-01 00:00:00', +TIMESTAMP '2000-01-01 00:30:00', +TIMESTAMP '2000-01-01 00:30:00', +TIMESTAMP '2000-01-01 01:30:00'); +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMP '2000-01-01 00:30:00', +TIMESTAMP '2000-01-01 00:30:00', +TIMESTAMP '2000-01-01 00:30:00', +TIMESTAMP '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMPTZ '2000-01-01 00:00:00', +TIMESTAMPTZ '2000-01-01 01:00:00', +TIMESTAMPTZ '2000-01-01 00:30:00', +TIMESTAMPTZ '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMPTZ '2000-01-01 01:00:00', +TIMESTAMPTZ '2000-01-01 00:00:00', +TIMESTAMPTZ '2000-01-01 00:30:00', +TIMESTAMPTZ '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMPTZ '2000-01-01 00:00:00', +TIMESTAMPTZ '2000-01-01 00:15:00', +TIMESTAMPTZ '2000-01-01 00:30:00', +TIMESTAMPTZ '2000-01-01 01:30:00'); +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMPTZ '2000-01-01 00:00:00', +TIMESTAMPTZ '2000-01-01 00:30:00', +TIMESTAMPTZ '2000-01-01 00:30:00', +TIMESTAMPTZ '2000-01-01 01:30:00'); +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMPTZ '2000-01-01 00:30:00', +TIMESTAMPTZ '2000-01-01 00:30:00', +TIMESTAMPTZ '2000-01-01 00:30:00', +TIMESTAMPTZ '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIME '2000-01-01 00:00:00', +TIME '2000-01-01 01:00:00', +TIME '2000-01-01 00:30:00', +TIME '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIME '2000-01-01 01:00:00', +TIME '2000-01-01 00:00:00', +TIME '2000-01-01 00:30:00', +TIME '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIME '2000-01-01 00:00:00', +TIME '2000-01-01 00:15:00', +TIME '2000-01-01 00:30:00', +TIME '2000-01-01 01:30:00'); +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIME '2000-01-01 00:00:00', +TIME '2000-01-01 00:30:00', +TIME '2000-01-01 00:30:00', +TIME '2000-01-01 01:30:00'); +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIME '2000-01-01 00:30:00', +TIME '2000-01-01 00:30:00', +TIME '2000-01-01 00:30:00', +TIME '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMETZ '2000-01-01 00:00:00', +TIMETZ '2000-01-01 01:00:00', +TIMETZ '2000-01-01 00:30:00', +TIMETZ '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMETZ '2000-01-01 01:00:00', +TIMETZ '2000-01-01 00:00:00', +TIMETZ '2000-01-01 00:30:00', +TIMETZ '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMETZ '2000-01-01 00:00:00', +TIMETZ '2000-01-01 00:15:00', +TIMETZ '2000-01-01 00:30:00', +TIMETZ '2000-01-01 01:30:00'); +---- +false -# Sanity-check crdb_internal.check_consistency. +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMETZ '2000-01-01 00:00:00', +TIMETZ '2000-01-01 00:30:00', +TIMETZ '2000-01-01 00:30:00', +TIMETZ '2000-01-01 01:30:00'); +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMETZ '2000-01-01 00:30:00', +TIMETZ '2000-01-01 00:30:00', +TIMETZ '2000-01-01 00:30:00', +TIMETZ '2000-01-01 01:30:00'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +DATE '2000-01-01', +DATE '2000-01-03', +DATE '2000-01-02', +DATE '2000-01-04'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +DATE '2000-01-03', +DATE '2000-01-01', +DATE '2000-01-02', +DATE '2000-01-04'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +DATE '2000-01-01', +DATE '2000-01-02', +DATE '2000-01-03', +DATE '2000-01-04'); +---- +false -statement error start key must be >= "\\x02" -SELECT crdb_internal.check_consistency(true, '\x01', '\xffff') +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +DATE '2000-01-01', +DATE '2000-01-03', +DATE '2000-01-03', +DATE '2000-01-04'); +---- +false -statement error end key must be < "\\xff\\xff" -SELECT crdb_internal.check_consistency(true, '\x02', '\xffff00') +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +DATE '2000-01-03', +DATE '2000-01-03', +DATE '2000-01-03', +DATE '2000-01-04'); +---- +true -statement error start key must be less than end key -SELECT crdb_internal.check_consistency(true, '\x02', '\x02') +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMP '2000-01-01 00:00:00', +INTERVAL '100 days', +TIMESTAMP '2000-01-01 00:30:00', +INTERVAL '30 minutes'); +---- +true -statement error start key must be less than end key -SELECT crdb_internal.check_consistency(true, '\x03', '\x02') +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMP '2000-01-01 00:00:00', +INTERVAL '100 s', +TIMESTAMP '2000-01-01 00:30:00', +INTERVAL '30 minutes'); +---- +false -query ITT -SELECT range_id, status, regexp_replace(detail, '[0-9]+', '', 'g') FROM crdb_internal.check_consistency(true, '\x02', '\xffff') WHERE range_id = 1 +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMP '2000-01-01 00:00:00', +INTERVAL '30 minutes', +TIMESTAMP '2000-01-01 00:30:00', +INTERVAL '30 minutes'); ---- -1 RANGE_CONSISTENT stats: {ContainsEstimates:false LastUpdateNanos: IntentAge: GCBytesAge: LiveBytes: LiveCount: KeyBytes: KeyCount: ValBytes: ValCount: IntentBytes: IntentCount: SysBytes: SysCount: XXX_NoUnkeyedLiteral:{} XXX_sizecache:} +false -# Without explicit keys, scans all ranges (we don't test this too precisely to -# avoid flaking the test when the range count changes, just want to know that -# we're touching multiple ranges). +# Not supported by Materialize. +onlyif cockroach query B -SELECT count(*) > 5 FROM crdb_internal.check_consistency(true, '', '') +SELECT overlaps( +TIMESTAMPTZ '2000-01-01 00:00:00', +INTERVAL '100 days', +TIMESTAMPTZ '2000-01-01 00:30:00', +INTERVAL '30 minutes'); ---- true -# Query that should touch only a single range. +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMPTZ '2000-01-01 00:00:00', +INTERVAL '100 s', +TIMESTAMPTZ '2000-01-01 00:30:00', +INTERVAL '30 minutes'); +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMESTAMPTZ '2000-01-01 00:00:00', +INTERVAL '30 minutes', +TIMESTAMPTZ '2000-01-01 00:30:00', +INTERVAL '30 minutes'); +---- +false + +# Not supported by Materialize. +onlyif cockroach query B -SELECT count(*) = 1 FROM crdb_internal.check_consistency(true, '\x03', '\x0300') +SELECT overlaps( +TIME '2000-01-01 00:00:00', +INTERVAL '2 hours', +TIME '2000-01-01 00:30:00', +INTERVAL '30 minutes'); ---- true -# Ditto, but implicit start key \x02 +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIME '2000-01-01 00:00:00', +INTERVAL '100 s', +TIME '2000-01-01 00:30:00', +INTERVAL '30 minutes'); +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIME '2000-01-01 00:00:00', +INTERVAL '30 minutes', +TIME '2000-01-01 00:30:00', +INTERVAL '30 minutes'); +---- +false + +# Not supported by Materialize. +onlyif cockroach query B -SELECT count(*) = 1 FROM crdb_internal.check_consistency(true, '', '\x0200') +SELECT overlaps( +TIMETZ '00:00:00', +INTERVAL '3 hours', +TIMETZ '00:30:00', +INTERVAL '30 minutes'); ---- true -# Ditto, but implicit end key. +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMETZ '00:00:00', +INTERVAL '100 s', +TIMETZ '00:30:00', +INTERVAL '30 minutes'); +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +TIMETZ '00:00:00', +INTERVAL '30 minutes', +TIMETZ '00:30:00', +INTERVAL '30 minutes'); +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +DATE '2000-01-01', +INTERVAL '3 hours', +DATE '2000-01-02', +INTERVAL '2 days'); +---- +false + +# Not supported by Materialize. +onlyif cockroach query B -SELECT count(*) = 1 FROM crdb_internal.check_consistency(true, '\xff', '') +SELECT overlaps( +DATE '2000-01-01', +INTERVAL '2 days', +DATE '2000-01-02', +INTERVAL '2 days'); ---- true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT overlaps( +DATE '2000-01-01', +INTERVAL '1 day', +DATE '2000-01-02', +INTERVAL '2 days'); +---- +false + +query error function "overlaps" does not exist +SELECT overlaps +(DATE '2000-01-03', +DATE '2000-02-03', +DATE '2000-03-03', +DATE '2000-01-03', +DATE '2000-01-04'); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT overlaps(NULL, NULL, NULL, NULL); +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT overlaps(NULL, INTERVAL '1 day', NULL, NULL); +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT overlaps(DATE '2000-01-01', INTERVAL '1 day', NULL, NULL); +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT overlaps(DATE '2000-01-01', NULL, DATE '2000-01-01', DATE '2000-01-02'); +---- +NULL + +query error function "overlaps" does not exist +SELECT overlaps( +TIMESTAMP '2000-01-01 00:00:00', +TIME '2000-01-01 01:00:00', +TIME '2000-01-01 00:30:00', +TIMESTAMP '2000-01-01 01:30:00'); + +query error function "overlaps" does not exist +SELECT overlaps( +TIMESTAMP '2000-01-01 00:00:00', +INTERVAL '2 days', +DATE '2000-01-01', +TIMESTAMPTZ '2000-01-01 01:30:00'); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT encode(decompress(compress('Hello World', 'gzip'), 'gzip'), 'escape'); +---- +Hello World + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT encode(decompress(compress('Hello World', 'zstd'), 'zstd'), 'escape'); +---- +Hello World + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT encode(decompress(compress('Hello World', 'snappy'), 'snappy'), 'escape'); +---- +Hello World + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT encode(decompress(compress('Hello World', 'lz4'), 'LZ4'), 'escape'); +---- +Hello World + +query error function "decompress" does not exist +SELECT encode(decompress(compress('Hello World', 'snappy'), 'lz4'), 'escape'); + +query error function "compress" does not exist +SELECT compress('Hello World', 'infiniteCompressionCodec'); + +# Not supported by Materialize. +onlyif cockroach +subtest crdb_internal.hide_sql_constants +query T +SELECT crdb_internal.hide_sql_constants('select 1, 2, 3') +---- +SELECT _, _, _ + +# Not supported by Materialize. +onlyif cockroach +# Passing a redacted sql stmt shouldn't have any effect. +query T +SELECT crdb_internal.hide_sql_constants('select _, _, _') +---- +SELECT _, _, _ + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.hide_sql_constants(ARRAY('select 1', NULL, 'select ''hello''', '', 'not a sql stmt')) +---- +{"SELECT _",NULL,"SELECT '_'","",""} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.hide_sql_constants(ARRAY['banana']) +---- +{""} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.hide_sql_constants('SELECT ''yes'' IN (''no'', ''maybe'', ''yes'')') +---- +SELECT '_' IN ('_', '_', __more1_10__) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.hide_sql_constants('') +---- +· + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.hide_sql_constants(NULL) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.hide_sql_constants('not a sql stmt') +---- +· + + +# Not supported by Materialize. +onlyif cockroach +query T +select crdb_internal.hide_sql_constants(e'\r'); +---- +· + + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.hide_sql_constants(create_statement) from crdb_internal.create_statements where descriptor_name = 'foo' +---- +CREATE TABLE public.foo (a INT8 NULL, rowid INT8 NOT NULL NOT VISIBLE DEFAULT unique_rowid(), CONSTRAINT foo_pkey PRIMARY KEY (rowid ASC)) + +# Not supported by Materialize. +onlyif cockroach +# More tests are in parse_ident_builtin_test.go. +query T +SELECT parse_ident(str) FROM ( VALUES + ('a.b.c'), + ('"YesCaps".NoCaps'), + ('"a""b".xyz'), + ('"a\b".xyz') +) tbl(str) +---- +{a,b,c} +{YesCaps,nocaps} +{"a\"b",xyz} +{"a\\b",xyz} + +query T +SELECT parse_ident('ab.xyz()', false) +---- +{ab,xyz} + +query error string is not a valid identifier: \"ab.xyz\(\)\" +SELECT parse_ident('ab.xyz()', true) + +# Test that we return appropriate user-facing errors when trying to decode invalid bytes. +query error pgcode 22023 unknown schema 'crdb_internal' +select crdb_internal.job_payload_type('invalid'::BYTES); + +query error pgcode 22023 unknown schema 'crdb_internal' +select crdb_internal.job_payload_type(''); + +# Not supported by Materialize. +onlyif cockroach +subtest crdb_internal.redactable_sql_constants +query T +SELECT crdb_internal.redactable_sql_constants(NULL) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants('') +---- +‹› + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants('SELECT 1, 2, 3') +---- +SELECT ‹1›, ‹2›, ‹3› + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants('UPDATE mytable SET col = ''abc'' WHERE key = 0') +---- +UPDATE mytable SET col = ‹'abc'› WHERE key = ‹0› + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants('not a sql statement') +---- +‹not a sql statement› + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants('1') +---- +‹1› + +statement error unknown schema 'crdb_internal' +SELECT crdb_internal.redactable_sql_constants(1) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants(ARRAY[]::string[]) +---- +{} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants(ARRAY['']) +---- +{‹›} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants(ARRAY[NULL]) +---- +{NULL} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants(ARRAY['banana']) +---- +{‹banana›} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants(ARRAY['SELECT 1', NULL, 'SELECT ''hello''', '']) +---- +{"SELECT ‹1›",NULL,"SELECT ‹'hello'›",‹›} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants('SELECT ''yes'' IN (''no'', ''maybe'', ''yes'')') +---- +SELECT ‹'yes'› IN (‹'no'›, ‹'maybe'›, ‹'yes'›) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants(e'\r') +---- +‹ +› + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants('SELECT crdb_internal.redactable_sql_constants('''')') +---- +SELECT crdb_internal.redactable_sql_constants(‹''›) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants('WITH j AS (VALUES (0.1, false, ''{}''::jsonb, ARRAY[''x'', ''y'', ''''])) INSERT INTO i SELECT *, 7 FROM j WHERE true') +---- +WITH j AS (VALUES (‹0.1›, ‹false›, ‹'{}'›::JSONB, ARRAY[‹'x'›, ‹'y'›, ‹''›])) INSERT INTO i SELECT *, ‹7› FROM j WHERE ‹true› + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants(create_statement) +FROM crdb_internal.create_statements +WHERE descriptor_name = 'foo' +---- +CREATE TABLE public.foo (a INT8 NULL, rowid INT8 NOT NULL NOT VISIBLE DEFAULT unique_rowid(), CONSTRAINT foo_pkey PRIMARY KEY (rowid ASC)) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE redactable_sql_constants_table ( + a INT PRIMARY KEY, + b STRING DEFAULT 'yo' CHECK (b != 'grapefruit'), + c STRING AS (b || 'foo') VIRTUAL, + FAMILY (a, b), + INDEX (b) WHERE b > 'z' +); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redactable_sql_constants(create_statement) +FROM crdb_internal.create_statements +WHERE descriptor_name = 'redactable_sql_constants_table' +---- +CREATE TABLE public.redactable_sql_constants_table (a INT8 NOT NULL, b STRING NULL DEFAULT ‹'yo'›:::STRING, c STRING NULL AS (b || ‹'foo'›:::STRING) VIRTUAL, CONSTRAINT redactable_sql_constants_table_pkey PRIMARY KEY (a ASC), INDEX redactable_sql_constants_table_b_idx (b ASC) WHERE b > ‹'z'›:::STRING, FAMILY fam_0_a_b (a, b), CONSTRAINT check_b CHECK (b != ‹'grapefruit'›:::STRING)) + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE redactable_sql_constants_table + +subtest crdb_internal.redact + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact(NULL) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact('') +---- +· + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact('0') +---- +0 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact('‹0›') +---- +‹×› + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact('‹‹0››') +---- +‹‹×›› + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact('‹0› ‹0›') +---- +‹×› ‹×› + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact('‹‹0›') +---- +‹‹×› + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact(ARRAY[]::string[]) +---- +{} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact(ARRAY[NULL]) +---- +{NULL} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact(ARRAY['']) +---- +{""} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact(ARRAY['‹0›', '', NULL, '‹0› ‹0›', '‹0']) +---- +{‹×›,"",NULL,"‹×› ‹×›",‹0} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact(crdb_internal.redactable_sql_constants('SELECT 1, 2, 3')) +---- +SELECT ‹×›, ‹×›, ‹×› + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.redact(crdb_internal.redactable_sql_constants(ARRAY['SELECT 1', NULL, 'SELECT ''hello''', ''])) +---- +{"SELECT ‹×›",NULL,"SELECT ‹×›",‹×›} + +subtest check_consistency + +# Sanity-check crdb_internal.check_consistency. + +statement error unknown schema 'crdb_internal' +SELECT crdb_internal.check_consistency(true, '\x00', crdb_internal.tenant_span()[2]) + +statement error unknown schema 'crdb_internal' +SELECT crdb_internal.check_consistency(true, crdb_internal.tenant_span()[1], '\xffff00') + +statement error unknown schema 'crdb_internal' +SELECT crdb_internal.check_consistency(true, crdb_internal.tenant_span()[2], crdb_internal.tenant_span()[2]) + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT status, regexp_replace(detail, '[0-9]+', '', 'g') +FROM crdb_internal.check_consistency(true, crdb_internal.tenant_span()[1], crdb_internal.tenant_span()[2]) +ORDER BY range_id +LIMIT 1 +---- +RANGE_CONSISTENT stats: {ContainsEstimates: LastUpdateNanos: IntentAge: GCBytesAge: LiveBytes: LiveCount: KeyBytes: KeyCount: ValBytes: ValCount: IntentBytes: IntentCount: SeparatedIntentCount: RangeKeyCount: RangeKeyBytes: RangeValCount: RangeValBytes: SysBytes: SysCount: AbortSpanBytes:} + +# Not supported by Materialize. +onlyif cockroach +# Fill a table with consistency check results. This used to panic. +# See: https://github.com/cockroachdb/cockroach/issues/88222 +statement ok +CREATE TABLE conscheckresult AS (SELECT * FROM crdb_internal.check_consistency(false, '', '')); + +subtest end diff --git a/test/sqllogictest/cockroach/bytes.slt b/test/sqllogictest/cockroach/bytes.slt index 0b3cd30eb95b3..2e648a479cee2 100644 --- a/test/sqllogictest/cockroach/bytes.slt +++ b/test/sqllogictest/cockroach/bytes.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,144 +9,219 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/bytes +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/bytes # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -# query T -# SHOW bytea_output -# ---- -# hex +# Not supported by Materialize. +onlyif cockroach +query T +SHOW bytea_output +---- +hex +# Not supported by Materialize. +onlyif cockroach query T -SELECT 'non-escaped-string'::bytea::text +SELECT 'non-escaped-string':::BYTES::STRING ---- \x6e6f6e2d657363617065642d737472696e67 -# TODO(benesch): support escape string literals. -# -# query T -# SELECT e'\x5c\x78'::text -# ---- -# \x -# -# query T -# SELECT e'a\\134b\nc\'e'::text::bytea::text -# ---- -# \x615c620a632765 +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '\Xabcd':::BYTES::STRING +---- +\xabcd +# Not supported by Materialize. +onlyif cockroach +query T +SELECT b'\x5c\x78':::BYTES +---- +\x + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT b'\x5c\x78':::BYTES::STRING +---- +\x5c78 +# Not supported by Materialize. +onlyif cockroach query T -SELECT '日本語'::text::bytea::text +SELECT b'\x5c\x58':::BYTES::STRING +---- +\x5c58 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT e'\x5c\x78'::STRING +---- +\x + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '\X':::BYTES::STRING +---- +\x + +query T +SELECT e'a\\134b\nc\'e'::STRING::BYTES::STRING +---- +\x615c620a632765 + + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '日本語':::STRING::BYTES::STRING ---- \xe697a5e69cace8aa9e -query error invalid input syntax for type bytea: invalid escape sequence +query error invalid input syntax for type bytea: invalid escape sequence: "\\400" SELECT '\400'::bytea -# TODO(benesch): support bytea_output. -# -# statement ok -# SET bytea_output = escape -# -# query T -# SELECT 'non-escaped-text'::bytea::text -# ---- -# non-escaped-text -# -# query T -# SELECT '\Xabcd'::bytea::text -# ---- -# \253\315 -# -# query T -# SELECT b'\x5c\x78'::bytea -# ---- -# \x -# -# query T -# SELECT b'\x5c\x78'::bytea::text -# ---- -# \\x -# -# query T -# SELECT b'\x5c\x58'::bytea::text -# ---- -# \\X -# -# query T -# SELECT e'\x5c\x78'::text -# ---- -# \x -# -# query T -# SELECT '\X'::bytea::text -# ---- -# · -# -# query T -# SELECT e'a\\134b\nc\'e'::text::bytea::text -# ---- -# a\\b\012c'e -# -# query T -# SELECT '日本語'::text::bytea::text -# ---- -# \346\227\245\346\234\254\350\252\236 +statement ok +SET bytea_output = escape + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT 'non-escaped-string':::BYTES::STRING +---- +non-escaped-string + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '\Xabcd':::BYTES::STRING +---- +\253\315 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT b'\x5c\x78':::BYTES +---- +\x + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT b'\x5c\x78':::BYTES::STRING +---- +\\x + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT b'\x5c\x58':::BYTES::STRING +---- +\\X + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT e'\x5c\x78'::STRING +---- +\x + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '\X':::BYTES::STRING +---- +· + +query T +SELECT e'a\\134b\nc\'e'::STRING::BYTES::STRING +---- +\x615c620a632765 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '日本語':::STRING::BYTES::STRING +---- +\346\227\245\346\234\254\350\252\236 subtest Regression_25841 -# statement ok -# set bytea_output = hex +statement ok +set bytea_output = hex query T -SELECT 'a\\b'::text::bytea +SELECT e'a\\\\b'::STRING::BYTEA ---- a\b query I -SELECT length('a\\b'::text::bytea) +SELECT length(e'a\\\\b'::STRING::BYTEA) ---- 3 -query error invalid input syntax for type bytea: invalid escape sequence -SELECT 'a\bcde'::text::bytea - -query error invalid input syntax for type bytea: invalid escape sequence -SELECT 'a\01'::text::bytea +query error invalid input syntax for type bytea: invalid escape sequence: "a\\bcde" +SELECT e'a\\bcde'::STRING::BYTEA -query error invalid input syntax for type bytea: ends with escape character -SELECT 'a\'::text::bytea +query error invalid input syntax for type bytea: invalid escape sequence: "a\\01" +SELECT e'a\\01'::STRING::BYTEA subtest Regression_27950 -# statement ok -# set bytea_output = hex - statement ok -CREATE TABLE t(b bytea) +set bytea_output = hex statement ok -INSERT INTO t(b) VALUES ('\xe697a5e69cace8aa9e'::bytea) +CREATE TABLE t(b BYTES); INSERT INTO t(b) VALUES ('\xe697a5e69cace8aa9e'::BYTES) query TT -SELECT b, b::text FROM t +SELECT b, b::STRING FROM t ---- 日本語 \xe697a5e69cace8aa9e -# statement ok -# set bytea_output = escape -# -# query TT -# SELECT b, b::text FROM t -# ---- -# 日本語 \346\227\245\346\234\254\350\252\236 +statement ok +set bytea_output = escape + +query TT +SELECT b, b::STRING FROM t +---- +日本語 \xe697a5e69cace8aa9e statement ok DROP TABLE t + +subtest Regression_4312 + +# Not supported by Materialize. +onlyif cockroach +statement ok +PREPARE r1(bytes) AS SELECT descriptor::STRING FROM system.descriptor WHERE descriptor != $1 ORDER BY descriptor DESC LIMIT 1 + +# Not supported by Materialize. +onlyif cockroach +query T +EXECUTE r1('abc') +---- +\022Y\012\011defaultdb\020d\0320\012\013\012\005admin\020\002\030\002\012\015\012\006public\020\200\020\030\000\012\012\012\004root\020\002\030\002\022\004root\030\002"\000(\001:\014\012\006public\022\002\010e@\000J\000Z\002\020\000 + +statement ok +create table regression_71444 (col bytes[]); +insert into regression_71444 VALUES ('{"a"}'), ('{"b", "c"}') + +query T +SELECT * FROM regression_71444 WHERE col = '{"a"}' +---- +{"\\x61"} diff --git a/test/sqllogictest/cockroach/case_sensitive_names.slt b/test/sqllogictest/cockroach/case_sensitive_names.slt index bd4d2f4a86ad9..d44473abe0283 100644 --- a/test/sqllogictest/cockroach/case_sensitive_names.slt +++ b/test/sqllogictest/cockroach/case_sensitive_names.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,40 +9,42 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/case_sensitive_names +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/case_sensitive_names # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - # Case sensitivity of database names -# statement ok -# CREATE DATABASE D +statement ok +CREATE DATABASE D -# statement ok -# SHOW TABLES FROM d +# Not supported by Materialize. +onlyif cockroach +statement ok +SHOW TABLES FROM d -# statement error target database or schema does not exist -# SHOW TABLES FROM "D" +statement error unknown schema 'D' +SHOW TABLES FROM "D" -# statement ok -# CREATE DATABASE "E" +statement ok +CREATE DATABASE "E" -# statement error target database or schema does not exist -# SHOW TABLES FROM e +statement error unknown schema 'e' +SHOW TABLES FROM e -# statement ok -# SHOW TABLES FROM "E" +# Not supported by Materialize. +onlyif cockroach +statement ok +SHOW TABLES FROM "E" # Case sensitivity of table names: # When non-quoted, table names are normalized during creation. @@ -53,35 +55,35 @@ CREATE TABLE A(x INT) statement error pgcode 42P01 unknown catalog item 'A' SHOW COLUMNS FROM "A" -statement error pgcode 42P01 unknown catalog item 'A' -SHOW INDEXES ON "A" +statement error pgcode 42P01 unknown schema 'A' +SHOW INDEXES FROM "A" -# statement error pgcode 42P01 catalog item '"A"' does not exist -# SHOW CREATE TABLE "A" +statement error pgcode 42P01 unknown catalog item 'A' +SHOW CREATE TABLE "A" -# statement error pgcode 42P01 catalog item '"A"' does not exist -# SHOW GRANTS ON TABLE "A" +statement error pgcode 42P01 Expected end of statement, found ON +SHOW GRANTS ON TABLE "A" -# statement error pgcode 42P01 catalog item '"test.A"' does not exist -# SHOW GRANTS ON TABLE test."A" +statement error pgcode 42P01 Expected end of statement, found ON +SHOW GRANTS ON TABLE test."A" -# statement error pgcode 42P01 catalog item '"A"' does not exist -# SHOW CONSTRAINTS FROM "A" +statement error pgcode 42P01 Expected end of statement, found FROM +SHOW CONSTRAINTS FROM "A" statement error pgcode 42P01 unknown catalog item 'A' SELECT * FROM "A" -# statement error pgcode 42P01 catalog item '"A"' does not exist -# INSERT INTO "A"(x) VALUES(1) +statement error pgcode 42P01 unknown catalog item 'A' +INSERT INTO "A"(x) VALUES(1) -# statement error pgcode 42P01 catalog item '"A"' does not exist -# UPDATE "A" SET x = 42 +statement error pgcode 42P01 unknown catalog item 'A' +UPDATE "A" SET x = 42 -# statement error pgcode 42P01 catalog item '"A"' does not exist -# DELETE FROM "A" +statement error pgcode 42P01 unknown catalog item 'A' +DELETE FROM "A" -# statement error pgcode 42P01 catalog item '"A"' does not exist -# TRUNCATE "A" +statement error pgcode 42P01 Expected a keyword at the beginning of a statement, found identifier "truncate" +TRUNCATE "A" statement error pgcode 42P01 unknown catalog item 'A' DROP TABLE "A" @@ -89,14 +91,18 @@ DROP TABLE "A" statement ok SHOW COLUMNS FROM a +# Not supported by Materialize. +onlyif cockroach statement ok -SHOW INDEXES ON a +SHOW INDEXES FROM a -# statement ok -# SHOW CREATE TABLE a +statement ok +SHOW CREATE TABLE a -# statement ok -# SHOW CONSTRAINTS FROM a +# Not supported by Materialize. +onlyif cockroach +statement ok +SHOW CONSTRAINTS FROM a statement ok SELECT * FROM a @@ -110,8 +116,10 @@ UPDATE a SET x = 42 statement ok DELETE FROM a -# statement ok -# TRUNCATE a +# Not supported by Materialize. +onlyif cockroach +statement ok +TRUNCATE a statement ok DROP TABLE a @@ -125,35 +133,35 @@ CREATE TABLE "B"(x INT) statement error pgcode 42P01 unknown catalog item 'b' SHOW COLUMNS FROM B -statement error pgcode 42P01 unknown catalog item 'b' -SHOW INDEXES ON B +statement error pgcode 42P01 unknown schema 'b' +SHOW INDEXES FROM B -# statement error pgcode 42P01 catalog item 'b' does not exist -# SHOW CREATE TABLE B +statement error pgcode 42P01 unknown catalog item 'b' +SHOW CREATE TABLE B -# statement error pgcode 42P01 catalog item 'b' does not exist -# SHOW GRANTS ON TABLE B +statement error pgcode 42P01 Expected end of statement, found ON +SHOW GRANTS ON TABLE B -# statement error pgcode 42P01 catalog item 'test.b' does not exist -# SHOW GRANTS ON TABLE test.B +statement error pgcode 42P01 Expected end of statement, found ON +SHOW GRANTS ON TABLE test.B -# statement error pgcode 42P01 catalog item 'b' does not exist -# SHOW CONSTRAINTS FROM B +statement error pgcode 42P01 Expected end of statement, found FROM +SHOW CONSTRAINTS FROM B statement error pgcode 42P01 unknown catalog item 'b' SELECT * FROM B -# statement error pgcode 42P01 catalog item 'b' does not exist -# INSERT INTO B(x) VALUES(1) +statement error pgcode 42P01 unknown catalog item 'b' +INSERT INTO B(x) VALUES(1) -# statement error pgcode 42P01 catalog item 'b' does not exist -# UPDATE B SET x = 42 +statement error pgcode 42P01 unknown catalog item 'b' +UPDATE B SET x = 42 -# statement error pgcode 42P01 catalog item 'b' does not exist -# DELETE FROM B +statement error pgcode 42P01 unknown catalog item 'b' +DELETE FROM B -# statement error pgcode 42P01 catalog item 'b' does not exist -# TRUNCATE B +statement error pgcode 42P01 Expected a keyword at the beginning of a statement, found identifier "truncate" +TRUNCATE B statement error pgcode 42P01 unknown catalog item 'b' DROP TABLE B @@ -161,20 +169,28 @@ DROP TABLE B statement ok SHOW COLUMNS FROM "B" +# Not supported by Materialize. +onlyif cockroach statement ok -SHOW INDEXES ON "B" +SHOW INDEXES FROM "B" -# statement ok -# SHOW CREATE TABLE "B" +statement ok +SHOW CREATE TABLE "B" -# statement ok -# SHOW GRANTS ON TABLE "B" +# Not supported by Materialize. +onlyif cockroach +statement ok +SHOW GRANTS ON TABLE "B" -# statement ok -# SHOW GRANTS ON TABLE test."B" +# Not supported by Materialize. +onlyif cockroach +statement ok +SHOW GRANTS ON TABLE test."B" -# statement ok -# SHOW CONSTRAINTS FROM "B" +# Not supported by Materialize. +onlyif cockroach +statement ok +SHOW CONSTRAINTS FROM "B" statement ok SELECT * FROM "B" @@ -188,8 +204,10 @@ UPDATE "B" SET x = 42 statement ok DELETE FROM "B" -# statement ok -# TRUNCATE "B" +# Not supported by Materialize. +onlyif cockroach +statement ok +TRUNCATE "B" statement ok DROP TABLE "B" @@ -197,83 +215,36 @@ DROP TABLE "B" # Case sensitivity of column names. statement ok -CREATE TABLE foo(X INT, "Y" INT, "created_AT" timestamp) +CREATE TABLE foo(X INT, "Y" INT) query III colnames SELECT x, X, "Y" FROM foo ---- x x Y -statement error column "X" does not exist\nHINT: The similarly named column "x" does exist. +statement error column "X" does not exist SELECT "X" FROM foo -statement error column "y" does not exist\nHINT: The similarly named column "Y" does exist. +statement error column "y" does not exist SELECT Y FROM foo -simple -SELECT creaetd_at FROM foo ----- -db error: ERROR: column "creaetd_at" does not exist -HINT: The similarly named column "created_AT" does exist. Make sure to surround case sensitive names in double quotes. - # The following should not be ambiguous. query II colnames SELECT Y, "Y" FROM (SELECT x as y, "Y" FROM foo) ---- y Y -statement ok -CREATE TABLE foo_multi_case ("cAsE" INT, "CASE" INT) - -statement error ERROR: column "foo_multi_case.case" does not exist\nHINT: There are similarly named columns that do exist: "foo_multi_case.cAsE", "foo_multi_case.CASE". Make sure to surround case sensitive names in double quotes. -SELECT foo_multi_case.case FROM foo_multi_case; - -statement ok -CREATE TABLE j1 ("X" int); - -statement ok -INSERT INTO j1 VALUES (1), (2), (3); - -statement ok -CREATE TABLE j2 ("X" int, "Y" int); - -statement ok -INSERT INTO j2 VALUES (1, 5), (2, 7), (8, 9); - -statement ok -CREATE TABLE j3 ("X" int, "Z" int); - -statement ok -INSERT INTO j3 VALUES (1, 7), (10, 11), (12, 13); - -statement error column "Y" does not exist\nHINT: The similarly named column "y" does exist. -SELECT "Y" FROM ( SELECT "X" as y FROM j1 NATURAL JOIN j2 ); - -query I -SELECT y FROM ( SELECT "X" as y FROM j1 NATURAL JOIN j2 ); ----- -1 -2 - -# Even though the column "Y" exists, it should not get suggested since it's not in scope. - -statement error column "y" does not exist -SELECT "X", y FROM j1 LEFT JOIN ( SELECT "X", "Z" FROM j2 LEFT JOIN j3 USING ("X") ) USING ("X"); - # Case sensitivity of view names. -mode standard - statement ok CREATE VIEW XV AS SELECT X, "Y" FROM foo query TT SHOW CREATE VIEW xv ---- -materialize.public.xv -CREATE VIEW materialize.public.xv AS SELECT x, "Y" FROM materialize.public.foo; +materialize.public.xv CREATE␠VIEW␠materialize.public.xv␠AS␠SELECT␠x,␠"Y"␠FROM␠materialize.public.foo; -query error unknown catalog item 'XV' +query error pgcode 42P01 unknown catalog item 'XV' SHOW CREATE VIEW "XV" statement ok @@ -282,81 +253,66 @@ CREATE VIEW "YV" AS SELECT X, "Y" FROM foo query TT SHOW CREATE VIEW "YV" ---- -materialize.public.YV -CREATE VIEW materialize.public."YV" AS SELECT x, "Y" FROM materialize.public.foo; +materialize.public.YV CREATE␠VIEW␠materialize.public."YV"␠AS␠SELECT␠x,␠"Y"␠FROM␠materialize.public.foo; -query error unknown catalog item 'yv' +query error pgcode 42P01 unknown catalog item 'yv' SHOW CREATE VIEW YV -mode cockroach - # Case sensitivity of index names. statement ok -CREATE TABLE a(x INT, y INT, CONSTRAINT FooIdx PRIMARY KEY(x)) - -statement ok -CREATE INDEX I ON a(y) - -# statement error index "I" not found -# SELECT * FROM a@"I" - -# statement error index "FooIdx" not found -# SELECT * FROM a@"FooIdx" - -# statement error index "I" not found -# SELECT * FROM a ORDER BY INDEX a@"I" - -# statement error index "FooIdx" not found -# SELECT * FROM a ORDER BY INDEX a@"FooIdx" +CREATE TABLE a(x INT, y INT, CONSTRAINT Foo PRIMARY KEY(x)); CREATE INDEX I ON a(y) -# statement error index "I" does not exist -# DROP INDEX a@"I" +statement error Expected end of statement, found operator "@" +SELECT * FROM a@"I" -# statement ok -# SELECT * FROM a@I +statement error Expected end of statement, found operator "@" +SELECT * FROM a@"Foo" -# statement ok -# SELECT * FROM a@FooIdx +statement error Expected end of statement, found identifier "a" +SELECT * FROM a ORDER BY INDEX a@"I" -# statement ok -# SELECT * FROM a ORDER BY INDEX a@I +statement error Expected end of statement, found identifier "a" +SELECT * FROM a ORDER BY INDEX a@"Foo" -# statement ok -# SELECT * FROM a ORDER BY INDEX a@FooIdx +statement error Expected end of statement, found operator "@" +DROP INDEX a@"I" +# Not supported by Materialize. +onlyif cockroach statement ok -DROP INDEX I - -# Unicode sequences are preserved. +SELECT * FROM a@I +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE Amelie("Amélie" INT, "Amélie" INT) +SELECT * FROM a@Foo +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO Amelie VALUES (1, 2) +SELECT * FROM a ORDER BY INDEX a@I -# # Check that the column names were encoded properly -# query I -# SELECT ordinal_position FROM information_schema.columns WHERE table_name = 'amelie' AND column_name::BYTES = b'Ame\xcc\x81lie' -# ---- -# 1 +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM a ORDER BY INDEX a@Foo -# query I -# SELECT ordinal_position FROM information_schema.columns WHERE table_name = 'amelie' AND column_name::BYTES = b'Am\xc3\xa9lie' -# ---- -# 2 +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX a@I -# Check that the non-normalized names propagate throughout until results. +# Unicode sequences are preserved. -query II colnames -SELECT "Amélie", "Amélie" FROM Amelie ----- -Amélie Amélie -2 1 +# Not supported by Materialize. +onlyif cockroach +# Check that normalization occurs +statement error duplicate column name: "Amélie" +CREATE TABLE Amelie("Amélie" INT, "Amélie" INT); INSERT INTO Amelie VALUES (1, 2) # Check that function names are also recognized case-insensitively. -query T -SELECT AsCIi('abc') +query I +SELECT LENGTH('abc') -- lint: uppercase function OK ---- -97 +3 diff --git a/test/sqllogictest/cockroach/collatedstring.slt b/test/sqllogictest/cockroach/collatedstring.slt index 340c1865a395f..d0584943903ad 100644 --- a/test/sqllogictest/cockroach/collatedstring.slt +++ b/test/sqllogictest/cockroach/collatedstring.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,209 +9,296 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/collatedstring +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/collatedstring # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach -statement error pq: invalid locale bad_locale: language: subtag "locale" is well-formed but unknown +statement error COLLATE not yet supported SELECT 'a' COLLATE bad_locale -statement error pq: unsupported comparison operator: = +statement error COLLATE not yet supported SELECT 'A' COLLATE en = 'a' -statement error pq: unsupported comparison operator: = +statement error COLLATE not yet supported SELECT 'A' COLLATE en = 'a' COLLATE de -statement error pq: unsupported comparison operator: \('a' COLLATE en_u_ks_level1\) IN \('A' COLLATE en_u_ks_level1, 'b' COLLATE en\): expected 'b' COLLATE en to be of type collatedstring{en_u_ks_level1}, found type collatedstring{en} +statement error COLLATE not yet supported SELECT ('a' COLLATE en_u_ks_level1) IN ('A' COLLATE en_u_ks_level1, 'b' COLLATE en) -statement error pq: tuples \('a' COLLATE en_u_ks_level1, 'a' COLLATE en\), \('A' COLLATE en, 'B' COLLATE en\) are not comparable at index 1: unsupported comparison operator: < 'a' COLLATE en_u_ks_level1 ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 'A' COLLATE en_u_ks_level1 < 'a' COLLATE en_u_ks_level1 ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 'A' COLLATE en_u_ks_level1 >= 'a' COLLATE en_u_ks_level1 ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 'A' COLLATE en_u_ks_level1 <= 'a' COLLATE en_u_ks_level1 ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 'A' COLLATE en_u_ks_level1 > 'a' COLLATE en_u_ks_level1 ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 'a' COLLATE en_u_ks_level1 = 'B' COLLATE en_u_ks_level1 ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 'a' COLLATE en_u_ks_level1 <> 'B' COLLATE en_u_ks_level1 ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 'a' COLLATE en_u_ks_level1 < 'B' COLLATE en_u_ks_level1 ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 'a' COLLATE en_u_ks_level1 >= 'B' COLLATE en_u_ks_level1 ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 'a' COLLATE en_u_ks_level1 <= 'B' COLLATE en_u_ks_level1 ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 'a' COLLATE en_u_ks_level1 > 'B' COLLATE en_u_ks_level1 ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 'B' COLLATE en_u_ks_level1 = 'A' COLLATE en_u_ks_level1 ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 'B' COLLATE en_u_ks_level1 <> 'A' COLLATE en_u_ks_level1 ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 'B' COLLATE en_u_ks_level1 < 'A' COLLATE en_u_ks_level1 ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 'B' COLLATE en_u_ks_level1 >= 'A' COLLATE en_u_ks_level1 ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 'B' COLLATE en_u_ks_level1 <= 'A' COLLATE en_u_ks_level1 ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 'B' COLLATE en_u_ks_level1 > 'A' COLLATE en_u_ks_level1 ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT ('a' COLLATE en_u_ks_level1) IN ('A' COLLATE en_u_ks_level1, 'b' COLLATE en_u_ks_level1) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT ('a' COLLATE en_u_ks_level1) NOT IN ('A' COLLATE en_u_ks_level1, 'b' COLLATE en_u_ks_level1) ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT ('a' COLLATE en) IN ('A' COLLATE en, 'b' COLLATE en) ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT ('a' COLLATE en) NOT IN ('A' COLLATE en, 'b' COLLATE en) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 'Fussball' COLLATE de = 'Fußball' COLLATE de ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 'Fussball' COLLATE de_u_ks_level1 = 'Fußball' COLLATE de_u_ks_level1 ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 'ü' COLLATE da < 'x' COLLATE da ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 'ü' COLLATE de < 'x' COLLATE de ---- true -statement error invalid locale e: language: tag is not well-formed at or near "\)" +# Not supported by Materialize. +onlyif cockroach +statement error syntax error: invalid locale e: language: tag is not well-formed CREATE TABLE e1 ( a STRING COLLATE e ) -statement error multiple COLLATE declarations for column "a" at or near "\)" +statement error Expected column option, found COLLATE CREATE TABLE e2 ( a STRING COLLATE en COLLATE de ) -statement error COLLATE declaration for non-string-typed column "a" at or near "\)" +# Not supported by Materialize. +onlyif cockroach +statement error COLLATE declaration for non-string-typed column "a" CREATE TABLE e3 ( a INT COLLATE en ) @@ -224,11 +311,10 @@ CREATE TABLE t ( query TT SHOW CREATE TABLE t ---- -t CREATE TABLE t ( - a STRING COLLATE en NULL, - FAMILY "primary" (a, rowid) - ) +materialize.public.t CREATE␠TABLE␠materialize.public.t␠(a␠pg_catalog.text␠COLLATE␠en); +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO t VALUES ('A' COLLATE en), @@ -238,19 +324,20 @@ INSERT INTO t VALUES ('x' COLLATE en), ('ü' COLLATE en) -statement error value type collatedstring{de} doesn't match type collatedstring{en} of column "a" -INSERT INTO t VALUES ('X' COLLATE de) +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t VALUES + ('X' COLLATE de), + ('y' COLLATE de) query T SELECT a FROM t ORDER BY t.a ---- -a -A -b -B -ü -x + +# Not supported by Materialize. +onlyif cockroach query T SELECT a FROM t ORDER BY t.a COLLATE da ---- @@ -259,53 +346,82 @@ A b B x +X +y ü +# Not supported by Materialize. +onlyif cockroach query T SELECT a FROM t WHERE a = 'A' COLLATE en; ---- A +# Not supported by Materialize. +onlyif cockroach query T SELECT 'a' COLLATE en::STRING || 'b' ---- ab +# Not supported by Materialize. +onlyif cockroach +query T +SELECT 'a🐛b🏠c' COLLATE en::VARCHAR(3) +---- +a🐛b + +# Not supported by Materialize. +onlyif cockroach query B SELECT 't' COLLATE en::BOOLEAN ---- true +# Not supported by Materialize. +onlyif cockroach query I SELECT '42' COLLATE en::INTEGER ---- 42 +# Not supported by Materialize. +onlyif cockroach query R SELECT '42.0' COLLATE en::FLOAT ---- 42 +# Not supported by Materialize. +onlyif cockroach query R SELECT '42.0' COLLATE en::DECIMAL ---- 42.0 +# Not supported by Materialize. +onlyif cockroach query T SELECT 'a' COLLATE en::BYTES ---- a +# Not supported by Materialize. +onlyif cockroach query T SELECT '2017-01-10 16:05:50.734049+00:00' COLLATE en::TIMESTAMP ---- 2017-01-10 16:05:50.734049 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2017-01-10 16:05:50.734049+00:00' COLLATE en::TIMESTAMPTZ ---- 2017-01-10 16:05:50.734049 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '40 days' COLLATE en::INTERVAL ---- @@ -314,9 +430,13 @@ SELECT '40 days' COLLATE en::INTERVAL statement ok CREATE TABLE foo(a STRING COLLATE en_u_ks_level2) +# Not supported by Materialize. +onlyif cockroach statement ok PREPARE x AS INSERT INTO foo VALUES ($1 COLLATE en_u_ks_level2) RETURNING a +# Not supported by Materialize. +onlyif cockroach query T EXECUTE x(NULL) ---- @@ -325,18 +445,24 @@ NULL query T SELECT a FROM foo ---- -NULL -# Regression test for database-issues#7300 +# Regression test for #24449 + +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO foo VALUES ('aBcD' COLLATE en_u_ks_level2) +# Not supported by Materialize. +onlyif cockroach query T SELECT * FROM foo WHERE a = 'aBcD' COLLATE en_u_ks_level2 ---- aBcD +# Not supported by Materialize. +onlyif cockroach query T SELECT * FROM foo WHERE a = 'abcd' COLLATE en_u_ks_level2 ---- @@ -344,23 +470,255 @@ aBcD # Test quoted collations. +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE quoted_coll ( a STRING COLLATE "en", b STRING COLLATE "en_US", c STRING COLLATE "en-Us" DEFAULT ('c' COLLATE "en-Us"), d STRING COLLATE "en-u-ks-level1" DEFAULT ('d'::STRING COLLATE "en-u-ks-level1"), - e STRING COLLATE "en-us" AS (a COLLATE "en-us") STORED + e STRING COLLATE "en-us" AS (a COLLATE "en-us") STORED, + FAMILY "primary" (a, b, c, d, e, rowid) ) +# Not supported by Materialize. +onlyif cockroach query TT SHOW CREATE TABLE quoted_coll ---- -quoted_coll CREATE TABLE quoted_coll ( - a STRING COLLATE en NULL, - b STRING COLLATE en_US NULL, - c STRING COLLATE en_Us NULL DEFAULT 'c':::STRING COLLATE en_Us, - d STRING COLLATE en_u_ks_level1 NULL DEFAULT 'd':::STRING::STRING COLLATE en_u_ks_level1, - e STRING COLLATE en_us NULL AS (a COLLATE en_us) STORED, - FAMILY "primary" (a, b, c, d, e, rowid) +quoted_coll CREATE TABLE public.quoted_coll ( + a STRING COLLATE en NULL, + b STRING COLLATE en_US NULL, + c STRING COLLATE en_US NULL DEFAULT 'c':::STRING COLLATE en_US, + d STRING COLLATE en_u_ks_level1 NULL DEFAULT 'd':::STRING COLLATE en_u_ks_level1, + e STRING COLLATE en_US NULL AS (a COLLATE en_US) STORED, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT quoted_coll_pkey PRIMARY KEY (rowid ASC) + ) + +# Not supported by Materialize. +onlyif cockroach +# Regression for #46570. +statement ok +CREATE TABLE t46570(c0 BOOL, c1 STRING COLLATE en); +CREATE INDEX ON t46570(rowid, c1 DESC); +INSERT INTO t46570(c1, rowid) VALUES('' COLLATE en, 0); +UPSERT INTO t46570(rowid) VALUES (0), (1) + +# Test trailing spaces are truncated for char types. +subtest regression_50015 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT + t +FROM + ( + VALUES + ('hello '::CHAR(100) COLLATE en_US), + ('hello t'::CHAR(100) COLLATE en_US), + ('hello '::STRING::CHAR(100) COLLATE en_US), + ('hello t'::STRING::CHAR(100) COLLATE en_US) + ) g(t) +---- +hello +hello t +hello +hello t + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t50015(id int PRIMARY KEY, a char(100), b char(100) COLLATE en); +INSERT INTO t50015 VALUES + (1, 'hello', 'hello' COLLATE en), + (2, 'hello ', 'hello ' COLLATE en), + (3, repeat('hello ', 2), repeat('hello ', 2) COLLATE en) + +# Not supported by Materialize. +onlyif cockroach +query ITITI +SELECT id, a, length(a), b, length(b::string) FROM t50015 ORDER BY id ASC +---- +1 hello 5 hello 5 +2 hello 5 hello 5 +3 hello hello 11 hello hello 11 + +statement ok +CREATE TABLE t54989( + no_collation_str text, + no_collation_str_array text[], + collated_str text COLLATE en, + default_collation text COLLATE "default" ) + +query TT +SELECT + a.attname AS column_name, + collname AS collation +FROM pg_attribute a +LEFT JOIN pg_collation co ON a.attcollation = co.oid +JOIN pg_class c ON a.attrelid = c.oid +JOIN pg_namespace n ON c.relnamespace = n.oid +WHERE c.relname = 't54989' +ORDER BY column_name +---- +collated_str NULL +default_collation NULL +no_collation_str NULL +no_collation_str_array NULL + +# Not supported by Materialize. +onlyif cockroach +# "default", "C", and "POSIX" all behave the same as normal strings when +# used in an expression. +query BBB +SELECT 'cat' = ('cat'::text collate "default"), 'cat' = ('cat'::VARCHAR(64) collate "C"), 'cat' = ('cat'::CHAR(3) collate "POSIX") +---- +true true true + +statement ok +INSERT INTO t54989 VALUES ('a', '{b}', 'c', 'd') + +# Not supported by Materialize. +onlyif cockroach +query BB +SELECT default_collation = 'd' COLLATE "C", no_collation_str = 'a' COLLATE "POSIX" FROM t54989 +---- +true true + +# Not supported by Materialize. +onlyif cockroach +# Creating a "C" or "POSIX" column is not allowed. In the future, we may +# add better support for collations, and it would be hard to do that if we +# start allowing columns like these. +statement error invalid locale C: language: tag is not well-formed +CREATE TABLE disallowed(a text COLLATE "C") + +# Not supported by Materialize. +onlyif cockroach +statement error invalid locale POSIX: language: tag is not well-formed +CREATE TABLE disallowed(a text COLLATE "POSIX") + +# Regression test for collated string lowercase and hyphen/underscore equality. +subtest nocase_strings + +statement ok +CREATE TABLE nocase_strings (s STRING COLLATE "en-US-u-ks-level2"); + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO nocase_strings VALUES ('Aaa' COLLATE "en-US-u-ks-level2"), ('Bbb' COLLATE "en-US-u-ks-level2"); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT s FROM nocase_strings WHERE s = ('bbb' COLLATE "en-US-u-ks-level2") +---- +Bbb + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT s FROM nocase_strings WHERE s = ('bbb' COLLATE "en-us-u-ks-level2") +---- +Bbb + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT s FROM nocase_strings WHERE s = ('bbb' COLLATE "en_US_u_ks_level2") +---- +Bbb + +statement ok +CREATE TABLE collation_name_case (s STRING COLLATE en_us_u_ks_level2); + +query TT +SHOW CREATE TABLE collation_name_case +---- +materialize.public.collation_name_case CREATE␠TABLE␠materialize.public.collation_name_case␠(s␠pg_catalog.text␠COLLATE␠en_us_u_ks_level2); + +statement error table "materialize\.public\.nocase_strings" already exists +CREATE TABLE nocase_strings (s STRING COLLATE "en-US-u-ks-le""vel2"); + +statement error unterminated quoted identifier +CREATE TABLE nocase_strings (s STRING COLLATE "en-US-u-ks-le"vel2"); + +statement error WHERE clause error: COLLATE not yet supported +SELECT s FROM nocase_strings WHERE s = ('bbb' COLLATE "en-us-u-ks-l""evel2") + +statement error unterminated quoted identifier +SELECT s FROM nocase_strings WHERE s = ('bbb' COLLATE "en-us-u-ks-l"evel2") + +statement ok +CREATE TABLE nocase_strings2 ( + i INT, + s STRING COLLATE "en-US-u-ks-level2" +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO nocase_strings2 VALUES (1, 'Aaa' COLLATE "en-US-u-ks-level2"), (2, 'Bbb' COLLATE "en-US-u-ks-level2"); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT s FROM nocase_strings2 WHERE s = ('bbb' COLLATE "en-US-u-ks-level2") +---- +Bbb + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT s FROM nocase_strings2 WHERE s = ('bbb' COLLATE "en-us-u-ks-level2") +---- +Bbb + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT s FROM nocase_strings2 WHERE s = ('bbb' COLLATE "en_US_u_ks_level2") +---- +Bbb + +# Test "char" is supposed to truncate long values +subtest char_long_values + +statement ok +CREATE TABLE t65631(a "char", b "char" COLLATE en) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t65631 VALUES ('abc', 'abc' COLLATE en) + +query TT +SELECT a, b FROM t65631 +---- + + +subtest regression_45142 + +statement ok +CREATE TABLE t45142(c STRING COLLATE en); + +# Not supported by Materialize. +onlyif cockroach +query error unsupported comparison operator +SELECT * FROM t45142 WHERE c < SOME ('' COLLATE de, '' COLLATE en); + +# Not supported by Materialize. +onlyif cockroach +query error unsupported comparison operator +SELECT * FROM t45142 WHERE c < SOME ('' COLLATE en, '' COLLATE de); + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t45142 WHERE c < SOME (CASE WHEN true THEN NULL END, '' COLLATE en); +SELECT * FROM t45142 WHERE c < SOME ('' COLLATE en, CASE WHEN true THEN NULL END); diff --git a/test/sqllogictest/cockroach/collatedstring_constraint.slt b/test/sqllogictest/cockroach/collatedstring_constraint.slt index 623754eb5ef24..d8f5034f19b82 100644 --- a/test/sqllogictest/cockroach/collatedstring_constraint.slt +++ b/test/sqllogictest/cockroach/collatedstring_constraint.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,12 +9,15 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/collatedstring_constraint +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/collatedstring_constraint # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach @@ -23,81 +26,95 @@ mode cockroach statement ok CREATE TABLE p ( - a TEXT COLLATE en_u_ks_level1 PRIMARY KEY + a STRING COLLATE en_u_ks_level1 PRIMARY KEY ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO p VALUES ('a' COLLATE en_u_ks_level1) -statement error duplicate key value \(a\)=\('a' COLLATE en_u_ks_level1\) violates unique constraint "primary" +statement error COLLATE not yet supported INSERT INTO p VALUES ('A' COLLATE en_u_ks_level1) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO p VALUES ('b' COLLATE en_u_ks_level1) statement ok CREATE TABLE c1 ( - a TEXT COLLATE en_u_ks_level1 PRIMARY KEY, - b TEXT COLLATE en_u_ks_level1 -) INTERLEAVE IN PARENT p (a) + a STRING COLLATE en_u_ks_level1 PRIMARY KEY, + b STRING COLLATE en_u_ks_level1 +) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO c1 VALUES ('A' COLLATE en_u_ks_level1, 'apple' COLLATE en_u_ks_level1) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO c1 VALUES ('b' COLLATE en_u_ks_level1, 'banana' COLLATE en_u_ks_level1) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO c1 VALUES ('p' COLLATE en_u_ks_level1, 'pear' COLLATE en_u_ks_level1) query T SELECT a FROM p ORDER BY a ---- -a -b + query T SELECT a FROM c1 ORDER BY a ---- -A -b -p + query T SELECT b FROM c1 ORDER BY a ---- -apple -banana -pear + +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE c2 ( - a TEXT COLLATE en_u_ks_level1 PRIMARY KEY, - b TEXT COLLATE en_u_ks_level1, + a STRING COLLATE en_u_ks_level1 PRIMARY KEY, + b STRING COLLATE en_u_ks_level1, CONSTRAINT fk_p FOREIGN KEY (a) REFERENCES p -) INTERLEAVE IN PARENT p (a) +) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO c2 VALUES ('A' COLLATE en_u_ks_level1, 'apple' COLLATE en_u_ks_level1) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO c2 VALUES ('b' COLLATE en_u_ks_level1, 'banana' COLLATE en_u_ks_level1) -statement error foreign key violation: value \['p' COLLATE en_u_ks_level1\] not found in p@primary \[a\] +statement error unknown catalog item 'c2' INSERT INTO c2 VALUES ('p' COLLATE en_u_ks_level1, 'pear' COLLATE en_u_ks_level1) query T SELECT a FROM p ORDER BY a ---- -a -b + +# Not supported by Materialize. +onlyif cockroach query T SELECT a FROM c2 ORDER BY a ---- A b +# Not supported by Materialize. +onlyif cockroach query T SELECT b FROM c2 ORDER BY a ---- diff --git a/test/sqllogictest/cockroach/collatedstring_index1.slt b/test/sqllogictest/cockroach/collatedstring_index1.slt index 03fabc2b2106b..e0d84ff1111be 100644 --- a/test/sqllogictest/cockroach/collatedstring_index1.slt +++ b/test/sqllogictest/cockroach/collatedstring_index1.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/collatedstring_index1 +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/collatedstring_index1 # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach ## @@ -35,6 +35,8 @@ CREATE TABLE t ( PRIMARY KEY (a, b) ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO t VALUES ('A' COLLATE da, 1, TRUE), @@ -50,39 +52,29 @@ INSERT INTO t VALUES query TI SELECT a, b FROM t ORDER BY a, b ---- -a 2 -a 3 -A 1 -A 2 -b 4 -B 3 -x 5 -ü 5 -ü 6 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 A -2 a -2 A -3 a -3 B -4 b -5 x -5 ü -6 ü + +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('a' COLLATE da) ---- 2 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('y' COLLATE da) ---- 0 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE da) AND a < ('c' COLLATE da) ---- @@ -90,45 +82,37 @@ SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE da) AND a < ('c' COLLATE da) # Create an index and try again. +# Not supported by Materialize. +onlyif cockroach statement ok CREATE INDEX ON t (b, a) STORING (c) query TI SELECT a, b FROM t ORDER BY a, b ---- -a 2 -a 3 -A 1 -A 2 -b 4 -B 3 -x 5 -ü 5 -ü 6 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 A -2 a -2 A -3 a -3 B -4 b -5 x -5 ü -6 ü + +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('a' COLLATE da) ---- 2 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('y' COLLATE da) ---- 0 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE da) AND a < ('c' COLLATE da) ---- @@ -136,58 +120,33 @@ SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE da) AND a < ('c' COLLATE da) # Update and try again. +# Not supported by Materialize. +onlyif cockroach statement ok UPDATE t SET a = (a :: STRING || a :: STRING) COLLATE da query TI SELECT a, b FROM t ORDER BY a, b ---- -bb 4 -BB 3 -xx 5 -üü 5 -üü 6 -aa 2 -aa 3 -AA 1 -AA 2 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 AA -2 aa -2 AA -3 BB -3 aa -4 bb -5 xx -5 üü -6 üü + # Delete and try again +# Not supported by Materialize. +onlyif cockroach statement ok DELETE FROM t WHERE a > ('a' COLLATE da) AND a < ('c' COLLATE da) query TI SELECT a, b FROM t ORDER BY a, b ---- -xx 5 -üü 5 -üü 6 -aa 2 -aa 3 -AA 1 -AA 2 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 AA -2 aa -2 AA -3 aa -5 xx -5 üü -6 üü diff --git a/test/sqllogictest/cockroach/collatedstring_index2.slt b/test/sqllogictest/cockroach/collatedstring_index2.slt index c19ae4464ce6c..ff0e5c3271187 100644 --- a/test/sqllogictest/cockroach/collatedstring_index2.slt +++ b/test/sqllogictest/cockroach/collatedstring_index2.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/collatedstring_index2 +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/collatedstring_index2 # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach ## @@ -35,6 +35,8 @@ CREATE TABLE t ( PRIMARY KEY (b, a) ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO t VALUES ('A' COLLATE de, 1, TRUE), @@ -50,39 +52,29 @@ INSERT INTO t VALUES query TI SELECT a, b FROM t ORDER BY a, b ---- -a 2 -a 3 -A 1 -A 2 -b 4 -B 3 -ü 5 -ü 6 -x 5 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 A -2 a -2 A -3 a -3 B -4 b -5 ü -5 x -6 ü + +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('a' COLLATE de) ---- 2 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('y' COLLATE de) ---- 0 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE de) AND a < ('c' COLLATE de) ---- @@ -90,45 +82,37 @@ SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE de) AND a < ('c' COLLATE de) # Create an index and try again. +# Not supported by Materialize. +onlyif cockroach statement ok CREATE INDEX ON t (a, b) STORING (c) query TI SELECT a, b FROM t ORDER BY a, b ---- -a 2 -a 3 -A 1 -A 2 -b 4 -B 3 -ü 5 -ü 6 -x 5 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 A -2 a -2 A -3 a -3 B -4 b -5 ü -5 x -6 ü + +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('a' COLLATE de) ---- 2 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('y' COLLATE de) ---- 0 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE de) AND a < ('c' COLLATE de) ---- @@ -136,50 +120,33 @@ SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE de) AND a < ('c' COLLATE de) # Update and try again. +# Not supported by Materialize. +onlyif cockroach statement ok UPDATE t SET a = (a :: STRING || a :: STRING) COLLATE de query TI SELECT a, b FROM t ORDER BY a, b ---- -aa 2 -aa 3 -AA 1 -AA 2 -bb 4 -BB 3 -üü 5 -üü 6 -xx 5 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 AA -2 aa -2 AA -3 aa -3 BB -4 bb -5 üü -5 xx -6 üü + # Delete and try again +# Not supported by Materialize. +onlyif cockroach statement ok DELETE FROM t WHERE a > ('a' COLLATE de) AND a < ('c' COLLATE de) query TI SELECT a, b FROM t ORDER BY a, b ---- -üü 5 -üü 6 -xx 5 + query IT SELECT b, a FROM t ORDER BY b, a ---- -5 üü -5 xx -6 üü diff --git a/test/sqllogictest/cockroach/collatedstring_normalization.slt b/test/sqllogictest/cockroach/collatedstring_normalization.slt index 351fc9c84d63c..f56737e7ee28a 100644 --- a/test/sqllogictest/cockroach/collatedstring_normalization.slt +++ b/test/sqllogictest/cockroach/collatedstring_normalization.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/collatedstring_normalization +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/collatedstring_normalization # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach statement ok @@ -27,10 +27,14 @@ CREATE TABLE t ( a STRING COLLATE fr PRIMARY KEY ) +# Not supported by Materialize. +onlyif cockroach # Insert Amélie in NFD form. statement ok INSERT INTO t VALUES (b'Ame\xcc\x81lie' COLLATE fr) +# Not supported by Materialize. +onlyif cockroach # Retrieve Amélie in NFC form. query T SELECT a FROM t WHERE a = (b'Am\xc3\xa9lie' COLLATE fr) @@ -40,10 +44,14 @@ Amélie statement ok DELETE FROM t +# Not supported by Materialize. +onlyif cockroach # Insert Amélie in NFC form. statement ok INSERT INTO t VALUES (b'Am\xc3\xa9lie' COLLATE fr) +# Not supported by Materialize. +onlyif cockroach # Retrieve Amélie in NFD form. query T SELECT a FROM t WHERE a = (b'Ame\xcc\x81lie' COLLATE fr) diff --git a/test/sqllogictest/cockroach/collatedstring_nullinindex.slt b/test/sqllogictest/cockroach/collatedstring_nullinindex.slt index 5cf0ba8f37eaf..dedf5c28d0c05 100644 --- a/test/sqllogictest/cockroach/collatedstring_nullinindex.slt +++ b/test/sqllogictest/cockroach/collatedstring_nullinindex.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/collatedstring_nullinindex +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/collatedstring_nullinindex # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach statement ok @@ -28,6 +28,8 @@ CREATE TABLE t ( b STRING COLLATE en ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO t VALUES (1, 'foo' COLLATE en), (2, NULL), (3, 'bar' COLLATE en) @@ -46,6 +48,3 @@ SELECT b FROM t ORDER BY b ---- NULL NULL -NULL -bar -foo diff --git a/test/sqllogictest/cockroach/collatedstring_uniqueindex1.slt b/test/sqllogictest/cockroach/collatedstring_uniqueindex1.slt index cb53389c4d4bf..06098255e61e3 100644 --- a/test/sqllogictest/cockroach/collatedstring_uniqueindex1.slt +++ b/test/sqllogictest/cockroach/collatedstring_uniqueindex1.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/collatedstring_uniqueindex1 +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/collatedstring_uniqueindex1 # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach ## @@ -35,6 +35,8 @@ CREATE TABLE t ( PRIMARY KEY (a, b) ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO t VALUES ('A' COLLATE da, 1, TRUE), @@ -53,39 +55,29 @@ CREATE UNIQUE INDEX ON t (b, a) query TI SELECT a, b FROM t ORDER BY a, b ---- -a 2 -a 3 -A 1 -A 2 -b 4 -B 3 -x 5 -ü 5 -ü 6 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 A -2 a -2 A -3 a -3 B -4 b -5 x -5 ü -6 ü + +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('a' COLLATE da) ---- 2 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('y' COLLATE da) ---- 0 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE da) AND a < ('c' COLLATE da) ---- @@ -93,58 +85,33 @@ SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE da) AND a < ('c' COLLATE da) # Update and try again. +# Not supported by Materialize. +onlyif cockroach statement ok UPDATE t SET a = (a :: STRING || a :: STRING) COLLATE da query TI SELECT a, b FROM t ORDER BY a, b ---- -bb 4 -BB 3 -xx 5 -üü 5 -üü 6 -aa 2 -aa 3 -AA 1 -AA 2 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 AA -2 aa -2 AA -3 BB -3 aa -4 bb -5 xx -5 üü -6 üü + # Delete and try again +# Not supported by Materialize. +onlyif cockroach statement ok DELETE FROM t WHERE a > ('a' COLLATE da) AND a < ('c' COLLATE da) query TI SELECT a, b FROM t ORDER BY a, b ---- -xx 5 -üü 5 -üü 6 -aa 2 -aa 3 -AA 1 -AA 2 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 AA -2 aa -2 AA -3 aa -5 xx -5 üü -6 üü diff --git a/test/sqllogictest/cockroach/collatedstring_uniqueindex2.slt b/test/sqllogictest/cockroach/collatedstring_uniqueindex2.slt index d22236c9d4b50..a7f864925d191 100644 --- a/test/sqllogictest/cockroach/collatedstring_uniqueindex2.slt +++ b/test/sqllogictest/cockroach/collatedstring_uniqueindex2.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/collatedstring_uniqueindex2 +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/collatedstring_uniqueindex2 # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach ## @@ -35,6 +35,8 @@ CREATE TABLE t ( PRIMARY KEY (b, a) ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO t VALUES ('A' COLLATE de, 1, TRUE), @@ -53,39 +55,29 @@ CREATE UNIQUE INDEX ON t (a, b) query TI SELECT a, b FROM t ORDER BY a, b ---- -a 2 -a 3 -A 1 -A 2 -b 4 -B 3 -ü 5 -ü 6 -x 5 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 A -2 a -2 A -3 a -3 B -4 b -5 ü -5 x -6 ü + +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('a' COLLATE de) ---- 2 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a = ('y' COLLATE de) ---- 0 +# Not supported by Materialize. +onlyif cockroach query I SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE de) AND a < ('c' COLLATE de) ---- @@ -93,50 +85,33 @@ SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE de) AND a < ('c' COLLATE de) # Update and try again. +# Not supported by Materialize. +onlyif cockroach statement ok UPDATE t SET a = (a :: STRING || a :: STRING) COLLATE de query TI SELECT a, b FROM t ORDER BY a, b ---- -aa 2 -aa 3 -AA 1 -AA 2 -bb 4 -BB 3 -üü 5 -üü 6 -xx 5 + query IT SELECT b, a FROM t ORDER BY b, a ---- -1 AA -2 aa -2 AA -3 aa -3 BB -4 bb -5 üü -5 xx -6 üü + # Delete and try again +# Not supported by Materialize. +onlyif cockroach statement ok DELETE FROM t WHERE a > ('a' COLLATE de) AND a < ('c' COLLATE de) query TI SELECT a, b FROM t ORDER BY a, b ---- -üü 5 -üü 6 -xx 5 + query IT SELECT b, a FROM t ORDER BY b, a ---- -5 üü -5 xx -6 üü diff --git a/test/sqllogictest/cockroach/column_families.slt b/test/sqllogictest/cockroach/column_families.slt new file mode 100644 index 0000000000000..2026a0e81e714 --- /dev/null +++ b/test/sqllogictest/cockroach/column_families.slt @@ -0,0 +1,125 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/column_families +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: local 3node-tenant + +# Test that different operations still succeed when the primary key is not in column family 0. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t (x INT PRIMARY KEY, y INT, z INT, FAMILY (y), FAMILY (z), FAMILY (x)); +INSERT INTO t VALUES (1, 2, 3), (4, 5, 6) + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT * FROM t +---- +1 2 3 +4 5 6 + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE t SET x = 2 WHERE y = 2 + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT * FROM t +---- +2 2 3 +4 5 6 + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE t SET z = 3 WHERE x = 4 + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT * FROM t +---- +2 2 3 +4 5 3 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT y, z FROM t WHERE x = 2 +---- +2 3 + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE t; + +statement ok +CREATE TABLE t (x DECIMAL PRIMARY KEY, y INT, FAMILY (y), FAMILY (x)); + +statement ok +INSERT INTO t VALUES (5.607, 1), (5.6007, 2) + +query TI rowsort +SELECT * FROM t +---- +5.607 1 +5.6007 2 + +# Ensure that primary indexes with encoded composite values that are not in family 0 have their +# composite values stored in the corresponding family. + +statement ok +DROP TABLE t; + +statement ok +CREATE TABLE t (x DECIMAL, y DECIMAL, z INT, FAMILY (z), FAMILY (y), FAMILY (x), PRIMARY KEY (x, y)); + +statement ok +INSERT INTO t VALUES (1.00, 2.00, 1) + +# Not supported by Materialize. +onlyif cockroach +query TTI +SET tracing=on,kv,results; +SELECT * FROM t; +---- +1.00 2.00 1 + +statement ok +SET tracing=off + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT message FROM [SHOW KV TRACE FOR SESSION] WHERE +message LIKE 'fetched: /t/t_pkey/%' +ORDER BY message +---- +fetched: /t/t_pkey/1/2.00/x -> /1.00 +fetched: /t/t_pkey/1/2/y -> /2.00 +fetched: /t/t_pkey/1/2/z -> /1 diff --git a/test/sqllogictest/cockroach/comment_on.slt b/test/sqllogictest/cockroach/comment_on.slt new file mode 100644 index 0000000000000..9ca5e63ec8c4b --- /dev/null +++ b/test/sqllogictest/cockroach/comment_on.slt @@ -0,0 +1,361 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/comment_on +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: default-configs local-mixed-22.2-23.1 +statement ok +CREATE DATABASE db + +statement ok +COMMENT ON DATABASE db IS 'A' + +# Not supported by Materialize. +onlyif cockroach +query TTTTTTT colnames +SHOW DATABASES WITH COMMENT +---- +database_name owner primary_region secondary_region regions survival_goal comment +db root NULL NULL {} NULL A +defaultdb root NULL NULL {} NULL NULL +postgres root NULL NULL {} NULL NULL +system node NULL NULL {} NULL NULL +test root NULL NULL {} NULL NULL + +statement ok +COMMENT ON DATABASE db IS 'AAA' + +# Not supported by Materialize. +onlyif cockroach +query TTTTTTT colnames +SHOW DATABASES WITH COMMENT +---- +database_name owner primary_region secondary_region regions survival_goal comment +db root NULL NULL {} NULL AAA +defaultdb root NULL NULL {} NULL NULL +postgres root NULL NULL {} NULL NULL +system node NULL NULL {} NULL NULL +test root NULL NULL {} NULL NULL + +statement ok +COMMENT ON DATABASE db IS NULL; + +# Not supported by Materialize. +onlyif cockroach +query TTTTTTT colnames +SHOW DATABASES WITH COMMENT +---- +database_name owner primary_region secondary_region regions survival_goal comment +db root NULL NULL {} NULL NULL +defaultdb root NULL NULL {} NULL NULL +postgres root NULL NULL {} NULL NULL +system node NULL NULL {} NULL NULL +test root NULL NULL {} NULL NULL + +statement ok +CREATE SCHEMA sc + +statement ok +COMMENT ON SCHEMA sc IS 'SC' + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT COMMENT FROM system.comments WHERE type = 4; +---- +SC + +statement ok +COMMENT ON SCHEMA sc IS 'SC AGAIN' + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT COMMENT FROM system.comments WHERE type = 4; +---- +SC AGAIN + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t( + a INT PRIMARY KEY, + b INT NOT NULL, + CONSTRAINT ckb CHECK (b > 1), + INDEX idxb (b), + FAMILY fam_0_b_a (a, b) +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON TABLE t IS 'table t'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +); +COMMENT ON TABLE public.t IS 'table t' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON TABLE t IS 'table t AGAIN'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +); +COMMENT ON TABLE public.t IS 'table t AGAIN' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON TABLE t IS NULL; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON COLUMN t.b IS 'column b'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +); +COMMENT ON COLUMN public.t.b IS 'column b' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON COLUMN t.b IS 'column b AGAIN'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +); +COMMENT ON COLUMN public.t.b IS 'column b AGAIN' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON COLUMN t.b IS NULL; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON INDEX t@idxb IS 'index b'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +); +COMMENT ON INDEX public.t@idxb IS 'index b' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON INDEX t@idxb IS 'index b AGAIN'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +); +COMMENT ON INDEX public.t@idxb IS 'index b AGAIN' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON INDEX t@idxb IS NULL; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON CONSTRAINT ckb ON t IS 'cst b'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +); +COMMENT ON CONSTRAINT ckb ON public.t IS 'cst b' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON CONSTRAINT ckb ON t IS 'cst b AGAIN'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +); +COMMENT ON CONSTRAINT ckb ON public.t IS 'cst b AGAIN' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON CONSTRAINT ckb ON t IS NULL; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NOT NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + INDEX idxb (b ASC), + FAMILY fam_0_b_a (a, b), + CONSTRAINT ckb CHECK (b > 1:::INT8) +) + +# Make sure invalid comment type does not crash a server. +subtest regression_99316 + +statement ok +CREATE TABLE t_99316(a INT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO system.comments VALUES (4294967122, 't_99316'::regclass::OID, 0, 'bar'); + +statement error pgcode XX000 relation "t" does not exist +SELECT * FROM pg_catalog.pg_description WHERE objoid = 't'::regclass::OID; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DELETE FROM system.comments WHERE type = 4294967122 diff --git a/test/sqllogictest/cockroach/composite_types.slt b/test/sqllogictest/cockroach/composite_types.slt new file mode 100644 index 0000000000000..670910d186bb2 --- /dev/null +++ b/test/sqllogictest/cockroach/composite_types.slt @@ -0,0 +1,296 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/composite_types +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TYPE t AS (a INT, b INT) + +statement ok +DROP TYPE t + +statement ok +CREATE TYPE t AS (a INT, b INT) + +statement error unknown catalog item 't' +SELECT * FROM t + +statement error type "materialize\.public\.t" already exists +CREATE TABLE t (x INT) + +statement error type "materialize\.public\.t" already exists +CREATE TYPE t AS (a INT) + +statement ok +CREATE TABLE torename (x INT) + +statement error catalog item 't' already exists +ALTER TABLE torename RENAME TO t + +query TII +SELECT (1, 2)::t, ((1, 2)::t).a, ((1, 2)::t).b +---- +(1,2) 1 2 + +statement error field foo not found in data type t +SELECT ((1, 2)::t).foo + +statement ok +CREATE TABLE tab (a t, i int default 0) + +statement ok +INSERT INTO tab VALUES (NULL), ((1, 2)) + +statement ok +INSERT INTO tab VALUES ((1, NULL)) + +# Not supported by Materialize. +onlyif cockroach +# TODO(jordan): this should work fine, but is blocked behind a type-system issue: +# see #93349. +statement error VALUES types tuple{int, unknown} and tuple{int, int} cannot be matched +INSERT INTO tab VALUES ((1, 2)), ((1, NULL)) + +query TII rowsort +SELECT a, (a).a, (a).b FROM tab +---- +NULL NULL NULL +(1,2) 1 2 +(1,) 1 NULL + +statement error cannot drop type "t": still depended upon by table "tab" +DROP TYPE t + +# Not supported by Materialize. +onlyif cockroach +# Test arrays of composite types. +statement ok +CREATE TABLE atyp(a t[]) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE atyp +---- +atyp CREATE TABLE public.atyp ( + a T[] NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT atyp_pkey PRIMARY KEY (rowid ASC) + ) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO atyp VALUES(ARRAY[(1, 2), (3, 4), NULL, (5, NULL)]) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM atyp +---- +{"(1,2)","(3,4)",NULL,"(5,)"} + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE atyp + +# Not supported by Materialize. +onlyif cockroach +# Nested types not supported. #91779 +statement error composite types that reference user-defined types not yet supported +CREATE TYPE t2 AS (t1 t, t2 t) + +# Uncomment the below when #91779 is resolved. + +#statement ok +#CREATE TABLE tab2 (a t2) +# +#query TTT +#SELECT ((1, 2), (3, 4))::t2, (((1, 2), (3, 4))::t2).t1, (((1, 2), (3, 4))::t2).t2 +#---- +#("(1,2)","(3,4)") (1,2) (3,4) +# +#query II +#SELECT ((((1, 2), (3, 4))::t2).t1).a, ((((1, 2), (3, 4))::t2).t1).b +#---- +#1 2 +# +## TODO(jordan): this syntax works in Postgres. +#query error syntax error +#SELECT (((1, 2), (3, 4))::t2).t1.a +# +#statement ok +#INSERT INTO tab2 VALUES(((1, 2), (3, 4))) +# +#query TTII +#SELECT a, (a).t1, ((a).t1).a, ((a).t1).b FROM tab2 +#---- +#("(1,2)","(3,4)") (1,2) 1 2 +# +## Can't drop type t because tab, tab2, and t2 depend on it +#statement error cannot drop type \"t\" because other objects .* still depend on it +#DROP TYPE t +# +## Can't drop type t2 because tab2 depends on it +#statement error cannot drop type \"t2\" because other objects .* still depend on it +#DROP TYPE t2 +# +#statement ok +#DROP TABLE tab2 + +statement ok +DROP TABLE tab + +# Not supported by Materialize. +onlyif cockroach +query TTTT +SELECT database_name, schema_name, descriptor_name, create_statement FROM crdb_internal.create_type_statements +---- +test public t CREATE TYPE public.t AS (a INT8, b INT8) + +## Can't drop type t because t2 depends on it +#statement error cannot drop type \"t\" because other objects .* still depend on it +#DROP TYPE t +# +#statement ok +#DROP TYPE t2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TYPE t + +# Not supported by Materialize. +onlyif cockroach +# An empty type is valid. +statement ok +CREATE TYPE t AS () + +statement ok +DROP TYPE t + +# Not supported by Materialize. +onlyif cockroach +# Composite types which reference other types of UDTs are not yet supported. +statement ok +CREATE TYPE e AS ENUM ('a', 'b', 'c') + +# We'll use tab to check the implicit table alias type. +statement ok +CREATE TABLE tab (a INT, b INT) + +statement error type "e" does not exist +CREATE TYPE t AS (e e) + +# This should fail - we shouldn't persist implicit table types. +statement error type "tab" does not exist +CREATE TYPE t AS (a tab) + +statement error type "pg_catalog\.pg_class" does not exist +CREATE TYPE t AS (a pg_catalog.pg_class) + +# Test that if an composite type value is being used by a default expression or +# computed column, we disallow dropping it. +subtest drop_used_composite_type_values + +statement ok +CREATE TYPE t AS (a INT, b TEXT) + +statement ok +CREATE TABLE a (a INT DEFAULT (((1, 'hi')::t).a)) + +statement error cannot drop type "t": still depended upon by table "a" +DROP TYPE t + +# Re-enable when #91972 is resolved. +#statement ok +#ALTER TABLE a ALTER COLUMN a SET DEFAULT 3 +# +#statement ok +#DROP TYPE t; +#CREATE TYPE t AS (a INT, b TEXT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE a; +CREATE TABLE a (a INT ON UPDATE (((1, 'hi')::t).a)) + +statement error cannot drop type "t": still depended upon by table "a" +DROP TYPE t + +# Re-enable when #91972 is resolved. +#statement ok +#ALTER TABLE a ALTER COLUMN a SET ON UPDATE 3 +# +#statement ok +#DROP TYPE t; +#CREATE TYPE t AS (a INT, b TEXT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE a; +CREATE TABLE a (a INT AS (((1, 'hi')::t).a) STORED) + +statement error cannot drop type "t": still depended upon by table "a" +DROP TYPE t + +# Re-enable when #91972 is resolved. +#statement ok +#ALTER TABLE a ALTER COLUMN a DROP STORED +# +#statement ok +#DROP TYPE t; +#CREATE TYPE t AS (a INT, b TEXT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE a; +CREATE TABLE a (a INT, INDEX (a) WHERE a > (((1, 'hi')::t).a)) + +statement error cannot drop type "t": still depended upon by table "a" +DROP TYPE t + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE a; +DROP TYPE t; +CREATE TYPE t AS (a INT, b TEXT); +CREATE TABLE a (a INT CHECK (a > (((1, 'hi')::t).a))) + +statement error cannot drop type "t": still depended upon by table "a" +DROP TYPE t + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE a DROP CONSTRAINT check_a + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TYPE t; +DROP TABLE a diff --git a/test/sqllogictest/cockroach/computed.slt b/test/sqllogictest/cockroach/computed.slt deleted file mode 100644 index 0ce066fd3a724..0000000000000 --- a/test/sqllogictest/cockroach/computed.slt +++ /dev/null @@ -1,796 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/computed -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -statement ok -CREATE TABLE with_no_column_refs ( - a INT, - b INT, - c INT AS (3) STORED -) - -query TT -SHOW CREATE TABLE with_no_column_refs ----- -with_no_column_refs CREATE TABLE with_no_column_refs ( - a INT8 NULL, - b INT8 NULL, - c INT8 NULL AS (3) STORED, - FAMILY "primary" (a, b, c, rowid) -) - -statement ok -CREATE TABLE extra_parens ( - a INT, - b INT, - c INT AS ((3)) STORED -) - -query TT -SHOW CREATE TABLE extra_parens ----- -extra_parens CREATE TABLE extra_parens ( - a INT8 NULL, - b INT8 NULL, - c INT8 NULL AS ((3)) STORED, - FAMILY "primary" (a, b, c, rowid) -) - - -statement error cannot write directly to computed column "c" -INSERT INTO with_no_column_refs VALUES (1, 2, 3) - -statement error cannot write directly to computed column "c" -INSERT INTO with_no_column_refs (SELECT 1, 2, 3) - -statement error cannot write directly to computed column "c" -INSERT INTO with_no_column_refs (a, c) (SELECT 1, 3) - -statement error cannot write directly to computed column "c" -INSERT INTO with_no_column_refs (c) VALUES (1) - -statement ok -INSERT INTO with_no_column_refs (a, b) VALUES (1, 2) - -statement ok -INSERT INTO with_no_column_refs VALUES (1, 2) - -statement error cannot write directly to computed column "c" -UPDATE with_no_column_refs SET c = 1 - -statement error cannot write directly to computed column "c" -UPDATE with_no_column_refs SET (a, b, c) = (1, 2, 3) - -statement error cannot write directly to computed column "c" -UPDATE with_no_column_refs SET (a, b, c) = (SELECT 1, 2, 3) - -query I -SELECT c FROM with_no_column_refs ----- -3 -3 - -statement ok -CREATE TABLE x ( - a INT DEFAULT 3, - b INT DEFAULT 7, - c INT AS (a) STORED, - d INT AS (a + b) STORED -) - -query TT -SHOW CREATE TABLE x ----- -x CREATE TABLE x ( - a INT8 NULL DEFAULT 3:::INT8, - b INT8 NULL DEFAULT 7:::INT8, - c INT8 NULL AS (a) STORED, - d INT8 NULL AS (a + b) STORED, - FAMILY "primary" (a, b, c, d, rowid) -) - -query TTBTTTB colnames -SHOW COLUMNS FROM x ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -a INT8 true 3:::INT8 · {} false -b INT8 true 7:::INT8 · {} false -c INT8 true NULL a {} false -d INT8 true NULL a + b {} false -rowid INT8 false unique_rowid() · {primary} true - -statement error cannot write directly to computed column "c" -INSERT INTO x (c) VALUES (1) - -statement ok -INSERT INTO x (a, b) VALUES (1, 2) - -query II -SELECT c, d FROM x ----- -1 3 - -statement ok -DELETE FROM x - -statement ok -DELETE FROM x - -statement ok -DROP TABLE x - -statement ok -CREATE TABLE x ( - a INT NOT NULL, - b INT, - c INT AS (a) STORED, - d INT AS (a + b) STORED -) - -statement ok -INSERT INTO x (a) VALUES (1) - -statement error null value in column "a" violates not-null constraint -INSERT INTO x (b) VALUES (1) - -query II -SELECT c, d FROM x ----- -1 NULL - -statement ok -DROP TABLE x - -# Check with upserts -statement ok -CREATE TABLE x ( - a INT PRIMARY KEY, - b INT, - c INT AS (b + 1) STORED, - d INT AS (b - 1) STORED -) - -statement ok -INSERT INTO x (a, b) VALUES (1, 1) ON CONFLICT (a) DO UPDATE SET b = excluded.b + 1 - -query II -SELECT c, d FROM x ----- -2 0 - -statement ok -INSERT INTO x (a, b) VALUES (1, 1) ON CONFLICT (a) DO UPDATE SET b = excluded.b + 1 - -query IIII -SELECT a, b, c, d FROM x ----- -1 2 3 1 - -statement ok -INSERT INTO x (a, b) VALUES (1, 1) ON CONFLICT (a) DO UPDATE SET b = x.b + 1 - -query III -SELECT a, b, c FROM x ----- -1 3 4 - -# Update. - -statement ok -UPDATE x SET b = 3 - -query III -SELECT a, b, c FROM x ----- -1 3 4 - -# Update/self-reference. - -statement ok -UPDATE x SET b = c - -query III -SELECT a, b, c FROM x ----- -1 4 5 - -# Updating with default is not allowed. - -statement error cannot write directly to computed column "c" -UPDATE x SET (b, c) = (1, DEFAULT) - -# Upsert using the UPSERT shorthand. - -statement ok -UPSERT INTO x (a, b) VALUES (1, 2) - -query IIII -SELECT a, b, c, d FROM x ----- -1 2 3 1 - -statement ok -TRUNCATE x - -# statement ok -# INSERT INTO x VALUES (2, 3) ON CONFLICT (a) DO UPDATE SET a = 2, b = 3 - -statement ok -UPSERT INTO x VALUES (2, 3) - -query IIII -SELECT a, b, c, d FROM x ----- -2 3 4 2 - -statement ok -TRUNCATE x - -statement error cannot write directly to computed column "c" -UPSERT INTO x VALUES (2, 3, 12) - -statement ok -UPSERT INTO x (a, b) VALUES (2, 3) - -query IIII -SELECT a, b, c, d FROM x ----- -2 3 4 2 - -statement ok -DROP TABLE x - -# TODO(justin): cockroach#22434 -# statement ok -# CREATE TABLE x ( -# b INT AS a STORED, -# a INT -# ) -# -# statement ok -# INSERT INTO x VALUES (DEFAULT, 1) -# -# statement ok -# INSERT INTO x VALUES (DEFAULT, '2') -# -# query I -# SELECT b FROM x ORDER BY b -# ---- -# 1 -# 2 -# -# statement ok -# DROP TABLE x - -statement error use AS \( \) STORED -CREATE TABLE y ( - a INT AS 3 STORED -) - -statement error use AS \( \) STORED -CREATE TABLE y ( - a INT AS (3) -) - -statement error unimplemented at or near "virtual" -CREATE TABLE y ( - a INT AS (3) VIRTUAL -) - -statement error expected computed column expression to have type int, but .* has type text -CREATE TABLE y ( - a INT AS ('not an integer!'::STRING) STORED -) - -# We utilize the types from other columns. - -statement error expected computed column expression to have type int, but 'a' has type text -CREATE TABLE y ( - a STRING, - b INT AS (a) STORED -) - -statement error impure functions are not allowed in computed column -CREATE TABLE y ( - a TIMESTAMP AS (now()) STORED -) - -statement error impure functions are not allowed in computed column -CREATE TABLE y ( - a STRING AS (concat(now()::STRING, uuid_v4()::STRING)) STORED -) - -statement error computed columns cannot reference other computed columns -CREATE TABLE y ( - a INT AS (3) STORED, - b INT AS (a) STORED -) - -statement error column "a" does not exist -CREATE TABLE y ( - b INT AS (a) STORED -) - -statement error aggregate functions are not allowed in computed column -CREATE TABLE y ( - b INT AS (count(1)) STORED -) - -statement error computed columns cannot have default values -CREATE TABLE y ( - a INT AS (3) STORED DEFAULT 4 -) - -# TODO(justin,bram): this should be allowed. -statement ok -CREATE TABLE x (a INT PRIMARY KEY) - -statement error computed columns cannot reference non-restricted FK columns -CREATE TABLE y ( - q INT REFERENCES x (a) ON UPDATE CASCADE, - r INT AS (q) STORED -) - -statement error computed columns cannot reference non-restricted FK columns -CREATE TABLE y ( - q INT REFERENCES x (a) ON DELETE CASCADE, - r INT AS (q) STORED -) - -statement error computed column "r" cannot be a foreign key reference -CREATE TABLE y ( - r INT AS (1) STORED REFERENCES x (a) -) - -statement error computed column "r" cannot be a foreign key reference -CREATE TABLE y ( - r INT AS (1) STORED REFERENCES x -) - -statement error computed column "r" cannot be a foreign key reference -CREATE TABLE y ( - a INT, - r INT AS (1) STORED REFERENCES x -) - -# Regression test for cockroach#36036. -statement ok -CREATE TABLE tt (i INT8 AS (1) STORED) - -statement error variable sub-expressions are not allowed in computed column -ALTER TABLE tt ADD COLUMN c STRING AS ((SELECT NULL)) STORED - -statement error computed columns cannot reference other computed columns -ALTER TABLE tt ADD COLUMN c INT8 AS (i) STORED - -# Composite FK. - -statement ok -CREATE TABLE xx ( - a INT, - b INT, - UNIQUE (a, b) -) - -statement error computed column "y" cannot be a foreign key reference -CREATE TABLE yy ( - x INT, - y INT AS (3) STORED, - FOREIGN KEY (x, y) REFERENCES xx (a, b) -) - -statement error computed column "y" cannot be a foreign key reference -CREATE TABLE yy ( - x INT, - y INT AS (3) STORED, - FOREIGN KEY (y, x) REFERENCES xx (a, b) -) - -statement ok -DROP TABLE xx - -statement ok -CREATE TABLE y ( - r INT AS (1) STORED, - INDEX (r) -) - -statement error computed column "r" cannot be a foreign key reference -ALTER TABLE y ADD FOREIGN KEY (r) REFERENCES x (a) - -statement ok -DROP TABLE y - -statement error variable sub-expressions are not allowed in computed column -CREATE TABLE y ( - r INT AS ((SELECT 1)) STORED -) - -statement error no data source matches prefix: x -CREATE TABLE y ( - r INT AS (x.a) STORED -) - -statement error no data source matches prefix: x -CREATE TABLE y ( - q INT, - r INT AS (x.q) STORED -) - -statement ok -CREATE TABLE y ( - q INT, - r INT AS (y.q) STORED -) - -statement ok -DROP TABLE y - -# It's ok if they exist and we don't reference them. -statement ok -CREATE TABLE y ( - q INT REFERENCES x (a) ON UPDATE CASCADE, - r INT AS (3) STORED -) - -statement ok -DROP TABLE y - -statement ok -DROP TABLE x - -# Indexes on computed columns -statement ok -CREATE TABLE x ( - k INT PRIMARY KEY, - a JSON, - b TEXT AS (a->>'q') STORED, - INDEX (b) -) - -statement error cannot write directly to computed column -INSERT INTO x (k, a, b) VALUES (1, '{"q":"xyz"}', 'not allowed!'), (2, '{"q":"abc"}', 'also not allowed') - -statement error cannot write directly to computed column -UPDATE x SET (k, a, b) = (1, '{"q":"xyz"}', 'not allowed!') - -statement ok -INSERT INTO x (k, a) VALUES (1, '{"q":"xyz"}'), (2, '{"q":"abc"}') - -query IT -SELECT k, b FROM x ORDER BY b ----- -2 abc -1 xyz - -statement ok -DROP TABLE x - -statement ok -CREATE TABLE x ( - k INT AS ((data->>'id')::INT) STORED PRIMARY KEY, - data JSON -) - -statement ok -INSERT INTO x (data) VALUES - ('{"id": 1, "name": "lucky"}'), - ('{"id": 2, "name": "rascal"}'), - ('{"id": 3, "name": "captain"}'), - ('{"id": 4, "name": "lola"}') - -# ON CONFLICT that modifies a PK. -statement ok -INSERT INTO x (data) VALUES ('{"id": 1, "name": "ernie"}') -ON CONFLICT (k) DO UPDATE SET data = '{"id": 5, "name": "ernie"}' - -# ON CONFLICT that modifies a PK which then also conflicts. -statement error duplicate key value -INSERT INTO x (data) VALUES ('{"id": 5, "name": "oliver"}') -ON CONFLICT (k) DO UPDATE SET data = '{"id": 2, "name": "rascal"}' - -# Updating a non-PK column. -statement ok -UPDATE x SET data = data || '{"name": "carl"}' WHERE k = 2 - -query T -SELECT data->>'name' FROM x WHERE k = 2 ----- -carl - -query T -SELECT data->>'name' FROM x WHERE k = 5 ----- -ernie - -# Referencing a computed column. -statement ok -create table y ( - a INT REFERENCES x (k) -) - -statement ok -INSERT INTO y VALUES (5) - -statement error foreign key violation -INSERT INTO y VALUES (100) - -statement ok -DROP TABLE x CASCADE - -statement ok -CREATE TABLE x ( - a INT, - b INT, - c INT, - d INT[] AS (ARRAY[a, b, c]) STORED -) - -statement ok -INSERT INTO x (a, b, c) VALUES (1, 2, 3) - -query T -SELECT d FROM x ----- -{1,2,3} - -statement ok -TRUNCATE x - -# Make sure we get the permutation on the inserts correct. - -statement ok -INSERT INTO x (b, a, c) VALUES (1, 2, 3) - -query T -SELECT d FROM x ----- -{2,1,3} - -# Make sure we get the permutation on the updates correct. -statement ok -UPDATE x SET (c, a, b) = (1, 2, 3) - -query T -SELECT d FROM x ----- -{2,3,1} - -statement ok -UPDATE x SET (a, c) = (1, 2) - -query T -SELECT d FROM x ----- -{1,3,2} - -statement ok -UPDATE x SET c = 2, a = 3, b = 1 - -query T -SELECT d FROM x ----- -{3,1,2} - -# Make sure we get the permutation on upserts correct. -statement ok -INSERT INTO x (rowid) VALUES ((SELECT rowid FROM x)) ON CONFLICT(rowid) DO UPDATE SET (a, b, c) = (1, 2, 3) - -query T -SELECT d FROM x ----- -{1,2,3} - -statement ok -INSERT INTO x (rowid) VALUES ((SELECT rowid FROM x)) ON CONFLICT(rowid) DO UPDATE SET (c, a, b) = (1, 2, 3) - -query T -SELECT d FROM x ----- -{2,3,1} - -statement ok -INSERT INTO x (rowid) VALUES ((SELECT rowid FROM x)) ON CONFLICT(rowid) DO UPDATE SET (c, a) = (1, 2) - -query T -SELECT d FROM x ----- -{2,3,1} - -statement ok -DROP TABLE x - -statement ok -CREATE TABLE x ( - a INT, - b INT as (x.a) STORED -) - -query TT -SHOW CREATE TABLE x ----- -x CREATE TABLE x ( - a INT8 NULL, - b INT8 NULL AS (a) STORED, - FAMILY "primary" (a, b, rowid) -) - -statement ok -DROP TABLE x - -# Check that computed columns are resilient to column renames. -statement ok -CREATE TABLE x ( - a INT, - b INT AS (a) STORED -) - -statement ok -ALTER TABLE x RENAME COLUMN a TO c - -query TT -SHOW CREATE TABLE x ----- -x CREATE TABLE x ( - c INT8 NULL, - b INT8 NULL AS (c) STORED, - FAMILY "primary" (c, b, rowid) -) - -statement ok -DROP TABLE x - -statement ok -CREATE TABLE x ( - a INT, - b INT AS (a * 2) STORED -) - -query T colnames -SELECT generation_expression FROM information_schema.columns -WHERE table_name = 'x' and column_name = 'b' ----- -generation_expression -a * 2 - -query I -SELECT count(*) FROM information_schema.columns -WHERE table_name = 'x' and generation_expression = '' ----- -2 - -statement ok -INSERT INTO x VALUES (3) - -# Verify computed columns work. -statement ok -ALTER TABLE x ADD COLUMN c INT NOT NULL AS (a + 4) STORED - -query TT -SHOW CREATE TABLE x ----- -x CREATE TABLE x ( - a INT8 NULL, - b INT8 NULL AS (a * 2) STORED, - c INT8 NOT NULL AS (a + 4) STORED, - FAMILY "primary" (a, b, rowid, c) -) - -statement ok -INSERT INTO x VALUES (6) - -query III -SELECT * FROM x ORDER BY a ----- -3 6 7 -6 12 10 - -# Verify a bad statement fails. -statement error unsupported binary operator: \+ \(desired \) -ALTER TABLE x ADD COLUMN d INT AS (a + 'a') STORED - -statement error could not parse "a" as type int -ALTER TABLE x ADD COLUMN d INT AS ('a') STORED - -statement error unsupported binary operator -ALTER TABLE x ADD COLUMN d INT AS (a / 0) STORED - -# Verify an error during computation fails. -statement error division by zero -ALTER TABLE x ADD COLUMN d INT AS (a // 0) STORED - -statement ok -DROP TABLE x - -# Regression test for materialize#23109 -statement ok -CREATE TABLE x ( - a INT DEFAULT 1, - b INT AS (2) STORED -) - -statement ok -INSERT INTO x (a) SELECT 1 - -statement ok -DROP TABLE x - -statement ok -CREATE TABLE x ( - b INT AS (2) STORED, - a INT DEFAULT 1 -) - -statement ok -INSERT INTO x (a) SELECT 1 - -statement ok -DROP TABLE x - -# Verify errors emitted from computed columns contain the column name -statement ok -CREATE TABLE error_check (k INT PRIMARY KEY, s STRING, i INT AS (s::INT) STORED) - -statement ok -INSERT INTO error_check VALUES(1, '1') - -statement error could not parse "foo" as type int: strconv.ParseInt -INSERT INTO error_check VALUES(2, 'foo') - -statement error could not parse "foo" as type int: strconv.ParseInt: parsing "foo": invalid syntax -UPDATE error_check SET s = 'foo' WHERE k = 1 - -# Upsert -> update -# NOTE: The CBO cannot show the name of the computed column in the error message -# because the computation is part of an overall SQL statement. -statement error could not parse "foo" as type int: strconv.ParseInt: parsing "foo": invalid syntax -UPSERT INTO error_check VALUES (1, 'foo') - -# Upsert -> insert -statement error could not parse "foo" as type int: strconv.ParseInt: parsing "foo": invalid syntax -UPSERT INTO error_check VALUES (3, 'foo') - -statement ok -CREATE TABLE x ( - a INT PRIMARY KEY, - b INT AS (a+1) STORED -) - -query error value type decimal doesn't match type int of column "a" -INSERT INTO x VALUES(1.4) - -# Regression test for cockroach#34901: verify that builtins can be used in computed -# column expressions without a "memory budget exceeded" error while backfilling -statement ok -CREATE TABLE t34901 (x STRING) - -statement ok -INSERT INTO t34901 VALUES ('a') - -statement ok -ALTER TABLE t34901 ADD COLUMN y STRING AS (concat(x, 'b')) STORED - -query TT -SELECT * FROM t34901 ----- -a ab diff --git a/test/sqllogictest/cockroach/conditional.slt b/test/sqllogictest/cockroach/conditional.slt index 99eb71e8a6265..6b60a3ff488e9 100644 --- a/test/sqllogictest/cockroach/conditional.slt +++ b/test/sqllogictest/cockroach/conditional.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,16 +9,21 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/conditional +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/conditional # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach +# Not supported by Materialize. +onlyif cockroach query II SELECT IF(1 = 2, NULL, 1), IF(2 = 2, NULL, 2) ---- @@ -29,6 +34,8 @@ SELECT NULLIF(1, 2), NULLIF(2, 2), NULLIF(NULL, NULL) ---- 1 NULL NULL +# Not supported by Materialize. +onlyif cockroach query IIII SELECT IFNULL(1, 2), @@ -38,9 +45,13 @@ SELECT ---- 1 2 1 2 +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE t (a) AS VALUES (1), (2), (3) +# Not supported by Materialize. +onlyif cockroach query IT SELECT a, @@ -58,6 +69,8 @@ ORDER BY 2 two 3 other +# Not supported by Materialize. +onlyif cockroach query IT SELECT a, @@ -75,6 +88,8 @@ ORDER BY 2 two 3 other +# Not supported by Materialize. +onlyif cockroach query III SELECT a, NULLIF(a, 2), IF(a = 2, NULL, a) FROM t ORDER BY a ---- @@ -128,3 +143,17 @@ SELECT END ---- one one three four two + +subtest regression_95560 + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #95560. COALESCE should only evaluate arguments to the +# right of the first non-NULL argument, and an error (in this case a "division +# by zero" error) should not occur from a branch that should never be evaluated. +statement ok +CREATE TABLE t95560a (a INT); +INSERT INTO t95560a VALUES (1); +CREATE TABLE t95560b (b INT); +INSERT INTO t95560b VALUES (0); +SELECT coalesce(a, (SELECT (a/b)::INT FROM t95560b)) FROM t95560a; diff --git a/test/sqllogictest/cockroach/connect_privilege.slt b/test/sqllogictest/cockroach/connect_privilege.slt new file mode 100644 index 0000000000000..f3a85dcf89486 --- /dev/null +++ b/test/sqllogictest/cockroach/connect_privilege.slt @@ -0,0 +1,70 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/connect_privilege +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE a (k STRING PRIMARY KEY, v STRING) + +query TTT +SELECT schemaname, tablename, tableowner FROM pg_catalog.pg_tables WHERE tablename = 'a' +---- +public a materialize + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE CONNECT ON DATABASE test FROM public + +user testuser + +query TTT +SELECT schemaname, tablename, tableowner FROM pg_catalog.pg_tables WHERE tablename = 'a' +---- +public a materialize + +query TTT +SELECT table_catalog, table_schema, table_name FROM information_schema.tables WHERE table_name = 'a' +---- +materialize public a + +# Granting CONNECT privilege on database test to testuser should +# allow testuser to see table a in pg_catalog / information_schema. + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CONNECT ON DATABASE test TO testuser + +user testuser + +query TTT +SELECT schemaname, tablename, tableowner FROM pg_catalog.pg_tables WHERE tablename = 'a' +---- +public a materialize + +query TTT +SELECT table_catalog, table_schema, table_name FROM information_schema.tables WHERE table_name = 'a' +---- +materialize public a diff --git a/test/sqllogictest/cockroach/create_as.slt b/test/sqllogictest/cockroach/create_as.slt deleted file mode 100644 index e873c5650e3d0..0000000000000 --- a/test/sqllogictest/cockroach/create_as.slt +++ /dev/null @@ -1,150 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/create_as -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -statement count 3 -CREATE TABLE stock (item, quantity) AS VALUES ('cups', 10), ('plates', 15), ('forks', 30) - -statement count 1 -CREATE TABLE runningOut AS SELECT * FROM stock WHERE quantity < 12 - -query TI -SELECT * FROM runningOut ----- -cups 10 - -statement count 3 -CREATE TABLE itemColors (color) AS VALUES ('blue'), ('red'), ('green') - -statement count 9 -CREATE TABLE itemTypes AS (SELECT item, color FROM stock, itemColors) - -query TT rowsort -SELECT * FROM itemTypes ----- -cups blue -cups red -cups green -plates blue -plates red -plates green -forks blue -forks red -forks green - -statement error pq: AS OF SYSTEM TIME must be provided on a top-level statement -CREATE TABLE t AS SELECT * FROM stock AS OF SYSTEM TIME '2016-01-01' - -statement error pgcode 42601 CREATE TABLE specifies 3 column names, but data source has 2 columns -CREATE TABLE t2 (col1, col2, col3) AS SELECT * FROM stock - -statement error pgcode 42601 CREATE TABLE specifies 1 column name, but data source has 2 columns -CREATE TABLE t2 (col1) AS SELECT * FROM stock - -statement count 5 -CREATE TABLE unionstock AS SELECT * FROM stock UNION VALUES ('spoons', 25), ('knives', 50) - -query TI -SELECT * FROM unionstock ORDER BY quantity ----- -cups 10 -plates 15 -spoons 25 -forks 30 -knives 50 - -statement count 0 -CREATE TABLE IF NOT EXISTS unionstock AS VALUES ('foo', 'bar') - -query TI -SELECT * FROM unionstock ORDER BY quantity LIMIT 1 ----- -cups 10 - -statement ok -CREATE DATABASE smtng - -statement count 3 -CREATE TABLE smtng.something AS SELECT * FROM stock - -statement count 0 -CREATE TABLE IF NOT EXISTS smtng.something AS SELECT * FROM stock - -query TI -SELECT * FROM smtng.something ORDER BY 1 LIMIT 1 ----- -cups 10 - -statement error pgcode 42P01 relation "something" does not exist -SELECT * FROM something LIMIT 1 - -# Check for memory leak (materialize#10466) -statement ok -CREATE TABLE foo (x, y, z) AS SELECT catalog_name, schema_name, sql_path FROM information_schema.schemata - -statement error pq: relation "foo" already exists -CREATE TABLE foo (x, y, z) AS SELECT catalog_name, schema_name, sql_path FROM information_schema.schemata - -statement error pq: value type tuple cannot be used for table columns -CREATE TABLE foo2 (x) AS (VALUES(ROW())) - -statement error pq: nested array unsupported as column type: int\[\]\[\] -CREATE TABLE foo2 (x) AS (VALUES(ARRAY[ARRAY[1]])) - -statement error generator functions are not allowed in VALUES -CREATE TABLE foo2 (x) AS (VALUES(generate_series(1,3))) - -statement error pq: value type unknown cannot be used for table columns -CREATE TABLE foo2 (x) AS (VALUES(NULL)) - -# Check nulls are handled properly (database-issues#3988) -query I -CREATE TABLE foo3 (x) AS VALUES (1), (NULL); SELECT * FROM foo3 ORDER BY x ----- -NULL -1 - -# Check that CREATE TABLE AS can use subqueries (materialize#23002) -query B -CREATE TABLE foo4 (x) AS SELECT EXISTS(SELECT * FROM foo3 WHERE x IS NULL); SELECT * FROM foo4 ----- -true - -# Regression test for cockroach#36930. -statement ok -CREATE TABLE bar AS SELECT 1 AS a, 2 AS b, count(*) AS c FROM foo - -query III colnames -SELECT * FROM bar ----- -a b c -1 2 4 - -statement ok -CREATE TABLE baz (a, b, c) AS SELECT 1, 2, count(*) FROM foo - -query III colnames -SELECT * FROM baz ----- -a b c -1 2 4 diff --git a/test/sqllogictest/cockroach/create_index.slt b/test/sqllogictest/cockroach/create_index.slt new file mode 100644 index 0000000000000..f0003623f51d0 --- /dev/null +++ b/test/sqllogictest/cockroach/create_index.slt @@ -0,0 +1,503 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/create_index +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: default-configs + +statement ok +CREATE TABLE t ( + a INT PRIMARY KEY, + b INT, + FAMILY (a), + FAMILY (b) +) + +statement ok +INSERT INTO t VALUES (1,1) + +user root + +statement ok +CREATE INDEX foo ON t (b) + +statement error pgcode 42P07 index "materialize\.public\.foo" already exists +CREATE INDEX foo ON t (a) + +statement error column "c" does not exist +CREATE INDEX bar ON t (c) + +# Not supported by Materialize. +onlyif cockroach +statement error index \"bar\" contains duplicate column \"b\" +CREATE INDEX bar ON t (b, b); + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM t +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +t foo true 1 b b ASC false false true +t foo true 2 a a ASC false true true +t t_pkey false 1 a a ASC false false true +t t_pkey false 2 b b N/A true false true + +statement ok +INSERT INTO t VALUES (2,1) + +statement error pgcode 23505 violates unique constraint "bar" +CREATE UNIQUE INDEX bar ON t (b) + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM t +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +t foo true 1 b b ASC false false true +t foo true 2 a a ASC false true true +t t_pkey false 1 a a ASC false false true +t t_pkey false 2 b b N/A true false true + +# test for DESC index + +statement ok +DROP TABLE t + +statement ok +CREATE TABLE t ( + a INT PRIMARY KEY, + b INT, + c INT +) + +statement ok +INSERT INTO t VALUES (1,1,1), (2,2,2) + +statement ok +CREATE INDEX b_desc ON t (b DESC) + +statement ok +CREATE INDEX b_asc ON t (b ASC, c DESC) + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM t +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +t b_asc true 1 b b ASC false false true +t b_asc true 2 c c DESC false false true +t b_asc true 3 a a ASC false true true +t b_desc true 1 b b DESC false false true +t b_desc true 2 a a ASC false true true +t t_pkey false 1 a a ASC false false true +t t_pkey false 2 b b N/A true false true +t t_pkey false 3 c c N/A true false true + +statement error pgcode 42P01 unknown catalog item 'foo' +CREATE INDEX fail ON foo (b DESC) + +statement ok +CREATE VIEW v AS SELECT a,b FROM t + +# Not supported by Materialize. +onlyif cockroach +statement error pgcode 42809 "v" is not a table or materialized view +CREATE INDEX failview ON v (b DESC) + +statement ok +CREATE TABLE privs (a INT PRIMARY KEY, b INT) + +user testuser + +skipif config local-legacy-schema-changer +skipif config local-mixed-22.2-23.1 +statement error must be owner of TABLE materialize\.public\.privs +CREATE INDEX foo ON privs (b) + +onlyif config local-legacy-schema-changer +onlyif config local-mixed-22.2-23.1 +statement error user testuser does not have CREATE privilege on relation privs +CREATE INDEX foo ON privs (b) + + +user root + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM privs +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +privs privs_pkey false 1 a a ASC false false true +privs privs_pkey false 2 b b N/A true false true + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON privs TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX foo ON privs (b) + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM privs +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +privs foo true 1 b b ASC false false true +privs foo true 2 a a ASC false true true +privs privs_pkey false 1 a a ASC false false true +privs privs_pkey false 2 b b N/A true false true + + +user root + +statement ok +CREATE TABLE telemetry ( + x INT PRIMARY KEY, + y INT, + z JSONB +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INVERTED INDEX ON telemetry (z); +CREATE INDEX ON telemetry (y) USING HASH WITH (bucket_count=4) + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT feature_name FROM crdb_internal.feature_usage +WHERE feature_name IN ( + 'sql.schema.inverted_index', + 'sql.schema.hash_sharded_index' +) +---- +sql.schema.inverted_index +sql.schema.hash_sharded_index + +subtest create_index_concurrently + +statement ok +CREATE TABLE create_index_concurrently_tbl (a int) + +query T noticetrace +CREATE INDEX CONCURRENTLY create_index_concurrently_idx ON create_index_concurrently_tbl(a) +---- +NOTICE: CONCURRENTLY is not required as all indexes are created concurrently + +query T noticetrace +CREATE INDEX CONCURRENTLY IF NOT EXISTS create_index_concurrently_idx ON create_index_concurrently_tbl(a) +---- + +query TT +SHOW CREATE TABLE create_index_concurrently_tbl +---- +materialize.public.create_index_concurrently_tbl CREATE␠TABLE␠materialize.public.create_index_concurrently_tbl␠(a␠pg_catalog.int4); + +query T noticetrace +DROP INDEX CONCURRENTLY create_index_concurrently_idx +---- +NOTICE: CONCURRENTLY is not required as all indexes are dropped concurrently +NOTICE: the data for dropped indexes is reclaimed asynchronously +HINT: The reclamation delay can be customized in the zone configuration for the table. + +query T noticetrace +DROP INDEX CONCURRENTLY IF EXISTS create_index_concurrently_idx +---- +NOTICE: CONCURRENTLY is not required as all indexes are dropped concurrently + +query TT +SHOW CREATE TABLE create_index_concurrently_tbl +---- +materialize.public.create_index_concurrently_tbl CREATE␠TABLE␠materialize.public.create_index_concurrently_tbl␠(a␠pg_catalog.int4); + +statement ok +DROP TABLE create_index_concurrently_tbl + +# Test that creating an index on a column which is currently being dropped +# causes an error. +subtest create_index_on_dropping_column + +statement ok +CREATE TABLE create_idx_drop_column (c0 INT PRIMARY KEY, c1 INT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +begin; ALTER TABLE create_idx_drop_column DROP COLUMN c1; + +# Not supported by Materialize. +onlyif cockroach +statement error column "c1" does not exist +CREATE INDEX idx_create_idx_drop_column ON create_idx_drop_column (c1); + +statement ok +ROLLBACK; + +statement ok +DROP TABLE create_idx_drop_column; + +subtest names-with-escaped-chars + +# Similarly try using special characters making an index for a new table, we +# will attempt to recreate it and expect the look up to find the old one. +statement ok +CREATE TABLE "'t1-esc'"(name int); + +statement ok +CREATE INDEX "'t1-esc-index'" ON "'t1-esc'"(name) + +statement error index "materialize\.public\.'t1\-esc\-index'" already exists +CREATE INDEX "'t1-esc-index'" ON "'t1-esc'"(name) + +subtest resume-with-diff-tenant-resume-spans + +let $schema_changer_state +SELECT value FROM information_schema.session_variables where variable='use_declarative_schema_changer' + +# Intentionally, disable the declarative schema changer for this +# part of the test, since we are pausing jobs intentionally below. +statement ok +SET use_declarative_schema_changer = 'off' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET CLUSTER SETTING jobs.registry.interval.adopt = '50ms'; + +# Not supported by Materialize. +onlyif cockroach +# Lower the job registry loop interval to accelerate the test. +statement ok +SET CLUSTER SETTING jobs.registry.interval.cancel = '50ms' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET CLUSTER SETTING jobs.debug.pausepoints = 'indexbackfill.before_flow'; + +statement ok +CREATE TABLE tbl (i INT PRIMARY KEY, j INT NOT NULL); + +statement ok +INSERT INTO tbl VALUES (1, 100), (2, 200), (3, 300); + +# Not supported by Materialize. +onlyif cockroach +statement error job .* was paused before it completed with reason: pause point "indexbackfill.before_flow" hit +CREATE INDEX pauseidx ON tbl(j); + +# Not supported by Materialize. +onlyif cockroach +# clear the pause point now that the job is paused. +statement ok +RESET CLUSTER SETTING jobs.debug.pausepoints + +let $tab_id +SELECT 'tbl'::regclass::int + +# Construct some resume spans where half of the span has the wrong +# tenant prefix and the other half has no tenant prefix. The variable will +# hold the json text for the resume spans we want. We'll verify them below. +# This is some really low-level mucking around. Things to know are that 0xfe +# is the tenant prefix. +let $spans + WITH span AS ( + SELECT j->'schemaChange'->'resumeSpanList'->0->'resumeSpans'->0 AS span + FROM ( + SELECT crdb_internal.pb_to_json('payload', payload) AS j + FROM crdb_internal.system_jobs + ) + WHERE j->>'description' LIKE 'CREATE INDEX pauseidx%' + ), + keys AS ( + SELECT key, + encode( + decode( + regexp_replace( + encode(decode(value->>0, 'base64'), 'hex'), + '^fe..', + '' + ), + 'hex' + ), + 'base64' + ) AS value + FROM (SELECT * FROM ROWS FROM (json_each((SELECT span FROM span)))) + ), + span_new AS (SELECT json_object_agg(key, value) AS span FROM keys), + mid_key AS (SELECT crdb_internal.encode_key($tab_id, 1, (100,)) AS k), + modified_mid_key AS ( + SELECT IF( + substring(k, 1, 1) = b'\xfe', + substring(k, 3), + k + ) AS k + FROM mid_key + ) +SELECT json_build_array( + json_build_object( + 'key', + encode(b'\xfe\xef' || decode(span->>'key', 'base64'), 'base64'), + 'endKey', + encode(b'\xfe\xef' || k, 'base64') + ), + json_build_object('key', encode(k, 'base64'), 'endKey', span->>'endKey') + ) + FROM span_new, modified_mid_key; + +# Not supported by Materialize. +onlyif cockroach +# while the backfill is paused, go in and replace the resume spans with some new +# spans that both the wrong tenant ID or no tenant ID before resuming it to make +# sure that on resume it re-keys the spans correctly. We pretty_key these below +# to confirm/show what is in them. +statement ok +UPDATE system.job_info + SET value = crdb_internal.json_to_pb( + 'cockroach.sql.jobs.jobspb.Payload', + json_set( + crdb_internal.pb_to_json('cockroach.sql.jobs.jobspb.Payload', value), + ARRAY['schemaChange', 'resumeSpanList', '0'], + '{"resumeSpans": $spans}'::jsonb + ) + ) +WHERE info_key = 'legacy_payload' AND crdb_internal.pb_to_json('cockroach.sql.jobs.jobspb.Payload', value)->>'description' LIKE 'CREATE INDEX pauseidx%'; + +# Not supported by Materialize. +onlyif cockroach +# confirm we see these bogus start and end keys in the job, both for the wrong +# tenant and for no tenant. +query TTTT +SELECT + crdb_internal.pretty_key(decode(j->'schemaChange'->'resumeSpanList'->0->'resumeSpans'->0->>'key', 'base64'), 0), + crdb_internal.pretty_key(decode(j->'schemaChange'->'resumeSpanList'->0->'resumeSpans'->0->>'endKey', 'base64'), 0), + crdb_internal.pretty_key(decode(j->'schemaChange'->'resumeSpanList'->0->'resumeSpans'->1->>'key', 'base64'), 0), + crdb_internal.pretty_key(decode(j->'schemaChange'->'resumeSpanList'->0->'resumeSpans'->1->>'endKey', 'base64'), 0) +FROM ( + SELECT crdb_internal.pb_to_json('cockroach.sql.jobs.jobspb.Payload', payload) j FROM crdb_internal.system_jobs +) WHERE j->>'description' LIKE 'CREATE INDEX pauseidx%'; +---- +/103/Table/114/1 /103/Table/114/1/100 /114/1/100 /114/2 + +# Not supported by Materialize. +onlyif cockroach +# resume the job and ensure it completes, which includes validation. +statement ok +RESUME JOB (SELECT job_id FROM crdb_internal.jobs WHERE description LIKE 'CREATE INDEX pauseidx%'); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT status FROM [SHOW JOB WHEN COMPLETE (SELECT job_id FROM crdb_internal.jobs WHERE description LIKE 'CREATE INDEX pauseidx%')]; +---- +succeeded + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET CLUSTER SETTING jobs.registry.interval.cancel = DEFAULT; + +# Not supported by Materialize. +onlyif cockroach +# Restore the schema changer state back. +statement ok +SET use_declarative_schema_changer = $schema_changer_state + +subtest test_old_bucket_count_syntax + +statement ok +CREATE TABLE t_hash ( + pk INT PRIMARY KEY, + a INT, + b INT, + FAMILY fam_0_pk_a_b (pk, a, b) +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX idx_t_hash_a ON t_hash (a) USING HASH WITH BUCKET_COUNT = 5; + +statement ok +CREATE UNIQUE INDEX idx_t_hash_b ON t_hash (b) USING HASH WITH BUCKET_COUNT = 5; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t_hash] +---- +CREATE TABLE public.t_hash ( + pk INT8 NOT NULL, + a INT8 NULL, + b INT8 NULL, + crdb_internal_a_shard_5 INT8 NOT VISIBLE NOT NULL AS (mod(fnv32(crdb_internal.datums_to_bytes(a)), 5:::INT8)) VIRTUAL, + crdb_internal_b_shard_5 INT8 NOT VISIBLE NOT NULL AS (mod(fnv32(crdb_internal.datums_to_bytes(b)), 5:::INT8)) VIRTUAL, + CONSTRAINT t_hash_pkey PRIMARY KEY (pk ASC), + INDEX idx_t_hash_a (a ASC) USING HASH WITH (bucket_count=5), + UNIQUE INDEX idx_t_hash_b (b ASC) USING HASH WITH (bucket_count=5), + FAMILY fam_0_pk_a_b (pk, a, b) +) + +statement ok +CREATE TABLE opclasses (a INT PRIMARY KEY, b TEXT, c JSON) + +# Make sure that we don't permit creating indexes with opclasses that aren't +# inverted. +statement error pgcode 42804 Expected right parenthesis, found identifier "blah_ops" +CREATE INDEX ON opclasses(b blah_ops) + +# Make sure that we don't permit creating indexes with opclasses that aren't +# inverted, even if the type is invertible. +statement error pgcode 42804 Expected right parenthesis, found identifier "blah_ops" +CREATE INDEX ON opclasses(c blah_ops) + +# Make sure that we don't permit creating indexes with opclasses that don't exist +statement error pgcode 42704 Expected DATABASE, SCHEMA, ROLE, TYPE, INDEX, SINK, SOURCE, \[TEMPORARY\] TABLE, SECRET, \[OR REPLACE\] \[TEMPORARY\] VIEW, or \[OR REPLACE\] MATERIALIZED VIEW after CREATE, found identifier "inverted" +CREATE INVERTED INDEX ON opclasses(c blah_ops) + +subtest create_index_on_materialized_view + +statement ok +DROP TABLE t CASCADE; +CREATE TABLE t (a INT PRIMARY KEY); +INSERT INTO t SELECT generate_series(0, 9); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE MATERIALIZED VIEW v (b) AS SELECT a * 2 FROM t WITH DATA; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX ON v (b); diff --git a/test/sqllogictest/cockroach/create_statements.slt b/test/sqllogictest/cockroach/create_statements.slt new file mode 100644 index 0000000000000..7525d09cd7aa8 --- /dev/null +++ b/test/sqllogictest/cockroach/create_statements.slt @@ -0,0 +1,146 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/create_statements +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t ( + a INT REFERENCES t, + FAMILY "primary" (a, rowid) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE v ( + "'" INT REFERENCES t, s STRING UNIQUE REFERENCES v (s), + FAMILY "primary" ("'", s, rowid) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE c ( + a INT NOT NULL, + b INT NULL, + INDEX c_a_b_idx (a ASC, b ASC), + FAMILY fam_0_a_rowid (a, rowid), + FAMILY fam_1_b (b) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON TABLE c IS 'table' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON COLUMN c.a IS 'column' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON INDEX c_a_b_idx IS 'index' + +# Not supported by Materialize. +onlyif cockroach +query TTTT colnames +SELECT + regexp_replace(create_statement, '\n', ' ', 'g'), + regexp_replace(create_nofks, '\n', ' ', 'g'), + alter_statements, + validate_statements +FROM + crdb_internal.create_statements +WHERE + database_name = 'test' +AND + schema_name NOT IN ('pg_catalog', 'pg_extension', 'crdb_internal', 'information_schema') +---- +regexp_replace regexp_replace alter_statements validate_statements +CREATE TABLE public.t ( a INT8 NULL, rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), CONSTRAINT t_pkey PRIMARY KEY (rowid ASC), CONSTRAINT t_a_fkey FOREIGN KEY (a) REFERENCES public.t(rowid) ) CREATE TABLE public.t ( a INT8 NULL, rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) ) {"ALTER TABLE public.t ADD CONSTRAINT t_a_fkey FOREIGN KEY (a) REFERENCES public.t(rowid)"} {"ALTER TABLE public.t VALIDATE CONSTRAINT t_a_fkey"} +CREATE TABLE public.v ( "'" INT8 NULL, s STRING NULL, rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), CONSTRAINT v_pkey PRIMARY KEY (rowid ASC), CONSTRAINT "v_'_fkey" FOREIGN KEY ("'") REFERENCES public.t(rowid), CONSTRAINT v_s_fkey FOREIGN KEY (s) REFERENCES public.v(s), UNIQUE INDEX v_s_key (s ASC) ) CREATE TABLE public.v ( "'" INT8 NULL, s STRING NULL, rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), CONSTRAINT v_pkey PRIMARY KEY (rowid ASC), UNIQUE INDEX v_s_key (s ASC) ) {"ALTER TABLE public.v ADD CONSTRAINT \"v_'_fkey\" FOREIGN KEY (\"'\") REFERENCES public.t(rowid)","ALTER TABLE public.v ADD CONSTRAINT v_s_fkey FOREIGN KEY (s) REFERENCES public.v(s)"} {"ALTER TABLE public.v VALIDATE CONSTRAINT \"v_'_fkey\"","ALTER TABLE public.v VALIDATE CONSTRAINT v_s_fkey"} +CREATE TABLE public.c ( a INT8 NOT NULL, b INT8 NULL, rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), CONSTRAINT c_pkey PRIMARY KEY (rowid ASC), INDEX c_a_b_idx (a ASC, b ASC), FAMILY fam_0_a_rowid (a, rowid), FAMILY fam_1_b (b) ); COMMENT ON TABLE public.c IS 'table'; COMMENT ON COLUMN public.c.a IS 'column'; COMMENT ON INDEX public.c@c_a_b_idx IS 'index' CREATE TABLE public.c ( a INT8 NOT NULL, b INT8 NULL, rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), CONSTRAINT c_pkey PRIMARY KEY (rowid ASC), INDEX c_a_b_idx (a ASC, b ASC), FAMILY fam_0_a_rowid (a, rowid), FAMILY fam_1_b (b) ); COMMENT ON TABLE public.c IS 'table'; COMMENT ON COLUMN public.c.a IS 'column'; COMMENT ON INDEX public.c@c_a_b_idx IS 'index' {} {} + +query T noticetrace +CREATE UNLOGGED TABLE unlogged_tbl (col int PRIMARY KEY) +---- +NOTICE: UNLOGGED TABLE will behave as a regular table in CockroachDB + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE unlogged_tbl +---- +unlogged_tbl CREATE TABLE public.unlogged_tbl ( + col INT8 NOT NULL, + CONSTRAINT unlogged_tbl_pkey PRIMARY KEY (col ASC) + ) + +statement error pgcode 22023 Expected one of PARTITION or RETAIN, found identifier "foo" +CREATE TABLE a (b INT) WITH (foo=100); + +statement error Expected one of PARTITION or RETAIN, found identifier "fillfactor" +CREATE TABLE a (b INT) WITH (fillfactor=true); + +statement error Expected one of PARTITION or RETAIN, found identifier "toast_tuple_target" +CREATE TABLE a (b INT) WITH (toast_tuple_target=100); + +query T noticetrace +CREATE TABLE a (b INT) WITH (fillfactor=99.9) +---- +NOTICE: storage parameter "fillfactor" is ignored + +query T noticetrace +CREATE INDEX a_idx ON a(b) WITH (fillfactor=50) +---- +NOTICE: storage parameter "fillfactor" is ignored + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE a CASCADE; + +query T noticetrace +CREATE TABLE a (b INT) WITH (autovacuum_enabled=off) +---- +NOTICE: storage parameter "autovacuum_enabled = 'off'" is ignored + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE a CASCADE; + +query T noticetrace +CREATE TABLE a (b INT) WITH (autovacuum_enabled=on) +---- + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE a CASCADE; + +statement error Expected one of PARTITION or RETAIN, found identifier "autovacuum_enabled" +CREATE TABLE a (b INT) WITH (autovacuum_enabled='11') diff --git a/test/sqllogictest/cockroach/custom_escape_character.slt b/test/sqllogictest/cockroach/custom_escape_character.slt index 6e720251fc67f..2cf0572b857af 100644 --- a/test/sqllogictest/cockroach/custom_escape_character.slt +++ b/test/sqllogictest/cockroach/custom_escape_character.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,24 +9,28 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/custom_escape_character +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/custom_escape_character # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach +# Not supported by Materialize. +onlyif cockroach query B SELECT '%' LIKE 't%' ESCAPE CASE WHEN (SELECT '-A' SIMILAR TO '--A' ESCAPE '-') THEN 't' ELSE 'f' END ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '%' LIKE 't%' ESCAPE CASE WHEN (SELECT 'A' SIMILAR TO '-A' ESCAPE '') THEN 't' ELSE 'f' END ---- @@ -73,48 +77,64 @@ SELECT 'A' LIKE 'AA' ESCAPE 'AA' query error invalid escape string SELECT '春A' LIKE '春春_' ESCAPE '春春' +# Not supported by Materialize. +onlyif cockroach query B SELECT 'A' SIMILAR TO '\A' ESCAPE '\' ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '\A' SIMILAR TO '\A' ESCAPE '' ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '%A' SIMILAR TO '_A' ESCAPE '%' ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '%A' SIMILAR TO '%A' ESCAPE '%' ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '123A_' SIMILAR TO '%A_' ESCAPE '_' ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '123A_' SIMILAR TO '%A__' ESCAPE '_' ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '春A' SIMILAR TO '春春_' ESCAPE '春' ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '春A_春春' SIMILAR TO '%_春_%' ESCAPE '春' ---- true -query error invalid escape string +query error Expected end of statement, found TO SELECT 'A' SIMILAR TO 'AA' ESCAPE 'AA' -query error invalid escape string +query error Expected end of statement, found TO SELECT '春A' SIMILAR TO '春春_' ESCAPE '春春' diff --git a/test/sqllogictest/cockroach/database.slt b/test/sqllogictest/cockroach/database.slt deleted file mode 100644 index 661a5bf7db5d7..0000000000000 --- a/test/sqllogictest/cockroach/database.slt +++ /dev/null @@ -1,202 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/database -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -statement ok -CREATE DATABASE a - -statement error pgcode 42P04 database "a" already exists -CREATE DATABASE a - -statement ok -CREATE DATABASE IF NOT EXISTS a - -statement error empty database name -CREATE DATABASE "" - -query T colnames -SHOW DATABASES ----- -database_name -a -materialize -postgres -system -test - -query T colnames -SHOW SCHEMAS FROM a ----- -schema_name -crdb_internal -information_schema -pg_catalog -public - -statement ok -CREATE DATABASE b TEMPLATE=template0 - -statement error unsupported template: nope -CREATE DATABASE c TEMPLATE=NOPE - -statement error unsupported template: nope -CREATE DATABASE IF NOT EXISTS c TEMPLATE=NOPE - -statement ok -CREATE DATABASE b2 ENCODING='UTF8' - -statement error unsupported encoding: NOPE -CREATE DATABASE c ENCODING='NOPE' - -statement error unsupported encoding: NOPE -CREATE DATABASE IF NOT EXISTS c ENCODING='NOPE' - -statement ok -CREATE DATABASE b3 LC_COLLATE='C.UTF-8' - -statement error unsupported collation: NOPE -CREATE DATABASE c LC_COLLATE='NOPE' - -statement error unsupported collation: NOPE -CREATE DATABASE IF NOT EXISTS c LC_COLLATE='NOPE' - -statement ok -CREATE DATABASE b4 LC_CTYPE='C.UTF-8' - -statement error unsupported character classification: NOPE -CREATE DATABASE c LC_CTYPE='NOPE' - -statement error unsupported character classification: NOPE -CREATE DATABASE IF NOT EXISTS c LC_CTYPE='NOPE' - -statement ok -CREATE DATABASE b5 TEMPLATE=template0 ENCODING='UTF8' LC_COLLATE='C.UTF-8' LC_CTYPE='C.UTF-8' - -statement ok -CREATE DATABASE b6 TEMPLATE template0 ENCODING 'UTF8' LC_COLLATE 'C.UTF-8' LC_CTYPE 'C.UTF-8' - -statement ok -CREATE DATABASE c - -query T -SHOW DATABASES ----- -a -b -b2 -b3 -b4 -b5 -b6 -c -materialize -postgres -system -test - -statement ok -CREATE TABLE b.a (id INT PRIMARY KEY) - -statement ok -INSERT INTO b.a VALUES (3),(7),(2) - -query I rowsort -SELECT * FROM b.a ----- -2 -3 -7 - -statement error database "b" is not empty -DROP DATABASE b RESTRICT - -statement ok -DROP DATABASE b CASCADE - -statement error pgcode 42P01 relation "b.a" does not exist -SELECT * FROM b.a - -statement error database "b" does not exist -DROP DATABASE b - -statement ok -DROP DATABASE IF EXISTS b - -statement ok -DROP DATABASE b2 CASCADE; - DROP DATABASE b3 CASCADE; - DROP DATABASE b4 CASCADE; - DROP DATABASE b5 CASCADE; - DROP DATABASE b6 CASCADE - -statement error empty database name -DROP DATABASE "" - -query T colnames -SHOW DATABASES ----- -database_name -a -c -materialize -postgres -system -test - -statement ok -CREATE DATABASE b - -statement error pgcode 42P01 relation "b.a" does not exist -SELECT * FROM b.a - -statement ok -CREATE TABLE b.a (id INT PRIMARY KEY) - -query I -SELECT * FROM b.a ----- - -user testuser - -statement error only superusers are allowed to CREATE DATABASE -CREATE DATABASE privs - -user root - -statement ok -CREATE DATABASE privs - -user testuser - -statement error user testuser does not have DROP privilege on database privs -DROP DATABASE privs CASCADE - -user root - -statement ok -GRANT DROP ON DATABASE privs TO testuser - -user testuser - -statement ok -DROP DATABASE privs CASCADE diff --git a/test/sqllogictest/cockroach/datetime.slt b/test/sqllogictest/cockroach/datetime.slt index a7ab94b8bc766..521ed19ac5873 100644 --- a/test/sqllogictest/cockroach/datetime.slt +++ b/test/sqllogictest/cockroach/datetime.slt @@ -36,12 +36,16 @@ CREATE TABLE t ( FAMILY (c) ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO t VALUES ('2015-08-30 03:34:45.34567', '2015-08-30', '34h2s'), ('2015-08-25 04:45:45.53453', '2015-08-25', '2h45m2s234ms'), ('2015-08-29 23:10:09.98763', '2015-08-29', '234h45m2s234ms') +# Not supported by Materialize. +onlyif cockroach # Spot-check date math. query T SELECT b + '6 month' from t order by a desc @@ -50,11 +54,15 @@ SELECT b + '6 month' from t order by a desc 2016-02-29 00:00:00 +0000 UTC 2016-02-25 00:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query TTT SELECT * FROM t WHERE a = '2015-08-25 04:45:45.53453+01:00'::timestamp ---- 2015-08-25 04:45:45.53453 +0000 +0000 2015-08-25 00:00:00 +0000 +0000 02:45:02.234 +# Not supported by Materialize. +onlyif cockroach # insert duplicate value with different time zone offset statement error duplicate key value \(a\)=\('2015-08-30 03:34:45\.34567\+00:00'\) violates unique constraint "primary" INSERT INTO t VALUES @@ -70,24 +78,34 @@ CREATE TABLE u ( e INTERVAL ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u VALUES (123, '2015-08-30 03:34:45.34567', '2015-08-30 03:34:45.34567', '2015-08-30', '34h2s'), (234, '2015-08-25 04:45:45.53453-02:00', '2015-08-25 04:45:45.53453-02:00', '2015-08-25', '2h45m2s234ms') +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE -5 +# Not supported by Materialize. +onlyif cockroach query TTT SELECT DATE '2000-01-01', DATE '2000-12-31', DATE '1993-05-16' ---- 2000-01-01 00:00:00 +0000 +0000 2000-12-31 00:00:00 +0000 +0000 1993-05-16 00:00:00 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u VALUES (345, '2015-08-29 23:10:09.98763', '2015-08-29 23:10:09.98763', '2015-08-29', '234h45m2s234ms'), (456, '2015-08-29 23:10:09.98763 UTC', '2015-08-29 23:10:09.98763 UTC', '2015-08-29', '234h45m2s234ms') +# Not supported by Materialize. +onlyif cockroach query ITTTT SELECT * FROM u ORDER BY a ---- @@ -99,6 +117,8 @@ SELECT * FROM u ORDER BY a statement ok SET TIME ZONE UTC +# Not supported by Materialize. +onlyif cockroach query ITTTT SELECT * FROM u ORDER BY a ---- @@ -107,14 +127,20 @@ SELECT * FROM u ORDER BY a 345 2015-08-29 23:10:09.98763 +0000 +0000 2015-08-30 04:10:09.98763 +0000 UTC 2015-08-29 00:00:00 +0000 +0000 234:45:02.234 456 2015-08-29 23:10:09.98763 +0000 +0000 2015-08-29 23:10:09.98763 +0000 UTC 2015-08-29 00:00:00 +0000 +0000 234:45:02.234 +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE -5 +# Not supported by Materialize. +onlyif cockroach query TTTT SELECT max(b), max(c), max(d), max(e) FROM u ---- 2015-08-30 03:34:45.34567 +0000 +0000 2015-08-29 23:10:09.98763 -0500 -0500 2015-08-30 00:00:00 +0000 +0000 234:45:02.234 +# Not supported by Materialize. +onlyif cockroach query TTTT SELECT min(b), min(c), min(d), min(e) FROM u ---- @@ -132,6 +158,8 @@ true true # Date sentinel values. +# Not supported by Materialize. +onlyif cockroach query TTT SELECT 'epoch'::date, 'infinity'::date, '-infinity'::date ---- @@ -139,14 +167,20 @@ SELECT 'epoch'::date, 'infinity'::date, '-infinity'::date # Date edge cases. +# Not supported by Materialize. +onlyif cockroach statement error year value 0 is out of range SELECT '0000-01-01'::date +# Not supported by Materialize. +onlyif cockroach query TTTTT SELECT '4714-11-24 BC'::date, '5874897-12-31'::date, '2000-01-01'::date, '0001-01-01'::date, '0001-12-13 BC'::date ---- -4713-11-24 00:00:00 +0000 +0000 5874897-12-31 00:00:00 +0000 +0000 2000-01-01 00:00:00 +0000 +0000 0001-01-01 00:00:00 +0000 +0000 0000-12-13 00:00:00 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach # Also test as strings because lib/pq marshals the previous results to # time.Times, which don't stringify the same. query TTTTT @@ -154,25 +188,37 @@ SELECT '4714-11-24 BC'::date::string, '5874897-12-31'::date::string, '2000-01-01 ---- 4714-11-24 BC 5874897-12-31 2000-01-01 0001-01-01 0001-12-13 BC +# Not supported by Materialize. +onlyif cockroach statement error date is out of range SELECT '4714-11-24 BC'::date - 1 +# Not supported by Materialize. +onlyif cockroach statement error date is out of range SELECT '5874897-12-31'::date + 1 +# Not supported by Materialize. +onlyif cockroach query TT SELECT ('4714-11-24 BC'::date + 1)::string, ('5874897-12-31'::date - 1)::string ---- 4714-11-25 BC 5874897-12-30 +# Not supported by Materialize. +onlyif cockroach query TTTT SELECT 'infinity'::date + 1, 'infinity'::date - 1, '-infinity'::date + 1, '-infinity'::date - 1 ---- infinity infinity -infinity -infinity +# Not supported by Materialize. +onlyif cockroach statement error cannot subtract infinite dates SELECT 'infinity'::date - 'infinity'::date +# Not supported by Materialize. +onlyif cockroach query I SELECT '5874897-12-31'::date - '4714-11-24 BC'::date ---- @@ -180,11 +226,15 @@ SELECT '5874897-12-31'::date - '4714-11-24 BC'::date # TIMESTAMP/DATE builtins. +# Not supported by Materialize. +onlyif cockroach query T SELECT age('2001-04-10 22:06:45', '1957-06-13') ---- 384190:06:45 +# Not supported by Materialize. +onlyif cockroach query B SELECT age('1957-06-13') - age(now(), '1957-06-13') = interval '0s' ---- @@ -215,6 +265,8 @@ SELECT now()::timestamp <= now(), now() <= now()::timestamp ---- true true +# Not supported by Materialize. +onlyif cockroach query B SELECT current_date - current_date() = 0 ---- @@ -230,16 +282,22 @@ SELECT now() - current_timestamp = interval '0s' ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT now() - statement_timestamp() < interval '10s' ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT clock_timestamp() - statement_timestamp() < interval '10s' ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT now() - transaction_timestamp() = interval '0s' ---- @@ -254,14 +312,20 @@ CREATE TABLE kv ( v TIMESTAMPTZ ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO kv (k,v) VALUES ('a', transaction_timestamp()) +# Not supported by Materialize. +onlyif cockroach query T SELECT k FROM kv ---- a +# Not supported by Materialize. +onlyif cockroach query T SELECT k FROM kv where v = transaction_timestamp() ---- @@ -272,9 +336,13 @@ COMMIT TRANSACTION # Changing timezones changes the output of current_date(). +# Not supported by Materialize. +onlyif cockroach statement ok RESET TIME ZONE +# Not supported by Materialize. +onlyif cockroach query BBB SELECT d = tz, d = t, d = n @@ -289,19 +357,27 @@ FROM ---- true true true +# Not supported by Materialize. +onlyif cockroach query B SELECT now() - current_date()::timestamptz < interval '24h10s' ---- true +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE 48 +# Not supported by Materialize. +onlyif cockroach query B SELECT now() - current_date()::timestamptz < interval '24h10s' ---- true +# Not supported by Materialize. +onlyif cockroach query BBB SELECT d = tz, d = t, d = n @@ -316,9 +392,13 @@ FROM ---- true true true +# Not supported by Materialize. +onlyif cockroach statement ok RESET TIME ZONE +# Not supported by Materialize. +onlyif cockroach # Check that the current_timestamp, now and transaction_timestamp are the same. # Test that the transaction_timestamp can differ from the statement_timestamp. # Check that the transaction_timestamp changes with each transaction. @@ -346,6 +426,8 @@ SELECT * FROM KV; INSERT INTO kv (k,v) VALUES ('i', transaction_timestamp()); COMMIT +# Not supported by Materialize. +onlyif cockroach query I SELECT count(DISTINCT (v)) FROM kv ---- @@ -356,22 +438,30 @@ SELECT count(DISTINCT (v)) FROM kv statement ok DELETE FROM kv +# Not supported by Materialize. +onlyif cockroach statement ok BEGIN; INSERT INTO kv (k,v) VALUES ('a', transaction_timestamp()); SELECT * FROM kv +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO kv (k,v) VALUES ('b', transaction_timestamp()); SELECT * FROM kv; COMMIT +# Not supported by Materialize. +onlyif cockroach statement ok BEGIN; SELECT * FROM KV; INSERT INTO kv (k,v) VALUES ('c', transaction_timestamp()); COMMIT +# Not supported by Materialize. +onlyif cockroach query I SELECT count(DISTINCT (v)) FROM kv ---- @@ -386,6 +476,8 @@ CREATE TABLE kv ( v DECIMAL ) +# Not supported by Materialize. +onlyif cockroach # Test that cluster_logical_timestamp() is consistent in transactions # spanning multiple batches of statements. statement ok @@ -393,17 +485,23 @@ BEGIN; INSERT INTO kv (k,v) VALUES (1, cluster_logical_timestamp()); SELECT * FROM kv +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO kv (k,v) VALUES (2, cluster_logical_timestamp()); SELECT * FROM kv; COMMIT +# Not supported by Materialize. +onlyif cockroach statement ok BEGIN; SELECT * FROM kv; INSERT INTO kv (k,v) VALUES (3, cluster_logical_timestamp()); COMMIT +# Not supported by Materialize. +onlyif cockroach query I SELECT count(DISTINCT (v)) FROM kv ---- @@ -415,34 +513,50 @@ DELETE FROM kv statement ok CREATE TABLE m (mints DECIMAL) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO m VALUES (cluster_logical_timestamp()) +# Not supported by Materialize. +onlyif cockroach # Test that cluster_logical_timestamp() is monotonic in transaction order statement ok INSERT INTO kv (k,v) VALUES (1, cluster_logical_timestamp()-(select mints from m)); SELECT * FROM kv +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO kv (k,v) VALUES (2, cluster_logical_timestamp()-(select mints from m)); SELECT * FROM kv +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO kv (k,v) VALUES (3, cluster_logical_timestamp()-(select mints from m)); SELECT * FROM kv +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO kv (k,v) VALUES (4, cluster_logical_timestamp()-(select mints from m)); SELECT * FROM kv +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO kv (k,v) VALUES (5, cluster_logical_timestamp()-(select mints from m)); SELECT * FROM kv +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO kv (k,v) VALUES (6, cluster_logical_timestamp()-(select mints from m)); SELECT * FROM kv +# Not supported by Materialize. +onlyif cockroach query I SELECT k FROM kv ORDER BY v ---- @@ -508,6 +622,8 @@ INSERT INTO ex VALUES (39, 'microsecond', '2016-02-10 19:46:33.306157519', 306158, '2016-02-10 19:46:33.306158'), (40, 'microseconds', '2016-02-10 19:46:33.306157519', 306158, '2016-02-10 19:46:33.306158') +# Not supported by Materialize. +onlyif cockroach query IBI SELECT k, extract(element, input::timestamp) = extract_result, extract(element, input::timestamp) FROM ex ORDER BY k ---- @@ -552,15 +668,23 @@ SELECT k, extract(element, input::timestamp) = extract_result, extract(element, 39 true 306158 40 true 306158 +# Not supported by Materialize. +onlyif cockroach query error extract\(\): unsupported timespan: nansecond SELECT extract(nansecond from '2001-04-10 12:04:59.34565423'::timestamp) +# Not supported by Materialize. +onlyif cockroach query error unknown unit "nanosecond" SELECT INTERVAL '1 nanosecond'; +# Not supported by Materialize. +onlyif cockroach query error unknown unit "ns" SELECT INTERVAL '1 ns'; +# Not supported by Materialize. +onlyif cockroach query IBI SELECT k, extract(element, input::timestamptz) = extract_result, extract(element, input::timestamptz) FROM ex ORDER BY k ---- @@ -605,19 +729,27 @@ SELECT k, extract(element, input::timestamptz) = extract_result, extract(element 39 true 306158 40 true 306158 +# Not supported by Materialize. +onlyif cockroach query error extract\(\): unsupported timespan: nansecond SELECT extract(nansecond from '2001-04-10 12:04:59.34565423'::timestamptz) +# Not supported by Materialize. +onlyif cockroach query I SELECT extract(hour from '2016-02-10 19:46:33.306157519-04'::timestamptz) ---- 19 +# Not supported by Materialize. +onlyif cockroach query I SELECT extract(hours from '2016-02-10 19:46:33.306157519-04'::timestamptz) ---- 19 +# Not supported by Materialize. +onlyif cockroach query IBT SELECT k, date_trunc(element, input::timestamp) = date_trunc_result, date_trunc(element, input::timestamp)::string FROM ex WHERE date_trunc_result IS NOT NULL ORDER BY k @@ -656,6 +788,8 @@ FROM ex WHERE date_trunc_result IS NOT NULL ORDER BY k 39 true 2016-02-10 19:46:33.306158+00:00 40 true 2016-02-10 19:46:33.306158+00:00 +# Not supported by Materialize. +onlyif cockroach query IBT SELECT k, date_trunc(element, input::timestamptz) = date_trunc_result, date_trunc(element, input::timestamptz)::string FROM ex WHERE date_trunc_result IS NOT NULL ORDER BY k @@ -694,16 +828,22 @@ FROM ex WHERE date_trunc_result IS NOT NULL ORDER BY k 39 true 2016-02-10 19:46:33.306158+00:00 40 true 2016-02-10 19:46:33.306158+00:00 +# Not supported by Materialize. +onlyif cockroach query T SELECT date_trunc('hour', '2016-02-10 19:46:33.306157519-04'::timestamptz)::string ---- 2016-02-10 19:00:00-04:00 +# Not supported by Materialize. +onlyif cockroach query T SELECT date_trunc('hours', '2016-02-10 19:46:33.306157519-04'::timestamptz)::string ---- 2016-02-10 19:00:00-04:00 +# Not supported by Materialize. +onlyif cockroach query IBT SELECT k, date_trunc(element, input::date) = date_trunc_result::date, date_trunc(element, input::date)::string FROM ex WHERE date_trunc_result IS NOT NULL ORDER BY k @@ -742,11 +882,15 @@ FROM ex WHERE date_trunc_result IS NOT NULL ORDER BY k 39 true 2016-02-10 00:00:00+00:00 40 true 2016-02-10 00:00:00+00:00 +# Not supported by Materialize. +onlyif cockroach query T SELECT (timestamp '2016-02-10 19:46:33.306157519')::string ---- 2016-02-10 19:46:33.306158+00:00 +# Not supported by Materialize. +onlyif cockroach query T SELECT (timestamptz '2016-02-10 19:46:33.306157519')::string ---- @@ -754,239 +898,343 @@ SELECT (timestamptz '2016-02-10 19:46:33.306157519')::string # Test SET TIME ZONE +# Not supported by Materialize. +onlyif cockroach # default time zone of UTC query T SELECT '2015-08-25 05:45:45.53453'::timestamp ---- 2015-08-25 05:45:45.53453 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45.53453'::timestamp ---- 2015-08-25 05:45:45.53453 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE 'Europe/Rome' +# Not supported by Materialize. +onlyif cockroach query error pq: unimplemented: timestamp abbreviations not supported SELECT '2015-08-25 05:45:45.53453 CET'::timestamptz WHERE false +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE +1 +# Not supported by Materialize. +onlyif cockroach query error pq: unimplemented: timestamp abbreviations not supported SELECT '2015-08-25 05:45:45.53453 CET'::timestamptz WHERE false +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45.53453'::timestamp ---- 2015-08-25 05:45:45.53453 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45.53453'::timestamptz ---- 2015-08-25 05:45:45.53453 +0100 +0100 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamp ---- 2015-08-25 05:45:45 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamp::timestamptz ---- 2015-08-25 05:45:45 +0100 +0100 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamptz::timestamp ---- 2015-08-25 07:45:45 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamptz ---- 2015-08-25 07:45:45 +0100 +0100 +# Not supported by Materialize. +onlyif cockroach # alias test: TIMEZONE instead of TIME ZONE statement ok SET TIMEZONE = +2 +# Not supported by Materialize. +onlyif cockroach query error pq: unimplemented: timestamp abbreviations not supported SELECT '2015-08-25 05:45:45.53453 CET'::timestamptz WHERE false +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45.53453'::timestamp ---- 2015-08-25 05:45:45.53453 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45.53453'::timestamptz ---- 2015-08-25 05:45:45.53453 +0200 +0200 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamp ---- 2015-08-25 05:45:45 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamp::timestamptz ---- 2015-08-25 05:45:45 +0200 +0200 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamptz::timestamp ---- 2015-08-25 08:45:45 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamptz ---- 2015-08-25 08:45:45 +0200 +0200 +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE -5 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 23:45:45.53453'::timestamp ---- 2015-08-24 23:45:45.53453 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 23:45:45.53453'::timestamptz ---- 2015-08-24 23:45:45.53453 -0500 -0500 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 23:45:45.53453 UTC'::timestamp ---- 2015-08-24 23:45:45.53453 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 23:45:45.53453 UTC'::timestamptz ---- 2015-08-24 18:45:45.53453 -0500 -0500 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 23:45:45.53453-02:00'::timestamp ---- 2015-08-24 23:45:45.53453 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 23:45:45.53453-02:00'::timestamptz ---- 2015-08-24 20:45:45.53453 -0500 -0500 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 23:45:45.53453-05:00'::timestamptz ---- 2015-08-24 23:45:45.53453 -0500 -0500 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 23:45:45.534 -02:00'::timestamp ---- 2015-08-24 23:45:45.534 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 23:45:45.534 -02:00'::timestamptz ---- 2015-08-24 20:45:45.534 -0500 -0500 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamp::timestamptz ---- 2015-08-25 05:45:45 -0500 -0500 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamptz::timestamp ---- 2015-08-25 01:45:45 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach # using Eastern instead of fixed -5 should handle DST. statement ok SET TIME ZONE 'America/New_York' +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamp::timestamptz ---- 2015-08-25 05:45:45 -0400 -0400 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 05:45:45-01:00'::timestamptz::timestamp ---- 2015-08-25 02:45:45 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach statement error cannot find time zone "foobar" SET TIME ZONE 'foobar' statement ok SET TIME ZONE default +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamptz ---- 2015-08-24 21:45:45.53453 +0000 UTC +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE local +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamptz ---- 2015-08-24 21:45:45.53453 +0000 UTC +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE 'DEFAULT' +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamptz ---- 2015-08-24 21:45:45.53453 +0000 UTC +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE '' +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamptz ---- 2015-08-24 21:45:45.53453 +0000 UTC +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE INTERVAL '-7h' +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamp ---- 2015-08-24 21:45:45.53453 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamptz ---- 2015-08-24 21:45:45.53453 -0700 -0700 +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE -7.5 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamp ---- 2015-08-24 21:45:45.53453 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamptz ---- 2015-08-24 21:45:45.53453 -0730 -0730 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453 UTC'::timestamptz ---- 2015-08-24 14:15:45.53453 -0730 -0730 +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE LOCAL +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 04:45:45.53453'::timestamp ---- @@ -995,6 +1243,8 @@ SELECT '2015-08-25 04:45:45.53453'::timestamp statement ok SET TIME ZONE DEFAULT +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-25 04:45:45.53453'::timestamp ---- @@ -1004,6 +1254,8 @@ SELECT '2015-08-25 04:45:45.53453'::timestamp statement ok SET TIME ZONE 'UTC' +# Not supported by Materialize. +onlyif cockroach # Check that casting from a timestamp to a date and vice versa # uses the time zone. query TTTT @@ -1011,19 +1263,27 @@ SELECT b, b::date, c, c::date FROM u WHERE a = 123 ---- 2015-08-30 03:34:45.34567 +0000 +0000 2015-08-30 00:00:00 +0000 +0000 2015-08-30 03:34:45.34567 +0000 UTC 2015-08-30 00:00:00 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT d::timestamp FROM u WHERE a = 123 ---- 2015-08-30 00:00:00 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE -5 +# Not supported by Materialize. +onlyif cockroach query TTTT SELECT b, b::date, c, c::date FROM u WHERE a = 123 ---- 2015-08-30 03:34:45.34567 +0000 +0000 2015-08-30 00:00:00 +0000 +0000 2015-08-29 22:34:45.34567 -0500 -0500 2015-08-29 00:00:00 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT d::timestamp FROM u WHERE a = 123 ---- @@ -1040,6 +1300,8 @@ CREATE TABLE tz ( d TIMESTAMPTZ ) +# Not supported by Materialize. +onlyif cockroach query TTBTTTB SHOW COLUMNS FROM tz ---- @@ -1053,15 +1315,21 @@ INSERT INTO tz VALUES (1, timestamp '2015-08-30 03:34:45', timestamptz '2015-08-30 03:34:45', timestamptz '2015-08-30 03:34:45'), (2, timestamp '2015-08-30 03:34:45+01:00', timestamptz '2015-08-30 03:34:45+01:00', timestamptz '2015-08-30 03:34:45') +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE -2 +# Not supported by Materialize. +onlyif cockroach query ITT SELECT a, b, c FROM tz ORDER BY a ---- 1 2015-08-30 03:34:45 +0000 +0000 2015-08-30 01:34:45 -0200 -0200 2 2015-08-30 03:34:45 +0000 +0000 2015-08-30 00:34:45 -0200 -0200 +# Not supported by Materialize. +onlyif cockroach query TTTT SELECT b + interval '1m', interval '1m' + b, c + interval '1m', interval '1m' + c FROM tz WHERE a = 1 ---- @@ -1084,6 +1352,8 @@ SELECT a FROM tz WHERE c < d 2 +# Not supported by Materialize. +onlyif cockroach query I rowsort SELECT a FROM tz WHERE b = c::timestamp ---- @@ -1097,65 +1367,95 @@ SELECT a FROM tz WHERE c = d::timestamp statement ok SET TIME ZONE 'UTC' +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE -5 +# Not supported by Materialize. +onlyif cockroach query T SHOW TIME ZONE ---- -5 +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE INTERVAL '+04:00' HOUR TO MINUTE +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamptz ---- 2015-08-24 21:45:45.53453 +0400 +0400 +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE INTERVAL '-04:00' MINUTE TO SECOND +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamptz ---- 2015-08-24 21:45:45.53453 -0400 -0400 +# Not supported by Materialize. +onlyif cockroach # alias test: TIMEZONE instead of TIME ZONE statement ok SET TIMEZONE TO INTERVAL '+05:00' HOUR TO MINUTE +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamptz ---- 2015-08-24 21:45:45.53453 +0500 +0500 +# Not supported by Materialize. +onlyif cockroach statement ok SET TIMEZONE TO INTERVAL '-05:00' MINUTE TO SECOND +# Not supported by Materialize. +onlyif cockroach query T SELECT '2015-08-24 21:45:45.53453'::timestamptz ---- 2015-08-24 21:45:45.53453 -0500 -0500 +# Not supported by Materialize. +onlyif cockroach statement ok SET TIME ZONE 0 +# Not supported by Materialize. +onlyif cockroach query T SHOW TIME ZONE ---- 0 +# Not supported by Materialize. +onlyif cockroach query T SELECT DATE '1999-01-01' + INTERVAL '4 minutes' ---- 1999-01-01 00:04:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT INTERVAL '4 minutes' + DATE '1999-01-01' ---- 1999-01-01 00:04:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT DATE '1999-01-01' - INTERVAL '4 minutes' ---- @@ -1242,6 +1542,8 @@ SELECT INTERVAL '5' DAY; ---- 5 days +# Not supported by Materialize. +onlyif cockroach query TT SELECT INTERVAL '5' MONTH, INTERVAL '5' YEAR TO MONTH; ---- @@ -1252,27 +1554,37 @@ SELECT INTERVAL '5' YEAR ---- 5 years +# Not supported by Materialize. +onlyif cockroach ## Test truncation via field specifiers query TTTT SELECT INTERVAL '1-2 3 4:5:6' SECOND, INTERVAL '1-2 3 4:5:6' MINUTE TO SECOND, INTERVAL '1-2 3 4:5:6' HOUR TO SECOND, INTERVAL '1-2 3 4:5:6' DAY TO SECOND; ---- 1 year 2 mons 3 days 04:05:06 1 year 2 mons 3 days 04:05:06 1 year 2 mons 3 days 04:05:06 1 year 2 mons 3 days 04:05:06 +# Not supported by Materialize. +onlyif cockroach query TTT SELECT INTERVAL '1-2 3 4:5:6' MINUTE, INTERVAL '1-2 3 4:5:6' HOUR TO MINUTE, INTERVAL '1-2 3 4:5:6' DAY TO MINUTE; ---- 1 year 2 mons 3 days 04:05:00 1 year 2 mons 3 days 04:05:00 1 year 2 mons 3 days 04:05:00 +# Not supported by Materialize. +onlyif cockroach query TT SELECT INTERVAL '1-2 3 4:5:6' HOUR, INTERVAL '1-2 3 4:5:6' DAY TO HOUR ---- 1 year 2 mons 3 days 04:00:00 1 year 2 mons 3 days 04:00:00 +# Not supported by Materialize. +onlyif cockroach query T SELECT INTERVAL '1-2 3 4:5:6' DAY; ---- 1 year 2 mons 3 days +# Not supported by Materialize. +onlyif cockroach query TT SELECT INTERVAL '1-2 3 4:5:6' MONTH, INTERVAL '1-2 3 4:5:6' YEAR TO MONTH; ---- @@ -1301,16 +1613,22 @@ INSERT INTO topics VALUES ( '2017-12-05 04:04:04.913231+00:00' ); +# Not supported by Materialize. +onlyif cockroach query T SELECT date_trunc('month', ts) AS date_trunc_month_created_at FROM "topics"; ---- 2017-12-01 00:00:00 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT date_trunc('month', tstz) AS date_trunc_month_created_at FROM "topics"; ---- 2017-12-01 00:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT date_trunc('month', "date") AS date_trunc_month_created_at FROM "topics"; ---- @@ -1323,22 +1641,32 @@ SELECT date_trunc('month', "date") AS date_trunc_month_created_at FROM "topics"; # dates from this issue are no longer possible to express. subtest regression_35255 +# Not supported by Materialize. +onlyif cockroach statement error date is out of range SELECT '-56325279622-12-26'::DATE +# Not supported by Materialize. +onlyif cockroach statement error date is out of range SELECT '-5632-12-26'::DATE +# Not supported by Materialize. +onlyif cockroach query T SELECT '-563-12-26'::DATE ---- -0563-12-26 00:00:00 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '-56-12-26'::DATE ---- -0056-12-26 00:00:00 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '-5-12-26'::DATE ---- @@ -1348,6 +1676,8 @@ SELECT '-5-12-26'::DATE # dates from this issue are no longer possible to express. subtest regression_36146 +# Not supported by Materialize. +onlyif cockroach statement error out of range WITH w (c) AS (VALUES (NULL), (NULL)) @@ -1358,6 +1688,8 @@ FROM ORDER BY c +# Not supported by Materialize. +onlyif cockroach statement error out of range SELECT '1971-03-18'::DATE + 300866802885581286 @@ -1366,17 +1698,25 @@ SELECT # dates from this issue are no longer possible to express. subtest regression_36557 +# Not supported by Materialize. +onlyif cockroach statement error out of range SELECT 7133080445639580613::INT8 + '1977-11-03'::DATE +# Not supported by Materialize. +onlyif cockroach statement error out of range SELECT '-239852040018-04-28':::DATE +# Not supported by Materialize. +onlyif cockroach statement error out of range SELECT(7133080445639580613::INT8 + '1977-11-03'::DATE) = '-239852040018-04-28':::DATE subtest interval_math +# Not supported by Materialize. +onlyif cockroach query TTTTTTT SELECT i, diff --git a/test/sqllogictest/cockroach/decimal.slt b/test/sqllogictest/cockroach/decimal.slt index c04537829f528..f2d19e8696516 100644 --- a/test/sqllogictest/cockroach/decimal.slt +++ b/test/sqllogictest/cockroach/decimal.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,33 +9,35 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/decimal +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/decimal # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - # The following tests have results equivalent to Postgres (differences # in string representation and number of decimals returned, but otherwise # the same). These do not pass using the inf package. The inf package # (http://gopkg.in/inf.v0) is what we used to use, but it had various problems # (for example, all the test cases below), and was replaced with apd. +# Not supported by Materialize. +onlyif cockroach # inf returns 0 query R SELECT (1.4238790346995263e-40::DECIMAL / 6.011482313728436e+41::DECIMAL) ---- 2.3685988919035999994E-82 +# Not supported by Materialize. +onlyif cockroach # inf returns -108.4851126682386588 query R SELECT ln(7.682705743584112e-48::DECIMAL) @@ -46,39 +48,39 @@ SELECT ln(7.682705743584112e-48::DECIMAL) query R SELECT sqrt(9.789765531128956e-34::DECIMAL) ---- -3.1288601009199749773E-17 +0.000000000000000031288608150571351357789 # inf returns 0.1547300000000000 query R SELECT pow(4.727998800941528e-14::DECIMAL, 0.06081860494226844::DECIMAL) ---- -0.15472926640705911955 +0.154729266407059119548130274175564532946 # inf returns 0, 0 query RR SELECT pow(sqrt(1e-10::DECIMAL), 2), sqrt(pow(1e-5::DECIMAL, 2)) ---- -1E-10 0.00001 +0.0000000001 0.00001 # inf returns 1e-16, 0, 2e-16 query RRR SELECT 1e-16::DECIMAL / 2, 1e-16::DECIMAL / 3, 1e-16::DECIMAL / 2 * 2 ---- -5E-17 3.3333333333333333333E-17 1.0E-16 +0.00000000000000005 0.000000000000000033333333333333333333333 0.0000000000000001 # inf returns 1e-8, 0, 0, 0 query RRRR SELECT pow(1e-4::DECIMAL, 2), pow(1e-5::DECIMAL, 2), pow(1e-8::DECIMAL, 2), pow(1e-9::DECIMAL, 2) ---- -1E-8 1E-10 1E-16 1E-18 +0.00000001 0.0000000001 0.0000000000000001 0.000000000000000001 # inf returns argument too large query R SELECT pow(1e-10::DECIMAL, 2) ---- -1E-20 +0.00000000000000000001 -# inf panics (materialize#13051) +# inf panics (#13051) query RR SELECT 'NaN'::FLOAT::DECIMAL, 'NaN'::DECIMAL ---- @@ -96,16 +98,18 @@ INSERT INTO t VALUES (0.000::decimal, 0.00::decimal), (1.00::decimal, 1.00::deci query RR SELECT * FROM t ORDER BY d ---- -0.000 0.0 -1.00 1.0 -2.0 2.0 -3 3.0 +0 0 +1 1 +2 2 +3 3 # Ensure trailing zeros are kept in an index. statement ok CREATE TABLE t2 (d decimal, v decimal(3, 1), primary key (d, v)) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO t2 VALUES (1.00::decimal, 1.00::decimal), @@ -119,39 +123,43 @@ INSERT INTO t2 VALUES query RR SELECT * FROM t2 ORDER BY d ---- -NaN NaN --Infinity -Infinity -0.0000 0.0 -1.00 1.0 -2.0 2.0 -3 3.0 -Infinity Infinity + # Ensure uniqueness in PK columns with +/- NaN and 0. -statement error duplicate key value +statement error invalid input syntax for type numeric: "\-NaN" INSERT INTO t2 VALUES ('-NaN'::decimal, '-NaN'::decimal) +# Not supported by Materialize. +onlyif cockroach statement error duplicate key value INSERT INTO t2 VALUES (0, 0) # Ensure NaN cannot be signaling or negative. +# Not supported by Materialize. +onlyif cockroach query RRRR SELECT 'NaN'::decimal, '-NaN'::decimal, 'sNaN'::decimal, '-sNaN'::decimal ---- NaN NaN NaN NaN +# Not supported by Materialize. +onlyif cockroach query RR SELECT * FROM t2 WHERE d IS NaN and v IS NaN ---- NaN NaN +# Not supported by Materialize. +onlyif cockroach query RR SELECT * FROM t2 WHERE d = 'Infinity' and v = 'Infinity' ---- Infinity Infinity +# Not supported by Materialize. +onlyif cockroach query RR SELECT * FROM t2 WHERE d = '-Infinity' and v = '-Infinity' ---- @@ -159,9 +167,13 @@ SELECT * FROM t2 WHERE d = '-Infinity' and v = '-Infinity' # Ensure special values are handled correctly. +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE s (d decimal null, index (d)) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO s VALUES (null), @@ -173,6 +185,8 @@ INSERT INTO s VALUES (1), (-1) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO s VALUES ('-0'::decimal), @@ -181,6 +195,8 @@ INSERT INTO s VALUES ('-0.00E-1'::decimal), ('-0.0E-3'::decimal) +# Not supported by Materialize. +onlyif cockroach query R rowsort SELECT * FROM s WHERE d = 0 ---- @@ -191,17 +207,23 @@ SELECT * FROM s WHERE d = 0 0.000 0.0000 +# Not supported by Materialize. +onlyif cockroach query R SELECT * FROM s WHERE d IS NAN ---- NaN NaN +# Not supported by Materialize. +onlyif cockroach query R SELECT * FROM s WHERE d = 'inf'::decimal ---- Infinity +# Not supported by Materialize. +onlyif cockroach query R SELECT * FROM s WHERE d = 'NaN' ---- @@ -211,6 +233,8 @@ NaN # In the following tests, the various zero values all compare equal to # each other so we must use two ORDER BY clauses to obtain a stable result. +# Not supported by Materialize. +onlyif cockroach # Check the ordering of decimal values. query R SELECT d FROM s ORDER BY d, d::TEXT @@ -229,9 +253,11 @@ NaN 1 Infinity +# Not supported by Materialize. +onlyif cockroach # Just test the NaN-ness of the values. query RBBB -SELECT d, d IS NaN, d = 'NaN', isnan(d) FROM s@{FORCE_INDEX=primary} ORDER BY d, d::TEXT +SELECT d, d IS NaN, d = 'NaN', isnan(d) FROM s@{FORCE_INDEX=s_pkey} ORDER BY d, d::TEXT ---- NULL NULL NULL NULL NaN true true true @@ -247,6 +273,8 @@ NaN true true true 1 false false false Infinity false false false +# Not supported by Materialize. +onlyif cockroach # Just test the NaN-ness of the values in secondary index query RBBB SELECT d, d IS NaN, d = 'NaN', isnan(d) FROM s@{FORCE_INDEX=s_d_idx} ORDER BY d, d::TEXT @@ -265,8 +293,10 @@ NaN true true true 1 false false false Infinity false false false +# Not supported by Materialize. +onlyif cockroach query RB -select d, d > 'NaN' from s@{FORCE_INDEX=primary} where d > 'NaN' ORDER BY d, d::TEXT +select d, d > 'NaN' from s@{FORCE_INDEX=s_pkey} where d > 'NaN' ORDER BY d, d::TEXT ---- -Infinity true -1 true @@ -279,6 +309,8 @@ select d, d > 'NaN' from s@{FORCE_INDEX=primary} where d > 'NaN' ORDER BY d, d:: 1 true Infinity true +# Not supported by Materialize. +onlyif cockroach query RB select d, d > 'NaN' from s@{FORCE_INDEX=s_d_idx} where d > 'NaN' ORDER BY d, d::TEXT ---- @@ -293,10 +325,14 @@ select d, d > 'NaN' from s@{FORCE_INDEX=s_d_idx} where d > 'NaN' ORDER BY d, d:: 1 true Infinity true +# Not supported by Materialize. +onlyif cockroach # Verify that decimals don't lose trailing 0s even when used for an index. statement ok CREATE INDEX idx ON s (d) +# Not supported by Materialize. +onlyif cockroach query R rowsort SELECT * FROM s@idx WHERE d = 0 ---- @@ -307,6 +343,8 @@ SELECT * FROM s@idx WHERE d = 0 0.000 0.0000 +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO s VALUES ('10'::decimal), @@ -317,8 +355,10 @@ INSERT INTO s VALUES ('1000000E-5'::decimal), ('1.0000000E+1'::decimal) +# Not supported by Materialize. +onlyif cockroach query R rowsort -SELECT * FROM s@primary WHERE d = 10 +SELECT * FROM s@s_pkey WHERE d = 10 ---- 10 10.0 @@ -328,6 +368,8 @@ SELECT * FROM s@primary WHERE d = 10 10.00000 10.000000 +# Not supported by Materialize. +onlyif cockroach query R rowsort SELECT * FROM s@idx WHERE d = 10 ---- @@ -342,32 +384,335 @@ SELECT * FROM s@idx WHERE d = 10 query R SELECT 1.00::decimal(6,4) ---- -1.0000 +1 +# Not supported by Materialize. +onlyif cockroach statement error value with precision 6, scale 4 must round to an absolute value less than 10\^2 SELECT 101.00::decimal(6,4) -statement error scale \(6\) must be between 0 and precision \(4\) +statement error scale for type numeric must be between 0 and precision 4 SELECT 101.00::decimal(4,6) +# Not supported by Materialize. +onlyif cockroach statement error value with precision 2, scale 2 must round to an absolute value less than 1 SELECT 1::decimal(2, 2) -# Regression test for materialize#16081 +# Regression test for #16081 -statement ok +statement CREATE TABLE a (b DECIMAL) -statement ok +# Not supported by Materialize. +onlyif cockroach +statement INSERT INTO a VALUES (142378208485490985369999605144727062141206925976498256305323716858805588894693616552055968571135475510700810219028167653516982373238641332965927953273383572708760984694356069974208844865675206339235758647159337463780100273189720943242182911961627806424621091859596571173867825568394327041453823674373002756096) query R SELECT * FROM a ---- -142378208485490985369999605144727062141206925976498256305323716858805588894693616552055968571135475510700810219028167653516982373238641332965927953273383572708760984694356069974208844865675206339235758647159337463780100273189720943242182911961627806424621091859596571173867825568394327041453823674373002756096 + +# Not supported by Materialize. +onlyif cockroach # Verify that NaNs are returned instead of invalid operation. query R SELECT 'inf'::decimal + '-inf'::decimal ---- NaN + +# Regression test for #40327 +query R +SELECT 1.0 / 'Infinity' + 2 FROM a; +---- + + +query R +SELECT 2.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +---- +2 + +# Test with infinity. Many of these tests come from +# https://github.com/postgres/postgres/commit/a57d312a7706321d850faa048a562a0c0c01b835 + +# Not supported by Materialize. +onlyif cockroach +query RR +SELECT var_pop('inf'::numeric), var_samp('inf'::numeric) +---- +NaN NULL + +# Not supported by Materialize. +onlyif cockroach +query RR +SELECT stddev_pop('inf'::numeric), stddev_samp('inf'::numeric) +---- +NaN NULL + +# Not supported by Materialize. +onlyif cockroach +query RRR +SELECT sum(x::numeric), avg(x::numeric), var_pop(x::numeric) +FROM (VALUES ('1'), ('infinity')) v(x) +---- +Infinity Infinity NaN + +# Not supported by Materialize. +onlyif cockroach +query RRR +SELECT sum(x::numeric), avg(x::numeric), var_pop(x::numeric) +FROM (VALUES ('infinity'), ('1')) v(x) +---- +Infinity Infinity NaN + +# Not supported by Materialize. +onlyif cockroach +query RRR +SELECT sum(x::numeric), avg(x::numeric), var_pop(x::numeric) +FROM (VALUES ('infinity'), ('infinity')) v(x) +---- +Infinity Infinity NaN + +# Not supported by Materialize. +onlyif cockroach +query RRR +SELECT sum(x::numeric), avg(x::numeric), var_pop(x::numeric) +FROM (VALUES ('-infinity'), ('infinity')) v(x) +---- +NaN NaN NaN + +# Not supported by Materialize. +onlyif cockroach +query RRR +SELECT sum(x::numeric), avg(x::numeric), var_pop(x::numeric) +FROM (VALUES ('-infinity'), ('-infinity')) v(x) +---- +-Infinity -Infinity NaN + +# Not supported by Materialize. +onlyif cockroach +query RRRRR +WITH v(x) AS + (VALUES('0'::numeric),('1'::numeric),('-1'::numeric),('4.2'::numeric),('inf'::numeric),('-inf'::numeric),('nan'::numeric)) +SELECT x1, x2, + x1 + x2 AS sum, + x1 - x2 AS diff, + x1 * x2 AS prod +FROM v AS v1(x1), v AS v2(x2) +---- +0 0 0 0 0 +0 1 1 -1 0 +0 -1 -1 1 -0 +0 4.2 4.2 -4.2 0.0 +0 Infinity Infinity -Infinity NaN +0 -Infinity -Infinity Infinity NaN +0 NaN NaN NaN NaN +1 0 1 1 0 +1 1 2 0 1 +1 -1 0 2 -1 +1 4.2 5.2 -3.2 4.2 +1 Infinity Infinity -Infinity Infinity +1 -Infinity -Infinity Infinity -Infinity +1 NaN NaN NaN NaN +-1 0 -1 -1 -0 +-1 1 0 -2 -1 +-1 -1 -2 0 1 +-1 4.2 3.2 -5.2 -4.2 +-1 Infinity Infinity -Infinity -Infinity +-1 -Infinity -Infinity Infinity Infinity +-1 NaN NaN NaN NaN +4.2 0 4.2 4.2 0.0 +4.2 1 5.2 3.2 4.2 +4.2 -1 3.2 5.2 -4.2 +4.2 4.2 8.4 0.0 17.64 +4.2 Infinity Infinity -Infinity Infinity +4.2 -Infinity -Infinity Infinity -Infinity +4.2 NaN NaN NaN NaN +Infinity 0 Infinity Infinity NaN +Infinity 1 Infinity Infinity Infinity +Infinity -1 Infinity Infinity -Infinity +Infinity 4.2 Infinity Infinity Infinity +Infinity Infinity Infinity NaN Infinity +Infinity -Infinity NaN Infinity -Infinity +Infinity NaN NaN NaN NaN +-Infinity 0 -Infinity -Infinity NaN +-Infinity 1 -Infinity -Infinity -Infinity +-Infinity -1 -Infinity -Infinity Infinity +-Infinity 4.2 -Infinity -Infinity -Infinity +-Infinity Infinity NaN -Infinity -Infinity +-Infinity -Infinity -Infinity NaN Infinity +-Infinity NaN NaN NaN NaN +NaN 0 NaN NaN NaN +NaN 1 NaN NaN NaN +NaN -1 NaN NaN NaN +NaN 4.2 NaN NaN NaN +NaN Infinity NaN NaN NaN +NaN -Infinity NaN NaN NaN +NaN NaN NaN NaN NaN + +# Not supported by Materialize. +onlyif cockroach +query RRRRR +WITH v(x) AS + (VALUES('0'::numeric),('1'::numeric),('-1'::numeric),('4.2'::numeric),('inf'::numeric),('-inf'::numeric),('nan'::numeric)) +SELECT x1, x2, + x1 / x2 AS quot, + x1 % x2 AS mod, + div(x1, x2) AS div +FROM v AS v1(x1), v AS v2(x2) WHERE x2 != 0 +---- +0 1 0 0 0 +0 -1 -0 0 -0 +0 4.2 0E+1 0.0 0 +0 Infinity 0E-2019 0 0 +0 -Infinity -0E-2019 0 -0 +0 NaN NaN NaN NaN +1 1 1.0000000000000000000 0 1 +1 -1 -1.0000000000000000000 0 -1 +1 4.2 0.23809523809523809524 1.0 0 +1 Infinity 0E-2019 1 0 +1 -Infinity -0E-2019 1 -0 +1 NaN NaN NaN NaN +-1 1 -1.0000000000000000000 -0 -1 +-1 -1 1.0000000000000000000 -0 1 +-1 4.2 -0.23809523809523809524 -1.0 -0 +-1 Infinity -0E-2019 -1 -0 +-1 -Infinity 0E-2019 -1 0 +-1 NaN NaN NaN NaN +4.2 1 4.2000000000000000000 0.2 4 +4.2 -1 -4.2000000000000000000 0.2 -4 +4.2 4.2 1.0000000000000000000 0.0 1 +4.2 Infinity 0E-2019 4.2 0 +4.2 -Infinity -0E-2019 4.2 -0 +4.2 NaN NaN NaN NaN +Infinity 1 Infinity NaN Infinity +Infinity -1 -Infinity NaN -Infinity +Infinity 4.2 Infinity NaN Infinity +Infinity Infinity NaN NaN NaN +Infinity -Infinity NaN NaN NaN +Infinity NaN NaN NaN NaN +-Infinity 1 -Infinity NaN -Infinity +-Infinity -1 Infinity NaN Infinity +-Infinity 4.2 -Infinity NaN -Infinity +-Infinity Infinity NaN NaN NaN +-Infinity -Infinity NaN NaN NaN +-Infinity NaN NaN NaN NaN +NaN 1 NaN NaN NaN +NaN -1 NaN NaN NaN +NaN 4.2 NaN NaN NaN +NaN Infinity NaN NaN NaN +NaN -Infinity NaN NaN NaN +NaN NaN NaN NaN NaN + +statement error invalid input syntax for type numeric: "inf" +SELECT 'inf'::numeric / '0' + +statement error invalid input syntax for type numeric: "\-inf" +SELECT '-inf'::numeric / '0' + +# Not supported by Materialize. +onlyif cockroach +query R +SELECT 'Infinity'::float8::numeric +---- +Infinity + +# Not supported by Materialize. +onlyif cockroach +query R +SELECT '-Infinity'::float8::numeric +---- +-Infinity + +query F +SELECT 'NaN'::numeric::float8 +---- +NaN + +# Not supported by Materialize. +onlyif cockroach +query F +SELECT 'Infinity'::numeric::float8 +---- +Infinity + +# Not supported by Materialize. +onlyif cockroach +query F +SELECT '-Infinity'::numeric::float8 +---- +-Infinity + +statement error "NaN" smallint out of range +SELECT 'NaN'::numeric::int2 + +statement error invalid input syntax for type numeric: "\-Infinity" +SELECT '-Infinity'::numeric::int8 + +statement error function "width_bucket" does not exist +SELECT width_bucket('inf', 3.0, 4.0, 888) + +statement error function "width_bucket" does not exist +SELECT width_bucket(2.0, 3.0, '-inf', 888) + +statement error function "width_bucket" does not exist +SELECT width_bucket(0, '-inf', 4.0, 888) + +# Not supported by Materialize. +onlyif cockroach +query RRR +select exp('nan'::numeric), exp('inf'::numeric), exp('-inf'::numeric) +---- +NaN Infinity 0 + +# Not supported by Materialize. +onlyif cockroach +query R +WITH v(x) AS +(VALUES (' inf '), (' +inf '), (' -inf '), (' Infinity '), (' +inFinity '), (' -INFINITY ')) +SELECT x1::decimal +FROM v AS v1(x1) +---- +Infinity +Infinity +-Infinity +Infinity +Infinity +-Infinity + +statement ok +CREATE TABLE t71926(no_typmod decimal, precision decimal(5), precision_and_width decimal(5,3)) + +# Not supported by Materialize. +onlyif cockroach +query TI +SELECT attname, atttypmod FROM pg_attribute WHERE attrelid = 't71926'::regclass::oid AND atttypid = 'decimal'::regtype::oid +---- +no_typmod -1 +precision 327684 +precision_and_width 327687 + +# Regression test for #86790 +statement ok +CREATE TABLE t86790 (x INT8 NOT NULL) + +statement ok +INSERT INTO t86790 VALUES (-4429772553778622992) + +query R +SELECT (x / 1)::DECIMAL FROM t86790 +---- +-4429772553778622992 + +statement ok +SET testing_optimizer_disable_rule_probability = 1 + +# The results should be the same as the previous SELECT. +query R +SELECT (x / 1)::DECIMAL FROM t86790 +---- +-4429772553778622992 + +statement ok +RESET testing_optimizer_disable_rule_probability diff --git a/test/sqllogictest/cockroach/default.slt b/test/sqllogictest/cockroach/default.slt new file mode 100644 index 0000000000000..1b30317756745 --- /dev/null +++ b/test/sqllogictest/cockroach/default.slt @@ -0,0 +1,225 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/default +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement error DEFAULT expression does not support casting from boolean to integer +CREATE TABLE t (a INT PRIMARY KEY DEFAULT false) + +statement error DEFAULT expression does not allow subqueries +CREATE TABLE t (a INT PRIMARY KEY DEFAULT (SELECT 1)) + +statement error column "b" does not exist +CREATE TABLE t (a INT PRIMARY KEY DEFAULT b) + +# Not supported by Materialize. +onlyif cockroach +# Issue #14308: support tables with DEFAULT NULL columns. +statement ok +CREATE TABLE null_default (ts TIMESTAMP PRIMARY KEY NULL DEFAULT NULL) + +# Aggregate function calls in CHECK are not ok. +statement error aggregate functions are not allowed in DEFAULT +CREATE TABLE bad (a INT DEFAULT count(1)) + +# Window function calls in CHECK are not ok. +statement error window functions are not allowed in DEFAULT +CREATE TABLE bad (a INT DEFAULT count(1) OVER ()) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t ( + a INT PRIMARY KEY DEFAULT 42, + b TIMESTAMP DEFAULT now(), + c FLOAT DEFAULT random(), + d DATE DEFAULT now() +) + +# Not supported by Materialize. +onlyif cockroach +query TTBTTTB colnames +SHOW COLUMNS FROM t +---- +column_name data_type is_nullable column_default generation_expression indices is_hidden +a INT8 false 42 · {t_pkey} false +b TIMESTAMP true now() · {t_pkey} false +c FLOAT8 true random() · {t_pkey} false +d DATE true now() · {t_pkey} false + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON COLUMN t.a IS 'a' + +# Not supported by Materialize. +onlyif cockroach +query TTBTTTBT colnames +SHOW COLUMNS FROM t WITH COMMENT +---- +column_name data_type is_nullable column_default generation_expression indices is_hidden comment +a INT8 false 42 · {t_pkey} false a +b TIMESTAMP true now() · {t_pkey} false NULL +c FLOAT8 true random() · {t_pkey} false NULL +d DATE true now() · {t_pkey} false NULL + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT) + +# Not supported by Materialize. +onlyif cockroach +query IBBB +SELECT a, b <= now(), c >= 0.0, d <= now() FROM t +---- +42 true true true + +# Not supported by Materialize. +onlyif cockroach +statement ok +TRUNCATE TABLE t + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t DEFAULT VALUES + +# Not supported by Materialize. +onlyif cockroach +query IBBB +SELECT a, b <= now(), c >= 0.0, d <= now() FROM t +---- +42 true true true + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t (a) VALUES (1) + +# Not supported by Materialize. +onlyif cockroach +query IBBB +SELECT a, b <= now(), c >= 0.0, d <= now() FROM t WHERE a = 1 +---- +1 true true true + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t VALUES (2) + +# Not supported by Materialize. +onlyif cockroach +query IBBB +SELECT a, b <= now(), c >= 0.0, d <= now() FROM t WHERE a = 2 +---- +2 true true true + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE t SET (b, c) = ('2015-09-18 00:00:00', -1.0) + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE t SET b = DEFAULT WHERE a = 1 + +# Not supported by Materialize. +onlyif cockroach +query IBBB +SELECT a, b <= now(), c = -1.0, d <= now() FROM t WHERE a = 1 +---- +1 true true true + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE t SET (b, c) = (DEFAULT, DEFAULT) WHERE a = 2 + +# Not supported by Materialize. +onlyif cockroach +query IBBB +SELECT a, b <= now(), c >= 0.0, d <= now() FROM t WHERE a = 2 +---- +2 true true true + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE t SET b = DEFAULT, c = DEFAULT, d = DEFAULT + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE t SET (b) = (DEFAULT), (c) = (DEFAULT), (d) = (DEFAULT) + +# Not supported by Materialize. +onlyif cockroach +# Test a table without a default and with a null default +statement ok +CREATE TABLE v ( + a INT PRIMARY KEY, + b TIMESTAMP NULL DEFAULT NULL, + c INT +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE v SET a = DEFAULT + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE v SET (a, c) = (DEFAULT, DEFAULT) + +# Not supported by Materialize. +onlyif cockroach +query TTBTTTB colnames +SHOW COLUMNS FROM v +---- +column_name data_type is_nullable column_default generation_expression indices is_hidden +a INT8 false NULL · {v_pkey} false +b TIMESTAMP true NULL · {v_pkey} false +c INT8 true NULL · {v_pkey} false + +# Regression test for #34901: verify that builtins can be used in default value +# expressions without a "memory budget exceeded" error while backfilling +statement ok +CREATE TABLE t34901 (x STRING) + +statement ok +INSERT INTO t34901 VALUES ('a') + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t34901 ADD COLUMN y STRING DEFAULT (concat('b', 'c')) + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT * FROM t34901 +---- +a bc diff --git a/test/sqllogictest/cockroach/delete.slt b/test/sqllogictest/cockroach/delete.slt index 8507a2f492f15..144443c84db2c 100644 --- a/test/sqllogictest/cockroach/delete.slt +++ b/test/sqllogictest/cockroach/delete.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/delete +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/delete # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach statement ok @@ -61,7 +61,7 @@ SELECT * FROM kview 5 6 7 8 -statement error "kview" is not a table +statement error cannot mutate view 'materialize\.public\.kview' DELETE FROM kview query II rowsort @@ -85,6 +85,8 @@ SELECT * FROM kv statement count 0 DELETE FROM kv WHERE k=5 +# Not supported by Materialize. +onlyif cockroach query II DELETE FROM kv RETURNING k, v ---- @@ -94,6 +96,8 @@ DELETE FROM kv RETURNING k, v query II SELECT * FROM kv ---- +1 2 +7 8 statement error column "nonexistent" does not exist DELETE FROM kv WHERE nonexistent = 1 @@ -107,6 +111,8 @@ SELECT * FROM unindexed 1 2 7 8 +# Not supported by Materialize. +onlyif cockroach query II DELETE FROM unindexed RETURNING k, v ---- @@ -116,10 +122,14 @@ DELETE FROM unindexed RETURNING k, v query II SELECT * FROM unindexed ---- +1 2 +7 8 statement count 4 INSERT INTO unindexed VALUES (1, 2), (3, 4), (5, 6), (7, 8) +# Not supported by Materialize. +onlyif cockroach query II colnames DELETE FROM unindexed WHERE k=3 or v=6 RETURNING * ---- @@ -127,6 +137,8 @@ k v 3 4 5 6 +# Not supported by Materialize. +onlyif cockroach query II colnames DELETE FROM unindexed RETURNING unindexed.* ---- @@ -141,11 +153,19 @@ query II colnames,rowsort SELECT k, v FROM unindexed ---- k v -1 2 -3 4 -5 6 -7 8 - +1 2 +1 2 +1 2 +3 4 +3 4 +5 6 +5 6 +7 8 +7 8 +7 8 + +# Not supported by Materialize. +onlyif cockroach statement count 4 DELETE FROM unindexed @@ -153,6 +173,8 @@ DELETE FROM unindexed statement count 4 INSERT INTO unindexed VALUES (1, 2), (3, 4), (5, 6), (7, 8) +# Not supported by Materialize. +onlyif cockroach statement count 1 DELETE FROM unindexed WHERE k >= 4 ORDER BY k LIMIT 1 @@ -160,10 +182,23 @@ query II colnames,rowsort SELECT k, v FROM unindexed ---- k v -1 2 -3 4 -7 8 - +1 2 +1 2 +1 2 +1 2 +3 4 +3 4 +3 4 +5 6 +5 6 +5 6 +7 8 +7 8 +7 8 +7 8 + +# Not supported by Materialize. +onlyif cockroach statement count 3 DELETE FROM unindexed @@ -171,6 +206,109 @@ query II colnames SELECT k, v FROM unindexed ---- k v +1 2 +1 2 +1 2 +1 2 +3 4 +3 4 +3 4 +5 6 +5 6 +5 6 +7 8 +7 8 +7 8 +7 8 + +# Confirm ONLY and * are no-ops + +statement count 4 +INSERT INTO unindexed VALUES (1, 2), (3, 4), (5, 6), (7, 8) + +# Not supported by Materialize. +onlyif cockroach +statement count 1 +DELETE FROM ONLY unindexed WHERE k >= 4 ORDER BY k LIMIT 1 + +query II colnames,rowsort +SELECT k, v FROM unindexed +---- +k v +1 2 +1 2 +1 2 +1 2 +1 2 +3 4 +3 4 +3 4 +3 4 +5 6 +5 6 +5 6 +5 6 +7 8 +7 8 +7 8 +7 8 +7 8 + +# Not supported by Materialize. +onlyif cockroach +statement count 1 +DELETE FROM unindexed * WHERE k >= 7 + +query II colnames,rowsort +SELECT k, v FROM unindexed +---- +k v +1 2 +1 2 +1 2 +1 2 +1 2 +3 4 +3 4 +3 4 +3 4 +5 6 +5 6 +5 6 +5 6 +7 8 +7 8 +7 8 +7 8 +7 8 + +# Not supported by Materialize. +onlyif cockroach +statement count 2 +DELETE FROM ONLY unindexed * WHERE k <=3 + +query II colnames,rowsort +SELECT k, v FROM unindexed +---- +k v +1 2 +1 2 +1 2 +1 2 +1 2 +3 4 +3 4 +3 4 +3 4 +5 6 +5 6 +5 6 +5 6 +7 8 +7 8 +7 8 +7 8 +7 8 statement ok CREATE TABLE indexed (id int primary key, value int, other int, index (value)) @@ -183,12 +321,16 @@ DELETE FROM indexed WHERE value = 5 statement ok INSERT INTO unindexed VALUES (1, 9), (8, 2), (3, 7), (6, 4) +# Not supported by Materialize. +onlyif cockroach query II DELETE FROM unindexed WHERE k > 1 AND v < 7 ORDER BY v DESC LIMIT 2 RETURNING v,k ---- 4 6 2 8 +# Not supported by Materialize. +onlyif cockroach query II DELETE FROM unindexed ORDER BY v LIMIT 2 RETURNING k,v ---- @@ -200,16 +342,22 @@ DELETE FROM unindexed ORDER BY v LIMIT 2 RETURNING k,v statement count 4 INSERT INTO unindexed VALUES (1, 2), (3, 4), (5, 6), (7, 8) +# Not supported by Materialize. +onlyif cockroach query I SELECT count(*) FROM [DELETE FROM unindexed LIMIT 2 RETURNING v] ---- 2 +# Not supported by Materialize. +onlyif cockroach query I SELECT count(*) FROM [DELETE FROM unindexed LIMIT 1 RETURNING v] ---- 1 +# Not supported by Materialize. +onlyif cockroach query I SELECT count(*) FROM [DELETE FROM unindexed LIMIT 5 RETURNING v] ---- @@ -220,29 +368,36 @@ subtest regression_29494 statement ok CREATE TABLE t29494(x INT PRIMARY KEY); INSERT INTO t29494 VALUES (12) +# Not supported by Materialize. +onlyif cockroach statement ok BEGIN; ALTER TABLE t29494 ADD COLUMN y INT NOT NULL DEFAULT 123 +# Not supported by Materialize. +onlyif cockroach # Check that the new column is not visible query T SELECT create_statement FROM [SHOW CREATE t29494] ---- -CREATE TABLE t29494 ( - x INT8 NOT NULL, - CONSTRAINT "primary" PRIMARY KEY (x ASC), - FAMILY "primary" (x) +CREATE TABLE public.t29494 ( + x INT8 NOT NULL, + CONSTRAINT t29494_pkey PRIMARY KEY (x ASC) ) # Check that the new column is not usable in RETURNING -statement error column "y" does not exist +statement error Expected end of statement, found RETURNING DELETE FROM t29494 RETURNING y statement ok ROLLBACK +# Not supported by Materialize. +onlyif cockroach statement ok BEGIN; ALTER TABLE t29494 ADD COLUMN y INT NOT NULL DEFAULT 123 +# Not supported by Materialize. +onlyif cockroach query I DELETE FROM t29494 RETURNING * ---- @@ -253,30 +408,34 @@ COMMIT subtest regression_33361 -# Disable automatic stats to avoid flakiness (sometimes causes retry errors). -statement ok -SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false - statement ok CREATE TABLE t33361(x INT PRIMARY KEY, y INT UNIQUE, z INT); INSERT INTO t33361 VALUES (1, 2, 3) +# Not supported by Materialize. +onlyif cockroach statement ok BEGIN; ALTER TABLE t33361 DROP COLUMN y -statement error column "y" does not exist +statement error Expected end of statement, found RETURNING DELETE FROM t33361 RETURNING y statement ok ROLLBACK +# Not supported by Materialize. +onlyif cockroach statement ok BEGIN; ALTER TABLE t33361 DROP COLUMN y +# Not supported by Materialize. +onlyif cockroach query II DELETE FROM t33361 RETURNING *; COMMIT ---- 1 3 +# Not supported by Materialize. +onlyif cockroach # Test that delete works with column families (no indexes, so fast path). statement ok CREATE TABLE family ( @@ -287,17 +446,325 @@ CREATE TABLE family ( ); INSERT INTO family VALUES (1, 1), (2, 2), (3, 3) +# Not supported by Materialize. +onlyif cockroach statement ok BEGIN; ALTER TABLE family ADD COLUMN z INT CREATE FAMILY +# Not supported by Materialize. +onlyif cockroach statement ok DELETE FROM family WHERE x=2 statement ok COMMIT +# Not supported by Materialize. +onlyif cockroach query III rowsort SELECT x, y, z FROM family ---- 1 1 NULL 3 3 NULL + +# Verify that the fast path does its deletes at the expected timestamp. +statement ok +CREATE TABLE a (a INT PRIMARY KEY) + +statement ok +INSERT INTO a SELECT generate_series(1,5) + +let $ts +SELECT cluster_logical_timestamp() + +statement ok +DELETE FROM a WHERE a <= 3 + +query I rowsort +SELECT * FROM a +---- +4 +5 + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT * FROM a AS OF SYSTEM TIME $ts +---- +1 +2 +3 +4 +5 + +# Test that USING works. + +subtest delete_using + +statement ok +CREATE TABLE u_a ( + a INT NOT NULL PRIMARY KEY, + b STRING, + c INT +) + +statement ok +CREATE TABLE u_b ( + a INT NOT NULL PRIMARY KEY, + b STRING +) + +statement ok +CREATE TABLE u_c ( + a INT NOT NULL PRIMARY KEY, + b STRING, + c INT +) + +statement ok +CREATE TABLE u_d ( + a INT, + b INT +) + +statement ok +INSERT INTO u_a VALUES (1, 'a', 10), (2, 'b', 20), (3, 'c', 30), (4, 'd', 40) + +statement ok +INSERT INTO u_b VALUES (10, 'a'), (20, 'b'), (30, 'c'), (40, 'd') + +statement ok +INSERT INTO u_c VALUES (1, 'a', 10), (2, 'b', 50), (3, 'c', 50), (4, 'd', 40) + +# Test a join with a filter. +statement ok +DELETE FROM u_a USING u_b WHERE c = u_b.a AND u_b.b = 'd' + +query ITI rowsort +SELECT * FROM u_a; +---- +1 a 10 +2 b 20 +3 c 30 + +# Test a self join. +statement ok +INSERT INTO u_a VALUES (5, 'd', 5), (6, 'e', 6) + +statement ok +DELETE FROM u_a USING u_a u_a2 WHERE u_a.a = u_a2.c + +query ITI rowsort +SELECT * FROM u_a; +---- +1 a 10 +2 b 20 +3 c 30 + +# Test when USING uses multiple tables. + +statement ok +INSERT INTO u_c VALUES (30, 'a', 1) + +statement ok +DELETE FROM u_a USING u_b, u_c WHERE u_a.c = u_b.a AND u_a.c = u_c.a + +query ITI rowsort +SELECT * FROM u_a; +---- +1 a 10 +2 b 20 + +# Not supported by Materialize. +onlyif cockroach +# Test if USING works well with RETURNING expressions that reference +# the USING table and target table. +query ITIT colnames,rowsort +DELETE FROM u_a USING u_b WHERE u_a.c = u_b.a RETURNING u_b.a, u_b.b, u_a.a, u_a.b; +---- +a b a b +10 a 1 a +20 b 2 b + +query ITI rowsort +SELECT * FROM u_a; +---- +1 a 10 +2 b 20 + +statement ok +INSERT INTO u_a VALUES (1, 'a', 10), (2, 'b', 20), (3, 'c', 30), (4, 'd', 40); + +# Not supported by Materialize. +onlyif cockroach +# Test if RETURNING * returns everything. +query ITIITI colnames,rowsort +DELETE FROM u_a USING u_c WHERE u_a.c = u_c.c RETURNING *; +---- +a b c a b c +1 a 10 1 a 10 +4 d 40 4 d 40 + +# Not supported by Materialize. +onlyif cockroach +# Clean u_a to input a new set of data, and to improve test readability. +statement ok +TRUNCATE u_a + +statement ok +INSERT INTO u_a VALUES (1, 'a', 5), (2, 'b', 10), (3, 'c', 15), (4, 'd', 20), (5, 'd', 25), (6, 'd', 30), (7, 'd', 35), (8, 'd', 40), (9, 'd', 45) + +# Using ORDER BY and LIMIT with a `DELETE ... USING` where ORDER BY and LIMIT references the USING +# table is not supported. +# TODO(#89817): Add support in DELETE ... USING for ORDER BY clauses to reference the USING +# table. This is not supported in UPDATE ... FROM either: #89817. +statement error Expected end of statement, found ORDER +DELETE FROM u_a AS foo USING u_b AS bar WHERE bar.a > foo.c ORDER BY bar.a DESC LIMIT 3 RETURNING *; + +# Not supported by Materialize. +onlyif cockroach +# Test aliased table names, ORDER BY and LIMIT where ORDER BY references the target +# table. +query ITI +DELETE FROM u_a AS foo USING u_b AS bar WHERE bar.a > foo.c ORDER BY foo.a DESC LIMIT 3 RETURNING foo.*; +---- +7 d 35 +6 d 30 +5 d 25 + +query ITI rowsort +SELECT * FROM u_a; +---- +1 a 10 +1 a 10 +1 a 5 +2 b 10 +2 b 20 +2 b 20 +3 c 15 +3 c 30 +4 d 20 +4 d 40 +5 d 25 +6 d 30 +7 d 35 +8 d 40 +9 d 45 + +statement ok +INSERT INTO u_d VALUES (1, 10), (2, 20), (3, 30), (4, 40) + +query IT rowsort +SELECT * FROM u_b; +---- +10 a +20 b +30 c +40 d + +query ITI rowsort +SELECT * FROM u_c; +---- +1 a 10 +2 b 50 +3 c 50 +4 d 40 +30 a 1 + +# Test if DELETE FROM ... USING works with LATERAL. + +statement ok +DELETE FROM u_a USING u_b, LATERAL (SELECT u_c.a, u_c.b, u_c.c FROM u_c WHERE u_b.b = u_c.b) AS other WHERE other.c = 1 AND u_a.c = 35 + +query ITI rowsort +SELECT * FROM u_a +---- +1 a 10 +1 a 10 +1 a 5 +2 b 10 +2 b 20 +2 b 20 +3 c 15 +3 c 30 +4 d 20 +4 d 40 +5 d 25 +6 d 30 +8 d 40 +9 d 45 + +# Test if DELETE FROM ... USING works with partial indexes. + +statement ok +CREATE TABLE pindex ( + a DECIMAL(10, 2), + INDEX (a) WHERE a > 3 +) + +statement ok +INSERT INTO pindex VALUES (1.0), (2.0), (3.0), (4.0), (5.0), (8.0) + +statement ok +DELETE FROM pindex USING (VALUES (5.0), (6.0)) v(b) WHERE pindex.a = v.b + +query F rowsort +SELECT * FROM pindex; +---- +1 +2 +3 +4 +8 + +# Not supported by Materialize. +onlyif cockroach +query F rowsort +SELECT a FROM pindex@pindex_a_idx WHERE a > 3 +---- +4.00 +8.00 + +# Not supported by Materialize. +onlyif cockroach +statement ok +DELETE FROM pindex USING (VALUES (2.0), (4.0)) v(b) WHERE pindex.a = v.b RETURNING v.b + +query F rowsort +SELECT * FROM pindex; +---- +1 +2 +3 +4 +8 + +# Not supported by Materialize. +onlyif cockroach +query F rowsort +SELECT a FROM pindex@pindex_a_idx WHERE a > 3 +---- +8.00 + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #99630. Partial index DEL columns should come after +# passthrough columns in the delete node's column list. +statement ok +CREATE TABLE t99630a (a INT, INDEX idx (a) WHERE a > 0); +CREATE TABLE t99630b (b BOOL); +INSERT INTO t99630a VALUES (11); +INSERT INTO t99630b VALUES (false); + +# Not supported by Materialize. +onlyif cockroach +query B +DELETE FROM t99630a USING t99630b RETURNING b +---- +false + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM t99630a@idx WHERE a > 0 +---- diff --git a/test/sqllogictest/cockroach/dependencies.slt b/test/sqllogictest/cockroach/dependencies.slt new file mode 100644 index 0000000000000..4ada54d410251 --- /dev/null +++ b/test/sqllogictest/cockroach/dependencies.slt @@ -0,0 +1,201 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/dependencies +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +SET experimental_enable_unique_without_index_constraints = true + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE test_kv(k INT PRIMARY KEY, v INT, w DECIMAL); + CREATE UNIQUE INDEX test_v_idx ON test_kv(v); + CREATE INDEX test_v_idx2 ON test_kv(v DESC) STORING(w); + CREATE INDEX test_v_idx3 ON test_kv(w) STORING(v); + CREATE TABLE test_kvr1(k INT PRIMARY KEY REFERENCES test_kv(k)); + CREATE TABLE test_kvr2(k INT, v INT UNIQUE REFERENCES test_kv(k)); + CREATE TABLE test_kvr3(k INT, v INT UNIQUE REFERENCES test_kv(v)); + CREATE TABLE test_kvi1(k INT PRIMARY KEY); + CREATE TABLE test_kvi2(k INT PRIMARY KEY, v INT); + CREATE UNIQUE INDEX test_kvi2_idx ON test_kvi2(v); + CREATE VIEW test_v1 AS SELECT v FROM test_kv; + CREATE VIEW test_v2 AS SELECT v FROM test_v1; + CREATE TABLE test_uwi_parent(a INT UNIQUE WITHOUT INDEX); + CREATE TABLE test_uwi_child(a INT REFERENCES test_uwi_parent(a)); + +# Not supported by Materialize. +onlyif cockroach +query ITITTBTB colnames +SELECT * FROM crdb_internal.table_columns WHERE descriptor_name LIKE 'test_%' ORDER BY descriptor_id, column_id +---- +descriptor_id descriptor_name column_id column_name column_type nullable default_expr hidden +106 test_kv 1 k family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false false NULL false +106 test_kv 2 v family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false true NULL false +106 test_kv 3 w family:DecimalFamily width:0 precision:0 locale:"" visible_type:0 oid:1700 time_precision_is_set:false true NULL false +107 test_kvr1 1 k family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false false NULL false +108 test_kvr2 1 k family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false true NULL false +108 test_kvr2 2 v family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false true NULL false +108 test_kvr2 3 rowid family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false false unique_rowid() true +109 test_kvr3 1 k family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false true NULL false +109 test_kvr3 2 v family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false true NULL false +109 test_kvr3 3 rowid family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false false unique_rowid() true +110 test_kvi1 1 k family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false false NULL false +111 test_kvi2 1 k family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false false NULL false +111 test_kvi2 2 v family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false true NULL false +112 test_v1 1 v family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false true NULL false +113 test_v2 1 v family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false true NULL false +114 test_uwi_parent 1 a family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false true NULL false +114 test_uwi_parent 2 rowid family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false false unique_rowid() true +115 test_uwi_child 1 a family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false true NULL false +115 test_uwi_child 2 rowid family:IntFamily width:64 precision:0 locale:"" visible_type:0 oid:20 time_precision_is_set:false false unique_rowid() true + +# Not supported by Materialize. +onlyif cockroach +query ITITTBBBI colnames + SELECT descriptor_id, descriptor_name, index_id, index_name, index_type, is_unique, is_inverted, is_sharded, shard_bucket_count + FROM crdb_internal.table_indexes + WHERE descriptor_name LIKE 'test_%' +ORDER BY descriptor_id, index_id +---- +descriptor_id descriptor_name index_id index_name index_type is_unique is_inverted is_sharded shard_bucket_count +106 test_kv 1 test_kv_pkey primary true false false NULL +106 test_kv 2 test_v_idx secondary true false false NULL +106 test_kv 4 test_v_idx2 secondary false false false NULL +106 test_kv 6 test_v_idx3 secondary false false false NULL +107 test_kvr1 1 test_kvr1_pkey primary true false false NULL +108 test_kvr2 1 test_kvr2_pkey primary true false false NULL +108 test_kvr2 2 test_kvr2_v_key secondary true false false NULL +109 test_kvr3 1 test_kvr3_pkey primary true false false NULL +109 test_kvr3 2 test_kvr3_v_key secondary true false false NULL +110 test_kvi1 1 test_kvi1_pkey primary true false false NULL +111 test_kvi2 1 test_kvi2_pkey primary true false false NULL +111 test_kvi2 2 test_kvi2_idx secondary true false false NULL +112 test_v1 0 · primary false false false NULL +113 test_v2 0 · primary false false false NULL +114 test_uwi_parent 1 test_uwi_parent_pkey primary true false false NULL +115 test_uwi_child 1 test_uwi_child_pkey primary true false false NULL + +# Not supported by Materialize. +onlyif cockroach +query ITITTITTB colnames +SELECT * FROM crdb_internal.index_columns WHERE descriptor_name LIKE 'test_%' ORDER BY descriptor_id, index_id, column_type, column_id +---- +descriptor_id descriptor_name index_id index_name column_type column_id column_name column_direction implicit +106 test_kv 1 test_kv_pkey key 1 k ASC false +106 test_kv 2 test_v_idx extra 1 NULL NULL false +106 test_kv 2 test_v_idx key 2 v ASC false +106 test_kv 4 test_v_idx2 extra 1 NULL NULL false +106 test_kv 4 test_v_idx2 key 2 v DESC false +106 test_kv 4 test_v_idx2 storing 3 NULL NULL false +106 test_kv 6 test_v_idx3 composite 3 NULL NULL false +106 test_kv 6 test_v_idx3 extra 1 NULL NULL false +106 test_kv 6 test_v_idx3 key 3 w ASC false +106 test_kv 6 test_v_idx3 storing 2 NULL NULL false +107 test_kvr1 1 test_kvr1_pkey key 1 k ASC false +108 test_kvr2 1 test_kvr2_pkey key 3 rowid ASC false +108 test_kvr2 2 test_kvr2_v_key extra 3 NULL NULL false +108 test_kvr2 2 test_kvr2_v_key key 2 v ASC false +109 test_kvr3 1 test_kvr3_pkey key 3 rowid ASC false +109 test_kvr3 2 test_kvr3_v_key extra 3 NULL NULL false +109 test_kvr3 2 test_kvr3_v_key key 2 v ASC false +110 test_kvi1 1 test_kvi1_pkey key 1 k ASC false +111 test_kvi2 1 test_kvi2_pkey key 1 k ASC false +111 test_kvi2 2 test_kvi2_idx extra 1 NULL NULL false +111 test_kvi2 2 test_kvi2_idx key 2 v ASC false +114 test_uwi_parent 1 test_uwi_parent_pkey key 2 rowid ASC false +115 test_uwi_child 1 test_uwi_child_pkey key 2 rowid ASC false + +# Not supported by Materialize. +onlyif cockroach +query ITIIITITT colnames +SELECT * FROM crdb_internal.backward_dependencies WHERE descriptor_name LIKE 'test_%' ORDER BY descriptor_id, index_id, dependson_type, dependson_id, dependson_index_id +---- +descriptor_id descriptor_name index_id column_id dependson_id dependson_type dependson_index_id dependson_name dependson_details +107 test_kvr1 NULL NULL 106 fk 1 test_kvr1_k_fkey NULL +108 test_kvr2 NULL NULL 106 fk 1 test_kvr2_v_fkey NULL +109 test_kvr3 NULL NULL 106 fk 2 test_kvr3_v_fkey NULL +112 test_v1 NULL NULL 106 view NULL NULL NULL +113 test_v2 NULL NULL 112 view NULL NULL NULL +115 test_uwi_child NULL NULL 114 fk 0 test_uwi_child_a_fkey NULL + +# Not supported by Materialize. +onlyif cockroach +query ITIITITT colnames +SELECT * FROM crdb_internal.forward_dependencies WHERE descriptor_name LIKE 'test_%' ORDER BY descriptor_id, index_id, dependedonby_type, dependedonby_id, dependedonby_index_id +---- +descriptor_id descriptor_name index_id dependedonby_id dependedonby_type dependedonby_index_id dependedonby_name dependedonby_details +106 test_kv NULL 107 fk NULL NULL NULL +106 test_kv NULL 108 fk NULL NULL NULL +106 test_kv NULL 109 fk NULL NULL NULL +106 test_kv NULL 112 view 0 NULL Columns: [2] +112 test_v1 NULL 113 view 0 NULL Columns: [1] +114 test_uwi_parent NULL 115 fk NULL NULL NULL + +# Checks view dependencies (#17306) +statement ok +CREATE TABLE moretest_t(k INT, v INT); + CREATE VIEW moretest_v AS SELECT v FROM moretest_t WHERE FALSE + +# Not supported by Materialize. +onlyif cockroach +query ITIIITITT colnames +SELECT * FROM crdb_internal.backward_dependencies WHERE descriptor_name LIKE 'moretest_%' ORDER BY descriptor_id, index_id, dependson_type, dependson_id, dependson_index_id +---- +descriptor_id descriptor_name index_id column_id dependson_id dependson_type dependson_index_id dependson_name dependson_details +117 moretest_v NULL NULL 116 view NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query ITIITITT colnames +SELECT * FROM crdb_internal.forward_dependencies WHERE descriptor_name LIKE 'moretest_%' ORDER BY descriptor_id, index_id, dependedonby_type, dependedonby_id, dependedonby_index_id +---- +descriptor_id descriptor_name index_id dependedonby_id dependedonby_type dependedonby_index_id dependedonby_name dependedonby_details +116 moretest_t NULL 117 view 0 NULL Columns: [2] + +# Check sequence dependencies. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE blog_posts_id_seq + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE blog_posts (id INT PRIMARY KEY DEFAULT nextval('blog_posts_id_seq'), title text) + +# Not supported by Materialize. +onlyif cockroach +query ITIIITITT colnames +SELECT * FROM crdb_internal.backward_dependencies WHERE descriptor_name LIKE 'blog_posts' +---- +descriptor_id descriptor_name index_id column_id dependson_id dependson_type dependson_index_id dependson_name dependson_details +119 blog_posts NULL 1 118 sequence NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query ITIITITT colnames +SELECT * FROM crdb_internal.forward_dependencies WHERE descriptor_name LIKE 'blog_posts%' +---- +descriptor_id descriptor_name index_id dependedonby_id dependedonby_type dependedonby_index_id dependedonby_name dependedonby_details +118 blog_posts_id_seq NULL 119 sequence 0 NULL Columns: [1] diff --git a/test/sqllogictest/cockroach/discard.slt b/test/sqllogictest/cockroach/discard.slt index a85dcd26269f3..88c014fc2d73b 100644 --- a/test/sqllogictest/cockroach/discard.slt +++ b/test/sqllogictest/cockroach/discard.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/discard +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/discard # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach statement ok @@ -38,23 +38,33 @@ SHOW SEARCH_PATH ---- public +# Not supported by Materialize. +onlyif cockroach query T SET timezone = 'Europe/Amsterdam'; SHOW TIMEZONE ---- Europe/Amsterdam +statement ok +DISCARD ALL; + query T -DISCARD ALL; SHOW TIMEZONE +SHOW TIMEZONE ---- UTC +# Not supported by Materialize. +onlyif cockroach query T SET TIME ZONE 'Europe/Amsterdam'; SHOW TIME ZONE ---- Europe/Amsterdam +statement ok +DISCARD ALL + query T -DISCARD ALL; SHOW TIME ZONE +SHOW TIME ZONE ---- UTC @@ -70,5 +80,143 @@ DEALLOCATE a statement ok BEGIN -statement error DISCARD ALL cannot run inside a transaction block +statement error DISCARD ALL cannot be run inside a transaction block DISCARD ALL + +statement ok +ROLLBACK + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE discard_seq_test START WITH 10 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT nextval('discard_seq_test') +---- +10 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT lastval() +---- +10 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT currval('discard_seq_test') +---- +10 + +# Not supported by Materialize. +onlyif cockroach +statement ok +DISCARD SEQUENCES + +statement error pgcode 55000 function "lastval" does not exist +SELECT lastval() + +statement error pgcode 55000 function "currval" does not exist +SELECT currval('discard_seq_test') + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE discard_seq_test_2 START WITH 10 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT nextval('discard_seq_test_2') +---- +10 + +statement ok +DISCARD ALL + +statement error pgcode 55000 function "lastval" does not exist +SELECT lastval() + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE S2 CACHE 10 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT nextval('s2') +---- +1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +DISCARD SEQUENCES + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT nextval('s2') +---- +11 + +statement ok +SET experimental_enable_temp_tables=on + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT count(*) FROM [SHOW SCHEMAS] WHERE schema_name LIKE 'pg_temp_%' +---- +0 + +statement ok +DISCARD TEMP; + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT count(*) FROM [SHOW SCHEMAS] WHERE schema_name LIKE 'pg_temp_%' +---- +0 + +statement ok +CREATE TEMP TABLE test (a int); + +statement ok +CREATE TEMP TABLE test2 (a uuid); + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT table_name FROM [SHOW TABLES FROM pg_temp] +---- +test +test2 + +statement ok +DISCARD TEMP; + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT table_name FROM [SHOW TABLES FROM pg_temp] +---- + +# Not supported by Materialize. +onlyif cockroach +#Ensure temp schema is not deleted +query I +SELECT count(*) FROM [SHOW SCHEMAS] WHERE schema_name LIKE 'pg_temp_%' +---- +1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +UNLISTEN temp diff --git a/test/sqllogictest/cockroach/disjunction_in_join.slt b/test/sqllogictest/cockroach/disjunction_in_join.slt new file mode 100644 index 0000000000000..1c7bc3bbd72c4 --- /dev/null +++ b/test/sqllogictest/cockroach/disjunction_in_join.slt @@ -0,0 +1,988 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/disjunction_in_join +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Test ORed ON clause predicates which may be split into unions or +# intersections. +# Use tables both with and without a primary key, to test when PK columns are +# not included and also to allow null values. + +statement ok +CREATE TABLE a(a1 INT, a2 INT, a3 INT, a4 INT, PRIMARY KEY(a1, a2, a3, a4)) + +statement ok +CREATE TABLE b(b1 INT, b2 INT, b3 INT, b4 INT, + INDEX (b1, b2) STORING (b3, b4), + INDEX (b2) STORING (b1, b3, b4), + INDEX (b3) STORING (b1, b2, b4)) + +statement ok +CREATE TABLE c(c1 INT, c2 INT, c3 INT, c4 INT) + +statement ok +CREATE TABLE d(d1 INT, d2 INT, d3 INT, d4 INT, + INDEX d (d1) STORING (d2, d3, d4)) + +# shared column values +statement ok +INSERT INTO a VALUES (0, 0, 0, 0),(1, 10, 100, 1000); +INSERT INTO b VALUES (0, 0, 0, 0),(1, 10, 100, 1000); +INSERT INTO c VALUES (0, 0, 0, 0),(1, 10, 100, 1000); +INSERT INTO d VALUES (0, 0, 0, 0),(1, 10, 100, 1000); + +# duplicate rows +statement ok +INSERT INTO a VALUES (11, 110, 1100, 11000); +INSERT INTO b VALUES (11, 110, 1100, 11000), (11, 110, 1100, 11000); +INSERT INTO c VALUES (11, 110, 1100, 11000), (11, 110, 1100, 11000), (11, 110, 1100, 11000); +INSERT INTO d VALUES (11, 110, 1100, 11000), (11, 110, 1100, 11000), (11, 110, 1100, 11000), (11, 110, 1100, 11000); + +# null values +statement ok +INSERT INTO b VALUES (NULL, NULL, NULL, NULL), (NULL, NULL, NULL, NULL); +INSERT INTO d VALUES (NULL, NULL, NULL, NULL), (NULL, NULL, NULL, NULL), (NULL, NULL, NULL, NULL), (NULL, NULL, NULL, NULL); + +# duplicates in first three columns +statement ok +INSERT INTO a VALUES (12, 120, 1200, 1), (12, 120, 1200, 2); +INSERT INTO b VALUES (12, 120, 1200, 1), (12, 120, 1200, 2), (12, 120, 1200, 2); + +# nulls combined with the duplicates +statement ok +INSERT INTO b VALUES (NULL, 120, 1200, 1) , (12, NULL, 1200, 2); +INSERT INTO d VALUES (11, NULL, NULL, 11000), (NULL, 110, 1100, 11000); + +# partially shared combinations +statement ok +INSERT INTO a VALUES (2, 20, 200, 2000), (3, 30, 300, 3000), (4, 40, 400, 4000), (5, 50, 500, 5000), (6, 60, 600, 6000), (7, 70, 700, 7000); +INSERT INTO b VALUES (2, 20, 200, 2000), (3, 30, 300, 3000), (5, 50, 500, 5000), (6, 60, 600, 6000) , (8, 80, 800, 8000), (9, 90, 900, 9000); +INSERT INTO c VALUES (2, 20, 200, 2000), (5, 50, 500, 5000) , (8, 80, 800, 8000) , (10, 100, 1000, 10000); +INSERT INTO d VALUES (5, 50, 500, 5000), (6, 60, 600, 6000), (7, 70, 700, 7000); + +# combinations with null values +statement ok +INSERT INTO b VALUES (2, NULL, 200, NULL), (3, 30, 300, NULL) , (NULL, 40, 400, 4000) , (NULL, NULL, NULL, 5000) , (7, NULL, 700, NULL); +INSERT INTO b VALUES (2, 20, NULL, 200) , (3, 30, 300, 3000) , (4, NULL, NULL, NULL) , (5, 50, NULL, 5000) , (7, NULL, 700, NULL); +INSERT INTO c VALUES (3, 30, NULL, NULL) , (NULL, NULL, 400, 4000), (5, 50, NULL, NULL), (6, NULL, NULL, 6000); +INSERT INTO d VALUES (NULL, 30, NULL, 3000) , (NULL, 90, NULL, NULL); + +# combinations with null and unique values +statement ok +INSERT INTO b VALUES (82, NULL, 207, NULL), (NULL, 567, NULL, 789); +INSERT INTO c VALUES (83, 208, NULL, NULL), (NULL, NULL, 84, 209); +INSERT INTO d VALUES (85, NULL, NULL, 210), (NULL, 86, 211, NULL); + +# combinations with unique values +statement ok +INSERT INTO a VALUES (15, 55, 555, 5555), (15, 55, 500, 5555), (15, 50, 555, 5555); +INSERT INTO b VALUES (17, 77, 777, 7777), (17, 77, 700, 7777), (17, 70, 777, 7777); +INSERT INTO b VALUES (NULL, 77, 777, 7777), (17, NULL, 777, 7777), (17, 77, NULL, 7777); + +# cross column value matches (e.g. a1 = b2) +statement ok +INSERT INTO a VALUES (101, 200, 3000, 40); +INSERT INTO a VALUES (102, 5, 60, 70); +INSERT INTO a VALUES (103, 7, 8, 70); +INSERT INTO a VALUES (104, 5, 5, 5); +INSERT INTO a VALUES (50, 5, 5000, 500); +INSERT INTO a VALUES (80, 11, 110, 11000); +INSERT INTO b VALUES (30, 7, 40, 2); +INSERT INTO b VALUES (120, 80, 90, 10); +INSERT INTO c VALUES (1, 2, 3, 4); +INSERT INTO d VALUES (5, 6, 7, 8), (9, 10, 11, 12); + +############# +# InnerJoin # +############# + +# The left AND right sides of the join already produce key columns +query IIIIIIII rowsort +SELECT t1.*, t2.* FROM a t1, a t2 WHERE t1.a1 = t2.a3 OR t1.a2 = t2.a4 OR t1.a1 = t2.a4 +---- +0 0 0 0 0 0 0 0 +1 10 100 1000 12 120 1200 1 +2 20 200 2000 12 120 1200 2 +4 40 400 4000 101 200 3000 40 +5 50 500 5000 104 5 5 5 +7 70 700 7000 102 5 60 70 +7 70 700 7000 103 7 8 70 +50 5 5000 500 104 5 5 5 +102 5 60 70 104 5 5 5 +104 5 5 5 104 5 5 5 + +# Join of tables with compound primary keys +query IIIIIIII rowsort +SELECT * FROM a t1, a t2 WHERE (t1.a2 = t2.a2 OR t1.a3 = t2.a3) AND (t1.a1 = t2.a1 OR t1.a4 = t2.a4) +---- +0 0 0 0 0 0 0 0 +1 10 100 1000 1 10 100 1000 +2 20 200 2000 2 20 200 2000 +3 30 300 3000 3 30 300 3000 +4 40 400 4000 4 40 400 4000 +5 50 500 5000 5 50 500 5000 +6 60 600 6000 6 60 600 6000 +7 70 700 7000 7 70 700 7000 +11 110 1100 11000 11 110 1100 11000 +12 120 1200 1 12 120 1200 1 +12 120 1200 1 12 120 1200 2 +12 120 1200 2 12 120 1200 1 +12 120 1200 2 12 120 1200 2 +15 50 555 5555 15 50 555 5555 +15 55 500 5555 15 55 500 5555 +15 55 500 5555 15 55 555 5555 +15 55 555 5555 15 55 500 5555 +15 55 555 5555 15 55 555 5555 +50 5 5000 500 50 5 5000 500 +80 11 110 11000 80 11 110 11000 +101 200 3000 40 101 200 3000 40 +102 5 60 70 102 5 60 70 +103 7 8 70 103 7 8 70 +104 5 5 5 104 5 5 5 +15 50 555 5555 15 55 555 5555 +15 55 555 5555 15 50 555 5555 + +query IIIIIIII rowsort +SELECT * FROM a, b WHERE (a2 = b2 OR a3 = b3) AND (a1 = b1 OR a4 = b4) +---- +0 0 0 0 0 0 0 0 +1 10 100 1000 1 10 100 1000 +2 20 200 2000 2 20 200 2000 +2 20 200 2000 2 20 NULL 200 +3 30 300 3000 3 30 300 3000 +3 30 300 3000 3 30 300 3000 +3 30 300 3000 3 30 300 NULL +4 40 400 4000 NULL 40 400 4000 +5 50 500 5000 5 50 500 5000 +5 50 500 5000 5 50 NULL 5000 +6 60 600 6000 6 60 600 6000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +12 120 1200 1 12 120 1200 1 +12 120 1200 1 NULL 120 1200 1 +12 120 1200 1 12 120 1200 2 +12 120 1200 1 12 120 1200 2 +12 120 1200 2 12 120 1200 1 +12 120 1200 2 12 120 1200 2 +12 120 1200 2 12 120 1200 2 +2 20 200 2000 2 NULL 200 NULL +7 70 700 7000 7 NULL 700 NULL +7 70 700 7000 7 NULL 700 NULL +12 120 1200 1 12 NULL 1200 2 +12 120 1200 2 12 NULL 1200 2 + +query III rowsort +SELECT a1,a2,a3 FROM a,b WHERE (a1=b1 AND a2=b2 AND (a1=1 OR b1=1)) OR (a3=b3 AND a4=b4) +---- +1 10 100 +0 0 0 +2 20 200 +3 30 300 +3 30 300 +4 40 400 +5 50 500 +6 60 600 +11 110 1100 +11 110 1100 +12 120 1200 +12 120 1200 +12 120 1200 +12 120 1200 +12 120 1200 + +query III rowsort +SELECT a1,a2,a3 FROM a,b WHERE a1=1 AND (a2=b2 OR a3=b3) +---- +1 10 100 + +# More than one disjunction in the filter +query IIIIIIII rowsort +SELECT * FROM a, c WHERE (a1 = c1 OR a2 = c2 OR a3 = c3 OR a4 = c4) +---- +0 0 0 0 0 0 0 0 +1 10 100 1000 1 10 100 1000 +1 10 100 1000 1 2 3 4 +2 20 200 2000 2 20 200 2000 +3 30 300 3000 3 30 NULL NULL +4 40 400 4000 NULL NULL 400 4000 +5 50 500 5000 5 50 500 5000 +5 50 500 5000 5 50 NULL NULL +6 60 600 6000 6 NULL NULL 6000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +15 50 555 5555 5 50 500 5000 +15 50 555 5555 5 50 NULL NULL +15 55 500 5555 5 50 500 5000 +80 11 110 11000 11 110 1100 11000 +80 11 110 11000 11 110 1100 11000 +80 11 110 11000 11 110 1100 11000 + +query IIIIIIII rowsort +SELECT * FROM a, c WHERE (a1 = c2 OR a2 = c1 OR a3 = c4 OR a3 = c4) +---- +0 0 0 0 0 0 0 0 +1 10 100 1000 10 100 1000 10000 +2 20 200 2000 1 2 3 4 +50 5 5000 500 5 50 500 5000 +50 5 5000 500 5 50 NULL NULL +80 11 110 11000 11 110 1100 11000 +80 11 110 11000 11 110 1100 11000 +80 11 110 11000 11 110 1100 11000 +80 11 110 11000 8 80 800 8000 +102 5 60 70 5 50 500 5000 +102 5 60 70 5 50 NULL NULL +104 5 5 5 5 50 500 5000 +104 5 5 5 5 50 NULL NULL + +# Equality filters that do not reference a column on each side of the join +query IIIIIIII rowsort +SELECT * FROM b, d WHERE (b1 = b2 OR b3 = d3) +---- +0 0 0 0 0 0 0 0 +1 10 100 1000 1 10 100 1000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 NULL 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 NULL 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +5 50 500 5000 5 50 500 5000 +6 60 600 6000 6 60 600 6000 +7 NULL 700 NULL 7 70 700 7000 +7 NULL 700 NULL 7 70 700 7000 +17 77 700 7777 7 70 700 7000 +0 0 0 0 1 10 100 1000 +0 0 0 0 11 110 1100 11000 +0 0 0 0 11 110 1100 11000 +0 0 0 0 11 110 1100 11000 +0 0 0 0 11 110 1100 11000 +0 0 0 0 NULL NULL NULL NULL +0 0 0 0 NULL NULL NULL NULL +0 0 0 0 NULL NULL NULL NULL +0 0 0 0 NULL NULL NULL NULL +0 0 0 0 11 NULL NULL 11000 +0 0 0 0 NULL 110 1100 11000 +0 0 0 0 5 50 500 5000 +0 0 0 0 6 60 600 6000 +0 0 0 0 7 70 700 7000 +0 0 0 0 NULL 30 NULL 3000 +0 0 0 0 NULL 90 NULL NULL +0 0 0 0 85 NULL NULL 210 +0 0 0 0 NULL 86 211 NULL +0 0 0 0 5 6 7 8 +0 0 0 0 9 10 11 12 + +query IIIIIIII rowsort +SELECT * FROM b, d WHERE (b1 = b2 OR b3 = d3 OR b4 = d4 OR d1 = d2) +---- +0 0 0 0 0 0 0 0 +0 0 0 0 1 10 100 1000 +0 0 0 0 11 110 1100 11000 +0 0 0 0 11 110 1100 11000 +0 0 0 0 11 110 1100 11000 +0 0 0 0 11 110 1100 11000 +0 0 0 0 NULL NULL NULL NULL +0 0 0 0 NULL NULL NULL NULL +0 0 0 0 NULL NULL NULL NULL +0 0 0 0 NULL NULL NULL NULL +0 0 0 0 11 NULL NULL 11000 +0 0 0 0 NULL 110 1100 11000 +0 0 0 0 5 50 500 5000 +0 0 0 0 6 60 600 6000 +0 0 0 0 7 70 700 7000 +0 0 0 0 NULL 30 NULL 3000 +0 0 0 0 NULL 90 NULL NULL +0 0 0 0 85 NULL NULL 210 +0 0 0 0 NULL 86 211 NULL +0 0 0 0 5 6 7 8 +0 0 0 0 9 10 11 12 +1 10 100 1000 0 0 0 0 +1 10 100 1000 1 10 100 1000 +11 110 1100 11000 0 0 0 0 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 NULL NULL 11000 +11 110 1100 11000 NULL 110 1100 11000 +11 110 1100 11000 0 0 0 0 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 NULL NULL 11000 +11 110 1100 11000 NULL 110 1100 11000 +NULL NULL NULL NULL 0 0 0 0 +NULL NULL NULL NULL 0 0 0 0 +12 120 1200 1 0 0 0 0 +12 120 1200 2 0 0 0 0 +12 120 1200 2 0 0 0 0 +NULL 120 1200 1 0 0 0 0 +12 NULL 1200 2 0 0 0 0 +2 20 200 2000 0 0 0 0 +3 30 300 3000 0 0 0 0 +3 30 300 3000 NULL 30 NULL 3000 +5 50 500 5000 0 0 0 0 +5 50 500 5000 5 50 500 5000 +6 60 600 6000 0 0 0 0 +6 60 600 6000 6 60 600 6000 +8 80 800 8000 0 0 0 0 +9 90 900 9000 0 0 0 0 +2 NULL 200 NULL 0 0 0 0 +3 30 300 NULL 0 0 0 0 +NULL 40 400 4000 0 0 0 0 +NULL NULL NULL 5000 0 0 0 0 +NULL NULL NULL 5000 5 50 500 5000 +7 NULL 700 NULL 0 0 0 0 +7 NULL 700 NULL 7 70 700 7000 +2 20 NULL 200 0 0 0 0 +3 30 300 3000 0 0 0 0 +3 30 300 3000 NULL 30 NULL 3000 +4 NULL NULL NULL 0 0 0 0 +5 50 NULL 5000 0 0 0 0 +5 50 NULL 5000 5 50 500 5000 +7 NULL 700 NULL 0 0 0 0 +7 NULL 700 NULL 7 70 700 7000 +82 NULL 207 NULL 0 0 0 0 +NULL 567 NULL 789 0 0 0 0 +17 77 777 7777 0 0 0 0 +17 77 700 7777 0 0 0 0 +17 77 700 7777 7 70 700 7000 +17 70 777 7777 0 0 0 0 +NULL 77 777 7777 0 0 0 0 +17 NULL 777 7777 0 0 0 0 +17 77 NULL 7777 0 0 0 0 +30 7 40 2 0 0 0 0 +120 80 90 10 0 0 0 0 + +query IIIIIIII rowsort +SELECT * FROM b, d WHERE (b1 = 0 OR b1 = d1) AND + (b1 = 0 OR b2 = 5) AND + (b2 = d1 OR b1 = d1) AND + (b2 = d1 OR b2 = 5) +---- +0 0 0 0 0 0 0 0 + +# ON filters that are a disjunction of equality filters AND And expressions +query IIIIIIII rowsort +SELECT * FROM c, d WHERE (c1 = d1 AND c2 = d2) OR c3 = d3 +---- +0 0 0 0 0 0 0 0 +1 10 100 1000 1 10 100 1000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +5 50 500 5000 5 50 500 5000 +5 50 NULL NULL 5 50 500 5000 +11 110 1100 11000 NULL 110 1100 11000 +11 110 1100 11000 NULL 110 1100 11000 +11 110 1100 11000 NULL 110 1100 11000 + +query IIIIIIII rowsort +SELECT * FROM a, d WHERE (a1 = d2 AND a2 = d1) OR (a3 = d4 AND a4 = d3) +---- +0 0 0 0 0 0 0 0 +50 5 5000 500 5 50 500 5000 + +######################### +# Uncorrelated semijoin # +######################### + +query IIII rowsort +SELECT * FROM a WHERE EXISTS (SELECT 1 FROM d WHERE d1 = 4 OR d2 = 50) +---- +0 0 0 0 +1 10 100 1000 +2 20 200 2000 +3 30 300 3000 +4 40 400 4000 +5 50 500 5000 +6 60 600 6000 +7 70 700 7000 +11 110 1100 11000 +12 120 1200 1 +12 120 1200 2 +15 50 555 5555 +15 55 500 5555 +15 55 555 5555 +50 5 5000 500 +80 11 110 11000 +101 200 3000 40 +102 5 60 70 +103 7 8 70 +104 5 5 5 + +query IIII rowsort +SELECT * FROM a WHERE EXISTS (SELECT 1 FROM c, d WHERE d1 = 4 OR c2 = 50 HAVING sum(d4) > 40) +---- +0 0 0 0 +1 10 100 1000 +2 20 200 2000 +3 30 300 3000 +4 40 400 4000 +5 50 500 5000 +6 60 600 6000 +7 70 700 7000 +11 110 1100 11000 +12 120 1200 1 +12 120 1200 2 +15 50 555 5555 +15 55 500 5555 +15 55 555 5555 +50 5 5000 500 +80 11 110 11000 +101 200 3000 40 +102 5 60 70 +103 7 8 70 +104 5 5 5 + +query IIII rowsort +SELECT * FROM a WHERE EXISTS (SELECT 1 FROM c, d WHERE c1 = d2 or c2 = d1) +---- +0 0 0 0 +1 10 100 1000 +2 20 200 2000 +3 30 300 3000 +4 40 400 4000 +5 50 500 5000 +6 60 600 6000 +7 70 700 7000 +11 110 1100 11000 +12 120 1200 1 +12 120 1200 2 +15 50 555 5555 +15 55 500 5555 +15 55 555 5555 +50 5 5000 500 +80 11 110 11000 +101 200 3000 40 +102 5 60 70 +103 7 8 70 +104 5 5 5 + +query IIII rowsort +SELECT * FROM a WHERE (a1, a2) IN (SELECT c1, d1 FROM c, d WHERE c3 = d3 or c3 = d4) +---- +0 0 0 0 + +query IIII rowsort +SELECT * FROM a WHERE (a1, a2) IN (SELECT c1, d1 FROM c, d WHERE c3 = d3 or c2 = d2 EXCEPT ALL + SELECT c1, d1 FROM c, d WHERE c3 = d3 or c2 = d2) +---- + +query IIII rowsort +SELECT * FROM a WHERE (a1, a2) IN (SELECT c1, d1 FROM c, d WHERE c1 IS NULL OR c1 = d1) +---- +0 0 0 0 + +query IIII rowsort +SELECT * FROM b WHERE b1 NOT IN (SELECT c1 FROM c, d WHERE c1 IS NULL OR c1 = d1) +---- + +query IIII rowsort +SELECT * FROM b WHERE (b1, b2) NOT IN (SELECT c1, c2 FROM c, d WHERE c1 IS NULL OR c1 = d1) +---- + +######################### +# Uncorrelated antijoin # +######################### + +query IIII rowsort +SELECT * FROM a WHERE NOT EXISTS (SELECT 1 FROM b WHERE b1 = 4 OR b2 = 50) +---- + +query IIII rowsort +SELECT * FROM a WHERE NOT EXISTS (SELECT 1 FROM c, d WHERE d1 = 4 OR c2 = 50 or d2+c3 > 5) +---- + +query IIII rowsort +SELECT * FROM a WHERE NOT EXISTS (SELECT 1 FROM c, d WHERE c3 = d4 or c4 = d3) +---- + +query IIII rowsort +SELECT * FROM a WHERE (a1, a2) NOT IN (SELECT c1, d1 FROM c, d WHERE c3 = d3 or c3 = d4) +---- +1 10 100 1000 +2 20 200 2000 +3 30 300 3000 +4 40 400 4000 +5 50 500 5000 +6 60 600 6000 +7 70 700 7000 +12 120 1200 1 +12 120 1200 2 +15 50 555 5555 +15 55 500 5555 +15 55 555 5555 +50 5 5000 500 +80 11 110 11000 +101 200 3000 40 +102 5 60 70 +103 7 8 70 +104 5 5 5 + +query IIII rowsort +SELECT * FROM a WHERE (a1, a2) NOT IN (SELECT c1, d1 FROM c, d WHERE c3 = d3 or c2 = d2 EXCEPT ALL + SELECT c1, d1 FROM c, d WHERE c3 = d3 or c2 = d2) +---- +0 0 0 0 +1 10 100 1000 +2 20 200 2000 +3 30 300 3000 +4 40 400 4000 +5 50 500 5000 +6 60 600 6000 +7 70 700 7000 +11 110 1100 11000 +12 120 1200 1 +12 120 1200 2 +15 50 555 5555 +15 55 500 5555 +15 55 555 5555 +50 5 5000 500 +80 11 110 11000 +101 200 3000 40 +102 5 60 70 +103 7 8 70 +104 5 5 5 + +query IIII rowsort +SELECT * FROM a WHERE (a1, a2) NOT IN (SELECT c1, d1 FROM c, d WHERE c1 IS NULL OR c1 = d1) +---- + +####################### +# Correlated semijoin # +####################### + +query III rowsort +SELECT a1,a2,a3 FROM a WHERE EXISTS (SELECT * FROM b WHERE a2 = b2 OR a3 = b3) +---- +0 0 0 +1 10 100 +2 20 200 +3 30 300 +4 40 400 +5 50 500 +6 60 600 +7 70 700 +11 110 1100 +12 120 1200 +12 120 1200 +15 50 555 +103 7 8 +15 55 500 + +query III rowsort +SELECT a1,a2,a3 FROM a WHERE EXISTS (SELECT * FROM b WHERE a1 = b1 OR a1 = b2) +---- +0 0 0 +1 10 100 +2 20 200 +3 30 300 +4 40 400 +5 50 500 +6 60 600 +7 70 700 +11 110 1100 +12 120 1200 +12 120 1200 +50 5 5000 +80 11 110 + +# The left side of the join already produces key columns +query IIII rowsort +SELECT * FROM a WHERE EXISTS (SELECT * FROM b WHERE a1 = b1 OR a2 = b2 OR a3 = b3 OR a4 = b4) +---- +0 0 0 0 +1 10 100 1000 +2 20 200 2000 +3 30 300 3000 +4 40 400 4000 +5 50 500 5000 +6 60 600 6000 +7 70 700 7000 +11 110 1100 11000 +12 120 1200 1 +12 120 1200 2 +80 11 110 11000 +15 50 555 5555 +103 7 8 70 +15 55 500 5555 + +# More than one disjunction in the filter +query IIII rowsort +SELECT * FROM a WHERE EXISTS (SELECT * FROM c WHERE a1 = c1 OR a2 = c2 OR a3 = c3 OR a4 = c4) +---- +0 0 0 0 +1 10 100 1000 +2 20 200 2000 +3 30 300 3000 +5 50 500 5000 +6 60 600 6000 +11 110 1100 11000 +4 40 400 4000 +80 11 110 11000 +15 50 555 5555 +15 55 500 5555 + +# More than one disjunction in the filter +query IIII rowsort +SELECT * FROM a WHERE EXISTS (SELECT * FROM c WHERE a1 = c2 OR a2 = c1 OR a3 = c4 OR a3 = c4) +---- +0 0 0 0 +2 20 200 2000 +50 5 5000 500 +80 11 110 11000 +1 10 100 1000 +102 5 60 70 +104 5 5 5 + +# IN subquery +query I rowsort +SELECT a1+a3-a2 FROM a WHERE a1 IN (SELECT b1 FROM b WHERE EXISTS (SELECT 1 FROM c WHERE c2 IS NULL OR c2=b2 OR c2=b3)) +---- +0 +91 +182 +273 +364 +455 +546 +637 +1001 +1092 +1092 + +# IN subquery, 2 columns +query I rowsort +SELECT a1+a3-a2 FROM a WHERE (a1,a2) IN (SELECT b1,b2 FROM b WHERE + EXISTS (SELECT 1 FROM c WHERE c2 IS NULL OR c2=b2 OR c2=b3)) +---- +0 +91 +182 +273 +455 +546 +1001 +1092 +1092 + +# ANDed disjuncts +query IIIIIII rowsort +SELECT a1,a2,a3,c.* FROM a,c + WHERE a2 = c2 AND EXISTS (SELECT * FROM b WHERE (a1 = b1 OR a1 = a2) AND (a1 = c1 OR c1 = c2)) +---- +0 0 0 0 0 0 0 +1 10 100 1 10 100 1000 +11 110 1100 11 110 1100 11000 +11 110 1100 11 110 1100 11000 +11 110 1100 11 110 1100 11000 +2 20 200 2 20 200 2000 +3 30 300 3 30 NULL NULL +5 50 500 5 50 500 5000 +5 50 500 5 50 NULL NULL + +query IIIIIII rowsort +SELECT a1,a2,a3,c.* FROM a,c + WHERE a2 = c2 AND EXISTS (SELECT * FROM b WHERE (a1 = b1 OR a1 = b2) AND (c1 = b1 OR c1 = b2)) +---- +0 0 0 0 0 0 0 +1 10 100 1 10 100 1000 +2 20 200 2 20 200 2000 +3 30 300 3 30 NULL NULL +5 50 500 5 50 500 5000 +5 50 500 5 50 NULL NULL +11 110 1100 11 110 1100 11000 +11 110 1100 11 110 1100 11000 +11 110 1100 11 110 1100 11000 + +query IIIIIII rowsort +SELECT a1,a2,a3,c.* FROM a,c + WHERE a2 = c2 AND EXISTS (SELECT * FROM b WHERE (a1 = b1 OR a1 = b3) AND (a1 = c1 OR a1 = c3)) +---- +0 0 0 0 0 0 0 +1 10 100 1 10 100 1000 +11 110 1100 11 110 1100 11000 +11 110 1100 11 110 1100 11000 +11 110 1100 11 110 1100 11000 +2 20 200 2 20 200 2000 +3 30 300 3 30 NULL NULL +5 50 500 5 50 500 5000 +5 50 500 5 50 NULL NULL + +# Nested EXISTS +query II rowsort +SELECT a2,a4 FROM a WHERE EXISTS(SELECT * FROM b WHERE (a1=b1 OR a1=b2) AND EXISTS(SELECT 1 FROM c WHERE b1=c1)) +---- +0 0 +10 1000 +110 11000 +20 2000 +50 5000 +5 500 +11 11000 +30 3000 +60 6000 + +# Two EXISTS at same nesting level; only one disjuction pair can be optimized +query II rowsort +SELECT a2,a4 FROM a WHERE EXISTS(SELECT * FROM b WHERE a1=b1 OR a1=b2) AND + EXISTS(SELECT * FROM c WHERE a1=c1 OR a1=c2) +---- +0 0 +10 1000 +110 11000 +20 2000 +50 5000 +5 500 +11 11000 +30 3000 +60 6000 + +# Two EXISTS at same nesting level; only one disjuction chain can be optimized +query II rowsort +SELECT a2,a4 FROM a WHERE EXISTS(SELECT * FROM b WHERE a1=b1 OR a1=b2 OR a1=b3 OR a1=b4) AND + EXISTS(SELECT * FROM c WHERE a1=c1 OR a1=c2 OR a1=c3 OR a1=c4) +---- +0 0 +10 1000 +110 11000 +20 2000 +50 5000 +5 500 +11 11000 +30 3000 +60 6000 +40 4000 + +# Outer Select is Join +query IIIIIIII rowsort +SELECT * FROM a JOIN (SELECT * FROM b WHERE b1 > 0 AND EXISTS (SELECT 1 FROM c WHERE c1=b1)) + AS foo on a1=foo.b1 OR a2=foo.b2 +---- +1 10 100 1000 1 10 100 1000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 +2 20 200 2000 2 NULL 200 NULL +2 20 200 2000 2 20 NULL 200 +2 20 200 2000 2 20 200 2000 +5 50 500 5000 5 50 500 5000 +15 50 555 5555 5 50 NULL 5000 +15 50 555 5555 5 50 500 5000 +5 50 500 5000 5 50 NULL 5000 +3 30 300 3000 3 30 300 3000 +3 30 300 3000 3 30 300 3000 +3 30 300 3000 3 30 300 NULL +6 60 600 6000 6 60 600 6000 + +query IIIIIIII rowsort +SELECT * FROM a JOIN (SELECT * FROM b WHERE b1 > 0 AND EXISTS (SELECT 1 FROM c WHERE c1=b1 or c2=b2)) + AS foo on a1=foo.b1 +---- +1 10 100 1000 1 10 100 1000 +2 20 200 2000 2 NULL 200 NULL +2 20 200 2000 2 20 NULL 200 +2 20 200 2000 2 20 200 2000 +3 30 300 3000 3 30 300 3000 +3 30 300 3000 3 30 300 3000 +3 30 300 3000 3 30 300 NULL +5 50 500 5000 5 50 500 5000 +5 50 500 5000 5 50 NULL 5000 +6 60 600 6000 6 60 600 6000 +11 110 1100 11000 11 110 1100 11000 +11 110 1100 11000 11 110 1100 11000 + +####################### +# Correlated antijoin # +####################### + +query III rowsort +SELECT a1,a2,a3 FROM a WHERE NOT EXISTS (SELECT * FROM b WHERE a2 = b2 OR a3 = b3) +---- +15 55 555 +50 5 5000 +80 11 110 +101 200 3000 +102 5 60 +104 5 5 + +query III rowsort +SELECT a1,a2,a3 FROM a WHERE NOT EXISTS (SELECT * FROM b WHERE a1 = b1 OR a1 = b2) +---- +15 50 555 +15 55 500 +15 55 555 +101 200 3000 +102 5 60 +103 7 8 +104 5 5 + +# The left side of the join already produces key columns +query IIII rowsort +SELECT * FROM a WHERE NOT EXISTS (SELECT * FROM b WHERE a1 = b1 OR a2 = b2 OR a3 = b3 OR a4 = b4) +---- +15 55 555 5555 +50 5 5000 500 +101 200 3000 40 +102 5 60 70 +104 5 5 5 + +# More than one disjunction in the filter +query IIII rowsort +SELECT * FROM a WHERE NOT EXISTS (SELECT * FROM c WHERE a1 = c1 OR a2 = c2 OR a3 = c3 OR a4 = c4) +---- +7 70 700 7000 +12 120 1200 1 +12 120 1200 2 +15 55 555 5555 +50 5 5000 500 +101 200 3000 40 +102 5 60 70 +103 7 8 70 +104 5 5 5 + +query IIII rowsort +SELECT * FROM a WHERE NOT EXISTS (SELECT * FROM c WHERE a1 = c2 OR a2 = c1 OR a3 = c4 OR a3 = c4) +---- +3 30 300 3000 +4 40 400 4000 +5 50 500 5000 +6 60 600 6000 +7 70 700 7000 +11 110 1100 11000 +12 120 1200 1 +12 120 1200 2 +15 50 555 5555 +15 55 500 5555 +15 55 555 5555 +101 200 3000 40 +103 7 8 70 + +# Nested NOT EXISTS +query II rowsort +SELECT a2,a4 FROM a WHERE NOT EXISTS(SELECT * FROM b WHERE (a1=b1 OR a1=b2) AND NOT EXISTS(SELECT 1 FROM c WHERE b1=c1)) +---- +0 0 +10 1000 +20 2000 +30 3000 +50 5000 +60 6000 +110 11000 +50 5555 +55 5555 +55 5555 +5 500 +200 40 +5 70 +7 70 +5 5 + +# Two NOT EXISTS at same nesting level; only one disjuction pair can be optimized +query II rowsort +SELECT a2,a4 FROM a WHERE NOT EXISTS(SELECT * FROM b WHERE a1=b1 OR a1=b2) AND + NOT EXISTS(SELECT * FROM c WHERE a1=c1 OR a1=c2) +---- +50 5555 +55 5555 +55 5555 +200 40 +5 70 +7 70 +5 5 + +# Outer Select is Join +query IIIIIIII rowsort +SELECT * FROM a JOIN (SELECT * FROM b WHERE b1 > 0 AND NOT EXISTS (SELECT 1 FROM c WHERE c1=b1)) + AS foo on a1=foo.b1 OR a2=foo.b2 +---- +4 40 400 4000 4 NULL NULL NULL +7 70 700 7000 7 NULL 700 NULL +7 70 700 7000 7 NULL 700 NULL +7 70 700 7000 17 70 777 7777 +12 120 1200 1 12 NULL 1200 2 +12 120 1200 1 12 120 1200 1 +12 120 1200 1 12 120 1200 2 +12 120 1200 1 12 120 1200 2 +12 120 1200 2 12 NULL 1200 2 +12 120 1200 2 12 120 1200 1 +12 120 1200 2 12 120 1200 2 +12 120 1200 2 12 120 1200 2 +103 7 8 70 30 7 40 2 + +query IIIIIIII rowsort +SELECT * FROM a JOIN (SELECT * FROM b WHERE b1 > 0 AND NOT EXISTS (SELECT 1 FROM c WHERE c1=b1 or c2=b2)) + AS foo on a1=foo.b1 +---- +4 40 400 4000 4 NULL NULL NULL +7 70 700 7000 7 NULL 700 NULL +7 70 700 7000 7 NULL 700 NULL +12 120 1200 1 12 NULL 1200 2 +12 120 1200 1 12 120 1200 1 +12 120 1200 1 12 120 1200 2 +12 120 1200 1 12 120 1200 2 +12 120 1200 2 12 NULL 1200 2 +12 120 1200 2 12 120 1200 1 +12 120 1200 2 12 120 1200 2 +12 120 1200 2 12 120 1200 2 + +# NOT IN subquery +query III rowsort +SELECT d3,d1,d2 FROM d WHERE d1 NOT IN (SELECT b1 FROM b WHERE EXISTS (SELECT 1 FROM c WHERE c2=b2 OR c2=b3)) +---- +600 6 60 +700 7 70 +NULL 85 NULL +11 9 10 + +# NOT IN subquery, 2 columns +query III rowsort +SELECT d3,d1,d2 FROM d WHERE (d1,d3) NOT IN (SELECT b1,b2 FROM b WHERE EXISTS (SELECT 1 FROM c WHERE c2=b2 OR c2=b3)) +---- +100 1 10 +1100 11 110 +1100 11 110 +1100 11 110 +1100 11 110 +1100 NULL 110 +500 5 50 +600 6 60 +700 7 70 +NULL 85 NULL +211 NULL 86 +7 5 6 +11 9 10 diff --git a/test/sqllogictest/cockroach/distinct.slt b/test/sqllogictest/cockroach/distinct.slt new file mode 100644 index 0000000000000..6ec17fdabdd32 --- /dev/null +++ b/test/sqllogictest/cockroach/distinct.slt @@ -0,0 +1,267 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/distinct +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE xyz ( + x INT PRIMARY KEY, + y INT, + z INT, + INDEX foo (z, y) +) + +statement ok +INSERT INTO xyz VALUES + (1, 2, 3), + (2, 5, 6), + (3, 2, 3), + (4, 5, 6), + (5, 2, 6), + (6, 3, 5), + (7, 2, 9) + +query II rowsort +SELECT y, z FROM xyz +---- +2 3 +5 6 +2 3 +5 6 +2 6 +3 5 +2 9 + +query II rowsort +SELECT DISTINCT y, z FROM xyz +---- +2 3 +5 6 +2 6 +3 5 +2 9 + +query I rowsort +SELECT y FROM (SELECT DISTINCT y, z FROM xyz) +---- +2 +5 +2 +3 +2 + +query II partialsort(2) +SELECT DISTINCT y, z FROM xyz ORDER BY z +---- +2 3 +3 5 +2 6 +5 6 +2 9 + +query II partialsort(1) +SELECT DISTINCT y, z FROM xyz ORDER BY y +---- +2 3 +2 6 +2 9 +3 5 +5 6 + +query II +SELECT DISTINCT y, z FROM xyz ORDER BY y, z +---- +2 3 +2 6 +2 9 +3 5 +5 6 + +query I +SELECT DISTINCT y + z FROM xyz ORDER by (y + z) +---- +5 +8 +11 + +query II +SELECT DISTINCT y AS w, z FROM xyz ORDER by z, w +---- +2 3 +3 5 +2 6 +5 6 +2 9 + +query I +SELECT DISTINCT y AS w FROM xyz ORDER by y +---- +2 +3 +5 + +# Insert NULL values for z. +statement ok +INSERT INTO xyz (x, y) VALUES (8, 2), (9, 2) + +query II rowsort +SELECT DISTINCT y,z FROM xyz +---- +2 3 +5 6 +2 6 +3 5 +2 9 +2 NULL + +query T rowsort +SELECT DISTINCT (y,z) FROM xyz +---- +(2,3) +(5,6) +(2,6) +(3,5) +(2,9) +(2,) + +query I +SELECT count(*) FROM (SELECT DISTINCT y FROM xyz) +---- +3 + +statement ok +CREATE TABLE kv (k INT PRIMARY KEY, v INT, UNIQUE INDEX idx(v)) + +statement ok +INSERT INTO kv VALUES (1, 1), (2, 2), (3, NULL), (4, NULL), (5, 5), (6, NULL) + +query I rowsort +SELECT DISTINCT v FROM kv +---- +NULL +1 +2 +5 + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT DISTINCT v FROM kv@idx +---- +NULL +1 +2 +5 + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT DISTINCT v FROM kv@idx WHERE v > 0 +---- +1 +2 +5 + +# Regression test for #44296. +statement ok +CREATE TABLE t0(c0 INT UNIQUE); + +statement ok +CREATE VIEW v0(c0) AS SELECT DISTINCT t0.c0 FROM t0; + +statement ok +INSERT INTO t0 (c0) VALUES (NULL), (NULL); + +query I +SELECT * FROM v0 WHERE v0.c0 IS NULL +---- +NULL +NULL + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #44079. +statement ok +CREATE TABLE t44079 (x INT[]); +INSERT INTO t44079 VALUES (NULL), (ARRAY[NULL]) + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT DISTINCT * FROM t44079 +---- +NULL +{NULL} + +statement ok +DROP TABLE IF EXISTS t; +CREATE TABLE t (x JSONB); +INSERT INTO t VALUES + ('{"foo" : "bar"}'), + ('{"foo" : "bar"}'), + ('[1, 2]'), + ('[2, 1]'), + ('[1, 2]'), + ('{"foo": {"bar" : "baz"}}') + +query T rowsort +SELECT DISTINCT (x) FROM t +---- +[1,2] +[2,1] +{"foo":"bar"} +{"foo":{"bar":"baz"}} + +statement ok +DROP TABLE IF EXISTS t; + +statement ok +CREATE TABLE t (x DECIMAL); + +statement ok +INSERT INTO t VALUES (1.0), (1.00), (1.000) + +# We want to ensure that this only returns 1 element. We don't +# check the element directly because it returns 1.0, 1.00, or +# 1.000 non-deterministically in a distributed setting. +query I +SELECT COUNT (*) FROM (SELECT DISTINCT (array[x]) FROM t) +---- +1 + +# Regression for #46709. +statement ok +DROP TABLE IF EXISTS t; + +statement ok +CREATE TABLE t (i INT, x INT, y INT, z STRING); + +statement ok +INSERT INTO t VALUES + (1, 1, 2, 'hello'), + (2, 1, 2, 'hello'), + (3, 1, 2, 'hello there') + +query IT +SELECT x, jsonb_agg(DISTINCT jsonb_build_object('y', y, 'z', z)) FROM (SELECT * FROM t ORDER BY i) GROUP BY x +---- +1 [{"y":2,"z":"hello"},{"y":2,"z":"hello␠there"}] diff --git a/test/sqllogictest/cockroach/distinct_on.slt b/test/sqllogictest/cockroach/distinct_on.slt index ac4aef84ab650..144ce47843aaa 100644 --- a/test/sqllogictest/cockroach/distinct_on.slt +++ b/test/sqllogictest/cockroach/distinct_on.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/distinct_on +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/distinct_on # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - statement ok CREATE TABLE xyz ( x INT, @@ -214,25 +212,23 @@ SELECT DISTINCT ON (x) x FROM xyz ORDER BY x DESC # We add a filter to eliminate one of the rows that may be flakily returned # depending on parallel execution of DISTINCT ON. -# Note: Result differs from Cockroach but matches Postgres. query III SELECT DISTINCT ON (x, z) y, z, x FROM xyz WHERE (x,y,z) != (4, 1, 6) ORDER BY z ---- -2 1 1 -1 2 1 -2 3 2 -5 6 4 -1 NULL 1 +2 1 1 +1 2 1 +2 3 2 +5 6 4 +1 NULL 1 -# Note: Result differs from Cockroach but matches Postgres. query III SELECT DISTINCT ON (x) y, z, x FROM xyz ORDER BY x ASC, z DESC, y DESC ---- -1 NULL 1 -2 3 2 -5 6 4 +1 NULL 1 +2 3 2 +5 6 4 -# Regression test for cockroach#35437: Discard extra ordering columns after performing +# Regression test for #35437: Discard extra ordering columns after performing # DISTINCT operation. query T SELECT (SELECT DISTINCT ON (a) a FROM abc ORDER BY a, b||'foo') || 'bar'; @@ -243,10 +239,10 @@ SELECT (SELECT DISTINCT ON (a) a FROM abc ORDER BY a, b||'foo') || 'bar'; # With aggregations # ##################### -statement error column "xyz.y" must appear in the GROUP BY clause or be used in an aggregate function +statement error column "xyz\.y" must appear in the GROUP BY clause or be used in an aggregate function SELECT DISTINCT ON(max(x)) y FROM xyz -statement error column "xyz.z" must appear in the GROUP BY clause or be used in an aggregate function +statement error column "xyz\.z" must appear in the GROUP BY clause or be used in an aggregate function SELECT DISTINCT ON(max(x), z) min(y) FROM xyz query I @@ -268,7 +264,7 @@ SELECT DISTINCT ON(min(a), max(b), min(c)) max(c) FROM abc # With GROUP BY # ################# -statement error column "xyz.x" must appear in the GROUP BY clause or be used in an aggregate function +statement error column "xyz\.x" must appear in the GROUP BY clause or be used in an aggregate function SELECT DISTINCT ON (x) min(x) FROM xyz GROUP BY y query I rowsort @@ -287,7 +283,6 @@ SELECT DISTINCT ON(min(x)) min(x) FROM xyz GROUP BY y HAVING min(x) = 1 # With window functions # ######################### -skipif postgresql # TODO(benesch): support row_number query I rowsort SELECT DISTINCT ON(row_number() OVER(ORDER BY (pk1, pk2))) y FROM xyz ---- @@ -299,7 +294,6 @@ SELECT DISTINCT ON(row_number() OVER(ORDER BY (pk1, pk2))) y FROM xyz 5 1 -skipif postgresql # TODO(benesch): support row_number query I SELECT DISTINCT ON(row_number() OVER(ORDER BY (pk1, pk2))) y FROM xyz ORDER BY row_number() OVER(ORDER BY (pk1, pk2)) DESC ---- @@ -315,7 +309,7 @@ SELECT DISTINCT ON(row_number() OVER(ORDER BY (pk1, pk2))) y FROM xyz ORDER BY r # With ordinal references # ########################### -statement error column reference 2 in DISTINCT ON clause is out of range \(1 - 1\) +statement error column reference 2 in DISTINCT ON clause is out of range \(1 \- 1\) SELECT DISTINCT ON (2) x FROM xyz query I rowsort @@ -397,7 +391,7 @@ SELECT DISTINCT ON (x, y, z) pk1 FROM (SELECT * FROM xyz WHERE x >= 2) ORDER BY 6 7 -# Regression tests for cockroach#34112: distinct on constant column. +# Regression tests for #34112: distinct on constant column. query II SELECT DISTINCT ON (x) x, y FROM xyz WHERE x = 1 ORDER BY x, y ---- @@ -407,3 +401,31 @@ query I SELECT count(*) FROM (SELECT DISTINCT ON (x) x, y FROM xyz WHERE x = 1 ORDER BY x, y) ---- 1 + +# Regression test for #90763. Ensure NULLS LAST works with DISTINCT ON. +statement ok +CREATE TABLE author ( + id INT PRIMARY KEY, + name TEXT, + genre TEXT +); +INSERT INTO author VALUES + (1, 'Alice', 'Action'), + (2, 'Bob', 'Biography'), + (3, 'Carol', 'Crime'), + (4, 'Dave', 'Action'), + (5, 'Eve', 'Crime'), + (6, 'Bart', null); + +query T +SELECT + DISTINCT ON ("genre") genre +FROM + "public"."author" +ORDER BY + "genre" ASC NULLS LAST +---- +Action +Biography +Crime +NULL diff --git a/test/sqllogictest/cockroach/drop_database.slt b/test/sqllogictest/cockroach/drop_database.slt deleted file mode 100644 index 0d0e8269fa41f..0000000000000 --- a/test/sqllogictest/cockroach/drop_database.slt +++ /dev/null @@ -1,270 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/drop_database -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -statement ok -CREATE DATABASE "foo-bar" - -query T -SHOW DATABASES ----- -materialize -foo-bar -postgres -system -test - -statement ok -CREATE TABLE "foo-bar".t(x INT) - -statement error database.*is not empty and RESTRICT was specified -DROP DATABASE "foo-bar" RESTRICT - -statement ok -DROP DATABASE "foo-bar" CASCADE - -query TTT -SELECT name, database_name, state FROM crdb_internal.tables WHERE name = 't' ----- -t [53] DROP - -query T -SHOW DATABASES ----- -materialize -postgres -system -test - -query TT -SELECT status, running_status FROM [SHOW JOBS] ----- -running waiting for GC TTL - -statement ok -CREATE DATABASE "foo bar" - -query T -SHOW DATABASES ----- -materialize -foo bar -postgres -system -test - -statement ok -DROP DATABASE "foo bar" CASCADE - -query T -SHOW DATABASES ----- -materialize -postgres -system -test - -statement ok -CREATE DATABASE d1 - -statement ok -CREATE DATABASE d2 - -statement ok -CREATE TABLE d1.t1 (k STRING PRIMARY KEY, v STRING) - -statement OK -CREATE TABLE d2.t1 (k STRING PRIMARY KEY, v STRING) - -statement ok -CREATE VIEW d1.v1 AS SELECT k,v FROM d1.t1 - -statement ok -CREATE VIEW d1.v2 AS SELECT k,v FROM d1.v1 - -statement ok -CREATE VIEW d2.v1 AS SELECT k,v FROM d2.t1 - -statement ok -CREATE VIEW d2.v2 AS SELECT k,v FROM d1.t1 - -statement ok -CREATE VIEW d2.v3 AS SELECT k,v FROM d1.v2 - -statement ok -CREATE VIEW d2.v4 AS SELECT count(*) FROM d1.t1 as x JOIN d2.t1 as y ON x.k = y.k - -statement ok -GRANT ALL ON DATABASE d1 TO testuser - -statement ok -GRANT ALL ON d1.t1 TO testuser - -statement ok -GRANT ALL ON d1.v1 TO testuser - -statement ok -GRANT ALL ON d1.v2 TO testuser - -statement ok -GRANT ALL ON d2.v2 TO testuser - -statement ok -GRANT ALL ON d2.v3 TO testuser - -user testuser - -statement error user testuser does not have DROP privilege on relation v4 -DROP DATABASE d1 CASCADE - -user root - -query TT -SELECT * FROM d1.v2 ----- - -query TT -SELECT * FROM d2.v1 ----- - -query TT -SELECT * FROM d2.v2 ----- - -query TT -SELECT * FROM d2.v3 ----- - -query I -SELECT * FROM d2.v4 ----- -0 - -query T -SHOW DATABASES ----- -d1 -d2 -materialize -postgres -system -test - -statement ok -DROP DATABASE d1 CASCADE - -query T -SHOW DATABASES ----- -d2 -materialize -postgres -system -test - -query error pgcode 42P01 relation "d1.v2" does not exist -SELECT * FROM d1.v2 - -query error pgcode 42P01 relation "d2.v2" does not exist -SELECT * FROM d2.v2 - -query error pgcode 42P01 relation "d2.v3" does not exist -SELECT * FROM d2.v3 - -query error pgcode 42P01 relation "d2.v4" does not exist -SELECT * FROM d2.v4 - -query TT -SELECT * FROM d2.v1 ----- - -statement ok -DROP DATABASE d2 CASCADE - -query T -SHOW DATABASES ----- -materialize -postgres -system -test - -query error pgcode 42P01 relation "d2.v1" does not exist -SELECT * FROM d2.v1 - -## drop a database containing tables with foreign key constraints, e.g. materialize#8497 - -statement ok -CREATE DATABASE constraint_db - -statement ok -CREATE TABLE constraint_db.t1 ( - p FLOAT PRIMARY KEY, - a INT UNIQUE CHECK (a > 4), - CONSTRAINT c2 CHECK (a < 99) -) - -statement ok -CREATE TABLE constraint_db.t2 ( - t1_ID INT, - CONSTRAINT fk FOREIGN KEY (t1_ID) REFERENCES constraint_db.t1(a), - INDEX (t1_ID) -) - -statement ok -DROP DATABASE constraint_db CASCADE - -query T -SHOW DATABASES ----- -materialize -postgres -system -test - -query error pgcode 42P01 relation "constraint_db.t1" does not exist -SELECT * FROM constraint_db.t1 - -# Check that the default option is CASCADE, but that safe_updates blocks it - -statement ok -CREATE DATABASE foo; CREATE TABLE foo.bar(x INT); - -statement ok -SET sql_safe_updates = TRUE; - -statement error DROP DATABASE on current database -DROP DATABASE test - -statement error DROP DATABASE on non-empty database without explicit CASCADE -DROP DATABASE foo - -statement ok -SET sql_safe_updates = FALSE; DROP DATABASE foo - -# Check that the default databases can be dropped and re-created like any other. -statement OK -DROP DATABASE materialize; DROP DATABASE postgres - -statement ok -CREATE DATABASE materialize; CREATE DATABASE postgres diff --git a/test/sqllogictest/cockroach/drop_index.slt b/test/sqllogictest/cockroach/drop_index.slt new file mode 100644 index 0000000000000..5a3c639d019fe --- /dev/null +++ b/test/sqllogictest/cockroach/drop_index.slt @@ -0,0 +1,586 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/drop_index +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: default-configs local-mixed-22.2-23.1 + +statement ok +CREATE TABLE users ( + id INT PRIMARY KEY, + name VARCHAR NOT NULL, + title VARCHAR, + INDEX foo (name), + UNIQUE INDEX bar (id, name), + INDEX baw (name, title) +) + +statement ok +CREATE TABLE othertable ( + x INT, + y INT, + INDEX baw (x), + INDEX yak (y, x) +) + +statement error unknown catalog item 'baw' +DROP INDEX baw + +# Not supported by Materialize. +onlyif cockroach +statement error index name "baw" is ambiguous +DROP INDEX IF EXISTS baw + +statement error pgcode 42704 unknown catalog item 'ark' +DROP INDEX ark + +statement ok +DROP INDEX IF EXISTS ark + +statement error pgcode 42704 Expected end of statement, found operator "@" +DROP INDEX users@ark + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX IF EXISTS users@ark + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX yak + +statement ok +CREATE INDEX yak ON othertable (y, x) + +statement ok +DROP INDEX IF EXISTS yak + +statement ok +DROP TABLE othertable + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX baw + +statement ok +INSERT INTO users VALUES (1, 'tom', 'cat'),(2, 'jerry', 'rat') + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users bar false 1 id id ASC false false true +users bar false 2 name name ASC false false true +users foo true 1 name name ASC false false true +users foo true 2 id id ASC false true true +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 name name N/A true false true +users users_pkey false 3 title title N/A true false true + +statement error Expected end of statement, found operator "@" +DROP INDEX users@zap + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX IF EXISTS users@zap + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users bar false 1 id id ASC false false true +users bar false 2 name name ASC false false true +users foo true 1 name name ASC false false true +users foo true 2 id id ASC false true true +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 name name N/A true false true +users users_pkey false 3 title title N/A true false true + +# Also test that dropping with a non-existing index still drops 'foo'. + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX IF EXISTS users@foo, users@zap + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users bar false 1 id id ASC false false true +users bar false 2 name name ASC false false true +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 name name N/A true false true +users users_pkey false 3 title title N/A true false true + +user testuser + +skipif config local-legacy-schema-changer +skipif config local-mixed-22.2-23.1 +statement error Expected end of statement, found operator "@" +DROP INDEX users@bar + +onlyif config local-legacy-schema-changer +statement error user testuser does not have CREATE privilege on relation users +DROP INDEX users@bar + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON TABLE users TO testuser + +user testuser + +statement error Expected end of statement, found operator "@" +DROP INDEX users@bar + +statement error Expected end of statement, found operator "@" +DROP INDEX users@bar RESTRICT + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX users@bar CASCADE + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 name name N/A true false true +users users_pkey false 3 title title N/A true false true + +user root + +query ITT rowsort +SELECT * FROM users +---- +1 tom cat +2 jerry rat + +statement ok +CREATE INDEX foo ON users (name) + +statement ok +CREATE INDEX bar ON users (title) + +statement ok +CREATE INDEX baz ON users (name, title) + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX IF EXISTS users@invalid, users@baz + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users bar true 1 title title ASC false false true +users bar true 2 id id ASC false true true +users foo true 1 name name ASC false false true +users foo true 2 id id ASC false true true +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 name name N/A true false true +users users_pkey false 3 title title N/A true false true + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW v AS SELECT name FROM users@{FORCE_INDEX=foo} + +statement error Expected end of statement, found operator "@" +DROP INDEX users@foo + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX users@bar + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users foo true 1 name name ASC false false true +users foo true 2 id id ASC false true true +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 name name N/A true false true +users users_pkey false 3 title title N/A true false true + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW v2 AS SELECT name FROM v + +# Not supported by Materialize. +onlyif cockroach +query TTTTIT +SHOW TABLES +---- +public users table root 0 NULL +public v view root 0 NULL +public v2 view root 0 NULL + +statement ok +GRANT ALL ON users to testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON v to testuser + +user testuser + +statement error Expected end of statement, found operator "@" +DROP INDEX users@foo CASCADE + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX users@foo CASCADE + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 name name N/A true false true +users users_pkey false 3 title title N/A true false true + +# Not supported by Materialize. +onlyif cockroach +query TTTTIT +SHOW TABLES +---- +public users table root 0 NULL + +# Test that schema change job description is correct #80889 +statement ok +CREATE TABLE tbl (c string); + +statement ok +CREATE INDEX expr_idx ON tbl(lower(c)); + +statement ok +DROP INDEX expr_idx; + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT description FROM [show jobs] ORDER BY created DESC LIMIT 2; +---- +description +GC for DROP INDEX test.public.tbl@expr_idx +DROP INDEX test.public.tbl@expr_idx + +# Test the syntax without a '@' + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX baz ON users (name) + +# Also test that dropping with a non-existing index still drops 'baz'. + +statement ok +DROP INDEX IF EXISTS baz, zap + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 name name N/A true false true +users users_pkey false 3 title title N/A true false true + +# Test that it still succeeds when an index does not exist. + +statement ok +DROP INDEX IF EXISTS baz + +# Test that presence of a view or sequence doesn't break DROP INDEX (#21834) + +statement ok +CREATE DATABASE view_test + +statement ok +SET DATABASE = view_test + +statement ok +CREATE TABLE t (id INT) + +statement ok +CREATE VIEW v AS SELECT id FROM t + +statement error pgcode 42704 unknown catalog item 'nonexistent_index' +DROP INDEX nonexistent_index + +statement ok +CREATE DATABASE sequence_test + +statement ok +SET DATABASE = sequence_test + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE s + +statement error pgcode 42704 unknown catalog item 'nonexistent_index' +DROP INDEX nonexistent_index + +statement ok +CREATE TABLE tu (a INT UNIQUE) + +statement ok +CREATE UNIQUE INDEX tu_a ON tu(a) + +statement error unknown catalog item 'tu_a_key' +DROP INDEX tu_a_key + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX tu_a + +# Test that we have more relaxed restrictions on dropping indexes referenced by fks. +subtest fk_drop + +# Ensure that DROP INDEX CASCADE does not delete the foreign key when +# there is another index that can satisfy the foreign key constraint. +statement ok +CREATE TABLE fk1 (x int); + +statement ok +CREATE TABLE fk2 (x int PRIMARY KEY); + +statement ok +CREATE INDEX i ON fk1 (x); + +statement ok +CREATE INDEX i2 ON fk1 (x); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE fk1 ADD CONSTRAINT fk1 FOREIGN KEY (x) REFERENCES fk2 (x); + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX fk1@i CASCADE + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE fk1 +---- +fk1 CREATE TABLE public.fk1 ( + x INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT fk1_pkey PRIMARY KEY (rowid ASC), + CONSTRAINT fk1 FOREIGN KEY (x) REFERENCES public.fk2(x), + INDEX i2 (x ASC) + ) + +# test that notices are generated on index drops +subtest notice_on_drop_index + +query T noticetrace +CREATE TABLE drop_index_test(a int); CREATE INDEX drop_index_test_index ON drop_index_test(a); DROP INDEX drop_index_test_index +---- +NOTICE: the data for dropped indexes is reclaimed asynchronously +HINT: The reclamation delay can be customized in the zone configuration for the table. + +# test correct error reporting from NewUniquenessConstraintViolationError; see #46276 +subtest new_uniqueness_constraint_error + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t (a INT PRIMARY KEY, b DECIMAL(10,1) NOT NULL DEFAULT(0), UNIQUE INDEX t_secondary (b), FAMILY (a, b)); +INSERT INTO t VALUES (100, 500.5); + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +DROP INDEX t_secondary CASCADE; +ALTER TABLE t DROP COLUMN b; +INSERT INTO t SELECT a + 1 FROM t; + +statement error pgcode 23505 Unexpected keyword UPSERT at the beginning of a statement +UPSERT INTO t SELECT a + 1 FROM t; + +statement ok +COMMIT; + +# test the primary key cannot be dropped with drop index; see #56853 +subtest drop_primary_key + +statement error pgcode 0A000 Expected end of statement, found operator "@" +CREATE TABLE drop_primary(); DROP INDEX drop_primary@drop_primary_pkey CASCADE; + +# This subtest tests that dropping a unique index that is serving +# a inbound FK constraint works properly: +# - no cascade: return error +# - cascade AND: +# - there exists another unique index on the same columns: only drop the index +# - there exists another unique index but not on the same columns: drop the index and the FK constraint +# - there exists another unique without index constraint on the same columns: only drop the index +# - there exists another unique_without_index constraint but not on the same columns: drop the index and the FK constraint +subtest drop_unique_index_serving_FK_96731 + +statement ok +CREATE TABLE t2_96731(i INT PRIMARY KEY, j INT); + +statement ok +CREATE UNIQUE INDEX t2_96731_idx ON t2_96731(j); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t1_96731(i INT PRIMARY KEY, j INT REFERENCES t2_96731(j)); + +statement error unknown catalog item 't2_96731_idx' +DROP INDEX t2_96731_idx; + +# Create another unique index on the same columns and ensure +# dropping the index won't drop the FK constraint. +statement ok +CREATE UNIQUE INDEX t2_96731_idx2 ON t2_96731(j); + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX t2_96731_idx CASCADE; + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW CONSTRAINTS FROM t1_96731; +---- +table_name constraint_name constraint_type details validated +t1_96731 t1_96731_j_fkey FOREIGN KEY FOREIGN KEY (j) REFERENCES t2_96731(j) true +t1_96731 t1_96731_pkey PRIMARY KEY PRIMARY KEY (i ASC) true + +# Not supported by Materialize. +onlyif cockroach +# Drop the last unique index will drop the FK as well this time. +statement ok +DROP INDEX t2_96731_idx2 CASCADE; + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW CONSTRAINTS FROM t1_96731; +---- +table_name constraint_name constraint_type details validated +t1_96731 t1_96731_pkey PRIMARY KEY PRIMARY KEY (i ASC) true + +# Recreate the unique index and FK constraint. +statement ok +CREATE UNIQUE INDEX t2_96731_idx ON t2_96731(j); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t1_96731 ADD FOREIGN KEY (j) REFERENCES t2_96731(j); + +# Not supported by Materialize. +onlyif cockroach +# Create a unique_without_index constraint on the same columns and ensure +# dropping the index won't drop the FK constraint. +statement ok +SET experimental_enable_unique_without_index_constraints = true; +ALTER TABLE t2_96731 ADD CONSTRAINT unique_j UNIQUE WITHOUT INDEX (j); + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX t2_96731_idx CASCADE; + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW CONSTRAINTS FROM t1_96731; +---- +table_name constraint_name constraint_type details validated +t1_96731 t1_96731_j_fkey FOREIGN KEY FOREIGN KEY (j) REFERENCES t2_96731(j) true +t1_96731 t1_96731_pkey PRIMARY KEY PRIMARY KEY (i ASC) true + +# Recreate the unique index, drop the unique_without_index constraint, +# and add another one on different columns. +statement ok +CREATE UNIQUE INDEX t2_96731_idx ON t2_96731(j); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t2_96731 DROP CONSTRAINT unique_j + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t2_96731 ADD CONSTRAINT unique_i UNIQUE WITHOUT INDEX (i); + +# Not supported by Materialize. +onlyif cockroach +# Now dropping the index will also drop the FK constraint. +statement ok +DROP INDEX t2_96731_idx CASCADE; + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW CONSTRAINTS FROM t1_96731; +---- +table_name constraint_name constraint_type details validated +t1_96731 t1_96731_pkey PRIMARY KEY PRIMARY KEY (i ASC) true + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE t1_96731, t2_96731; diff --git a/test/sqllogictest/cockroach/drop_role_with_default_privileges.slt b/test/sqllogictest/cockroach/drop_role_with_default_privileges.slt new file mode 100644 index 0000000000000..ee95920738bb9 --- /dev/null +++ b/test/sqllogictest/cockroach/drop_role_with_default_privileges.slt @@ -0,0 +1,229 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/drop_role_with_default_privileges +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER testuser1; +CREATE USER testuser2; +GRANT testuser1 TO ROOT; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE testuser1 GRANT SELECT ON TABLES TO testuser2; + +statement error unknown role 'testuser1' +DROP ROLE testuser1 + +statement error unknown role 'testuser2' +DROP ROLE testuser2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE testuser1 REVOKE SELECT ON TABLES FROM testuser2; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser1 GRANT USAGE ON SCHEMAS TO testuser2; + +statement error unknown role 'testuser1' +DROP ROLE testuser1 + +statement error unknown role 'testuser2' +DROP ROLE testuser2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE testuser1 REVOKE USAGE ON SCHEMAS FROM testuser2; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser1 GRANT USAGE ON TYPES TO testuser2; + +statement error unknown role 'testuser1' +DROP ROLE testuser1 + +statement error unknown role 'testuser2' +DROP ROLE testuser2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE testuser1 REVOKE USAGE ON TYPES FROM testuser2; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser1 GRANT SELECT ON SEQUENCES TO testuser2; + +statement error unknown role 'testuser1' +DROP ROLE testuser1 + +statement error unknown role 'testuser2' +DROP ROLE testuser2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE testuser1 REVOKE SELECT ON TABLES FROM testuser2; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser1 REVOKE USAGE ON SCHEMAS FROM testuser2; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser1 REVOKE USAGE ON TYPES FROM testuser2; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser1 REVOKE SELECT ON SEQUENCES FROM testuser2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP ROLE testuser1; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP ROLE testuser2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT SELECT ON TABLES TO testuser2 + +statement error unknown role 'testuser2' +DROP ROLE testuser2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES REVOKE SELECT ON TABLES FROM testuser2; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT USAGE ON SCHEMAS TO testuser2; + +statement error unknown role 'testuser2' +DROP ROLE testuser2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES REVOKE USAGE ON SCHEMAS FROM testuser2; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT USAGE ON TYPES TO testuser2; + +statement error unknown role 'testuser2' +DROP ROLE testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES REVOKE USAGE ON TYPES FROM testuser2; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT SELECT ON SEQUENCES TO testuser2; + +statement error unknown role 'testuser2' +DROP ROLE testuser2 + +# Not supported by Materialize. +onlyif cockroach +# Grant default privileges to testuser2 in a second database. +statement ok +CREATE ROLE testuser3; +GRANT testuser2 TO root; +GRANT testuser3 TO root; +CREATE DATABASE testdb2; +USE testdb2; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT SELECT ON SEQUENCES TO testuser2; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser3 GRANT SELECT ON SEQUENCES TO testuser2; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser2 GRANT SELECT ON SEQUENCES TO testuser3; + +statement error unknown role 'testuser2' +DROP ROLE testuser2 + +# Check the hint output. +statement error unknown role 'testuser2' +DROP ROLE testuser2 + +# Not supported by Materialize. +onlyif cockroach +# Tests where default privileges are defined on the schema. +statement ok +CREATE ROLE testuser4; +GRANT testuser4 TO root; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA PUBLIC GRANT SELECT ON SEQUENCES TO testuser4; + +statement error unknown role 'testuser4' +DROP ROLE testuser4 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA s; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA s GRANT SELECT ON SEQUENCES TO testuser4; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser3 IN SCHEMA s GRANT SELECT ON SEQUENCES TO testuser4; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser4 IN SCHEMA s GRANT SELECT ON SEQUENCES TO testuser3; + +statement error unknown role 'testuser4' +DROP ROLE testuser4 + +statement error unknown role 'testuser4' +DROP ROLE testuser4 + +# Now let's ensure we can revoke all the privileges and drop testuser2/3/4. + +# Not supported by Materialize. +onlyif cockroach +# Prepare to drop testuser2. +statement ok +USE test; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES REVOKE ALL ON SEQUENCES FROM testuser2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE testdb2; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser3 REVOKE ALL ON SEQUENCES FROM testuser2; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser2 REVOKE ALL ON SEQUENCES FROM testuser3; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES REVOKE ALL ON SEQUENCES FROM testuser2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP ROLE testuser2; + +# Not supported by Materialize. +onlyif cockroach +# Prepare to drop testuser3. +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE testuser3 IN SCHEMA s REVOKE ALL ON SEQUENCES FROM testuser4; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser4 IN SCHEMA s REVOKE ALL ON SEQUENCES FROM testuser3; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP ROLE testuser3; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA s REVOKE ALL ON SEQUENCES FROM testuser4; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA public REVOKE ALL ON SEQUENCES FROM testuser4; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP ROLE testuser4; diff --git a/test/sqllogictest/cockroach/drop_role_with_default_privileges_in_schema.slt b/test/sqllogictest/cockroach/drop_role_with_default_privileges_in_schema.slt new file mode 100644 index 0000000000000..0f844c8ab2a4a --- /dev/null +++ b/test/sqllogictest/cockroach/drop_role_with_default_privileges_in_schema.slt @@ -0,0 +1,162 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/drop_role_with_default_privileges_in_schema +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Test cases when a user has default privileges in a schema. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE ROLE test1; +CREATE ROLE test2; +GRANT test1, test2 TO root; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE test1 IN SCHEMA public GRANT SELECT ON TABLES TO test2; + +statement error unknown role 'test1' +DROP ROLE test1 + +statement error unknown role 'test2' +DROP ROLE test2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE test1 IN SCHEMA public REVOKE ALL ON TABLES FROM test2; +ALTER DEFAULT PRIVILEGES FOR ROLE test1 IN SCHEMA public REVOKE ALL ON TYPES FROM test2; +ALTER DEFAULT PRIVILEGES FOR ROLE test1 IN SCHEMA public REVOKE ALL ON SEQUENCES FROM test2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP ROLE test1; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP ROLE test2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER test2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA public GRANT SELECT ON TABLES TO test2 + +statement error unknown role 'test2' +DROP ROLE test2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA public REVOKE SELECT ON TABLES FROM test2; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA public GRANT USAGE ON TYPES TO test2; + +statement error unknown role 'test2' +DROP ROLE test2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA public REVOKE USAGE ON TYPES FROM test2; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA public GRANT SELECT ON SEQUENCES TO test2; + +statement error unknown role 'test2' +DROP ROLE test2 + +# In a user defined schema. + +statement ok +CREATE SCHEMA s + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE ROLE test3; +CREATE ROLE test4; +GRANT test3, test4 TO root; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE test3 IN SCHEMA s GRANT SELECT ON TABLES TO test4; + +statement error unknown role 'test3' +DROP ROLE test3 + +statement error unknown role 'test4' +DROP ROLE test4; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE test3 IN SCHEMA s REVOKE ALL ON TABLES FROM test4; +ALTER DEFAULT PRIVILEGES FOR ROLE test3 IN SCHEMA s REVOKE ALL ON TYPES FROM test4; +ALTER DEFAULT PRIVILEGES FOR ROLE test3 IN SCHEMA s REVOKE ALL ON SEQUENCES FROM test4; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP ROLE test3; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP ROLE test4; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER test4 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA s GRANT SELECT ON TABLES TO test4 + +statement error unknown role 'test4' +DROP ROLE test4; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA s REVOKE SELECT ON TABLES FROM test4; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA s GRANT USAGE ON TYPES TO test4; + +statement error unknown role 'test4' +DROP ROLE test4 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA s REVOKE USAGE ON TYPES FROM test4; +ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA s GRANT SELECT ON SEQUENCES TO test4; + +statement error unknown role 'test4' +DROP ROLE test4 diff --git a/test/sqllogictest/cockroach/drop_schema.slt b/test/sqllogictest/cockroach/drop_schema.slt new file mode 100644 index 0000000000000..9d20973bf074b --- /dev/null +++ b/test/sqllogictest/cockroach/drop_schema.slt @@ -0,0 +1,36 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/drop_schema +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: default-configs local-mixed-22.2-23.1 + +statement error must be owner of SCHEMA materialize\.public +DROP SCHEMA public + +statement ok +CREATE DATABASE test2 + +# Not supported by Materialize. +onlyif cockroach +statement error pq: cannot drop schema "public" +DROP SCHEMA test2.public diff --git a/test/sqllogictest/cockroach/drop_table.slt b/test/sqllogictest/cockroach/drop_table.slt index 2a70da88f54db..cc4b91bfe676c 100644 --- a/test/sqllogictest/cockroach/drop_table.slt +++ b/test/sqllogictest/cockroach/drop_table.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,30 +9,37 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/drop_table +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/drop_table # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach +# LogicTest: default-configs local-mixed-22.2-23.1 + statement ok CREATE TABLE a (id INT PRIMARY KEY) +let $t_id +SELECT id FROM system.namespace WHERE name='a' + statement ok CREATE TABLE b (id INT PRIMARY KEY) -query T +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test ---- -a -b +public a table root 0 NULL +public b table root 0 NULL statement ok INSERT INTO a VALUES (3),(7),(2) @@ -47,23 +54,44 @@ SELECT * FROM a statement ok DROP TABLE a +# Not supported by Materialize. +onlyif cockroach +# The "updating privileges" clause in the SELECT statement is for excluding jobs +# run by an unrelated startup migration. +# TODO (lucy): Update this if/when we decide to change how these jobs queued by +# the startup migration are handled. query TT -SELECT status, running_status FROM [SHOW JOBS] WHERE job_type = 'SCHEMA CHANGE' +SELECT replace(job_type, 'NEW SCHEMA CHANGE', 'SCHEMA CHANGE'), status + FROM [SHOW JOBS] + WHERE (user_name = 'root' OR user_name = 'node') + AND ( + job_type = 'SCHEMA CHANGE GC' + OR job_type = 'NEW SCHEMA CHANGE' + OR ( + job_type = 'SCHEMA CHANGE' + AND description != 'updating privileges' + ) + ) ORDER BY 1, 2; ---- -running waiting for GC TTL - -query T +SCHEMA CHANGE succeeded +SCHEMA CHANGE succeeded +SCHEMA CHANGE succeeded +SCHEMA CHANGE GC running + +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test ---- -b +public b table root 0 NULL -statement error pgcode 42P01 relation "a" does not exist +statement error pgcode 42P01 unknown catalog item 'a' SELECT * FROM a -statement error pq: \[53 AS a\]: table is being dropped -SELECT * FROM [53 AS a] +statement error unterminated dollar\-quoted string +SELECT * FROM [$t_id AS a] -statement error pgcode 42P01 relation "a" does not exist +statement error pgcode 42P01 unknown catalog item 'a' DROP TABLE a statement ok @@ -75,3 +103,146 @@ CREATE TABLE a (id INT PRIMARY KEY) query I SELECT * FROM a ---- + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON DATABASE test TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA s + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE s.t() + +user testuser + +# Not supported by Materialize. +onlyif cockroach +# Being the owner of schema s should allow testuser to drop table s.t. +statement ok +DROP TABLE s.t + +# Not supported by Materialize. +onlyif cockroach +# Verify that a table can successfully be dropped after performing +# a schema change to the table in the same transaction. +# See https://github.com/cockroachdb/cockroach/issues/56235. +subtest drop_after_schema_change_in_txn +statement ok +CREATE TABLE to_drop(); + +statement ok +BEGIN; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE to_drop ADD COLUMN foo int; + +statement ok +DROP TABLE to_drop; + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMIT; + +# Not supported by Materialize. +onlyif cockroach +statement error pgcode 42P01 unknown catalog item 'to_drop' +DROP TABLE to_drop; + +subtest drop_table_with_not_valid_constraints + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t_with_not_valid_constraints_1 (i INT PRIMARY KEY, j INT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t_with_not_valid_constraints_2 (i INT PRIMARY KEY, j INT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t_with_not_valid_constraints_1 ADD CHECK (i > 0) NOT VALID; + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET experimental_enable_unique_without_index_constraints = true; +ALTER TABLE t_with_not_valid_constraints_1 ADD UNIQUE WITHOUT INDEX (j) NOT VALID; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t_with_not_valid_constraints_1 ADD FOREIGN KEY (i) REFERENCES t_with_not_valid_constraints_2 (i) NOT VALID; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE t_with_not_valid_constraints_1; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE t_with_not_valid_constraints_2; + +# Tests for #97783 where unvalidated FK references were not cleaned up +subtest drop_table_with_not_valid_fk_and_check + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t_not_valid_src (i INT PRIMARY KEY, j INT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t_not_valid_dst (i INT PRIMARY KEY, j INT, c CHAR); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE t_not_valid_sq; + +# Not supported by Materialize. +onlyif cockroach +statement ok; +ALTER TABLE t_not_valid_dst ADD CONSTRAINT v_fk FOREIGN KEY(j) REFERENCES t_not_valid_src(i) NOT VALID; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t_not_valid_dst ADD CHECK (j > currval('t_not_valid_sq')) NOT VALID; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE t_not_valid_src CASCADE; + +# Not supported by Materialize. +onlyif cockroach +statement ok; +DROP SEQUENCE t_not_valid_sq CASCADE; + +# Record disabled, not supported by Materialize: +# # Sequence related check constraint should be cleaned, so inserts should work. +# # Also the destination descriptor should be valid after the FK clean up. Note: +# # skip on older configs since this is an existing bug, not a new regression +# # (see #97871). +# skipif config local-mixed-22.2-23.1 +# skipif config local-legacy-schema-changer +# statement ok +# INSERT INTO t_not_valid_dst VALUES(5,5,5); diff --git a/test/sqllogictest/cockroach/drop_temp.slt b/test/sqllogictest/cockroach/drop_temp.slt new file mode 100644 index 0000000000000..45e4ed8e40766 --- /dev/null +++ b/test/sqllogictest/cockroach/drop_temp.slt @@ -0,0 +1,86 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/drop_temp +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +subtest drop_temp_tables_seqs + +user root + +statement ok +SET experimental_enable_temp_tables=on; + +statement ok +CREATE TEMP TABLE t_tmp(X int); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TEMP SEQUENCE s_tmp START 1 INCREMENT 1; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER tmp_dropper; + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE tmp_dropper; + +# Not supported by Materialize. +onlyif cockroach +statement error pq: user tmp_dropper does not have DROP privilege on relation t_tmp +DROP TABLE t_tmp; + +statement error Expected one of TABLE or VIEW or MATERIALIZED or SOURCE or SINK or INDEX or TYPE or ROLE or USER or CLUSTER or SECRET or CONNECTION or DATABASE or SCHEMA or FUNCTION or NETWORK, found identifier "sequence" +DROP SEQUENCE s_tmp; + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE root; + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT DROP ON TABLE t_tmp to tmp_dropper; +GRANT DROP ON SEQUENCE s_tmp to tmp_dropper; + + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE tmp_dropper; + +statement ok +DROP TABLE t_tmp; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP SEQUENCE s_tmp; + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE root; diff --git a/test/sqllogictest/cockroach/drop_user.slt b/test/sqllogictest/cockroach/drop_user.slt index 4010f17305f1f..d9020cdc883dc 100644 --- a/test/sqllogictest/cockroach/drop_user.slt +++ b/test/sqllogictest/cockroach/drop_user.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,162 +9,287 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/drop_user +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/drop_user # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach +# Not supported by Materialize. +onlyif cockroach statement ok CREATE USER user1 -query T colnames +# Not supported by Materialize. +onlyif cockroach +query TTT colnames SHOW USERS ---- -user_name -root -testuser -user1 - +username options member_of +admin · {} +root · {admin} +testuser · {} +user1 · {} + +# Not supported by Materialize. +onlyif cockroach statement ok DROP USER user1 -query T colnames +# Not supported by Materialize. +onlyif cockroach +query TTT colnames SHOW USERS ---- -user_name -root -testuser +username options member_of +admin · {} +root · {admin} +testuser · {} +# Not supported by Materialize. +onlyif cockroach statement ok CREATE USER user1 -query T colnames +# Not supported by Materialize. +onlyif cockroach +query TTT colnames SHOW USERS ---- -user_name -root -testuser -user1 - +username options member_of +admin · {} +root · {admin} +testuser · {} +user1 · {} + +# Not supported by Materialize. +onlyif cockroach statement ok DROP USER USEr1 -query T colnames +# Not supported by Materialize. +onlyif cockroach +query TTT colnames SHOW USERS ---- -user_name -root -testuser +username options member_of +admin · {} +root · {admin} +testuser · {} -statement error user user1 does not exist +statement error unknown role 'user1' DROP USER user1 -statement error user user1 does not exist +statement error unknown role 'user1' DROP USER usER1 statement ok DROP USER IF EXISTS user1 -statement error username "node" reserved +statement error pgcode 42939 unknown role 'node' DROP USER node -statement error pq: username "foo☂" invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters +statement error pgcode 42939 role name "public" is reserved +DROP USER public + +statement error pgcode 42939 unknown role 'none' +DROP USER "none" + +statement error pgcode 22023 unknown role 'current_user' +DROP ROLE CURRENT_USER + +statement error pgcode 22023 unknown role 'user4' +DROP ROLE user4, SESSION_USER + +statement error unknown role 'foo☂' DROP USER foo☂ +# Not supported by Materialize. +onlyif cockroach statement ok CREATE USER user1 +# Not supported by Materialize. +onlyif cockroach statement ok CREATE USER user2 +# Not supported by Materialize. +onlyif cockroach statement ok CREATE USER user3 +# Not supported by Materialize. +onlyif cockroach statement ok CREATE USER user4 -query T colnames +# Not supported by Materialize. +onlyif cockroach +query TTT colnames SHOW USERS ---- -user_name -root -testuser -user1 -user2 -user3 -user4 - +username options member_of +admin · {} +root · {admin} +testuser · {} +user1 · {} +user2 · {} +user3 · {} +user4 · {} + +# Not supported by Materialize. +onlyif cockroach statement ok DROP USER user1,user2 -query T colnames +# Not supported by Materialize. +onlyif cockroach +query TTT colnames SHOW USERS ---- -user_name -root -testuser -user3 -user4 - -statement error user user1 does not exist +username options member_of +admin · {} +root · {admin} +testuser · {} +user3 · {} +user4 · {} + +statement error unknown role 'user1' DROP USER user1,user3 -query T colnames +# Not supported by Materialize. +onlyif cockroach +query TTT colnames SHOW USERS ---- -user_name -root -testuser -user3 -user4 - +username options member_of +admin · {} +root · {admin} +testuser · {} +user3 · {} +user4 · {} + +# Not supported by Materialize. +onlyif cockroach statement ok CREATE USER user1 +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE foo(x INT); - GRANT SELECT ON foo TO user3; - GRANT SELECT ON DATABASE test TO user1 +GRANT SELECT ON foo TO user3; +GRANT CONNECT ON DATABASE test TO user1 -statement error cannot drop users or roles user1, user3: grants still exist on test, test.public.foo +# Not supported by Materialize. +onlyif cockroach +statement error cannot drop roles/users user1, user3: grants still exist on test, test.public.foo DROP USER IF EXISTS user1,user3 -statement error cannot drop users or roles user1, user3: grants still exist on test +# Not supported by Materialize. +onlyif cockroach +statement ok REVOKE SELECT ON foo FROM user3; - DROP USER IF EXISTS user1,user3 + +# Not supported by Materialize. +onlyif cockroach +statement error cannot drop roles/users user1, user3: grants still exist on test +DROP USER IF EXISTS user1,user3 + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE CONNECT ON DATABASE test FROM user1; statement ok -REVOKE SELECT ON DATABASE test FROM user1; - DROP USER IF EXISTS user1,user3 +DROP USER IF EXISTS user1,user3 +# Not supported by Materialize. +onlyif cockroach statement ok -PREPARE du AS DROP USER $1; - EXECUTE du('user4') +PREPARE du AS DROP USER user4; +EXECUTE du -query T colnames +# Not supported by Materialize. +onlyif cockroach +query TTT colnames SHOW USERS ---- -user_name -root -testuser +username options member_of +admin · {} +root · {admin} +testuser · {} user testuser -statement error pq: user testuser does not have DELETE privilege on relation users +statement error unknown role 'user2' DROP USER user2 user root -statement error pq: cannot drop user or role root: grants still exist on .* +statement error unknown role 'root' DROP USER root -statement error pq: cannot drop user or role admin: grants still exist on .* +statement error unknown role 'admin' DROP USER admin + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER user1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO system.scheduled_jobs (schedule_name, owner, executor_type,execution_args) values('schedule', 'user1', 'invalid', ''); + +statement error unknown role 'user1' +DROP USER user1 + +# Verify that schemas are fully qualified in the error message. +subtest same_schema_name + +statement ok +CREATE ROLE schema_owner + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT admin TO schema_owner + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE schema_owner + +statement ok +CREATE SCHEMA the_schema + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE defaultdb + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA the_schema + +statement ok +RESET ROLE; +RESET DATABASE + +# Not supported by Materialize. +onlyif cockroach +statement error role schema_owner cannot be dropped because some objects depend on it\nowner of schema defaultdb.the_schema\nowner of schema test.the_schema +DROP ROLE schema_owner + +subtest end diff --git a/test/sqllogictest/cockroach/drop_view.slt b/test/sqllogictest/cockroach/drop_view.slt index 3ff633fb1e8df..fc264af5d2198 100644 --- a/test/sqllogictest/cockroach/drop_view.slt +++ b/test/sqllogictest/cockroach/drop_view.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,19 +9,21 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/drop_view +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/drop_view # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach +# LogicTest: default-configs local-mixed-22.2-23.1 + statement ok CREATE TABLE a (k STRING PRIMARY KEY, v STRING) @@ -34,20 +36,22 @@ CREATE VIEW b AS SELECT k,v from a statement ok CREATE VIEW c AS SELECT k,v from b -query TT +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test ---- -a (empty) -b (empty) -c (empty) +public a table root 0 NULL +public b view root 0 NULL +public c view root 0 NULL -statement error cannot drop relation "a" because view "b" depends on it +statement error cannot drop table "a": still depended upon by view "b" DROP TABLE a -statement error pgcode 42809 "b" is not a table +statement error pgcode 42809 b is a view not a table DROP TABLE b -statement error cannot drop relation "b" because view "c" depends on it +statement error cannot drop view "b": still depended upon by view "c" DROP VIEW b statement ok @@ -56,27 +60,31 @@ CREATE VIEW d AS SELECT k,v FROM a statement ok CREATE VIEW diamond AS SELECT count(*) FROM b AS b JOIN d AS d ON b.k = d.k -statement error cannot drop relation "d" because view "diamond" depends on it +statement error cannot drop view "d": still depended upon by view "diamond" DROP VIEW d +# Not supported by Materialize. +onlyif cockroach statement ok GRANT ALL ON d TO testuser -query TT +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test ---- -a (empty) -b (empty) -c (empty) -d (empty) -diamond (empty) +public a table root 0 NULL +public b view root 0 NULL +public c view root 0 NULL +public d view root 0 NULL +public diamond view root 0 NULL user testuser -statement error user testuser does not have DROP privilege on relation diamond +statement error must be owner of VIEW materialize\.public\.diamond DROP VIEW diamond -statement error cannot drop relation "d" because view "diamond" depends on it +statement error cannot drop view "d": still depended upon by view "diamond" DROP VIEW d user root @@ -99,45 +107,61 @@ GRANT ALL ON testuser2 to testuser statement ok GRANT ALL ON testuser3 to testuser -query TT +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test ---- -a (empty) -b (empty) -c (empty) -d (empty) -diamond (empty) -testuser1 (empty) -testuser2 (empty) -testuser3 (empty) +public a table root 0 NULL +public b view root 0 NULL +public c view root 0 NULL +public d view root 0 NULL +public diamond view root 0 NULL +public testuser1 view root 0 NULL +public testuser2 view root 0 NULL +public testuser3 view root 0 NULL + +# Not supported by Materialize. +onlyif cockroach +# Revoke needed for a meaningful test for testuser. +statement ok +REVOKE CONNECT ON DATABASE test FROM public user testuser +# Not supported by Materialize. +onlyif cockroach statement ok DROP VIEW testuser3 -query TT +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test ---- -d (empty) -testuser1 (empty) -testuser2 (empty) +public d view root 0 NULL +public testuser1 view root 0 NULL +public testuser2 view root 0 NULL -statement error cannot drop relation "testuser1" because view "testuser2" depends on it +statement error cannot drop view "testuser1": still depended upon by view "testuser2" DROP VIEW testuser1 -statement error cannot drop relation "testuser1" because view "testuser2" depends on it +statement error cannot drop view "testuser1": still depended upon by view "testuser2" DROP VIEW testuser1 RESTRICT +# Not supported by Materialize. +onlyif cockroach statement ok DROP VIEW testuser1 CASCADE -query TT +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test ---- -d (empty) +public d view root 0 NULL -statement error pgcode 42P01 relation "testuser2" does not exist +statement error pgcode 42P01 cannot drop view "testuser2": still depended upon by view "testuser3" DROP VIEW testuser2 user root @@ -156,7 +180,7 @@ GRANT ALL ON d to testuser user testuser -statement error user testuser does not have DROP privilege on relation diamond +statement error must be owner of TABLE materialize\.public\.a DROP TABLE a CASCADE user root @@ -164,7 +188,9 @@ user root statement ok DROP TABLE a CASCADE -query TT +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test ---- @@ -174,7 +200,7 @@ CREATE VIEW x AS VALUES (1, 2), (3, 4) statement ok CREATE VIEW y AS SELECT column1, column2 FROM x -statement error cannot drop relation "x" because view "y" depends on it +statement error cannot drop view "x": still depended upon by view "y" DROP VIEW x statement ok @@ -186,14 +212,14 @@ CREATE VIEW x AS VALUES (1, 2), (3, 4) statement ok CREATE VIEW y AS SELECT column1, column2 FROM x -statement error cannot drop relation "x" because view "y" depends on it +statement error cannot drop view "x": still depended upon by view "y" DROP VIEW x statement ok DROP VIEW y, x # Ensure that dropping a database works even when views get referred to more= -# than once. See materialize#15953 for more details. +# than once. See #15953 for more details. statement ok CREATE DATABASE a diff --git a/test/sqllogictest/cockroach/edge.slt b/test/sqllogictest/cockroach/edge.slt new file mode 100644 index 0000000000000..82feacbbd2cef --- /dev/null +++ b/test/sqllogictest/cockroach/edge.slt @@ -0,0 +1,314 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/edge +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Test on-disk SQL semantics of edge cases and overflows. On-disk is +# important because it avoids any constant folding that could happen +# in the parse or normalization phases, forcing it to be handled by the +# execution engine itself. + +# TODO(mjibson): Remove family definition when #41277 is fixed. +statement ok +CREATE TABLE t ( + key + STRING PRIMARY KEY, + _date + DATE, + _float4 + FLOAT4, + _float8 + FLOAT8, + _int2 + INT2, + _int4 + INT4, + _int8 + INT8, + FAMILY "primary" (key, _date, _float4, _float8, _int2, _int4, _int8) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT +INTO + t +VALUES + ( + 'min', + '4714-11-24 BC', + -3.40282346638528859811704183484516925440e+38, + -1.7976931348623e+308, + -32768, + -2147483648, + -9223372036854775808 + ), + ( + 'max', + '5874897-12-31', + 3.40282346638528859811704183484516925440e+38, + 1.7976931348623e+308, + 32767, + 2147483647, + 9223372036854775807 + ) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT +INTO + t (key, _date) +VALUES + ('+inf', 'infinity'), ('-inf', '-infinity') + +# min and min + 1 + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT _date, _date + 1 FROM t WHERE key = 'min' +---- +-4713-11-24 00:00:00 +0000 +0000 -4713-11-25 00:00:00 +0000 +0000 + +# Not supported by Materialize. +onlyif cockroach +query IIIIIIRRRR +SELECT + _int2, + _int2 + 1:::INT2, + _int4, + _int4 + 1:::INT4, + _int8, + _int8 + 1:::INT8, + _float4, + _float4 + 1, + _float8, + _float8 + 1 +FROM + t +WHERE + key = 'min' +---- +-32768 -32767 -2147483648 -2147483647 -9223372036854775808 -9223372036854775807 -3.4028235e+38 -3.4028234663852886e+38 -1.7976931348623e+308 -1.7976931348623e+308 + +# min - 1 + +statement error operator does not exist: date \- integer +SELECT _date - 1 FROM t WHERE key = 'min' + +# Not supported by Materialize. +onlyif cockroach +# For now we incorrectly do type promotion int2 -> int. +query I +SELECT _int2 - 1:::INT2 FROM t WHERE key = 'min' +---- +-32769 + +# Not supported by Materialize. +onlyif cockroach +# Incorrect type promotion. +query I +SELECT _int4 - 1:::INT4 FROM t WHERE key = 'min' +---- +-2147483649 + +statement error Expected a data type name, found colon +SELECT _int8 - 1:::INT8 FROM t WHERE key = 'min' + +# Not supported by Materialize. +onlyif cockroach +query R +SELECT _float8 - 1e300 FROM t WHERE key = 'min' +---- +-Inf + +# max and max - 1 + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT _date, _date - 1 FROM t WHERE key = 'max' +---- +5874897-12-31 00:00:00 +0000 +0000 5874897-12-30 00:00:00 +0000 +0000 + +# Not supported by Materialize. +onlyif cockroach +query IIIIIIRRRR +SELECT + _int2, + _int2 - 1:::INT2, + _int4, + _int4 - 1:::INT4, + _int8, + _int8 - 1:::INT8, + _float4, + _float4 - 1, + _float8, + _float8 - 1 +FROM + t +WHERE + key = 'max' +---- +32767 32766 2147483647 2147483646 9223372036854775807 9223372036854775806 3.4028235e+38 3.4028234663852886e+38 1.7976931348623e+308 1.7976931348623e+308 + +# max + 1 + +statement error operator does not exist: date \+ integer +SELECT _date + 1 FROM t WHERE key = 'max' + +# Not supported by Materialize. +onlyif cockroach +# For now we incorrectly do type promotion int2 -> int. +query I +SELECT _int2 + 1:::INT2 FROM t WHERE key = 'max' +---- +32768 + +# Not supported by Materialize. +onlyif cockroach +# Incorrect type promotion. +query I +SELECT _int4 + 1:::INT4 FROM t WHERE key = 'max' +---- +2147483648 + +statement error Expected a data type name, found colon +SELECT _int8 + 1:::INT8 FROM t WHERE key = 'max' + +# Not supported by Materialize. +onlyif cockroach +query R +SELECT _float8 + 1e300 FROM t WHERE key = 'max' +---- ++Inf + +# infinity + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT _date, _date + 1, _date - 1 FROM t WHERE key = '+inf' +---- +infinity infinity infinity + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT _date, _date + 1, _date - 1 FROM t WHERE key = '-inf' +---- +-infinity -infinity -infinity + +# aggregates + +query RRRRRR +SELECT + sum(t._int2), + sum(t._int4), + sum(t._int8), + avg(t._int2), + avg(t._int4), + avg(t._int8) +FROM + t, t AS u +WHERE + t.key = 'max' +---- +NULL NULL NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT + sum_int(t._int2), sum_int(t._int4) +FROM + t, t AS u +WHERE + t.key = 'max' +---- +131068 8589934588 + +statement error function "sum_int" does not exist +SELECT sum_int(t._int8) FROM t, t AS u WHERE t.key = 'max' + +query RRRRRRRRRR +SELECT + sum(t._int2), + sum(t._int4), + sum(t._int8), + sum(t._float4), + sum(t._float8), + avg(t._int2), + avg(t._int4), + avg(t._int8), + avg(t._float4), + avg(t._float8) +FROM + t, t AS u +WHERE + t.key = 'min' +---- +NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT + sum_int(t._int2), sum_int(t._int4) +FROM + t, t AS u +WHERE + t.key = 'min' +---- +-131072 -8589934592 + +statement error function "sum_int" does not exist +SELECT sum_int(t._int8) FROM t, t AS u WHERE t.key = 'min' + +query RRRRRRRRRR +SELECT + sum(t._int2), + sum(t._int4), + sum(t._int8), + sum(t._float4), + sum(t._float8), + avg(t._int2), + avg(t._int4), + avg(t._int8), + avg(t._float4), + avg(t._float8) +FROM + t +---- +NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT + sum_int(t._int2), sum_int(t._int4), sum_int(t._int8) +FROM + t +---- +-1 -1 -1 diff --git a/test/sqllogictest/cockroach/errors.slt b/test/sqllogictest/cockroach/errors.slt index 29d6ba2c98983..fefc4b4de36dd 100644 --- a/test/sqllogictest/cockroach/errors.slt +++ b/test/sqllogictest/cockroach/errors.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,36 +9,36 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/errors +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/errors # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach -statement error pgcode 42P01 relation "fake1" does not exist +statement error pgcode 42P01 Expected one of SET or RENAME or OWNER or RESET or ADD, found DROP ALTER TABLE fake1 DROP COLUMN a -statement error pgcode 42P01 relation "fake2" does not exist +statement error pgcode 42P01 unknown catalog item 'fake2' CREATE INDEX i ON fake2 (a) -statement error pgcode 42P01 relation "fake3" does not exist +statement error pgcode 42P01 Expected end of statement, found operator "@" DROP INDEX fake3@i -statement error pgcode 42P01 relation "fake4" does not exist +statement error pgcode 42P01 unknown catalog item 'fake4' DROP TABLE fake4 -statement error pgcode 42P01 relation "fake5" does not exist +statement error pgcode 42P01 unknown catalog item 'fake5' SHOW COLUMNS FROM fake5 -statement error pgcode 42P01 relation "fake6" does not exist +statement error pgcode 42P01 unknown catalog item 'fake6' INSERT INTO fake6 VALUES (1, 2) -statement error pgcode 42P01 relation "fake7" does not exist +statement error pgcode 42P01 unknown catalog item 'fake7' SELECT * FROM fake7 diff --git a/test/sqllogictest/cockroach/exec_window.slt b/test/sqllogictest/cockroach/exec_window.slt deleted file mode 100644 index 20e1fc9b2e019..0000000000000 --- a/test/sqllogictest/cockroach/exec_window.slt +++ /dev/null @@ -1,114 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/exec_window -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -statement ok -CREATE TABLE t (a INT, b STRING, PRIMARY KEY (b,a)) - -statement ok -INSERT INTO t VALUES - (0, 'a'), - (1, 'a'), - (0, 'b'), - (1, 'b') - -# We sort the output on all queries to get deterministic results. -query ITI -SELECT a, b, row_number() OVER () FROM t ORDER BY b, a ----- -0 a 1 -1 a 2 -0 b 3 -1 b 4 - -query ITI -SELECT a, b, row_number() OVER (ORDER BY a, b) FROM t ORDER BY b, a ----- -0 a 1 -1 a 3 -0 b 2 -1 b 4 - -query ITI -SELECT a, b, row_number() OVER (PARTITION BY a) FROM t ORDER BY b, a ----- -0 a 1 -1 a 1 -0 b 2 -1 b 2 - -query ITI -SELECT a, b, row_number() OVER (PARTITION BY a, b) FROM t ORDER BY b, a ----- -0 a 1 -1 a 1 -0 b 1 -1 b 1 - -query ITI -SELECT a, b, rank() OVER () FROM t ORDER BY b, a ----- -0 a 1 -1 a 1 -0 b 1 -1 b 1 - -query ITI -SELECT a, b, rank() OVER (ORDER BY a) FROM t ORDER BY b, a ----- -0 a 1 -1 a 3 -0 b 1 -1 b 3 - -query ITI -SELECT a, b, rank() OVER (PARTITION BY a ORDER BY b) FROM t ORDER BY b, a ----- -0 a 1 -1 a 1 -0 b 2 -1 b 2 - -query ITI -SELECT a, b, dense_rank() OVER () FROM t ORDER BY b, a ----- -0 a 1 -1 a 1 -0 b 1 -1 b 1 - -query ITI -SELECT a, b, dense_rank() OVER (ORDER BY a) FROM t ORDER BY b, a ----- -0 a 1 -1 a 2 -0 b 1 -1 b 2 - -query ITI -SELECT a, b, dense_rank() OVER (PARTITION BY a ORDER BY b) FROM t ORDER BY b, a ----- -0 a 1 -1 a 1 -0 b 2 -1 b 2 diff --git a/test/sqllogictest/cockroach/external_connection_privileges.slt b/test/sqllogictest/cockroach/external_connection_privileges.slt new file mode 100644 index 0000000000000..55d37858f43f9 --- /dev/null +++ b/test/sqllogictest/cockroach/external_connection_privileges.slt @@ -0,0 +1,155 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/external_connection_privileges +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# external_connection_privileges tests the basic interaction of granting and +# revoking privileges to an external connection. For more detailed tests around +# usage please refer to backup, restore, import and CDC tests that use external +# connections. +user root + +# Not supported by Materialize. +onlyif cockroach +query TTTTO +SELECT * FROM system.privileges +---- + +# Attempt to grant on an external connection that does not exist. +statement error Expected TO, found CONNECTION +GRANT USAGE ON EXTERNAL CONNECTION foo TO testuser + +statement error Expected TO, found ON +GRANT DROP ON EXTERNAL CONNECTION foo TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE EXTERNAL CONNECTION foo AS 'nodelocal://1/foo' + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT USAGE,DROP ON EXTERNAL CONNECTION foo TO testuser + +# Not supported by Materialize. +onlyif cockroach +query TTTTO +SELECT * FROM system.privileges ORDER by username +---- +root /externalconn/foo {ALL} {} 1 +testuser /externalconn/foo {DROP,USAGE} {} 100 + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE USAGE,DROP ON EXTERNAL CONNECTION foo FROM testuser + +# Not supported by Materialize. +onlyif cockroach +query TTTTO +SELECT * FROM system.privileges ORDER by username +---- +root /externalconn/foo {ALL} {} 1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT USAGE,DROP ON EXTERNAL CONNECTION foo TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER bar + +# Attempt to grant usage as testuser, this should fail since we did not specify WITH GRANT OPTION +user testuser + +statement error Expected ON, found DROP +GRANT USAGE,DROP ON EXTERNAL CONNECTION foo TO bar + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT USAGE,DROP ON EXTERNAL CONNECTION foo TO testuser WITH GRANT OPTION + +# Attempt to grant usage as testuser, this should succeed since we did specify WITH GRANT OPTION +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT USAGE,DROP ON EXTERNAL CONNECTION foo TO bar + +user root + +# Not supported by Materialize. +onlyif cockroach +query TTTTO +SELECT * FROM system.privileges ORDER BY username +---- +bar /externalconn/foo {DROP,USAGE} {} 101 +root /externalconn/foo {ALL} {} 1 +testuser /externalconn/foo {DROP,USAGE} {DROP,USAGE} 100 + +# Invalid grants on external connections. + +statement error Expected TO, found CONNECTION +GRANT SELECT ON EXTERNAL CONNECTION foo TO testuser + +statement error Expected TO, found CONNECTION +GRANT INSERT ON EXTERNAL CONNECTION foo TO testuser + +statement ok +CREATE ROLE testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT DROP, USAGE ON EXTERNAL CONNECTION foo TO testuser2 WITH GRANT OPTION + +# Not supported by Materialize. +onlyif cockroach +query TTTB colnames +SHOW GRANTS ON EXTERNAL CONNECTION foo +---- +connection_name grantee privilege_type is_grantable +foo bar DROP false +foo bar USAGE false +foo root ALL false +foo testuser DROP true +foo testuser USAGE true +foo testuser2 DROP true +foo testuser2 USAGE true + +# Not supported by Materialize. +onlyif cockroach +query TTTB colnames +SHOW GRANTS ON EXTERNAL CONNECTION foo FOR testuser, testuser2 +---- +connection_name grantee privilege_type is_grantable +foo testuser DROP true +foo testuser USAGE true +foo testuser2 DROP true +foo testuser2 USAGE true diff --git a/test/sqllogictest/cockroach/family.slt b/test/sqllogictest/cockroach/family.slt new file mode 100644 index 0000000000000..9abe98cace25c --- /dev/null +++ b/test/sqllogictest/cockroach/family.slt @@ -0,0 +1,565 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/family +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# a is the primary key so b gets optimized into a one column value. The c, d +# family has two columns, so it's encoded as a tuple +statement ok +CREATE TABLE abcd( + a INT PRIMARY KEY, + b INT, + c INT, + d INT, + FAMILY f1 (a, b), + FAMILY (c, d) +) + +query TT +SHOW CREATE TABLE abcd +---- +materialize.public.abcd CREATE␠TABLE⏎␠␠␠␠materialize.public.abcd⏎␠␠␠␠␠␠␠␠(a␠pg_catalog.int4␠PRIMARY␠KEY,␠b␠pg_catalog.int4,␠c␠pg_catalog.int4,␠d␠pg_catalog.int4); + +statement ok +CREATE INDEX d_idx ON abcd(d) + +statement ok +INSERT INTO abcd VALUES (1, 2, 3, 4), (5, 6, 7, 8) + +query IIII rowsort +SELECT * FROM abcd +---- +1 2 3 4 +5 6 7 8 + +# Test point lookup, which triggers an optimization for only scanning one +# column family. +query I +SELECT c FROM abcd WHERE a = 1 +---- +3 + +query I +SELECT count(*) FROM abcd +---- +2 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT count(*) FROM abcd@d_idx +---- +2 + +statement ok +UPDATE abcd SET b = 9, d = 10, c = NULL where c = 7 + +query IIII rowsort +SELECT * FROM abcd +---- +1 2 3 4 +5 9 NULL 10 + +statement ok +DELETE FROM abcd where c = 3 + +query IIII +SELECT * FROM abcd +---- +5 9 NULL 10 + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPSERT INTO abcd VALUES (1, 2, 3, 4), (5, 6, 7, 8) + +query IIII rowsort +SELECT * FROM abcd +---- +5 9 NULL 10 + +statement ok +UPDATE abcd SET b = NULL, c = NULL, d = NULL WHERE a = 1 + +query IIII +SELECT * FROM abcd WHERE a = 1 +---- + + +# Test updating a NULL family +statement ok +INSERT INTO abcd (a) VALUES (2) + +query IIII +SELECT * FROM abcd WHERE a = 2 +---- +2 NULL NULL NULL + +statement ok +UPDATE abcd SET d = 5 WHERE a = 2 + +query IIII +SELECT * FROM abcd WHERE a = 2 +---- +2 NULL NULL 5 + +statement ok +DELETE FROM abcd WHERE a = 2 + +query IIII +SELECT * FROM abcd WHERE a = 2 +---- + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE abcd ADD e STRING FAMILY f1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO abcd VALUES (9, 10, 11, 12, 'foo') + +# Not supported by Materialize. +onlyif cockroach +query IIIIT rowsort +SELECT * from abcd WHERE a > 1 +---- +5 6 7 8 NULL +9 10 11 12 foo + +# Not supported by Materialize. +onlyif cockroach +# Check the descriptor bookkeeping +statement ok +ALTER TABLE abcd ADD COLUMN f DECIMAL + +statement error Expected end of statement, found identifier "family" +ALTER TABLE abcd ADD COLUMN g INT FAMILY foo + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE abcd ADD COLUMN g INT CREATE FAMILY + +statement error Expected end of statement, found CREATE +ALTER TABLE abcd ADD COLUMN h INT CREATE FAMILY F1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE abcd ADD COLUMN h INT CREATE FAMILY f_h + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE abcd ADD COLUMN i INT CREATE IF NOT EXISTS FAMILY F_H + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE abcd ADD COLUMN j INT CREATE IF NOT EXISTS FAMILY f_j + +query TT +SHOW CREATE TABLE abcd +---- +materialize.public.abcd CREATE␠TABLE⏎␠␠␠␠materialize.public.abcd⏎␠␠␠␠␠␠␠␠(a␠pg_catalog.int4␠PRIMARY␠KEY,␠b␠pg_catalog.int4,␠c␠pg_catalog.int4,␠d␠pg_catalog.int4); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE abcd DROP c, DROP d, DROP e, DROP h, DROP i, DROP j + +query TT +SHOW CREATE TABLE abcd +---- +materialize.public.abcd CREATE␠TABLE⏎␠␠␠␠materialize.public.abcd⏎␠␠␠␠␠␠␠␠(a␠pg_catalog.int4␠PRIMARY␠KEY,␠b␠pg_catalog.int4,␠c␠pg_catalog.int4,␠d␠pg_catalog.int4); + +statement ok +CREATE TABLE f1 ( + a INT PRIMARY KEY, b STRING, c STRING, + FAMILY "primary" (a, b, c) +) + +query TT +SHOW CREATE TABLE f1 +---- +materialize.public.f1 CREATE␠TABLE⏎␠␠␠␠materialize.public.f1␠(a␠pg_catalog.int4␠PRIMARY␠KEY,␠b␠pg_catalog.text,␠c␠pg_catalog.text); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE assign_at_create (a INT PRIMARY KEY FAMILY pri, b INT FAMILY foo, c INT CREATE FAMILY) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE assign_at_create +---- +assign_at_create CREATE TABLE public.assign_at_create ( + a INT8 NOT NULL, + b INT8 NULL, + c INT8 NULL, + CONSTRAINT assign_at_create_pkey PRIMARY KEY (a ASC), + FAMILY pri (a), + FAMILY foo (b), + FAMILY fam_2_c (c) + ) + +# Check the the diff-column-id storage +statement ok +CREATE TABLE unsorted_colids (a INT PRIMARY KEY, b INT NOT NULL, c INT NOT NULL, FAMILY (c, b, a)) + +statement ok +INSERT INTO unsorted_colids VALUES (1, 1, 1) + +statement ok +UPDATE unsorted_colids SET b = 2, c = 3 WHERE a = 1 + +query III +SELECT * FROM unsorted_colids +---- +1 2 3 + +# Check that family bookkeeping correctly tracks column renames +statement ok +CREATE TABLE rename_col (a INT PRIMARY KEY, b INT, c STRING, FAMILY (a, b), FAMILY (c)) + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE rename_col RENAME b TO d + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE rename_col RENAME c TO e + +query TT +SHOW CREATE TABLE rename_col +---- +materialize.public.rename_col CREATE␠TABLE⏎␠␠␠␠materialize.public.rename_col⏎␠␠␠␠␠␠␠␠(a␠pg_catalog.int4␠PRIMARY␠KEY,␠b␠pg_catalog.int4,␠c␠pg_catalog.text); + +# Regression tests for https://github.com/cockroachdb/cockroach/issues/41007. +statement ok +CREATE TABLE xyz (x INT PRIMARY KEY, y INT, z INT, FAMILY (x, y), FAMILY (z), INDEX (y)) + +statement ok +INSERT INTO xyz VALUES (1, 1, NULL) + +query I +SELECT z FROM xyz WHERE y = 1 +---- +NULL + +statement ok +CREATE TABLE y (y INT) + +statement ok +INSERT INTO y VALUES (1) + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT xyz.z FROM y INNER LOOKUP JOIN xyz ON y.y = xyz.y +---- +NULL + +# Tests for NeededColumnFamilyIDs logic. This function is used for point lookups +# to determine the minimal set of column families which need to be scanned. +subtest needed_column_families + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t1 ( + a INT PRIMARY KEY, b INT NOT NULL, c INT, d INT, + FAMILY (d), FAMILY (c), FAMILY (b), FAMILY (a) +); +INSERT INTO t1 VALUES (10, 20, 30, 40) + +# Not supported by Materialize. +onlyif cockroach +# A point lookup on the primary key column should use family 0 (even if the +# column is not in that family) because the column can be decoded from the key. +query I +SELECT a FROM t1 WHERE a = 10 +---- +10 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT info FROM [EXPLAIN SELECT a FROM t1 WHERE a = 10] WHERE info LIKE '%table%' OR info LIKE '%spans%' +---- + table: t1@t1_pkey + spans: [/10 - /10] + +# Not supported by Materialize. +onlyif cockroach +# A point lookup on a non-nullable column allows us to scan only that column +# family. +query I +SELECT b FROM t1 WHERE a = 10 +---- +20 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT info FROM [EXPLAIN SELECT b FROM t1 WHERE a = 10] WHERE info LIKE '%table%' OR info LIKE '%spans%' +---- + table: t1@t1_pkey + spans: [/10 - /10] + +# Not supported by Materialize. +onlyif cockroach +# Even if we also select the primary key column, we can still scan the single +# column family because that column can be decoded from the key. +query II +SELECT a, b FROM t1 WHERE a = 10 +---- +10 20 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT info FROM [EXPLAIN SELECT a, b FROM t1 WHERE a = 10] WHERE info LIKE '%table%' OR info LIKE '%spans%' +---- + table: t1@t1_pkey + spans: [/10 - /10] + +# Not supported by Materialize. +onlyif cockroach +# A point lookup on a nullable column requires also scanning column family 0 as +# a sentinel. +query I +SELECT c FROM t1 WHERE a = 10 +---- +30 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT info FROM [EXPLAIN SELECT c FROM t1 WHERE a = 10] WHERE info LIKE '%table%' OR info LIKE '%spans%' +---- + table: t1@t1_pkey + spans: [/10 - /10] + +# Not supported by Materialize. +onlyif cockroach +# A point lookup on two columns in non-adjacent column families results in two +# spans. +query II +SELECT b, d FROM t1 WHERE a = 10 +---- +20 40 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT info FROM [EXPLAIN SELECT b, d FROM t1 WHERE a = 10] WHERE info LIKE '%table%' OR info LIKE '%spans%' +---- + table: t1@t1_pkey + spans: [/10 - /10] + +# Unique secondary indexes store non-indexed primary key columns in column +# family 0. +statement ok +CREATE UNIQUE INDEX b_idx ON t1 (b) STORING (c, d) + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM t1 WHERE b = 20 +---- +10 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT info FROM [EXPLAIN SELECT a FROM t1 WHERE b = 20] WHERE info LIKE '%table%' OR info LIKE '%spans%' +---- + table: t1@b_idx + spans: [/20 - /20] + +# Not supported by Materialize. +onlyif cockroach +# If the primary key column is composite, we do need to scan its column family +# to retrieve its value. +statement ok +CREATE TABLE t2 ( + a DECIMAL PRIMARY KEY, b INT, c INT NOT NULL, d INT, + FAMILY (d), FAMILY (c), FAMILY (b), FAMILY (a) +); +INSERT INTO t2 VALUES (10.00, 20, 30, 40) + +# Not supported by Materialize. +onlyif cockroach +# A point lookup on the primary key column should use its family. +query T +SELECT a FROM t2 WHERE a = 10 +---- +10.00 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT info FROM [EXPLAIN SELECT a FROM t2 WHERE a = 10] WHERE info LIKE '%table%' OR info LIKE '%spans%' +---- + table: t2@t2_pkey + spans: [/10 - /10] + +# Not supported by Materialize. +onlyif cockroach +# A point lookup on `a` and `b` should scan both of their families. +query TI +SELECT a, b FROM t2 WHERE a = 10 +---- +10.00 20 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT info FROM [EXPLAIN SELECT a, b FROM t2 WHERE a = 10] WHERE info LIKE '%table%' OR info LIKE '%spans%' +---- + table: t2@t2_pkey + spans: [/10 - /10] + +# Secondary indexes always store their composite values in column family 0. +statement ok +CREATE UNIQUE INDEX a_idx ON t2 (a) STORING (b, c, d) + +# Not supported by Materialize. +onlyif cockroach +# A point lookup on the composite column should use family 0. +query TI +SELECT a, b FROM t2@a_idx WHERE a = 10 +---- +10.00 20 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT info FROM [EXPLAIN SELECT a FROM t2@a_idx WHERE a = 10] WHERE info LIKE '%table%' OR info LIKE '%spans%' +---- + table: t2@a_idx + spans: [/10 - /10] + +# Not supported by Materialize. +onlyif cockroach +# A point lookup on `a` and `b` should use column family 0 and b's family. +query TI +SELECT a, b FROM t2@a_idx WHERE a = 10 +---- +10.00 20 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT info FROM [EXPLAIN SELECT a, b FROM t2@a_idx WHERE a = 10] WHERE info LIKE '%table%' OR info LIKE '%spans%' +---- + table: t2@a_idx + spans: [/10 - /10] + +# ------------------------------------------------------------------------------ +# UPSERT/INSERT..ON CONFLICT cases. +# ------------------------------------------------------------------------------ + +# No secondary index. +statement ok +CREATE TABLE fam (x INT PRIMARY KEY, y INT, y2 INT, y3 INT, FAMILY (x), FAMILY (y, y2), FAMILY (y3)) + +statement ok +INSERT INTO fam VALUES (1, NULL, NULL, NULL) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO fam (x, y) VALUES (1, 1), (2, 2) ON CONFLICT (x) DO UPDATE SET y2=excluded.y, y3=excluded.y + +query IIII rowsort +SELECT * from fam +---- +1 NULL NULL NULL + +# Add secondary index. +statement ok +CREATE UNIQUE INDEX secondary ON fam (y) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO fam (x, y) VALUES (2, NULL), (3, NULL) ON CONFLICT (x) DO UPDATE SET y=NULL, y3=2 + +query IIII rowsort +SELECT * from fam +---- +1 NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query IIII rowsort +SELECT * from fam@secondary +---- +1 NULL 1 1 +2 NULL NULL 2 +3 NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +# Add secondary index with STORING column. +statement ok +DROP INDEX secondary + +statement ok +CREATE UNIQUE INDEX secondary ON fam (y) STORING (y2) + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPSERT INTO fam (x, y) VALUES (4, 4), (5, 5) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO fam (x, y) VALUES (4, 4), (5, 5) +ON CONFLICT (y) DO UPDATE SET y=NULL, y2=excluded.y, y3=excluded.y + +query IIII rowsort +SELECT * from fam +---- +1 NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query IIII rowsort +SELECT * from fam@secondary +---- +1 NULL 1 1 +2 NULL NULL 2 +3 NULL NULL NULL +4 NULL 4 4 +5 NULL 5 5 + +statement ok +DROP TABLE fam diff --git a/test/sqllogictest/cockroach/float.slt b/test/sqllogictest/cockroach/float.slt index cd210f50663ed..7285e80ffa406 100644 --- a/test/sqllogictest/cockroach/float.slt +++ b/test/sqllogictest/cockroach/float.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,41 +9,47 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/float +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/float # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - # -0 and 0 should not be possible in a unique index. +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE p (f float null, unique index (f)) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO p VALUES (NULL), ('NaN'::float), ('Inf'::float), ('-Inf'::float), ('0'::float), (1), (-1) # -0 and 0 should both equate to zero with or without an index. -statement error duplicate key value +statement error unknown catalog item 'p' INSERT INTO p VALUES ('-0'::float) +# Not supported by Materialize. +onlyif cockroach query R SELECT * FROM p WHERE f = 'NaN' ---- NaN +# Not supported by Materialize. +onlyif cockroach query RBBB -SELECT f, f IS NaN, f = 'NaN', isnan(f) FROM p@{FORCE_INDEX=primary} ORDER BY 1 +SELECT f, f IS NaN, f = 'NaN', isnan(f) FROM p@{FORCE_INDEX=p_pkey} ORDER BY 1 ---- NULL NULL NULL NULL NaN true true true @@ -53,6 +59,8 @@ NaN true true true 1 false false false +Inf false false false +# Not supported by Materialize. +onlyif cockroach query RBBB SELECT f, f IS NaN, f = 'NaN', isnan(f) FROM p@{FORCE_INDEX=p_f_key} ORDER BY 1 ---- @@ -64,8 +72,10 @@ NaN true true true 1 false false false +Inf false false false +# Not supported by Materialize. +onlyif cockroach query RB -select f, f > 'NaN' from p@{FORCE_INDEX=primary} where f > 'NaN' ORDER BY f +select f, f > 'NaN' from p@{FORCE_INDEX=p_pkey} where f > 'NaN' ORDER BY f ---- -Inf true -1 true @@ -73,6 +83,8 @@ select f, f > 'NaN' from p@{FORCE_INDEX=primary} where f > 'NaN' ORDER BY f 1 true +Inf true +# Not supported by Materialize. +onlyif cockroach query RB select f, f > 'NaN' from p@{FORCE_INDEX=p_f_key} where f > 'NaN' ORDER BY f ---- @@ -95,11 +107,29 @@ SELECT * FROM i WHERE f = 0 0 statement ok -CREATE INDEX ON i (f) +CREATE INDEX i_f_asc ON i (f) query R rowsort SELECT * FROM i WHERE f = 0 ---- +0 + +statement ok +CREATE INDEX i_f_desc ON i (f DESC) + +# Not supported by Materialize. +onlyif cockroach +query R rowsort +SELECT * FROM i@i_f_asc; +---- +-0 +0 + +# Not supported by Materialize. +onlyif cockroach +query R rowsort +SELECT * FROM i@i_f_desc; +---- -0 0 @@ -115,10 +145,10 @@ CREATE TABLE vals(f FLOAT); query RT rowsort SELECT f, f::string FROM vals ---- -0 0 -123.456789012346 123.456789012346 -1.23456789012346e+22 1.23456789012346e+22 -0.000123456789012346 0.000123456789012346 +0 0 +0.00012345678901234567 0.00012345678901234567 +123.45678901234568 123.45678901234568 +12345678901234568000000 1.2345678901234568e+22 statement ok SET extra_float_digits = 3 @@ -126,10 +156,10 @@ SET extra_float_digits = 3 query RT rowsort SELECT f, f::string FROM vals ---- -0 0 -123.45678901234568 123.45678901234568 -1.2345678901234568e+22 1.2345678901234568e+22 +0 0 0.00012345678901234567 0.00012345678901234567 +123.45678901234568 123.45678901234568 +12345678901234568000000 1.2345678901234568e+22 statement ok SET extra_float_digits = -8 @@ -137,10 +167,10 @@ SET extra_float_digits = -8 query RT rowsort SELECT f, f::string FROM vals ---- -0 0 -123.4568 123.4568 -1.234568e+22 1.234568e+22 -0.0001234568 0.0001234568 +0 0 +0.00012345678901234567 0.00012345678901234567 +123.45678901234568 123.45678901234568 +12345678901234568000000 1.2345678901234568e+22 statement ok SET extra_float_digits = -15 @@ -148,13 +178,89 @@ SET extra_float_digits = -15 query RT rowsort SELECT f, f::string FROM vals ---- -0 0 -100 1e+02 -1e+22 1e+22 -0.0001 0.0001 +0 0 +0.00012345678901234567 0.00012345678901234567 +123.45678901234568 123.45678901234568 +12345678901234568000000 1.2345678901234568e+22 statement ok DROP TABLE vals statement ok RESET extra_float_digits + +# Test that floating point numbers are compared with 15 decimal digits +# precision. +query FFF +SELECT -0.1234567890123456, 123456789012345.6, 1234567.890123456 +---- +-0.1234567890123456 123456789012345.6 1234567.890123456 + +# Regression test to make sure `IS NAN` does not coerce NaN to a string. +statement error Expected NULL, NOT NULL, TRUE, NOT TRUE, FALSE, NOT FALSE, UNKNOWN, NOT UNKNOWN after IS, found identifier "nan" +SELECT ROW() IS NAN + +statement error Expected NULL, NOT NULL, TRUE, NOT TRUE, FALSE, NOT FALSE, UNKNOWN, NOT UNKNOWN after IS, found identifier "nan" +SELECT ROW() IS NOT NAN + +statement error Expected NULL, NOT NULL, TRUE, NOT TRUE, FALSE, NOT FALSE, UNKNOWN, NOT UNKNOWN after IS, found identifier "nan" +SELECT 'NaN'::string IS NAN + +# Not supported by Materialize. +onlyif cockroach +query BB +SELECT 'nan'::float IS NAN, 'nan'::float IS NOT NAN +---- +true false + +# Not supported by Materialize. +onlyif cockroach +query BB +SELECT 'nan'::decimal IS NAN, 'nan'::decimal IS NOT NAN +---- +true false + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t87605 (col2 FLOAT8 NULL) + +# Not supported by Materialize. +onlyif cockroach +statement ok +insert into t87605 values (1.234567890123456e+13), (1.234567890123456e+6) + +# Not supported by Materialize. +onlyif cockroach +# Regression test for issue #87605. +# The floor division operator `//` should not be folded away. +query F +SELECT ((col2::FLOAT8 // 1.0:::FLOAT8::FLOAT8)::FLOAT8) FROM t87605@[0] ORDER BY 1 +---- +1.234567e+06 +1.2345678901234e+13 + +# Regression test for issue #89961. + +statement ok +CREATE TABLE t89961 (a float PRIMARY KEY, INDEX (a DESC)) + +statement ok +INSERT INTO t89961 VALUES ('NaN') + +# We use st_makepointm because it is sensitive to different NaN encodings. The +# following two queries should have the same result. + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT st_makepointm(a, 1.234567890123456e+07, -0.6571774097533073)::string FROM t89961@t89961_pkey +---- +0101000040010000000000F87FDCE9D6DC298C67412DEF51EB9807E5BF + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT st_makepointm(a, 1.234567890123456e+07, -0.6571774097533073)::string FROM t89961@t89961_a_idx; +---- +0101000040010000000000F87FDCE9D6DC298C67412DEF51EB9807E5BF diff --git a/test/sqllogictest/cockroach/format.slt b/test/sqllogictest/cockroach/format.slt new file mode 100644 index 0000000000000..696e6ccc9d260 --- /dev/null +++ b/test/sqllogictest/cockroach/format.slt @@ -0,0 +1,277 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/format +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# tests from https://github.com/postgres/postgres/blob/4ca9985957881c223b4802d309c0bbbcf8acd1c1/src/test/regress/sql/text.sql#L55 + +# Not supported by Materialize. +onlyif cockroach +query T +select format(NULL) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +select format('Hello') +---- +Hello + +# Not supported by Materialize. +onlyif cockroach +query T +select format('Hello %s', 'World') +---- +Hello World + +# Not supported by Materialize. +onlyif cockroach +query T +select format('Hello %%') +---- +Hello % + +# Not supported by Materialize. +onlyif cockroach +query T +select format('Hello %%%%') +---- +Hello %% + +query error function "format" does not exist +select format('Hello %s %s', 'World') + +query error function "format" does not exist +select format('Hello %s') + +query error function "format" does not exist +select format('Hello %x', 20) + +# Not supported by Materialize. +onlyif cockroach +query T +select format('INSERT INTO %I VALUES(%L,%L)', 'mytab', 10, 'Hello') +---- +INSERT INTO mytab VALUES('10','Hello') + +# Not supported by Materialize. +onlyif cockroach +query T +select format('%s%s%s','Hello', NULL,'World') +---- +HelloWorld + +# Not supported by Materialize. +onlyif cockroach +query T +select format('INSERT INTO %I VALUES(%L,%L)', 'mytab', 10, NULL) +---- +INSERT INTO mytab VALUES('10',NULL) + +# Not supported by Materialize. +onlyif cockroach +query T +select format('INSERT INTO %I VALUES(%L,%L)', 'mytab', NULL, 'Hello'); +---- +INSERT INTO mytab VALUES(NULL,'Hello') + +query error function "format" does not exist +select format('INSERT INTO %I VALUES(%L,%L)', NULL, 10, 'Hello') + +# Not supported by Materialize. +onlyif cockroach +# Many of the below tests involve strings with a literal $. +# This can break TestLogic under some conditions. If you're seeing mysterious errors in this file, +# they can likely be fixed by escaping $ into \x24, e.g. replace '%1$s' with E'%\x24s'. +# For now, strings are left unescaped here for readability. +query T +select format('%1$s %3$s', 1, 2, 3) +---- +1 3 + +# Not supported by Materialize. +onlyif cockroach +query T +select format('%1$s %12$s', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) +---- +1 12 + +query error function "format" does not exist +select format('%1$s %4$s', 1, 2, 3) + +query error function "format" does not exist +select format('%1$s %13$s', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) + +query error function "format" does not exist +select format('%0$s', 'Hello') + +query error function "format" does not exist +select format('%*0$s', 'Hello') + +query error function "format" does not exist +select format('%1$', 1) + +query error function "format" does not exist +select format('%1$1', 1) + +query error function "format" does not exist +select format('%1$1', 1) + +# Mixing positional and non-positional placeholders is allowed here, unusually. +# A non-positional placeholder consumes the argument after the last one, +# whether or not the last one was positional. + +# Not supported by Materialize. +onlyif cockroach +query T +select format('Hello %s %1$s %s', 'World', 'Hello again') +---- +Hello World World Hello again + +# Not supported by Materialize. +onlyif cockroach +query T +select format('Hello %s %s, %2$s %2$s', 'World', 'Hello again') +---- +Hello World Hello again, Hello again Hello again + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%10s<<', 'Hello') +---- +>> Hello<< + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%10s<<', NULL) +---- +>> << + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%10s<<', '') +---- +>> << + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%-10s<<', '') +---- +>> << + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%-10s<<', 'Hello') +---- +>>Hello << + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%-10s<<', NULL) +---- +>> << + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%1$10s<<', 'Hello') +---- +>> Hello<< + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%1$-10I<<', 'Hello') +---- +>>"Hello" << + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%2$*1$L<<', 10, 'Hello') +---- +>> 'Hello'<< + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%2$*1$L<<', 10, NULL) +---- +>> NULL<< + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%*s<<', 10, 'Hello') +---- +>> Hello<< + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%*1$s<<', 10, 'Hello') +---- +>> Hello<< + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%-s<<', 'Hello') +---- +>>Hello<< + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%10L<<', NULL) +---- +>> NULL<< + +# Not supported by Materialize. +onlyif cockroach +# Null is equivalent to zero minimum width. +# Zero minimum width has no effect. +query T +select format('>>%2$*1$L<<', NULL, 'Hello') +---- +>>'Hello'<< + +# Not supported by Materialize. +onlyif cockroach +query T +select format('>>%2$*1$L<<', 0, 'Hello') +---- +>>'Hello'<< + +# This isn't a Postgres test case, but Postgres +# errors with 'unrecognized format() type specifier "2"', +# so for compatibility we'll also error here. +query error function "format" does not exist +select format('>>%*1$2$L<<', 10, 'Hello') diff --git a/test/sqllogictest/cockroach/function_lookup.slt b/test/sqllogictest/cockroach/function_lookup.slt new file mode 100644 index 0000000000000..abef976162447 --- /dev/null +++ b/test/sqllogictest/cockroach/function_lookup.slt @@ -0,0 +1,68 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/function_lookup +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE foo(x INT DEFAULT length(pg_typeof(1234))-1) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE bar(x INT, CHECK(pg_typeof(123) = 'bigint')) + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE foo ALTER COLUMN x SET DEFAULT length(pg_typeof(123)) + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE foo ADD CONSTRAINT z CHECK(pg_typeof(123) = 'bigint') + +query T +SELECT pg_typeof(123) +---- +integer + +query I +SELECT count(*) FROM foo GROUP BY pg_typeof(x) +---- + +query I +SELECT * FROM foo LIMIT length(pg_typeof(123)) +---- + +query I +SELECT * FROM foo WHERE pg_typeof(x) = 'bigint' +---- + +query T +INSERT INTO foo(x) VALUES (42) RETURNING pg_typeof(x) +---- +integer + +# CockroachDB is case-preserving for quoted identifiers like pg, and +# function names only exist in lowercase. +query error function "PG_TYPEOF" does not exist +SELECT "PG_TYPEOF"(123) diff --git a/test/sqllogictest/cockroach/fuzzystrmatch.slt b/test/sqllogictest/cockroach/fuzzystrmatch.slt new file mode 100644 index 0000000000000..26cd96388719b --- /dev/null +++ b/test/sqllogictest/cockroach/fuzzystrmatch.slt @@ -0,0 +1,92 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/fuzzystrmatch +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE fuzzystrmatch_table( + id int primary key, + a text, + b text +) + +statement ok +INSERT INTO fuzzystrmatch_table VALUES + (1, 'apple', 'banana'), + (2, '', 'pear'), + (3, '😄', '🐯'), + (4, null, 'a'), + (5, 'a', null), + (6, null, null) + +statement error function "levenshtein" does not exist +SELECT levenshtein(lpad('', 256, 'x'), '') + +statement error function "levenshtein" does not exist +SELECT levenshtein(lpad('', 256, 'x'), '', 2, 3, 4) + +# Not supported by Materialize. +onlyif cockroach +query TTII +SELECT a, b, levenshtein(a, b), levenshtein(a, b, 2, 3, 4) FROM fuzzystrmatch_table ORDER BY id +---- +apple banana 5 18 +· pear 4 8 +😄 🐯 1 4 +NULL a NULL NULL +a NULL NULL NULL +NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT soundex('hello world!') +---- +H464 + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT soundex('Anne'), soundex('Ann'), difference('Anne', 'Ann'); +---- +A500 A500 4 + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT soundex('Anne'), soundex('Andrew'), difference('Anne', 'Andrew'); +---- +A500 A536 2 + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT soundex('Anne'), soundex('Margaret'), difference('Anne', 'Margaret'); +---- +A500 M626 0 + +# Not supported by Materialize. +onlyif cockroach +query TTTT +SELECT soundex('Anne'), soundex(NULL), difference('Anne', NULL), difference(NULL, 'Bob'); +---- +A500 NULL NULL NULL diff --git a/test/sqllogictest/cockroach/grant_database.slt b/test/sqllogictest/cockroach/grant_database.slt new file mode 100644 index 0000000000000..69c9f187e1205 --- /dev/null +++ b/test/sqllogictest/cockroach/grant_database.slt @@ -0,0 +1,288 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/grant_database +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE DATABASE a + +# Not supported by Materialize. +onlyif cockroach +query TTTB colnames +SHOW GRANTS ON DATABASE a +---- +database_name grantee privilege_type is_grantable +a admin ALL true +a public CONNECT false +a root ALL true + +statement error Expected FROM, found ON +REVOKE CONNECT ON DATABASE a FROM root + +statement error Expected FROM, found ON +REVOKE CONNECT ON DATABASE a FROM admin + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER readwrite + +statement error unknown role 'readwrite' +GRANT ALL ON DATABASE a TO readwrite, "test-user" + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO system.users VALUES('test-user','',false,3); + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL PRIVILEGES ON DATABASE a TO readwrite, "test-user" WITH GRANT OPTION + +statement error Expected ON, found ALL +GRANT SELECT,ALL ON DATABASE a TO readwrite + +statement error Expected ON, found ALL +REVOKE SELECT,ALL ON DATABASE a FROM readwrite + +# Not supported by Materialize. +onlyif cockroach +query TTTB +SHOW GRANTS ON DATABASE a +---- +a admin ALL true +a public CONNECT false +a readwrite ALL true +a root ALL true +a test-user ALL true + +# Not supported by Materialize. +onlyif cockroach +query TTTB +SHOW GRANTS ON DATABASE a FOR readwrite, "test-user" +---- +a readwrite ALL true +a test-user ALL true + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE CONNECT ON DATABASE a FROM "test-user",readwrite + +# Not supported by Materialize. +onlyif cockroach +query TTTB +SHOW GRANTS ON DATABASE a +---- +a admin ALL true +a public CONNECT false +a readwrite BACKUP true +a readwrite CREATE true +a readwrite DROP true +a readwrite RESTORE true +a readwrite ZONECONFIG true +a root ALL true +a test-user BACKUP true +a test-user CREATE true +a test-user DROP true +a test-user RESTORE true +a test-user ZONECONFIG true + +# Not supported by Materialize. +onlyif cockroach +query TTTB +SHOW GRANTS ON DATABASE a FOR readwrite, "test-user" +---- +a readwrite BACKUP true +a readwrite CREATE true +a readwrite DROP true +a readwrite RESTORE true +a readwrite ZONECONFIG true +a test-user BACKUP true +a test-user CREATE true +a test-user DROP true +a test-user RESTORE true +a test-user ZONECONFIG true + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE CREATE ON DATABASE a FROM "test-user" + +# Not supported by Materialize. +onlyif cockroach +query TTTB +SHOW GRANTS ON DATABASE a +---- +a admin ALL true +a public CONNECT false +a readwrite BACKUP true +a readwrite CREATE true +a readwrite DROP true +a readwrite RESTORE true +a readwrite ZONECONFIG true +a root ALL true +a test-user BACKUP true +a test-user DROP true +a test-user RESTORE true +a test-user ZONECONFIG true + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE ALL PRIVILEGES ON DATABASE a FROM "test-user" + +# Not supported by Materialize. +onlyif cockroach +query TTTB +SHOW GRANTS ON DATABASE a FOR readwrite, "test-user" +---- +a readwrite BACKUP true +a readwrite CREATE true +a readwrite DROP true +a readwrite RESTORE true +a readwrite ZONECONFIG true + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE ALL ON DATABASE a FROM readwrite,"test-user" + +# Not supported by Materialize. +onlyif cockroach +query TTTB +SHOW GRANTS ON DATABASE a +---- +a admin ALL true +a public CONNECT false +a root ALL true + +# Not supported by Materialize. +onlyif cockroach +query TTTB +SHOW GRANTS ON DATABASE a FOR readwrite, "test-user" +---- + +# Usage privilege should not be grantable on databases. + +statement error unknown role 'testuser' +GRANT USAGE ON DATABASE a TO testuser + +statement ok +CREATE DATABASE b + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE, CONNECT ON DATABASE b TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE b.t() + +# CONNECT privilege should not be inherited from DB when creating a table. + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON b.t +---- +database_name schema_name table_name grantee privilege_type is_grantable +b public t admin ALL true +b public t root ALL true +b public t testuser ALL true + +# Calling SHOW GRANTS on an invalid user should error out. + +statement error Expected end of statement, found FOR +SHOW GRANTS FOR invaliduser + +# Verify that owner and child of owner have is_grantable implicitly. + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER owner_grant_option_child + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT testuser to owner_grant_option_child + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER USER testuser WITH createdb + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE DATABASE owner_grant_option + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CONNECT ON DATABASE owner_grant_option TO owner_grant_option_child + +# Not supported by Materialize. +onlyif cockroach +query TTTB colnames +SHOW GRANTS ON DATABASE owner_grant_option +---- +database_name grantee privilege_type is_grantable +owner_grant_option admin ALL true +owner_grant_option owner_grant_option_child CONNECT true +owner_grant_option public CONNECT false +owner_grant_option root ALL true +owner_grant_option testuser ALL true + +# Verify that is_grantable moves to the new owner. + +user root + +statement ok +CREATE ROLE other_owner + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DATABASE owner_grant_option OWNER TO other_owner + +# Not supported by Materialize. +onlyif cockroach +query TTTB colnames +SHOW GRANTS ON DATABASE owner_grant_option +---- +database_name grantee privilege_type is_grantable +owner_grant_option admin ALL true +owner_grant_option other_owner ALL true +owner_grant_option owner_grant_option_child CONNECT false +owner_grant_option public CONNECT false +owner_grant_option root ALL true diff --git a/test/sqllogictest/cockroach/grant_in_txn.slt b/test/sqllogictest/cockroach/grant_in_txn.slt new file mode 100644 index 0000000000000..52810f868fd7b --- /dev/null +++ b/test/sqllogictest/cockroach/grant_in_txn.slt @@ -0,0 +1,152 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/grant_in_txn +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# This tests ensures that transactions to perform grants on entities created +# inside of a transaction do not get blocked and take a very long time. + +statement ok +SET statement_timeout = '10s'; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE DATABASE IF NOT EXISTS db1; +CREATE DATABASE IF NOT EXISTS db2; +BEGIN; +CREATE TABLE IF NOT EXISTS db1.t (); +CREATE TABLE IF NOT EXISTS db2.t (); +CREATE USER user1; +CREATE USER user2; +CREATE USER user3; +CREATE USER user4; +CREATE USER user5; +CREATE USER user6; +CREATE USER user7; +CREATE ROLE role1; +CREATE ROLE role2; +CREATE ROLE role3; +CREATE ROLE role4; +CREATE ROLE role5; +CREATE ROLE role6; +CREATE ROLE role7; +CREATE ROLE role8; +GRANT CREATE ON DATABASE db1 TO role1; +GRANT CREATE ON TABLE db1.* TO role1; +GRANT CREATE ON DATABASE db2 TO role1; +GRANT select, insert, delete, update ON TABLE db2.* TO role1; +GRANT role1 TO user5; +GRANT role2 TO user7; +GRANT CREATE ON DATABASE db1 TO role3; +GRANT SELECT, INSERT, DELETE, UPDATE ON TABLE db1.* TO role3; +GRANT ALL ON DATABASE db1 TO role4; +GRANT ALL ON TABLE db1.* TO role4; +GRANT ALL ON DATABASE db1 TO role5; +GRANT ALL ON TABLE db1.* TO role5; +GRANT role5 TO user1; +GRANT CREATE ON DATABASE db2 TO role6; +GRANT SELECT, INSERT, DELETE, UPDATE ON TABLE db2.* TO role6; +GRANT ALL ON DATABASE db2 TO role7; +GRANT ALL ON TABLE db2.* TO role7; +GRANT ALL ON DATABASE db2 TO role8; +GRANT ALL ON TABLE db2.* TO role8; +GRANT admin TO user2; +GRANT admin TO user4; +GRANT admin TO role2; +CREATE ROLE role9; +GRANT role3 TO role9; +GRANT role6 TO role9; +GRANT role9 TO user1; +CREATE ROLE role10; +GRANT role4 TO role10; +GRANT role7 TO role10; +CREATE ROLE role11; +GRANT role5 TO role11; +GRANT role8 TO role11; +GRANT role11 TO user6; +DROP TABLE db1.t; +DROP TABLE db2.t; +COMMIT; + +# Ensure that we can inspect information_schema.applicable_roles inside of a +# transaction. Prior to the change which introduces this + +statement ok; +CREATE ROLE role_foo; + +statement ok; +CREATE ROLE role_bar; + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT role_bar TO role_foo WITH ADMIN OPTION; + +# Not supported by Materialize. +onlyif cockroach +statement ok; +GRANT role_foo TO testuser WITH ADMIN OPTION; + +# switch to testuser + +user testuser + +statement ok +BEGIN; + +query TTT colnames +SELECT * FROM information_schema.applicable_roles ORDER BY role_name; +---- +grantee role_name is_grantable + + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE role_foo FROM testuser; + +# Not supported by Materialize. +onlyif cockroach +statement ok +SAVEPOINT before_invalid_grant + +# This grant should fail as testuser no longer has right to this grant +# via role_foo. + +statement error transaction in read\-only mode +GRANT role_bar TO testuser; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ROLLBACK TO SAVEPOINT before_invalid_grant + +# Not supported by Materialize. +onlyif cockroach +query TTT colnames +SELECT * FROM information_schema.applicable_roles; +---- +grantee role_name is_grantable + +statement ok +COMMIT diff --git a/test/sqllogictest/cockroach/grant_on_all_sequences_in_schema.slt b/test/sqllogictest/cockroach/grant_on_all_sequences_in_schema.slt new file mode 100644 index 0000000000000..119954c5588d5 --- /dev/null +++ b/test/sqllogictest/cockroach/grant_on_all_sequences_in_schema.slt @@ -0,0 +1,146 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/grant_on_all_sequences_in_schema +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER testuser2 + +statement ok +CREATE SCHEMA s; +CREATE SCHEMA s2; + +# Not supported by Materialize. +onlyif cockroach +# Granting in a schema with no sequences should be okay. +statement ok +GRANT SELECT ON ALL SEQUENCES IN SCHEMA s TO testuser + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser +---- +database_name schema_name relation_name grantee privilege_type is_grantable + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE s.q; +CREATE SEQUENCE s2.q; +CREATE TABLE s.t(); +CREATE TABLE s2.t(); + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE testuser + +statement error unknown catalog item 's\.q' +SELECT * FROM s.q; + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT SELECT ON ALL SEQUENCES IN SCHEMA s TO testuser + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test s q testuser SELECT false + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT USAGE ON ALL SEQUENCES IN SCHEMA s TO testuser + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test s q testuser SELECT false +test s q testuser USAGE false + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT SELECT ON ALL SEQUENCES IN SCHEMA s, s2 TO testuser, testuser2 + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser, testuser2 +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test s q testuser SELECT false +test s q testuser USAGE false +test s q testuser2 SELECT false +test s2 q testuser SELECT false +test s2 q testuser2 SELECT false + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON ALL SEQUENCES IN SCHEMA s, s2 TO testuser, testuser2 + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser, testuser2 +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test s q testuser ALL false +test s q testuser2 ALL false +test s2 q testuser ALL false +test s2 q testuser2 ALL false + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER testuser3 + +# Not supported by Materialize. +onlyif cockroach +# Sequences are treated as a subset of tables. +statement ok +GRANT ALL ON ALL TABLES IN SCHEMA s2 TO testuser3 + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser3 +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test s2 q testuser3 ALL false +test s2 t testuser3 ALL false diff --git a/test/sqllogictest/cockroach/grant_on_all_tables_in_schema.slt b/test/sqllogictest/cockroach/grant_on_all_tables_in_schema.slt new file mode 100644 index 0000000000000..4c333607f2305 --- /dev/null +++ b/test/sqllogictest/cockroach/grant_on_all_tables_in_schema.slt @@ -0,0 +1,172 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/grant_on_all_tables_in_schema +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER testuser2 + +statement ok +CREATE SCHEMA s; +CREATE SCHEMA s2; + +# Not supported by Materialize. +onlyif cockroach +# Granting in a schema with no tables should be okay. +statement ok +GRANT SELECT ON ALL TABLES IN SCHEMA s TO testuser + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser +---- +database_name schema_name relation_name grantee privilege_type is_grantable + +statement ok +CREATE TABLE s.t(); +CREATE TABLE s2.t(); + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT SELECT ON ALL TABLES IN SCHEMA s TO testuser + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test s t testuser SELECT false + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT SELECT ON ALL TABLES IN SCHEMA s, s2 TO testuser, testuser2 + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser, testuser2 +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test s t testuser SELECT false +test s t testuser2 SELECT false +test s2 t testuser SELECT false +test s2 t testuser2 SELECT false + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON ALL TABLES IN SCHEMA s, s2 TO testuser, testuser2 + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser, testuser2 +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test s t testuser ALL false +test s t testuser2 ALL false +test s2 t testuser ALL false +test s2 t testuser2 ALL false + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE SELECT ON ALL TABLES IN SCHEMA s, s2 FROM testuser, testuser2 + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser, testuser2 +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test s t testuser BACKUP false +test s t testuser CHANGEFEED false +test s t testuser CREATE false +test s t testuser DELETE false +test s t testuser DROP false +test s t testuser INSERT false +test s t testuser UPDATE false +test s t testuser ZONECONFIG false +test s t testuser2 BACKUP false +test s t testuser2 CHANGEFEED false +test s t testuser2 CREATE false +test s t testuser2 DELETE false +test s t testuser2 DROP false +test s t testuser2 INSERT false +test s t testuser2 UPDATE false +test s t testuser2 ZONECONFIG false +test s2 t testuser BACKUP false +test s2 t testuser CHANGEFEED false +test s2 t testuser CREATE false +test s2 t testuser DELETE false +test s2 t testuser DROP false +test s2 t testuser INSERT false +test s2 t testuser UPDATE false +test s2 t testuser ZONECONFIG false +test s2 t testuser2 BACKUP false +test s2 t testuser2 CHANGEFEED false +test s2 t testuser2 CREATE false +test s2 t testuser2 DELETE false +test s2 t testuser2 DROP false +test s2 t testuser2 INSERT false +test s2 t testuser2 UPDATE false +test s2 t testuser2 ZONECONFIG false + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE ALL ON ALL TABLES IN SCHEMA s, s2 FROM testuser, testuser2 + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR testuser, testuser2 +---- +database_name schema_name relation_name grantee privilege_type is_grantable + +# Verify that the database name is resolved correctly if specified. +statement ok +CREATE DATABASE otherdb + +statement ok +CREATE TABLE otherdb.public.tbl (a int) + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT SELECT ON ALL TABLES IN SCHEMA otherdb.public TO testuser + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON TABLE otherdb.public.tbl +---- +database_name schema_name table_name grantee privilege_type is_grantable +otherdb public tbl admin ALL true +otherdb public tbl root ALL true +otherdb public tbl testuser SELECT false diff --git a/test/sqllogictest/cockroach/grant_role.slt b/test/sqllogictest/cockroach/grant_role.slt new file mode 100644 index 0000000000000..f38a144fdef83 --- /dev/null +++ b/test/sqllogictest/cockroach/grant_role.slt @@ -0,0 +1,68 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/grant_role +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Test that no-op grant role command is actually no-op (i.e. does not perform schema change) +subtest no_op_grant_role + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER developer WITH CREATEDB + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER roach WITH PASSWORD NULL + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT developer TO roach + +# Remember the current table version for `system.role_members`. +let $role_members_version +SELECT crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor)->'table'->>'version' FROM system.descriptor WHERE id = 'system.public.role_members'::REGCLASS + +# Not supported by Materialize. +onlyif cockroach +# Repeatedly grant membership of `developer` to `roach` which it's already a member of. +statement ok +GRANT developer TO roach + +# Not supported by Materialize. +onlyif cockroach +# Assert that it's indeed a no-op by checking the 'role_members' table's version remains the same +query B +SELECT crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor)->'table'->>'version' = $role_members_version::STRING FROM system.descriptor WHERE id = 'system.public.role_members'::REGCLASS +---- +true + +# GRANT or REVOKE on the public role should result in "not exists" +subtest grant_revoke_public + +statement error pgcode 42704 unknown role 'testuser' +GRANT testuser TO public + +statement error pgcode 42704 unknown role 'testuser' +REVOKE testuser FROM public diff --git a/test/sqllogictest/cockroach/grant_schema.slt b/test/sqllogictest/cockroach/grant_schema.slt new file mode 100644 index 0000000000000..64b538c576fbe --- /dev/null +++ b/test/sqllogictest/cockroach/grant_schema.slt @@ -0,0 +1,232 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/grant_schema +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: default-configs + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON DATABASE test TO testuser; +CREATE USER testuser2 + +statement ok +CREATE SCHEMA IF NOT EXISTS derp + +# Don't run these tests as an admin. +user testuser + +# Not supported by Materialize. +onlyif cockroach +# Check pg_catalog grants. +query TTTTB colnames +SHOW GRANTS ON SCHEMA pg_catalog +---- +database_name schema_name grantee privilege_type is_grantable +test pg_catalog public USAGE false + +# Not supported by Materialize. +onlyif cockroach +# Check information_schema grants. +query TTTTB colnames +SHOW GRANTS ON SCHEMA information_schema +---- +database_name schema_name grantee privilege_type is_grantable +test information_schema public USAGE false + +# Not supported by Materialize. +onlyif cockroach +# Check public schema grants. +query TTTTB colnames +SHOW GRANTS ON SCHEMA public +---- +database_name schema_name grantee privilege_type is_grantable +test public admin ALL true +test public public CREATE false +test public public USAGE false +test public root ALL true + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW GRANTS ON SCHEMA test.* +---- +database_name schema_name grantee privilege_type is_grantable +test derp admin ALL true +test derp root ALL true +test public admin ALL true +test public public CREATE false +test public public USAGE false +test public root ALL true + +statement ok +SET experimental_enable_temp_tables = true; +CREATE TEMP TABLE t(a INT) + +let $temp_schema +SELECT schema_name FROM [show schemas] WHERE schema_name LIKE '%pg_temp%' + +# Not supported by Materialize. +onlyif cockroach +# Check pg_temp grants. +query TT colnames +SELECT grantee, privilege_type FROM [SHOW GRANTS ON SCHEMA $temp_schema] +---- +grantee privilege_type +admin ALL +public CREATE +public USAGE +root ALL + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA s; +GRANT CREATE ON SCHEMA s TO testuser2 + +# Not supported by Materialize. +onlyif cockroach +# Check user-defined schema grants. +query TTTTB colnames +SHOW GRANTS ON SCHEMA s +---- +database_name schema_name grantee privilege_type is_grantable +test s admin ALL true +test s root ALL true +test s testuser ALL true +test s testuser2 CREATE false + +# Not supported by Materialize. +onlyif cockroach +# Check grant information in backing table. We have to strip off the session +# identifying information from the end of the pg_temp schema name. +query TTTTT colnames +SELECT + grantee, + table_catalog, + IF(table_schema LIKE 'pg_temp%', 'pg_temp', table_schema) AS table_schema, + privilege_type, + is_grantable +FROM information_schema.schema_privileges +---- +grantee table_catalog table_schema privilege_type is_grantable +public test crdb_internal USAGE NO +admin test derp ALL YES +root test derp ALL YES +public test information_schema USAGE NO +public test pg_catalog USAGE NO +public test pg_extension USAGE NO +admin test pg_temp ALL YES +public test pg_temp CREATE NO +public test pg_temp USAGE NO +root test pg_temp ALL YES +admin test public ALL YES +public test public CREATE NO +public test public USAGE NO +root test public ALL YES +admin test s ALL YES +root test s ALL YES +testuser2 test s CREATE NO +testuser test s ALL YES + +# Not supported by Materialize. +onlyif cockroach +# Check grants for testuser2, which should inherit from the public role. +query TBB colnames,rowsort +WITH schema_names(schema_name) AS ( + SELECT n.nspname AS schema_name + FROM pg_catalog.pg_namespace n +) SELECT IF(schema_name LIKE 'pg_temp%', 'pg_temp', schema_name) AS schema_name, + pg_catalog.has_schema_privilege('testuser2', schema_name, 'CREATE') AS has_create, + pg_catalog.has_schema_privilege('testuser2', schema_name, 'USAGE') AS has_usage +FROM schema_names +---- +schema_name has_create has_usage +crdb_internal false true +derp false false +information_schema false true +pg_catalog false true +pg_extension false true +pg_temp true true +public true true +s true false + +# Verify that owner and child of owner have is_grantable implicitly. + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER owner_grant_option_child + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT testuser to owner_grant_option_child + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA owner_grant_option + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT USAGE ON SCHEMA owner_grant_option TO owner_grant_option_child + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW GRANTS ON SCHEMA owner_grant_option +---- +database_name schema_name grantee privilege_type is_grantable +test owner_grant_option admin ALL true +test owner_grant_option owner_grant_option_child USAGE true +test owner_grant_option root ALL true +test owner_grant_option testuser ALL true + +# Verify that is_grantable moves to the new owner. + +user root + +statement ok +CREATE ROLE other_owner + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SCHEMA owner_grant_option OWNER TO other_owner + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW GRANTS ON SCHEMA owner_grant_option +---- +database_name schema_name grantee privilege_type is_grantable +test owner_grant_option admin ALL true +test owner_grant_option other_owner ALL true +test owner_grant_option owner_grant_option_child USAGE false +test owner_grant_option root ALL true diff --git a/test/sqllogictest/cockroach/grant_table.slt b/test/sqllogictest/cockroach/grant_table.slt new file mode 100644 index 0000000000000..cb1500d146a40 --- /dev/null +++ b/test/sqllogictest/cockroach/grant_table.slt @@ -0,0 +1,2283 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/grant_table +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: local + +statement ok +CREATE DATABASE a + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER readwrite + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON DATABASE a TO readwrite + +# Not supported by Materialize. +onlyif cockroach +query TTTB colnames +SHOW GRANTS ON DATABASE a +---- +database_name grantee privilege_type is_grantable +a admin ALL true +a public CONNECT false +a readwrite ALL false +a root ALL true + +# Not supported by Materialize. +onlyif cockroach +# Show that by default GRANT is restricted to the current database +query TTTTTB colnames +SHOW GRANTS +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test NULL NULL admin ALL true +test NULL NULL public CONNECT false +test NULL NULL root ALL true +test crdb_internal NULL public USAGE false +test crdb_internal active_range_feeds public SELECT false +test crdb_internal backward_dependencies public SELECT false +test crdb_internal builtin_functions public SELECT false +test crdb_internal cluster_contended_indexes public SELECT false +test crdb_internal cluster_contended_keys public SELECT false +test crdb_internal cluster_contended_tables public SELECT false +test crdb_internal cluster_contention_events public SELECT false +test crdb_internal cluster_database_privileges public SELECT false +test crdb_internal cluster_distsql_flows public SELECT false +test crdb_internal cluster_execution_insights public SELECT false +test crdb_internal cluster_inflight_traces public SELECT false +test crdb_internal cluster_locks public SELECT false +test crdb_internal cluster_queries public SELECT false +test crdb_internal cluster_sessions public SELECT false +test crdb_internal cluster_settings public SELECT false +test crdb_internal cluster_statement_statistics public SELECT false +test crdb_internal cluster_transaction_statistics public SELECT false +test crdb_internal cluster_transactions public SELECT false +test crdb_internal cluster_txn_execution_insights public SELECT false +test crdb_internal create_function_statements public SELECT false +test crdb_internal create_schema_statements public SELECT false +test crdb_internal create_statements public SELECT false +test crdb_internal create_type_statements public SELECT false +test crdb_internal cross_db_references public SELECT false +test crdb_internal databases public SELECT false +test crdb_internal default_privileges public SELECT false +test crdb_internal feature_usage public SELECT false +test crdb_internal forward_dependencies public SELECT false +test crdb_internal gossip_alerts public SELECT false +test crdb_internal gossip_liveness public SELECT false +test crdb_internal gossip_network public SELECT false +test crdb_internal gossip_nodes public SELECT false +test crdb_internal index_columns public SELECT false +test crdb_internal index_spans public SELECT false +test crdb_internal index_usage_statistics public SELECT false +test crdb_internal invalid_objects public SELECT false +test crdb_internal jobs public SELECT false +test crdb_internal kv_catalog_comments public SELECT false +test crdb_internal kv_catalog_descriptor public SELECT false +test crdb_internal kv_catalog_namespace public SELECT false +test crdb_internal kv_catalog_zones public SELECT false +test crdb_internal kv_dropped_relations public SELECT false +test crdb_internal kv_node_liveness public SELECT false +test crdb_internal kv_node_status public SELECT false +test crdb_internal kv_store_status public SELECT false +test crdb_internal leases public SELECT false +test crdb_internal lost_descriptors_with_data public SELECT false +test crdb_internal node_build_info public SELECT false +test crdb_internal node_contention_events public SELECT false +test crdb_internal node_distsql_flows public SELECT false +test crdb_internal node_execution_insights public SELECT false +test crdb_internal node_inflight_trace_spans public SELECT false +test crdb_internal node_memory_monitors public SELECT false +test crdb_internal node_metrics public SELECT false +test crdb_internal node_queries public SELECT false +test crdb_internal node_runtime_info public SELECT false +test crdb_internal node_sessions public SELECT false +test crdb_internal node_statement_statistics public SELECT false +test crdb_internal node_tenant_capabilities_cache public SELECT false +test crdb_internal node_transaction_statistics public SELECT false +test crdb_internal node_transactions public SELECT false +test crdb_internal node_txn_execution_insights public SELECT false +test crdb_internal node_txn_stats public SELECT false +test crdb_internal partitions public SELECT false +test crdb_internal pg_catalog_table_is_implemented public SELECT false +test crdb_internal ranges public SELECT false +test crdb_internal ranges_no_leases public SELECT false +test crdb_internal regions public SELECT false +test crdb_internal schema_changes public SELECT false +test crdb_internal session_trace public SELECT false +test crdb_internal session_variables public SELECT false +test crdb_internal statement_activity public SELECT false +test crdb_internal statement_statistics public SELECT false +test crdb_internal statement_statistics_persisted public SELECT false +test crdb_internal statement_statistics_persisted_v22_2 public SELECT false +test crdb_internal super_regions public SELECT false +test crdb_internal system_jobs public SELECT false +test crdb_internal table_columns public SELECT false +test crdb_internal table_indexes public SELECT false +test crdb_internal table_row_statistics public SELECT false +test crdb_internal table_spans public SELECT false +test crdb_internal tables public SELECT false +test crdb_internal tenant_usage_details public SELECT false +test crdb_internal transaction_activity public SELECT false +test crdb_internal transaction_contention_events public SELECT false +test crdb_internal transaction_statistics public SELECT false +test crdb_internal transaction_statistics_persisted public SELECT false +test crdb_internal transaction_statistics_persisted_v22_2 public SELECT false +test crdb_internal zones public SELECT false +test information_schema NULL public USAGE false +test information_schema administrable_role_authorizations public SELECT false +test information_schema applicable_roles public SELECT false +test information_schema attributes public SELECT false +test information_schema character_sets public SELECT false +test information_schema check_constraint_routine_usage public SELECT false +test information_schema check_constraints public SELECT false +test information_schema collation_character_set_applicability public SELECT false +test information_schema collations public SELECT false +test information_schema column_column_usage public SELECT false +test information_schema column_domain_usage public SELECT false +test information_schema column_options public SELECT false +test information_schema column_privileges public SELECT false +test information_schema column_statistics public SELECT false +test information_schema column_udt_usage public SELECT false +test information_schema columns public SELECT false +test information_schema columns_extensions public SELECT false +test information_schema constraint_column_usage public SELECT false +test information_schema constraint_table_usage public SELECT false +test information_schema data_type_privileges public SELECT false +test information_schema domain_constraints public SELECT false +test information_schema domain_udt_usage public SELECT false +test information_schema domains public SELECT false +test information_schema element_types public SELECT false +test information_schema enabled_roles public SELECT false +test information_schema engines public SELECT false +test information_schema events public SELECT false +test information_schema files public SELECT false +test information_schema foreign_data_wrapper_options public SELECT false +test information_schema foreign_data_wrappers public SELECT false +test information_schema foreign_server_options public SELECT false +test information_schema foreign_servers public SELECT false +test information_schema foreign_table_options public SELECT false +test information_schema foreign_tables public SELECT false +test information_schema information_schema_catalog_name public SELECT false +test information_schema key_column_usage public SELECT false +test information_schema keywords public SELECT false +test information_schema optimizer_trace public SELECT false +test information_schema parameters public SELECT false +test information_schema partitions public SELECT false +test information_schema plugins public SELECT false +test information_schema processlist public SELECT false +test information_schema profiling public SELECT false +test information_schema referential_constraints public SELECT false +test information_schema resource_groups public SELECT false +test information_schema role_column_grants public SELECT false +test information_schema role_routine_grants public SELECT false +test information_schema role_table_grants public SELECT false +test information_schema role_udt_grants public SELECT false +test information_schema role_usage_grants public SELECT false +test information_schema routine_privileges public SELECT false +test information_schema routines public SELECT false +test information_schema schema_privileges public SELECT false +test information_schema schemata public SELECT false +test information_schema schemata_extensions public SELECT false +test information_schema sequences public SELECT false +test information_schema session_variables public SELECT false +test information_schema sql_features public SELECT false +test information_schema sql_implementation_info public SELECT false +test information_schema sql_parts public SELECT false +test information_schema sql_sizing public SELECT false +test information_schema st_geometry_columns public SELECT false +test information_schema st_spatial_reference_systems public SELECT false +test information_schema st_units_of_measure public SELECT false +test information_schema statistics public SELECT false +test information_schema table_constraints public SELECT false +test information_schema table_constraints_extensions public SELECT false +test information_schema table_privileges public SELECT false +test information_schema tables public SELECT false +test information_schema tables_extensions public SELECT false +test information_schema tablespaces public SELECT false +test information_schema tablespaces_extensions public SELECT false +test information_schema transforms public SELECT false +test information_schema triggered_update_columns public SELECT false +test information_schema triggers public SELECT false +test information_schema type_privileges public SELECT false +test information_schema udt_privileges public SELECT false +test information_schema usage_privileges public SELECT false +test information_schema user_attributes public SELECT false +test information_schema user_defined_types public SELECT false +test information_schema user_mapping_options public SELECT false +test information_schema user_mappings public SELECT false +test information_schema user_privileges public SELECT false +test information_schema view_column_usage public SELECT false +test information_schema view_routine_usage public SELECT false +test information_schema view_table_usage public SELECT false +test information_schema views public SELECT false +test pg_catalog NULL public USAGE false +test pg_catalog "char" admin ALL false +test pg_catalog "char" public USAGE false +test pg_catalog "char" root ALL false +test pg_catalog "char"[] admin ALL false +test pg_catalog "char"[] public USAGE false +test pg_catalog "char"[] root ALL false +test pg_catalog anyelement admin ALL false +test pg_catalog anyelement public USAGE false +test pg_catalog anyelement root ALL false +test pg_catalog anyelement[] admin ALL false +test pg_catalog anyelement[] public USAGE false +test pg_catalog anyelement[] root ALL false +test pg_catalog bit admin ALL false +test pg_catalog bit public USAGE false +test pg_catalog bit root ALL false +test pg_catalog bit[] admin ALL false +test pg_catalog bit[] public USAGE false +test pg_catalog bit[] root ALL false +test pg_catalog bool admin ALL false +test pg_catalog bool public USAGE false +test pg_catalog bool root ALL false +test pg_catalog bool[] admin ALL false +test pg_catalog bool[] public USAGE false +test pg_catalog bool[] root ALL false +test pg_catalog box2d admin ALL false +test pg_catalog box2d public USAGE false +test pg_catalog box2d root ALL false +test pg_catalog box2d[] admin ALL false +test pg_catalog box2d[] public USAGE false +test pg_catalog box2d[] root ALL false +test pg_catalog bytes admin ALL false +test pg_catalog bytes public USAGE false +test pg_catalog bytes root ALL false +test pg_catalog bytes[] admin ALL false +test pg_catalog bytes[] public USAGE false +test pg_catalog bytes[] root ALL false +test pg_catalog char admin ALL false +test pg_catalog char public USAGE false +test pg_catalog char root ALL false +test pg_catalog char[] admin ALL false +test pg_catalog char[] public USAGE false +test pg_catalog char[] root ALL false +test pg_catalog date admin ALL false +test pg_catalog date public USAGE false +test pg_catalog date root ALL false +test pg_catalog date[] admin ALL false +test pg_catalog date[] public USAGE false +test pg_catalog date[] root ALL false +test pg_catalog decimal admin ALL false +test pg_catalog decimal public USAGE false +test pg_catalog decimal root ALL false +test pg_catalog decimal[] admin ALL false +test pg_catalog decimal[] public USAGE false +test pg_catalog decimal[] root ALL false +test pg_catalog float admin ALL false +test pg_catalog float public USAGE false +test pg_catalog float root ALL false +test pg_catalog float4 admin ALL false +test pg_catalog float4 public USAGE false +test pg_catalog float4 root ALL false +test pg_catalog float4[] admin ALL false +test pg_catalog float4[] public USAGE false +test pg_catalog float4[] root ALL false +test pg_catalog float[] admin ALL false +test pg_catalog float[] public USAGE false +test pg_catalog float[] root ALL false +test pg_catalog geography admin ALL false +test pg_catalog geography public USAGE false +test pg_catalog geography root ALL false +test pg_catalog geography[] admin ALL false +test pg_catalog geography[] public USAGE false +test pg_catalog geography[] root ALL false +test pg_catalog geometry admin ALL false +test pg_catalog geometry public USAGE false +test pg_catalog geometry root ALL false +test pg_catalog geometry[] admin ALL false +test pg_catalog geometry[] public USAGE false +test pg_catalog geometry[] root ALL false +test pg_catalog inet admin ALL false +test pg_catalog inet public USAGE false +test pg_catalog inet root ALL false +test pg_catalog inet[] admin ALL false +test pg_catalog inet[] public USAGE false +test pg_catalog inet[] root ALL false +test pg_catalog int admin ALL false +test pg_catalog int public USAGE false +test pg_catalog int root ALL false +test pg_catalog int2 admin ALL false +test pg_catalog int2 public USAGE false +test pg_catalog int2 root ALL false +test pg_catalog int2[] admin ALL false +test pg_catalog int2[] public USAGE false +test pg_catalog int2[] root ALL false +test pg_catalog int2vector admin ALL false +test pg_catalog int2vector public USAGE false +test pg_catalog int2vector root ALL false +test pg_catalog int2vector[] admin ALL false +test pg_catalog int2vector[] public USAGE false +test pg_catalog int2vector[] root ALL false +test pg_catalog int4 admin ALL false +test pg_catalog int4 public USAGE false +test pg_catalog int4 root ALL false +test pg_catalog int4[] admin ALL false +test pg_catalog int4[] public USAGE false +test pg_catalog int4[] root ALL false +test pg_catalog int[] admin ALL false +test pg_catalog int[] public USAGE false +test pg_catalog int[] root ALL false +test pg_catalog interval admin ALL false +test pg_catalog interval public USAGE false +test pg_catalog interval root ALL false +test pg_catalog interval[] admin ALL false +test pg_catalog interval[] public USAGE false +test pg_catalog interval[] root ALL false +test pg_catalog jsonb admin ALL false +test pg_catalog jsonb public USAGE false +test pg_catalog jsonb root ALL false +test pg_catalog jsonb[] admin ALL false +test pg_catalog jsonb[] public USAGE false +test pg_catalog jsonb[] root ALL false +test pg_catalog name admin ALL false +test pg_catalog name public USAGE false +test pg_catalog name root ALL false +test pg_catalog name[] admin ALL false +test pg_catalog name[] public USAGE false +test pg_catalog name[] root ALL false +test pg_catalog oid admin ALL false +test pg_catalog oid public USAGE false +test pg_catalog oid root ALL false +test pg_catalog oid[] admin ALL false +test pg_catalog oid[] public USAGE false +test pg_catalog oid[] root ALL false +test pg_catalog oidvector admin ALL false +test pg_catalog oidvector public USAGE false +test pg_catalog oidvector root ALL false +test pg_catalog oidvector[] admin ALL false +test pg_catalog oidvector[] public USAGE false +test pg_catalog oidvector[] root ALL false +test pg_catalog pg_aggregate public SELECT false +test pg_catalog pg_am public SELECT false +test pg_catalog pg_amop public SELECT false +test pg_catalog pg_amproc public SELECT false +test pg_catalog pg_attrdef public SELECT false +test pg_catalog pg_attribute public SELECT false +test pg_catalog pg_auth_members public SELECT false +test pg_catalog pg_authid public SELECT false +test pg_catalog pg_available_extension_versions public SELECT false +test pg_catalog pg_available_extensions public SELECT false +test pg_catalog pg_cast public SELECT false +test pg_catalog pg_class public SELECT false +test pg_catalog pg_collation public SELECT false +test pg_catalog pg_config public SELECT false +test pg_catalog pg_constraint public SELECT false +test pg_catalog pg_conversion public SELECT false +test pg_catalog pg_cursors public SELECT false +test pg_catalog pg_database public SELECT false +test pg_catalog pg_db_role_setting public SELECT false +test pg_catalog pg_default_acl public SELECT false +test pg_catalog pg_depend public SELECT false +test pg_catalog pg_description public SELECT false +test pg_catalog pg_enum public SELECT false +test pg_catalog pg_event_trigger public SELECT false +test pg_catalog pg_extension public SELECT false +test pg_catalog pg_file_settings public SELECT false +test pg_catalog pg_foreign_data_wrapper public SELECT false +test pg_catalog pg_foreign_server public SELECT false +test pg_catalog pg_foreign_table public SELECT false +test pg_catalog pg_group public SELECT false +test pg_catalog pg_hba_file_rules public SELECT false +test pg_catalog pg_index public SELECT false +test pg_catalog pg_indexes public SELECT false +test pg_catalog pg_inherits public SELECT false +test pg_catalog pg_init_privs public SELECT false +test pg_catalog pg_language public SELECT false +test pg_catalog pg_largeobject public SELECT false +test pg_catalog pg_largeobject_metadata public SELECT false +test pg_catalog pg_locks public SELECT false +test pg_catalog pg_matviews public SELECT false +test pg_catalog pg_namespace public SELECT false +test pg_catalog pg_opclass public SELECT false +test pg_catalog pg_operator public SELECT false +test pg_catalog pg_opfamily public SELECT false +test pg_catalog pg_partitioned_table public SELECT false +test pg_catalog pg_policies public SELECT false +test pg_catalog pg_policy public SELECT false +test pg_catalog pg_prepared_statements public SELECT false +test pg_catalog pg_prepared_xacts public SELECT false +test pg_catalog pg_proc public SELECT false +test pg_catalog pg_publication public SELECT false +test pg_catalog pg_publication_rel public SELECT false +test pg_catalog pg_publication_tables public SELECT false +test pg_catalog pg_range public SELECT false +test pg_catalog pg_replication_origin public SELECT false +test pg_catalog pg_replication_origin_status public SELECT false +test pg_catalog pg_replication_slots public SELECT false +test pg_catalog pg_rewrite public SELECT false +test pg_catalog pg_roles public SELECT false +test pg_catalog pg_rules public SELECT false +test pg_catalog pg_seclabel public SELECT false +test pg_catalog pg_seclabels public SELECT false +test pg_catalog pg_sequence public SELECT false +test pg_catalog pg_sequences public SELECT false +test pg_catalog pg_settings public SELECT false +test pg_catalog pg_shadow public SELECT false +test pg_catalog pg_shdepend public SELECT false +test pg_catalog pg_shdescription public SELECT false +test pg_catalog pg_shmem_allocations public SELECT false +test pg_catalog pg_shseclabel public SELECT false +test pg_catalog pg_stat_activity public SELECT false +test pg_catalog pg_stat_all_indexes public SELECT false +test pg_catalog pg_stat_all_tables public SELECT false +test pg_catalog pg_stat_archiver public SELECT false +test pg_catalog pg_stat_bgwriter public SELECT false +test pg_catalog pg_stat_database public SELECT false +test pg_catalog pg_stat_database_conflicts public SELECT false +test pg_catalog pg_stat_gssapi public SELECT false +test pg_catalog pg_stat_progress_analyze public SELECT false +test pg_catalog pg_stat_progress_basebackup public SELECT false +test pg_catalog pg_stat_progress_cluster public SELECT false +test pg_catalog pg_stat_progress_create_index public SELECT false +test pg_catalog pg_stat_progress_vacuum public SELECT false +test pg_catalog pg_stat_replication public SELECT false +test pg_catalog pg_stat_slru public SELECT false +test pg_catalog pg_stat_ssl public SELECT false +test pg_catalog pg_stat_subscription public SELECT false +test pg_catalog pg_stat_sys_indexes public SELECT false +test pg_catalog pg_stat_sys_tables public SELECT false +test pg_catalog pg_stat_user_functions public SELECT false +test pg_catalog pg_stat_user_indexes public SELECT false +test pg_catalog pg_stat_user_tables public SELECT false +test pg_catalog pg_stat_wal_receiver public SELECT false +test pg_catalog pg_stat_xact_all_tables public SELECT false +test pg_catalog pg_stat_xact_sys_tables public SELECT false +test pg_catalog pg_stat_xact_user_functions public SELECT false +test pg_catalog pg_stat_xact_user_tables public SELECT false +test pg_catalog pg_statio_all_indexes public SELECT false +test pg_catalog pg_statio_all_sequences public SELECT false +test pg_catalog pg_statio_all_tables public SELECT false +test pg_catalog pg_statio_sys_indexes public SELECT false +test pg_catalog pg_statio_sys_sequences public SELECT false +test pg_catalog pg_statio_sys_tables public SELECT false +test pg_catalog pg_statio_user_indexes public SELECT false +test pg_catalog pg_statio_user_sequences public SELECT false +test pg_catalog pg_statio_user_tables public SELECT false +test pg_catalog pg_statistic public SELECT false +test pg_catalog pg_statistic_ext public SELECT false +test pg_catalog pg_statistic_ext_data public SELECT false +test pg_catalog pg_stats public SELECT false +test pg_catalog pg_stats_ext public SELECT false +test pg_catalog pg_subscription public SELECT false +test pg_catalog pg_subscription_rel public SELECT false +test pg_catalog pg_tables public SELECT false +test pg_catalog pg_tablespace public SELECT false +test pg_catalog pg_timezone_abbrevs public SELECT false +test pg_catalog pg_timezone_names public SELECT false +test pg_catalog pg_transform public SELECT false +test pg_catalog pg_trigger public SELECT false +test pg_catalog pg_ts_config public SELECT false +test pg_catalog pg_ts_config_map public SELECT false +test pg_catalog pg_ts_dict public SELECT false +test pg_catalog pg_ts_parser public SELECT false +test pg_catalog pg_ts_template public SELECT false +test pg_catalog pg_type public SELECT false +test pg_catalog pg_user public SELECT false +test pg_catalog pg_user_mapping public SELECT false +test pg_catalog pg_user_mappings public SELECT false +test pg_catalog pg_views public SELECT false +test pg_catalog record admin ALL false +test pg_catalog record public USAGE false +test pg_catalog record root ALL false +test pg_catalog record[] admin ALL false +test pg_catalog record[] public USAGE false +test pg_catalog record[] root ALL false +test pg_catalog regclass admin ALL false +test pg_catalog regclass public USAGE false +test pg_catalog regclass root ALL false +test pg_catalog regclass[] admin ALL false +test pg_catalog regclass[] public USAGE false +test pg_catalog regclass[] root ALL false +test pg_catalog regnamespace admin ALL false +test pg_catalog regnamespace public USAGE false +test pg_catalog regnamespace root ALL false +test pg_catalog regnamespace[] admin ALL false +test pg_catalog regnamespace[] public USAGE false +test pg_catalog regnamespace[] root ALL false +test pg_catalog regproc admin ALL false +test pg_catalog regproc public USAGE false +test pg_catalog regproc root ALL false +test pg_catalog regproc[] admin ALL false +test pg_catalog regproc[] public USAGE false +test pg_catalog regproc[] root ALL false +test pg_catalog regprocedure admin ALL false +test pg_catalog regprocedure public USAGE false +test pg_catalog regprocedure root ALL false +test pg_catalog regprocedure[] admin ALL false +test pg_catalog regprocedure[] public USAGE false +test pg_catalog regprocedure[] root ALL false +test pg_catalog regrole admin ALL false +test pg_catalog regrole public USAGE false +test pg_catalog regrole root ALL false +test pg_catalog regrole[] admin ALL false +test pg_catalog regrole[] public USAGE false +test pg_catalog regrole[] root ALL false +test pg_catalog regtype admin ALL false +test pg_catalog regtype public USAGE false +test pg_catalog regtype root ALL false +test pg_catalog regtype[] admin ALL false +test pg_catalog regtype[] public USAGE false +test pg_catalog regtype[] root ALL false +test pg_catalog string admin ALL false +test pg_catalog string public USAGE false +test pg_catalog string root ALL false +test pg_catalog string[] admin ALL false +test pg_catalog string[] public USAGE false +test pg_catalog string[] root ALL false +test pg_catalog time admin ALL false +test pg_catalog time public USAGE false +test pg_catalog time root ALL false +test pg_catalog time[] admin ALL false +test pg_catalog time[] public USAGE false +test pg_catalog time[] root ALL false +test pg_catalog timestamp admin ALL false +test pg_catalog timestamp public USAGE false +test pg_catalog timestamp root ALL false +test pg_catalog timestamp[] admin ALL false +test pg_catalog timestamp[] public USAGE false +test pg_catalog timestamp[] root ALL false +test pg_catalog timestamptz admin ALL false +test pg_catalog timestamptz public USAGE false +test pg_catalog timestamptz root ALL false +test pg_catalog timestamptz[] admin ALL false +test pg_catalog timestamptz[] public USAGE false +test pg_catalog timestamptz[] root ALL false +test pg_catalog timetz admin ALL false +test pg_catalog timetz public USAGE false +test pg_catalog timetz root ALL false +test pg_catalog timetz[] admin ALL false +test pg_catalog timetz[] public USAGE false +test pg_catalog timetz[] root ALL false +test pg_catalog tsquery admin ALL false +test pg_catalog tsquery public USAGE false +test pg_catalog tsquery root ALL false +test pg_catalog tsquery[] admin ALL false +test pg_catalog tsquery[] public USAGE false +test pg_catalog tsquery[] root ALL false +test pg_catalog tsvector admin ALL false +test pg_catalog tsvector public USAGE false +test pg_catalog tsvector root ALL false +test pg_catalog tsvector[] admin ALL false +test pg_catalog tsvector[] public USAGE false +test pg_catalog tsvector[] root ALL false +test pg_catalog unknown admin ALL false +test pg_catalog unknown public USAGE false +test pg_catalog unknown root ALL false +test pg_catalog uuid admin ALL false +test pg_catalog uuid public USAGE false +test pg_catalog uuid root ALL false +test pg_catalog uuid[] admin ALL false +test pg_catalog uuid[] public USAGE false +test pg_catalog uuid[] root ALL false +test pg_catalog varbit admin ALL false +test pg_catalog varbit public USAGE false +test pg_catalog varbit root ALL false +test pg_catalog varbit[] admin ALL false +test pg_catalog varbit[] public USAGE false +test pg_catalog varbit[] root ALL false +test pg_catalog varchar admin ALL false +test pg_catalog varchar public USAGE false +test pg_catalog varchar root ALL false +test pg_catalog varchar[] admin ALL false +test pg_catalog varchar[] public USAGE false +test pg_catalog varchar[] root ALL false +test pg_catalog void admin ALL false +test pg_catalog void public USAGE false +test pg_catalog void root ALL false +test pg_extension NULL public USAGE false +test pg_extension geography_columns public SELECT false +test pg_extension geometry_columns public SELECT false +test pg_extension spatial_ref_sys public SELECT false +test public NULL admin ALL true +test public NULL public CREATE false +test public NULL public USAGE false +test public NULL root ALL true + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR root +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test NULL NULL root ALL true +test pg_catalog "char" root ALL false +test pg_catalog "char"[] root ALL false +test pg_catalog anyelement root ALL false +test pg_catalog anyelement[] root ALL false +test pg_catalog bit root ALL false +test pg_catalog bit[] root ALL false +test pg_catalog bool root ALL false +test pg_catalog bool[] root ALL false +test pg_catalog box2d root ALL false +test pg_catalog box2d[] root ALL false +test pg_catalog bytes root ALL false +test pg_catalog bytes[] root ALL false +test pg_catalog char root ALL false +test pg_catalog char[] root ALL false +test pg_catalog date root ALL false +test pg_catalog date[] root ALL false +test pg_catalog decimal root ALL false +test pg_catalog decimal[] root ALL false +test pg_catalog float root ALL false +test pg_catalog float4 root ALL false +test pg_catalog float4[] root ALL false +test pg_catalog float[] root ALL false +test pg_catalog geography root ALL false +test pg_catalog geography[] root ALL false +test pg_catalog geometry root ALL false +test pg_catalog geometry[] root ALL false +test pg_catalog inet root ALL false +test pg_catalog inet[] root ALL false +test pg_catalog int root ALL false +test pg_catalog int2 root ALL false +test pg_catalog int2[] root ALL false +test pg_catalog int2vector root ALL false +test pg_catalog int2vector[] root ALL false +test pg_catalog int4 root ALL false +test pg_catalog int4[] root ALL false +test pg_catalog int[] root ALL false +test pg_catalog interval root ALL false +test pg_catalog interval[] root ALL false +test pg_catalog jsonb root ALL false +test pg_catalog jsonb[] root ALL false +test pg_catalog name root ALL false +test pg_catalog name[] root ALL false +test pg_catalog oid root ALL false +test pg_catalog oid[] root ALL false +test pg_catalog oidvector root ALL false +test pg_catalog oidvector[] root ALL false +test pg_catalog record root ALL false +test pg_catalog record[] root ALL false +test pg_catalog regclass root ALL false +test pg_catalog regclass[] root ALL false +test pg_catalog regnamespace root ALL false +test pg_catalog regnamespace[] root ALL false +test pg_catalog regproc root ALL false +test pg_catalog regproc[] root ALL false +test pg_catalog regprocedure root ALL false +test pg_catalog regprocedure[] root ALL false +test pg_catalog regrole root ALL false +test pg_catalog regrole[] root ALL false +test pg_catalog regtype root ALL false +test pg_catalog regtype[] root ALL false +test pg_catalog string root ALL false +test pg_catalog string[] root ALL false +test pg_catalog time root ALL false +test pg_catalog time[] root ALL false +test pg_catalog timestamp root ALL false +test pg_catalog timestamp[] root ALL false +test pg_catalog timestamptz root ALL false +test pg_catalog timestamptz[] root ALL false +test pg_catalog timetz root ALL false +test pg_catalog timetz[] root ALL false +test pg_catalog tsquery root ALL false +test pg_catalog tsquery[] root ALL false +test pg_catalog tsvector root ALL false +test pg_catalog tsvector[] root ALL false +test pg_catalog unknown root ALL false +test pg_catalog uuid root ALL false +test pg_catalog uuid[] root ALL false +test pg_catalog varbit root ALL false +test pg_catalog varbit[] root ALL false +test pg_catalog varchar root ALL false +test pg_catalog varchar[] root ALL false +test pg_catalog void root ALL false +test public NULL root ALL true + +# With no database set, we show the grants everywhere +statement ok +SET DATABASE = '' + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames,rowsort +SELECT * FROM [SHOW GRANTS] + WHERE schema_name NOT IN ('crdb_internal', 'pg_catalog', 'information_schema') +---- +database_name schema_name relation_name grantee privilege_type is_grantable +system pg_extension geography_columns public SELECT false +system pg_extension geometry_columns public SELECT false +system pg_extension spatial_ref_sys public SELECT false +defaultdb pg_extension geography_columns public SELECT false +defaultdb pg_extension geometry_columns public SELECT false +defaultdb pg_extension spatial_ref_sys public SELECT false +postgres pg_extension geography_columns public SELECT false +postgres pg_extension geometry_columns public SELECT false +postgres pg_extension spatial_ref_sys public SELECT false +test pg_extension geography_columns public SELECT false +test pg_extension geometry_columns public SELECT false +test pg_extension spatial_ref_sys public SELECT false +a pg_extension geography_columns public SELECT false +a pg_extension geometry_columns public SELECT false +a pg_extension spatial_ref_sys public SELECT false +system public descriptor admin SELECT true +system public descriptor root SELECT true +system public users admin DELETE true +system public users admin INSERT true +system public users admin SELECT true +system public users admin UPDATE true +system public users root DELETE true +system public users root INSERT true +system public users root SELECT true +system public users root UPDATE true +system public zones admin DELETE true +system public zones admin INSERT true +system public zones admin SELECT true +system public zones admin UPDATE true +system public zones root DELETE true +system public zones root INSERT true +system public zones root SELECT true +system public zones root UPDATE true +system public settings admin DELETE true +system public settings admin INSERT true +system public settings admin SELECT true +system public settings admin UPDATE true +system public settings root DELETE true +system public settings root INSERT true +system public settings root SELECT true +system public settings root UPDATE true +system public descriptor_id_seq admin SELECT true +system public descriptor_id_seq root SELECT true +system public tenants admin SELECT true +system public tenants root SELECT true +system public lease admin DELETE true +system public lease admin INSERT true +system public lease admin SELECT true +system public lease admin UPDATE true +system public lease root DELETE true +system public lease root INSERT true +system public lease root SELECT true +system public lease root UPDATE true +system public eventlog admin DELETE true +system public eventlog admin INSERT true +system public eventlog admin SELECT true +system public eventlog admin UPDATE true +system public eventlog root DELETE true +system public eventlog root INSERT true +system public eventlog root SELECT true +system public eventlog root UPDATE true +system public rangelog admin DELETE true +system public rangelog admin INSERT true +system public rangelog admin SELECT true +system public rangelog admin UPDATE true +system public rangelog root DELETE true +system public rangelog root INSERT true +system public rangelog root SELECT true +system public rangelog root UPDATE true +system public ui admin DELETE true +system public ui admin INSERT true +system public ui admin SELECT true +system public ui admin UPDATE true +system public ui root DELETE true +system public ui root INSERT true +system public ui root SELECT true +system public ui root UPDATE true +system public jobs admin DELETE true +system public jobs admin INSERT true +system public jobs admin SELECT true +system public jobs admin UPDATE true +system public jobs root DELETE true +system public jobs root INSERT true +system public jobs root SELECT true +system public jobs root UPDATE true +system public web_sessions admin DELETE true +system public web_sessions admin INSERT true +system public web_sessions admin SELECT true +system public web_sessions admin UPDATE true +system public web_sessions root DELETE true +system public web_sessions root INSERT true +system public web_sessions root SELECT true +system public web_sessions root UPDATE true +system public table_statistics admin DELETE true +system public table_statistics admin INSERT true +system public table_statistics admin SELECT true +system public table_statistics admin UPDATE true +system public table_statistics root DELETE true +system public table_statistics root INSERT true +system public table_statistics root SELECT true +system public table_statistics root UPDATE true +system public locations admin DELETE true +system public locations admin INSERT true +system public locations admin SELECT true +system public locations admin UPDATE true +system public locations root DELETE true +system public locations root INSERT true +system public locations root SELECT true +system public locations root UPDATE true +system public role_members admin DELETE true +system public role_members admin INSERT true +system public role_members admin SELECT true +system public role_members admin UPDATE true +system public role_members root DELETE true +system public role_members root INSERT true +system public role_members root SELECT true +system public role_members root UPDATE true +system public comments admin DELETE true +system public comments admin INSERT true +system public comments admin SELECT true +system public comments admin UPDATE true +system public comments public SELECT false +system public comments root DELETE true +system public comments root INSERT true +system public comments root SELECT true +system public comments root UPDATE true +system public replication_constraint_stats admin DELETE true +system public replication_constraint_stats admin INSERT true +system public replication_constraint_stats admin SELECT true +system public replication_constraint_stats admin UPDATE true +system public replication_constraint_stats root DELETE true +system public replication_constraint_stats root INSERT true +system public replication_constraint_stats root SELECT true +system public replication_constraint_stats root UPDATE true +system public replication_critical_localities admin DELETE true +system public replication_critical_localities admin INSERT true +system public replication_critical_localities admin SELECT true +system public replication_critical_localities admin UPDATE true +system public replication_critical_localities root DELETE true +system public replication_critical_localities root INSERT true +system public replication_critical_localities root SELECT true +system public replication_critical_localities root UPDATE true +system public replication_stats admin DELETE true +system public replication_stats admin INSERT true +system public replication_stats admin SELECT true +system public replication_stats admin UPDATE true +system public replication_stats root DELETE true +system public replication_stats root INSERT true +system public replication_stats root SELECT true +system public replication_stats root UPDATE true +system public reports_meta admin DELETE true +system public reports_meta admin INSERT true +system public reports_meta admin SELECT true +system public reports_meta admin UPDATE true +system public reports_meta root DELETE true +system public reports_meta root INSERT true +system public reports_meta root SELECT true +system public reports_meta root UPDATE true +system public namespace admin SELECT true +system public namespace root SELECT true +system public protected_ts_meta admin SELECT true +system public protected_ts_meta root SELECT true +system public protected_ts_records admin SELECT true +system public protected_ts_records root SELECT true +system public role_options admin DELETE true +system public role_options admin INSERT true +system public role_options admin SELECT true +system public role_options admin UPDATE true +system public role_options root DELETE true +system public role_options root INSERT true +system public role_options root SELECT true +system public role_options root UPDATE true +system public statement_bundle_chunks admin DELETE true +system public statement_bundle_chunks admin INSERT true +system public statement_bundle_chunks admin SELECT true +system public statement_bundle_chunks admin UPDATE true +system public statement_bundle_chunks root DELETE true +system public statement_bundle_chunks root INSERT true +system public statement_bundle_chunks root SELECT true +system public statement_bundle_chunks root UPDATE true +system public statement_diagnostics_requests admin DELETE true +system public statement_diagnostics_requests admin INSERT true +system public statement_diagnostics_requests admin SELECT true +system public statement_diagnostics_requests admin UPDATE true +system public statement_diagnostics_requests root DELETE true +system public statement_diagnostics_requests root INSERT true +system public statement_diagnostics_requests root SELECT true +system public statement_diagnostics_requests root UPDATE true +system public statement_diagnostics admin DELETE true +system public statement_diagnostics admin INSERT true +system public statement_diagnostics admin SELECT true +system public statement_diagnostics admin UPDATE true +system public statement_diagnostics root DELETE true +system public statement_diagnostics root INSERT true +system public statement_diagnostics root SELECT true +system public statement_diagnostics root UPDATE true +system public scheduled_jobs admin DELETE true +system public scheduled_jobs admin INSERT true +system public scheduled_jobs admin SELECT true +system public scheduled_jobs admin UPDATE true +system public scheduled_jobs root DELETE true +system public scheduled_jobs root INSERT true +system public scheduled_jobs root SELECT true +system public scheduled_jobs root UPDATE true +system public sqlliveness admin DELETE true +system public sqlliveness admin INSERT true +system public sqlliveness admin SELECT true +system public sqlliveness admin UPDATE true +system public sqlliveness root DELETE true +system public sqlliveness root INSERT true +system public sqlliveness root SELECT true +system public sqlliveness root UPDATE true +system public migrations admin DELETE true +system public migrations admin INSERT true +system public migrations admin SELECT true +system public migrations admin UPDATE true +system public migrations root DELETE true +system public migrations root INSERT true +system public migrations root SELECT true +system public migrations root UPDATE true +system public join_tokens admin DELETE true +system public join_tokens admin INSERT true +system public join_tokens admin SELECT true +system public join_tokens admin UPDATE true +system public join_tokens root DELETE true +system public join_tokens root INSERT true +system public join_tokens root SELECT true +system public join_tokens root UPDATE true +system public statement_statistics admin SELECT true +system public statement_statistics root SELECT true +system public transaction_statistics admin SELECT true +system public transaction_statistics root SELECT true +system public database_role_settings admin DELETE true +system public database_role_settings admin INSERT true +system public database_role_settings admin SELECT true +system public database_role_settings admin UPDATE true +system public database_role_settings root DELETE true +system public database_role_settings root INSERT true +system public database_role_settings root SELECT true +system public database_role_settings root UPDATE true +system public tenant_usage admin DELETE true +system public tenant_usage admin INSERT true +system public tenant_usage admin SELECT true +system public tenant_usage admin UPDATE true +system public tenant_usage root DELETE true +system public tenant_usage root INSERT true +system public tenant_usage root SELECT true +system public tenant_usage root UPDATE true +system public sql_instances admin DELETE true +system public sql_instances admin INSERT true +system public sql_instances admin SELECT true +system public sql_instances admin UPDATE true +system public sql_instances root DELETE true +system public sql_instances root INSERT true +system public sql_instances root SELECT true +system public sql_instances root UPDATE true +system public span_configurations admin DELETE true +system public span_configurations admin INSERT true +system public span_configurations admin SELECT true +system public span_configurations admin UPDATE true +system public span_configurations root DELETE true +system public span_configurations root INSERT true +system public span_configurations root SELECT true +system public span_configurations root UPDATE true +system public role_id_seq admin SELECT true +system public role_id_seq admin UPDATE true +system public role_id_seq admin USAGE true +system public role_id_seq root SELECT true +system public role_id_seq root UPDATE true +system public role_id_seq root USAGE true +system public tenant_settings admin DELETE true +system public tenant_settings admin INSERT true +system public tenant_settings admin SELECT true +system public tenant_settings admin UPDATE true +system public tenant_settings root DELETE true +system public tenant_settings root INSERT true +system public tenant_settings root SELECT true +system public tenant_settings root UPDATE true +system public privileges admin DELETE true +system public privileges admin INSERT true +system public privileges admin SELECT true +system public privileges admin UPDATE true +system public privileges root DELETE true +system public privileges root INSERT true +system public privileges root SELECT true +system public privileges root UPDATE true +system public external_connections admin DELETE true +system public external_connections admin INSERT true +system public external_connections admin SELECT true +system public external_connections admin UPDATE true +system public external_connections root DELETE true +system public external_connections root INSERT true +system public external_connections root SELECT true +system public external_connections root UPDATE true +system public job_info admin DELETE true +system public job_info admin INSERT true +system public job_info admin SELECT true +system public job_info admin UPDATE true +system public job_info root DELETE true +system public job_info root INSERT true +system public job_info root SELECT true +system public job_info root UPDATE true +system public span_stats_unique_keys admin DELETE true +system public span_stats_unique_keys admin INSERT true +system public span_stats_unique_keys admin SELECT true +system public span_stats_unique_keys admin UPDATE true +system public span_stats_unique_keys root DELETE true +system public span_stats_unique_keys root INSERT true +system public span_stats_unique_keys root SELECT true +system public span_stats_unique_keys root UPDATE true +system public span_stats_buckets admin DELETE true +system public span_stats_buckets admin INSERT true +system public span_stats_buckets admin SELECT true +system public span_stats_buckets admin UPDATE true +system public span_stats_buckets root DELETE true +system public span_stats_buckets root INSERT true +system public span_stats_buckets root SELECT true +system public span_stats_buckets root UPDATE true +system public span_stats_samples admin DELETE true +system public span_stats_samples admin INSERT true +system public span_stats_samples admin SELECT true +system public span_stats_samples admin UPDATE true +system public span_stats_samples root DELETE true +system public span_stats_samples root INSERT true +system public span_stats_samples root SELECT true +system public span_stats_samples root UPDATE true +system public span_stats_tenant_boundaries admin DELETE true +system public span_stats_tenant_boundaries admin INSERT true +system public span_stats_tenant_boundaries admin SELECT true +system public span_stats_tenant_boundaries admin UPDATE true +system public span_stats_tenant_boundaries root DELETE true +system public span_stats_tenant_boundaries root INSERT true +system public span_stats_tenant_boundaries root SELECT true +system public span_stats_tenant_boundaries root UPDATE true +system public task_payloads admin DELETE true +system public task_payloads admin INSERT true +system public task_payloads admin SELECT true +system public task_payloads admin UPDATE true +system public task_payloads root DELETE true +system public task_payloads root INSERT true +system public task_payloads root SELECT true +system public task_payloads root UPDATE true +system public tenant_tasks admin DELETE true +system public tenant_tasks admin INSERT true +system public tenant_tasks admin SELECT true +system public tenant_tasks admin UPDATE true +system public tenant_tasks root DELETE true +system public tenant_tasks root INSERT true +system public tenant_tasks root SELECT true +system public tenant_tasks root UPDATE true +system public statement_activity admin SELECT true +system public statement_activity root SELECT true +system public transaction_activity admin SELECT true +system public transaction_activity root SELECT true +system public tenant_id_seq admin SELECT true +system public tenant_id_seq root SELECT true +a pg_extension NULL public USAGE false +a public NULL admin ALL true +a public NULL public CREATE false +a public NULL public USAGE false +a public NULL root ALL true +defaultdb pg_extension NULL public USAGE false +defaultdb public NULL admin ALL true +defaultdb public NULL public CREATE false +defaultdb public NULL public USAGE false +defaultdb public NULL root ALL true +postgres pg_extension NULL public USAGE false +postgres public NULL admin ALL true +postgres public NULL public CREATE false +postgres public NULL public USAGE false +postgres public NULL root ALL true +system pg_extension NULL public USAGE false +system public NULL admin ALL true +system public NULL public CREATE false +system public NULL public USAGE false +system public NULL root ALL true +test pg_extension NULL public USAGE false +test public NULL admin ALL true +test public NULL public CREATE false +test public NULL public USAGE false +test public NULL root ALL true + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR root +---- +database_name schema_name relation_name grantee privilege_type is_grantable +a NULL NULL root ALL true +a pg_catalog "char" root ALL false +a pg_catalog "char"[] root ALL false +a pg_catalog anyelement root ALL false +a pg_catalog anyelement[] root ALL false +a pg_catalog bit root ALL false +a pg_catalog bit[] root ALL false +a pg_catalog bool root ALL false +a pg_catalog bool[] root ALL false +a pg_catalog box2d root ALL false +a pg_catalog box2d[] root ALL false +a pg_catalog bytes root ALL false +a pg_catalog bytes[] root ALL false +a pg_catalog char root ALL false +a pg_catalog char[] root ALL false +a pg_catalog date root ALL false +a pg_catalog date[] root ALL false +a pg_catalog decimal root ALL false +a pg_catalog decimal[] root ALL false +a pg_catalog float root ALL false +a pg_catalog float4 root ALL false +a pg_catalog float4[] root ALL false +a pg_catalog float[] root ALL false +a pg_catalog geography root ALL false +a pg_catalog geography[] root ALL false +a pg_catalog geometry root ALL false +a pg_catalog geometry[] root ALL false +a pg_catalog inet root ALL false +a pg_catalog inet[] root ALL false +a pg_catalog int root ALL false +a pg_catalog int2 root ALL false +a pg_catalog int2[] root ALL false +a pg_catalog int2vector root ALL false +a pg_catalog int2vector[] root ALL false +a pg_catalog int4 root ALL false +a pg_catalog int4[] root ALL false +a pg_catalog int[] root ALL false +a pg_catalog interval root ALL false +a pg_catalog interval[] root ALL false +a pg_catalog jsonb root ALL false +a pg_catalog jsonb[] root ALL false +a pg_catalog name root ALL false +a pg_catalog name[] root ALL false +a pg_catalog oid root ALL false +a pg_catalog oid[] root ALL false +a pg_catalog oidvector root ALL false +a pg_catalog oidvector[] root ALL false +a pg_catalog record root ALL false +a pg_catalog record[] root ALL false +a pg_catalog regclass root ALL false +a pg_catalog regclass[] root ALL false +a pg_catalog regnamespace root ALL false +a pg_catalog regnamespace[] root ALL false +a pg_catalog regproc root ALL false +a pg_catalog regproc[] root ALL false +a pg_catalog regprocedure root ALL false +a pg_catalog regprocedure[] root ALL false +a pg_catalog regrole root ALL false +a pg_catalog regrole[] root ALL false +a pg_catalog regtype root ALL false +a pg_catalog regtype[] root ALL false +a pg_catalog string root ALL false +a pg_catalog string[] root ALL false +a pg_catalog time root ALL false +a pg_catalog time[] root ALL false +a pg_catalog timestamp root ALL false +a pg_catalog timestamp[] root ALL false +a pg_catalog timestamptz root ALL false +a pg_catalog timestamptz[] root ALL false +a pg_catalog timetz root ALL false +a pg_catalog timetz[] root ALL false +a pg_catalog tsquery root ALL false +a pg_catalog tsquery[] root ALL false +a pg_catalog tsvector root ALL false +a pg_catalog tsvector[] root ALL false +a pg_catalog unknown root ALL false +a pg_catalog uuid root ALL false +a pg_catalog uuid[] root ALL false +a pg_catalog varbit root ALL false +a pg_catalog varbit[] root ALL false +a pg_catalog varchar root ALL false +a pg_catalog varchar[] root ALL false +a pg_catalog void root ALL false +a public NULL root ALL true +defaultdb NULL NULL root ALL true +defaultdb pg_catalog "char" root ALL false +defaultdb pg_catalog "char"[] root ALL false +defaultdb pg_catalog anyelement root ALL false +defaultdb pg_catalog anyelement[] root ALL false +defaultdb pg_catalog bit root ALL false +defaultdb pg_catalog bit[] root ALL false +defaultdb pg_catalog bool root ALL false +defaultdb pg_catalog bool[] root ALL false +defaultdb pg_catalog box2d root ALL false +defaultdb pg_catalog box2d[] root ALL false +defaultdb pg_catalog bytes root ALL false +defaultdb pg_catalog bytes[] root ALL false +defaultdb pg_catalog char root ALL false +defaultdb pg_catalog char[] root ALL false +defaultdb pg_catalog date root ALL false +defaultdb pg_catalog date[] root ALL false +defaultdb pg_catalog decimal root ALL false +defaultdb pg_catalog decimal[] root ALL false +defaultdb pg_catalog float root ALL false +defaultdb pg_catalog float4 root ALL false +defaultdb pg_catalog float4[] root ALL false +defaultdb pg_catalog float[] root ALL false +defaultdb pg_catalog geography root ALL false +defaultdb pg_catalog geography[] root ALL false +defaultdb pg_catalog geometry root ALL false +defaultdb pg_catalog geometry[] root ALL false +defaultdb pg_catalog inet root ALL false +defaultdb pg_catalog inet[] root ALL false +defaultdb pg_catalog int root ALL false +defaultdb pg_catalog int2 root ALL false +defaultdb pg_catalog int2[] root ALL false +defaultdb pg_catalog int2vector root ALL false +defaultdb pg_catalog int2vector[] root ALL false +defaultdb pg_catalog int4 root ALL false +defaultdb pg_catalog int4[] root ALL false +defaultdb pg_catalog int[] root ALL false +defaultdb pg_catalog interval root ALL false +defaultdb pg_catalog interval[] root ALL false +defaultdb pg_catalog jsonb root ALL false +defaultdb pg_catalog jsonb[] root ALL false +defaultdb pg_catalog name root ALL false +defaultdb pg_catalog name[] root ALL false +defaultdb pg_catalog oid root ALL false +defaultdb pg_catalog oid[] root ALL false +defaultdb pg_catalog oidvector root ALL false +defaultdb pg_catalog oidvector[] root ALL false +defaultdb pg_catalog record root ALL false +defaultdb pg_catalog record[] root ALL false +defaultdb pg_catalog regclass root ALL false +defaultdb pg_catalog regclass[] root ALL false +defaultdb pg_catalog regnamespace root ALL false +defaultdb pg_catalog regnamespace[] root ALL false +defaultdb pg_catalog regproc root ALL false +defaultdb pg_catalog regproc[] root ALL false +defaultdb pg_catalog regprocedure root ALL false +defaultdb pg_catalog regprocedure[] root ALL false +defaultdb pg_catalog regrole root ALL false +defaultdb pg_catalog regrole[] root ALL false +defaultdb pg_catalog regtype root ALL false +defaultdb pg_catalog regtype[] root ALL false +defaultdb pg_catalog string root ALL false +defaultdb pg_catalog string[] root ALL false +defaultdb pg_catalog time root ALL false +defaultdb pg_catalog time[] root ALL false +defaultdb pg_catalog timestamp root ALL false +defaultdb pg_catalog timestamp[] root ALL false +defaultdb pg_catalog timestamptz root ALL false +defaultdb pg_catalog timestamptz[] root ALL false +defaultdb pg_catalog timetz root ALL false +defaultdb pg_catalog timetz[] root ALL false +defaultdb pg_catalog tsquery root ALL false +defaultdb pg_catalog tsquery[] root ALL false +defaultdb pg_catalog tsvector root ALL false +defaultdb pg_catalog tsvector[] root ALL false +defaultdb pg_catalog unknown root ALL false +defaultdb pg_catalog uuid root ALL false +defaultdb pg_catalog uuid[] root ALL false +defaultdb pg_catalog varbit root ALL false +defaultdb pg_catalog varbit[] root ALL false +defaultdb pg_catalog varchar root ALL false +defaultdb pg_catalog varchar[] root ALL false +defaultdb pg_catalog void root ALL false +defaultdb public NULL root ALL true +postgres NULL NULL root ALL true +postgres pg_catalog "char" root ALL false +postgres pg_catalog "char"[] root ALL false +postgres pg_catalog anyelement root ALL false +postgres pg_catalog anyelement[] root ALL false +postgres pg_catalog bit root ALL false +postgres pg_catalog bit[] root ALL false +postgres pg_catalog bool root ALL false +postgres pg_catalog bool[] root ALL false +postgres pg_catalog box2d root ALL false +postgres pg_catalog box2d[] root ALL false +postgres pg_catalog bytes root ALL false +postgres pg_catalog bytes[] root ALL false +postgres pg_catalog char root ALL false +postgres pg_catalog char[] root ALL false +postgres pg_catalog date root ALL false +postgres pg_catalog date[] root ALL false +postgres pg_catalog decimal root ALL false +postgres pg_catalog decimal[] root ALL false +postgres pg_catalog float root ALL false +postgres pg_catalog float4 root ALL false +postgres pg_catalog float4[] root ALL false +postgres pg_catalog float[] root ALL false +postgres pg_catalog geography root ALL false +postgres pg_catalog geography[] root ALL false +postgres pg_catalog geometry root ALL false +postgres pg_catalog geometry[] root ALL false +postgres pg_catalog inet root ALL false +postgres pg_catalog inet[] root ALL false +postgres pg_catalog int root ALL false +postgres pg_catalog int2 root ALL false +postgres pg_catalog int2[] root ALL false +postgres pg_catalog int2vector root ALL false +postgres pg_catalog int2vector[] root ALL false +postgres pg_catalog int4 root ALL false +postgres pg_catalog int4[] root ALL false +postgres pg_catalog int[] root ALL false +postgres pg_catalog interval root ALL false +postgres pg_catalog interval[] root ALL false +postgres pg_catalog jsonb root ALL false +postgres pg_catalog jsonb[] root ALL false +postgres pg_catalog name root ALL false +postgres pg_catalog name[] root ALL false +postgres pg_catalog oid root ALL false +postgres pg_catalog oid[] root ALL false +postgres pg_catalog oidvector root ALL false +postgres pg_catalog oidvector[] root ALL false +postgres pg_catalog record root ALL false +postgres pg_catalog record[] root ALL false +postgres pg_catalog regclass root ALL false +postgres pg_catalog regclass[] root ALL false +postgres pg_catalog regnamespace root ALL false +postgres pg_catalog regnamespace[] root ALL false +postgres pg_catalog regproc root ALL false +postgres pg_catalog regproc[] root ALL false +postgres pg_catalog regprocedure root ALL false +postgres pg_catalog regprocedure[] root ALL false +postgres pg_catalog regrole root ALL false +postgres pg_catalog regrole[] root ALL false +postgres pg_catalog regtype root ALL false +postgres pg_catalog regtype[] root ALL false +postgres pg_catalog string root ALL false +postgres pg_catalog string[] root ALL false +postgres pg_catalog time root ALL false +postgres pg_catalog time[] root ALL false +postgres pg_catalog timestamp root ALL false +postgres pg_catalog timestamp[] root ALL false +postgres pg_catalog timestamptz root ALL false +postgres pg_catalog timestamptz[] root ALL false +postgres pg_catalog timetz root ALL false +postgres pg_catalog timetz[] root ALL false +postgres pg_catalog tsquery root ALL false +postgres pg_catalog tsquery[] root ALL false +postgres pg_catalog tsvector root ALL false +postgres pg_catalog tsvector[] root ALL false +postgres pg_catalog unknown root ALL false +postgres pg_catalog uuid root ALL false +postgres pg_catalog uuid[] root ALL false +postgres pg_catalog varbit root ALL false +postgres pg_catalog varbit[] root ALL false +postgres pg_catalog varchar root ALL false +postgres pg_catalog varchar[] root ALL false +postgres pg_catalog void root ALL false +postgres public NULL root ALL true +system NULL NULL root CONNECT true +system pg_catalog "char" root ALL false +system pg_catalog "char"[] root ALL false +system pg_catalog anyelement root ALL false +system pg_catalog anyelement[] root ALL false +system pg_catalog bit root ALL false +system pg_catalog bit[] root ALL false +system pg_catalog bool root ALL false +system pg_catalog bool[] root ALL false +system pg_catalog box2d root ALL false +system pg_catalog box2d[] root ALL false +system pg_catalog bytes root ALL false +system pg_catalog bytes[] root ALL false +system pg_catalog char root ALL false +system pg_catalog char[] root ALL false +system pg_catalog date root ALL false +system pg_catalog date[] root ALL false +system pg_catalog decimal root ALL false +system pg_catalog decimal[] root ALL false +system pg_catalog float root ALL false +system pg_catalog float4 root ALL false +system pg_catalog float4[] root ALL false +system pg_catalog float[] root ALL false +system pg_catalog geography root ALL false +system pg_catalog geography[] root ALL false +system pg_catalog geometry root ALL false +system pg_catalog geometry[] root ALL false +system pg_catalog inet root ALL false +system pg_catalog inet[] root ALL false +system pg_catalog int root ALL false +system pg_catalog int2 root ALL false +system pg_catalog int2[] root ALL false +system pg_catalog int2vector root ALL false +system pg_catalog int2vector[] root ALL false +system pg_catalog int4 root ALL false +system pg_catalog int4[] root ALL false +system pg_catalog int[] root ALL false +system pg_catalog interval root ALL false +system pg_catalog interval[] root ALL false +system pg_catalog jsonb root ALL false +system pg_catalog jsonb[] root ALL false +system pg_catalog name root ALL false +system pg_catalog name[] root ALL false +system pg_catalog oid root ALL false +system pg_catalog oid[] root ALL false +system pg_catalog oidvector root ALL false +system pg_catalog oidvector[] root ALL false +system pg_catalog record root ALL false +system pg_catalog record[] root ALL false +system pg_catalog regclass root ALL false +system pg_catalog regclass[] root ALL false +system pg_catalog regnamespace root ALL false +system pg_catalog regnamespace[] root ALL false +system pg_catalog regproc root ALL false +system pg_catalog regproc[] root ALL false +system pg_catalog regprocedure root ALL false +system pg_catalog regprocedure[] root ALL false +system pg_catalog regrole root ALL false +system pg_catalog regrole[] root ALL false +system pg_catalog regtype root ALL false +system pg_catalog regtype[] root ALL false +system pg_catalog string root ALL false +system pg_catalog string[] root ALL false +system pg_catalog time root ALL false +system pg_catalog time[] root ALL false +system pg_catalog timestamp root ALL false +system pg_catalog timestamp[] root ALL false +system pg_catalog timestamptz root ALL false +system pg_catalog timestamptz[] root ALL false +system pg_catalog timetz root ALL false +system pg_catalog timetz[] root ALL false +system pg_catalog tsquery root ALL false +system pg_catalog tsquery[] root ALL false +system pg_catalog tsvector root ALL false +system pg_catalog tsvector[] root ALL false +system pg_catalog unknown root ALL false +system pg_catalog uuid root ALL false +system pg_catalog uuid[] root ALL false +system pg_catalog varbit root ALL false +system pg_catalog varbit[] root ALL false +system pg_catalog varchar root ALL false +system pg_catalog varchar[] root ALL false +system pg_catalog void root ALL false +system public NULL root ALL true +system public comments root DELETE true +system public comments root INSERT true +system public comments root SELECT true +system public comments root UPDATE true +system public database_role_settings root DELETE true +system public database_role_settings root INSERT true +system public database_role_settings root SELECT true +system public database_role_settings root UPDATE true +system public descriptor root SELECT true +system public descriptor_id_seq root SELECT true +system public eventlog root DELETE true +system public eventlog root INSERT true +system public eventlog root SELECT true +system public eventlog root UPDATE true +system public external_connections root DELETE true +system public external_connections root INSERT true +system public external_connections root SELECT true +system public external_connections root UPDATE true +system public job_info root DELETE true +system public job_info root INSERT true +system public job_info root SELECT true +system public job_info root UPDATE true +system public jobs root DELETE true +system public jobs root INSERT true +system public jobs root SELECT true +system public jobs root UPDATE true +system public join_tokens root DELETE true +system public join_tokens root INSERT true +system public join_tokens root SELECT true +system public join_tokens root UPDATE true +system public lease root DELETE true +system public lease root INSERT true +system public lease root SELECT true +system public lease root UPDATE true +system public locations root DELETE true +system public locations root INSERT true +system public locations root SELECT true +system public locations root UPDATE true +system public migrations root DELETE true +system public migrations root INSERT true +system public migrations root SELECT true +system public migrations root UPDATE true +system public namespace root SELECT true +system public privileges root DELETE true +system public privileges root INSERT true +system public privileges root SELECT true +system public privileges root UPDATE true +system public protected_ts_meta root SELECT true +system public protected_ts_records root SELECT true +system public rangelog root DELETE true +system public rangelog root INSERT true +system public rangelog root SELECT true +system public rangelog root UPDATE true +system public replication_constraint_stats root DELETE true +system public replication_constraint_stats root INSERT true +system public replication_constraint_stats root SELECT true +system public replication_constraint_stats root UPDATE true +system public replication_critical_localities root DELETE true +system public replication_critical_localities root INSERT true +system public replication_critical_localities root SELECT true +system public replication_critical_localities root UPDATE true +system public replication_stats root DELETE true +system public replication_stats root INSERT true +system public replication_stats root SELECT true +system public replication_stats root UPDATE true +system public reports_meta root DELETE true +system public reports_meta root INSERT true +system public reports_meta root SELECT true +system public reports_meta root UPDATE true +system public role_id_seq root SELECT true +system public role_id_seq root UPDATE true +system public role_id_seq root USAGE true +system public role_members root DELETE true +system public role_members root INSERT true +system public role_members root SELECT true +system public role_members root UPDATE true +system public role_options root DELETE true +system public role_options root INSERT true +system public role_options root SELECT true +system public role_options root UPDATE true +system public scheduled_jobs root DELETE true +system public scheduled_jobs root INSERT true +system public scheduled_jobs root SELECT true +system public scheduled_jobs root UPDATE true +system public settings root DELETE true +system public settings root INSERT true +system public settings root SELECT true +system public settings root UPDATE true +system public span_configurations root DELETE true +system public span_configurations root INSERT true +system public span_configurations root SELECT true +system public span_configurations root UPDATE true +system public span_stats_buckets root DELETE true +system public span_stats_buckets root INSERT true +system public span_stats_buckets root SELECT true +system public span_stats_buckets root UPDATE true +system public span_stats_samples root DELETE true +system public span_stats_samples root INSERT true +system public span_stats_samples root SELECT true +system public span_stats_samples root UPDATE true +system public span_stats_tenant_boundaries root DELETE true +system public span_stats_tenant_boundaries root INSERT true +system public span_stats_tenant_boundaries root SELECT true +system public span_stats_tenant_boundaries root UPDATE true +system public span_stats_unique_keys root DELETE true +system public span_stats_unique_keys root INSERT true +system public span_stats_unique_keys root SELECT true +system public span_stats_unique_keys root UPDATE true +system public sql_instances root DELETE true +system public sql_instances root INSERT true +system public sql_instances root SELECT true +system public sql_instances root UPDATE true +system public sqlliveness root DELETE true +system public sqlliveness root INSERT true +system public sqlliveness root SELECT true +system public sqlliveness root UPDATE true +system public statement_activity root SELECT true +system public statement_bundle_chunks root DELETE true +system public statement_bundle_chunks root INSERT true +system public statement_bundle_chunks root SELECT true +system public statement_bundle_chunks root UPDATE true +system public statement_diagnostics root DELETE true +system public statement_diagnostics root INSERT true +system public statement_diagnostics root SELECT true +system public statement_diagnostics root UPDATE true +system public statement_diagnostics_requests root DELETE true +system public statement_diagnostics_requests root INSERT true +system public statement_diagnostics_requests root SELECT true +system public statement_diagnostics_requests root UPDATE true +system public statement_statistics root SELECT true +system public table_statistics root DELETE true +system public table_statistics root INSERT true +system public table_statistics root SELECT true +system public table_statistics root UPDATE true +system public task_payloads root DELETE true +system public task_payloads root INSERT true +system public task_payloads root SELECT true +system public task_payloads root UPDATE true +system public tenant_id_seq root SELECT true +system public tenant_settings root DELETE true +system public tenant_settings root INSERT true +system public tenant_settings root SELECT true +system public tenant_settings root UPDATE true +system public tenant_tasks root DELETE true +system public tenant_tasks root INSERT true +system public tenant_tasks root SELECT true +system public tenant_tasks root UPDATE true +system public tenant_usage root DELETE true +system public tenant_usage root INSERT true +system public tenant_usage root SELECT true +system public tenant_usage root UPDATE true +system public tenants root SELECT true +system public transaction_activity root SELECT true +system public transaction_statistics root SELECT true +system public ui root DELETE true +system public ui root INSERT true +system public ui root SELECT true +system public ui root UPDATE true +system public users root DELETE true +system public users root INSERT true +system public users root SELECT true +system public users root UPDATE true +system public web_sessions root DELETE true +system public web_sessions root INSERT true +system public web_sessions root SELECT true +system public web_sessions root UPDATE true +system public zones root DELETE true +system public zones root INSERT true +system public zones root SELECT true +system public zones root UPDATE true +test NULL NULL root ALL true +test pg_catalog "char" root ALL false +test pg_catalog "char"[] root ALL false +test pg_catalog anyelement root ALL false +test pg_catalog anyelement[] root ALL false +test pg_catalog bit root ALL false +test pg_catalog bit[] root ALL false +test pg_catalog bool root ALL false +test pg_catalog bool[] root ALL false +test pg_catalog box2d root ALL false +test pg_catalog box2d[] root ALL false +test pg_catalog bytes root ALL false +test pg_catalog bytes[] root ALL false +test pg_catalog char root ALL false +test pg_catalog char[] root ALL false +test pg_catalog date root ALL false +test pg_catalog date[] root ALL false +test pg_catalog decimal root ALL false +test pg_catalog decimal[] root ALL false +test pg_catalog float root ALL false +test pg_catalog float4 root ALL false +test pg_catalog float4[] root ALL false +test pg_catalog float[] root ALL false +test pg_catalog geography root ALL false +test pg_catalog geography[] root ALL false +test pg_catalog geometry root ALL false +test pg_catalog geometry[] root ALL false +test pg_catalog inet root ALL false +test pg_catalog inet[] root ALL false +test pg_catalog int root ALL false +test pg_catalog int2 root ALL false +test pg_catalog int2[] root ALL false +test pg_catalog int2vector root ALL false +test pg_catalog int2vector[] root ALL false +test pg_catalog int4 root ALL false +test pg_catalog int4[] root ALL false +test pg_catalog int[] root ALL false +test pg_catalog interval root ALL false +test pg_catalog interval[] root ALL false +test pg_catalog jsonb root ALL false +test pg_catalog jsonb[] root ALL false +test pg_catalog name root ALL false +test pg_catalog name[] root ALL false +test pg_catalog oid root ALL false +test pg_catalog oid[] root ALL false +test pg_catalog oidvector root ALL false +test pg_catalog oidvector[] root ALL false +test pg_catalog record root ALL false +test pg_catalog record[] root ALL false +test pg_catalog regclass root ALL false +test pg_catalog regclass[] root ALL false +test pg_catalog regnamespace root ALL false +test pg_catalog regnamespace[] root ALL false +test pg_catalog regproc root ALL false +test pg_catalog regproc[] root ALL false +test pg_catalog regprocedure root ALL false +test pg_catalog regprocedure[] root ALL false +test pg_catalog regrole root ALL false +test pg_catalog regrole[] root ALL false +test pg_catalog regtype root ALL false +test pg_catalog regtype[] root ALL false +test pg_catalog string root ALL false +test pg_catalog string[] root ALL false +test pg_catalog time root ALL false +test pg_catalog time[] root ALL false +test pg_catalog timestamp root ALL false +test pg_catalog timestamp[] root ALL false +test pg_catalog timestamptz root ALL false +test pg_catalog timestamptz[] root ALL false +test pg_catalog timetz root ALL false +test pg_catalog timetz[] root ALL false +test pg_catalog tsquery root ALL false +test pg_catalog tsquery[] root ALL false +test pg_catalog tsvector root ALL false +test pg_catalog tsvector[] root ALL false +test pg_catalog unknown root ALL false +test pg_catalog uuid root ALL false +test pg_catalog uuid[] root ALL false +test pg_catalog varbit root ALL false +test pg_catalog varbit[] root ALL false +test pg_catalog varchar root ALL false +test pg_catalog varchar[] root ALL false +test pg_catalog void root ALL false +test public NULL root ALL true + +statement error pgcode 42P01 Expected end of statement, found ON +SHOW GRANTS ON a.t + +statement error pgcode 42P01 Expected end of statement, found ON +SHOW GRANTS ON t + +statement ok +SET DATABASE = a + +statement error pgcode 42P01 Expected end of statement, found ON +SHOW GRANTS ON t + +statement error pgcode 42P01 unknown schema 'a' +GRANT ALL ON a.t TO readwrite + +statement ok +CREATE TABLE t (id INT PRIMARY KEY) + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON t +---- +database_name schema_name table_name grantee privilege_type is_grantable +a public t admin ALL true +a public t root ALL true + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON a.t +---- +database_name schema_name table_name grantee privilege_type is_grantable +a public t admin ALL true +a public t root ALL true + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO system.users VALUES('test-user','',false,200); + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON t TO readwrite, "test-user" + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON t +---- +a public t admin ALL true +a public t readwrite ALL false +a public t root ALL true +a public t test-user ALL false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON t FOR readwrite, "test-user" +---- +a public t readwrite ALL false +a public t test-user ALL false + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE INSERT,DELETE ON t FROM "test-user",readwrite + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON t +---- +a public t admin ALL true +a public t readwrite BACKUP false +a public t readwrite CHANGEFEED false +a public t readwrite CREATE false +a public t readwrite DROP false +a public t readwrite SELECT false +a public t readwrite UPDATE false +a public t readwrite ZONECONFIG false +a public t root ALL true +a public t test-user BACKUP false +a public t test-user CHANGEFEED false +a public t test-user CREATE false +a public t test-user DROP false +a public t test-user SELECT false +a public t test-user UPDATE false +a public t test-user ZONECONFIG false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON t FOR readwrite, "test-user" +---- +a public t readwrite BACKUP false +a public t readwrite CHANGEFEED false +a public t readwrite CREATE false +a public t readwrite DROP false +a public t readwrite SELECT false +a public t readwrite UPDATE false +a public t readwrite ZONECONFIG false +a public t test-user BACKUP false +a public t test-user CHANGEFEED false +a public t test-user CREATE false +a public t test-user DROP false +a public t test-user SELECT false +a public t test-user UPDATE false +a public t test-user ZONECONFIG false + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE SELECT ON t FROM "test-user" + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON t +---- +a public t admin ALL true +a public t readwrite BACKUP false +a public t readwrite CHANGEFEED false +a public t readwrite CREATE false +a public t readwrite DROP false +a public t readwrite SELECT false +a public t readwrite UPDATE false +a public t readwrite ZONECONFIG false +a public t root ALL true +a public t test-user BACKUP false +a public t test-user CHANGEFEED false +a public t test-user CREATE false +a public t test-user DROP false +a public t test-user UPDATE false +a public t test-user ZONECONFIG false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON t FOR readwrite, "test-user" +---- +a public t readwrite BACKUP false +a public t readwrite CHANGEFEED false +a public t readwrite CREATE false +a public t readwrite DROP false +a public t readwrite SELECT false +a public t readwrite UPDATE false +a public t readwrite ZONECONFIG false +a public t test-user BACKUP false +a public t test-user CHANGEFEED false +a public t test-user CREATE false +a public t test-user DROP false +a public t test-user UPDATE false +a public t test-user ZONECONFIG false + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE ALL ON t FROM readwrite,"test-user" + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON t +---- +a public t admin ALL true +a public t root ALL true + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON t FOR readwrite, "test-user" +---- + +# The same as above, but on a view + +statement ok +CREATE VIEW v as SELECT id FROM t + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON v +---- +database_name schema_name table_name grantee privilege_type is_grantable +a public v admin ALL true +a public v root ALL true + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON a.v +---- +database_name schema_name table_name grantee privilege_type is_grantable +a public v admin ALL true +a public v root ALL true + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON v TO readwrite, "test-user" + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON v +---- +a public v admin ALL true +a public v readwrite ALL false +a public v root ALL true +a public v test-user ALL false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON v FOR readwrite, "test-user" +---- +a public v readwrite ALL false +a public v test-user ALL false + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE INSERT,DELETE ON v FROM "test-user",readwrite + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON v +---- +a public v admin ALL true +a public v readwrite BACKUP false +a public v readwrite CHANGEFEED false +a public v readwrite CREATE false +a public v readwrite DROP false +a public v readwrite SELECT false +a public v readwrite UPDATE false +a public v readwrite ZONECONFIG false +a public v root ALL true +a public v test-user BACKUP false +a public v test-user CHANGEFEED false +a public v test-user CREATE false +a public v test-user DROP false +a public v test-user SELECT false +a public v test-user UPDATE false +a public v test-user ZONECONFIG false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON v FOR readwrite, "test-user" +---- +a public v readwrite BACKUP false +a public v readwrite CHANGEFEED false +a public v readwrite CREATE false +a public v readwrite DROP false +a public v readwrite SELECT false +a public v readwrite UPDATE false +a public v readwrite ZONECONFIG false +a public v test-user BACKUP false +a public v test-user CHANGEFEED false +a public v test-user CREATE false +a public v test-user DROP false +a public v test-user SELECT false +a public v test-user UPDATE false +a public v test-user ZONECONFIG false + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE SELECT ON v FROM "test-user" + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON v +---- +a public v admin ALL true +a public v readwrite BACKUP false +a public v readwrite CHANGEFEED false +a public v readwrite CREATE false +a public v readwrite DROP false +a public v readwrite SELECT false +a public v readwrite UPDATE false +a public v readwrite ZONECONFIG false +a public v root ALL true +a public v test-user BACKUP false +a public v test-user CHANGEFEED false +a public v test-user CREATE false +a public v test-user DROP false +a public v test-user UPDATE false +a public v test-user ZONECONFIG false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON v FOR readwrite, "test-user" +---- +a public v readwrite BACKUP false +a public v readwrite CHANGEFEED false +a public v readwrite CREATE false +a public v readwrite DROP false +a public v readwrite SELECT false +a public v readwrite UPDATE false +a public v readwrite ZONECONFIG false +a public v test-user BACKUP false +a public v test-user CHANGEFEED false +a public v test-user CREATE false +a public v test-user DROP false +a public v test-user UPDATE false +a public v test-user ZONECONFIG false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS FOR readwrite, "test-user" +---- +a NULL NULL readwrite ALL false +a public v readwrite BACKUP false +a public v readwrite CHANGEFEED false +a public v readwrite CREATE false +a public v readwrite DROP false +a public v readwrite SELECT false +a public v readwrite UPDATE false +a public v readwrite ZONECONFIG false +a public v test-user BACKUP false +a public v test-user CHANGEFEED false +a public v test-user CREATE false +a public v test-user DROP false +a public v test-user UPDATE false +a public v test-user ZONECONFIG false + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE ALL ON v FROM readwrite,"test-user" + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON v +---- +a public v admin ALL true +a public v root ALL true + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON v FOR readwrite, "test-user" +---- + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS FOR readwrite, "test-user" +---- +a NULL NULL readwrite ALL false + +# Not supported by Materialize. +onlyif cockroach +# Verify that the DB privileges have not changed. +query TTTB colnames +SHOW GRANTS ON DATABASE a +---- +database_name grantee privilege_type is_grantable +a admin ALL true +a public CONNECT false +a readwrite ALL false +a root ALL true + + +# Not supported by Materialize. +onlyif cockroach +# Errors due to invalid targets. +statement ok +SET DATABASE = "" + +statement error Expected TO, found operator "@" +GRANT ALL ON a.t@xyz TO readwrite + +statement error Expected identifier, found star +GRANT ALL ON * TO readwrite + +statement error pgcode 42P01 unknown schema 'a' +GRANT ALL ON a.t, a.tt TO readwrite + +# '*' doesn't work for databases. +statement error Expected identifier, found star +GRANT ALL ON DATABASE * TO readwrite + +statement ok +CREATE DATABASE b + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE b.t (id INT PRIMARY KEY) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE b.t2 (id INT PRIMARY KEY) + +statement ok +CREATE DATABASE c + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE c.t (id INT PRIMARY KEY) + +# `*` works after you've set a database +statement ok +SET DATABASE = "b" + +statement error pgcode 42704 Expected identifier, found star +GRANT ALL ON * TO Vanilli + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER Vanilli + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON * TO Vanilli + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON * +---- +database_name schema_name table_name grantee privilege_type is_grantable +b public t admin ALL true +b public t root ALL true +b public t vanilli ALL false +b public t2 admin ALL true +b public t2 root ALL true +b public t2 vanilli ALL false + + +# Not supported by Materialize. +onlyif cockroach +# Multiple targets. +statement ok +CREATE USER Millie + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON c.*, b.t TO Millie + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON b.* +---- +database_name schema_name table_name grantee privilege_type is_grantable +b public t admin ALL true +b public t millie ALL false +b public t root ALL true +b public t vanilli ALL false +b public t2 admin ALL true +b public t2 root ALL true +b public t2 vanilli ALL false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON a.*, b.* +---- +database_name schema_name table_name grantee privilege_type is_grantable +a public t admin ALL true +a public t root ALL true +a public v admin ALL true +a public v root ALL true +b public t admin ALL true +b public t millie ALL false +b public t root ALL true +b public t vanilli ALL false +b public t2 admin ALL true +b public t2 root ALL true +b public t2 vanilli ALL false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON c.t +---- +database_name schema_name table_name grantee privilege_type is_grantable +c public t admin ALL true +c public t millie ALL false +c public t root ALL true + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE ALL ON *, c.* FROM Vanilli + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON b.* +---- +database_name schema_name table_name grantee privilege_type is_grantable +b public t admin ALL true +b public t millie ALL false +b public t root ALL true +b public t2 admin ALL true +b public t2 root ALL true + +statement ok +CREATE DATABASE empty + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON empty.* +---- +database_name schema_name table_name grantee privilege_type is_grantable + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON empty.*, b.* +---- +database_name schema_name table_name grantee privilege_type is_grantable +b public t admin ALL true +b public t millie ALL false +b public t root ALL true +b public t2 admin ALL true +b public t2 root ALL true + +# Usage privilege should not be grantable on tables. + +statement error unknown catalog item 't' +GRANT USAGE ON t TO testuser + +# Grant / Revoke should not work on system tables. + +statement error Expected TO, found dot +GRANT SELECT ON system.lease TO testuser + +statement error Expected FROM, found dot +REVOKE SELECT ON system.lease FROM testuser + +# Postgres does a no-op here, but since the RULE privilege is very legacy, +# we error explicitly instead of getting 100% compatibility. +statement error Expected TO, found ON +GRANT RULE ON t TO testuser + +# This glob expands to no tables, that should be fine and should return the +# correct errors. +statement error pgcode 42704 Expected identifier, found star +GRANT SELECT ON TABLE empty.* TO testuser; + +statement ok +create schema empty.sc + +statement error pgcode 42704 Expected identifier, found star +GRANT SELECT ON TABLE empty.sc.* TO testuser; + +# Add a test to ensure that when you mix virtual and physical tables in a grant +# that you get the error we +subtest mixed_virtual_physical + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE DATABASE db; +USE db; +CREATE TABLE t (i INT); + +statement error pgcode 0A000 unknown catalog item 't' +GRANT SELECT ON TABLE t, crdb_internal.tables TO testuser; + +statement error pgcode 0A000 unknown schema 'crdb_internal' +GRANT SELECT ON TABLE crdb_internal.tables, t TO testuser; diff --git a/test/sqllogictest/cockroach/grant_type.slt b/test/sqllogictest/cockroach/grant_type.slt new file mode 100644 index 0000000000000..2b91fe25d939a --- /dev/null +++ b/test/sqllogictest/cockroach/grant_type.slt @@ -0,0 +1,188 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/grant_type +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: local + +statement ok +CREATE SCHEMA schema_a + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER user1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE public.enum_a AS ENUM ('hello', 'goodbye'); +GRANT USAGE ON TYPE public.enum_a TO user1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE public."enum_a+b" AS ENUM ('hello', 'goodbye'); +GRANT USAGE ON TYPE public."enum_a+b" TO user1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE schema_a.enum_b AS ENUM ('hi', 'bye'); +GRANT ALL ON TYPE schema_a.enum_b TO user1 + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON TYPE schema_a.enum_b, "enum_a+b", enum_a, int4 +---- +database_name schema_name type_name grantee privilege_type is_grantable +test pg_catalog int4 admin ALL false +test pg_catalog int4 public USAGE false +test pg_catalog int4 root ALL false +test public enum_a admin ALL true +test public enum_a public USAGE false +test public enum_a root ALL true +test public enum_a user1 USAGE false +test public enum_a+b admin ALL true +test public enum_a+b public USAGE false +test public enum_a+b root ALL true +test public enum_a+b user1 USAGE false +test schema_a enum_b admin ALL true +test schema_a enum_b public USAGE false +test schema_a enum_b root ALL true +test schema_a enum_b user1 ALL false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON TYPE schema_a.enum_b, enum_a, int4 FOR user1 +---- +database_name schema_name type_name grantee privilege_type is_grantable +test public enum_a user1 USAGE false +test schema_a enum_b user1 ALL false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS FOR user1 +---- +database_name schema_name relation_name grantee privilege_type is_grantable +test public enum_a user1 USAGE false +test public enum_a+b user1 USAGE false +test schema_a enum_b user1 ALL false + +statement error Expected end of statement, found ON +SHOW GRANTS ON TYPE non_existent + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #67512: should be able to see grants for a type in a +# different database. +statement ok +CREATE DATABASE other; +CREATE TYPE other.typ AS ENUM(); +GRANT ALL ON TYPE other.typ TO user1 + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON TYPE other.typ +---- +other public typ admin ALL true +other public typ public USAGE false +other public typ root ALL true +other public typ user1 ALL false + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB +SHOW GRANTS ON TYPE other.typ FOR user1 +---- +other public typ user1 ALL false + +# Verify that owner and child of owner have is_grantable implicitly. + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER owner_grant_option_child + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT testuser to owner_grant_option_child + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON DATABASE test TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE owner_grant_option AS ENUM('a') + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT USAGE ON TYPE owner_grant_option TO owner_grant_option_child + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON TYPE owner_grant_option +---- +database_name schema_name type_name grantee privilege_type is_grantable +test public owner_grant_option admin ALL true +test public owner_grant_option owner_grant_option_child USAGE true +test public owner_grant_option public USAGE false +test public owner_grant_option root ALL true +test public owner_grant_option testuser ALL true + +# Verify that is_grantable moves to the new owner. + +user root + +statement ok +CREATE ROLE other_owner + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TYPE owner_grant_option OWNER TO other_owner + +# Not supported by Materialize. +onlyif cockroach +query TTTTTB colnames +SHOW GRANTS ON TYPE owner_grant_option +---- +database_name schema_name type_name grantee privilege_type is_grantable +test public owner_grant_option admin ALL true +test public owner_grant_option other_owner ALL true +test public owner_grant_option owner_grant_option_child USAGE false +test public owner_grant_option public USAGE false +test public owner_grant_option root ALL true diff --git a/test/sqllogictest/cockroach/group_join.slt b/test/sqllogictest/cockroach/group_join.slt new file mode 100644 index 0000000000000..3ef6876914e12 --- /dev/null +++ b/test/sqllogictest/cockroach/group_join.slt @@ -0,0 +1,59 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/group_join +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE data (a INT, b INT, c INT, d INT, PRIMARY KEY (a, b, c, d)) + +# Generate all combinations of values 1 to 3. +statement ok +INSERT INTO data SELECT a, b, c, d FROM + generate_series(1, 3) AS a(a), + generate_series(1, 3) AS b(b), + generate_series(1, 3) AS c(c), + generate_series(1, 3) AS d(d) + +statement ok +SET experimental_hash_group_join_enabled = true + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT data1.a, sum_int(data1.d) FROM data AS data1 INNER HASH JOIN data AS data2 ON data1.a = data2.c GROUP BY data1.a +---- +1 1458 +2 1458 +3 1458 + +statement ok +RESET experimental_hash_group_join_enabled + +# Not supported by Materialize. +onlyif cockroach +# Same query as above, but with the hash group-join disabled. +query II rowsort +SELECT data1.a, sum_int(data1.d) FROM data AS data1 INNER HASH JOIN data AS data2 ON data1.a = data2.c GROUP BY data1.a +---- +1 1458 +2 1458 +3 1458 diff --git a/test/sqllogictest/cockroach/hash_join.slt b/test/sqllogictest/cockroach/hash_join.slt new file mode 100644 index 0000000000000..f93c2b5c1889c --- /dev/null +++ b/test/sqllogictest/cockroach/hash_join.slt @@ -0,0 +1,257 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/hash_join +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE t1 (k INT PRIMARY KEY, v INT) + +statement ok +INSERT INTO t1 VALUES (0, 4), (2, 1), (5, 4), (3, 4), (-1, -1) + +statement ok +CREATE TABLE t2 (x INT PRIMARY KEY, y INT) + +statement ok +INSERT INTO t2 VALUES (1, 3), (4, 6), (0, 5), (3, 2) + +statement ok +CREATE TABLE a (k INT, v INT) + +statement ok +INSERT INTO a VALUES (0, 1), (1, 2), (2, 0) + +statement ok +CREATE TABLE b (a INT, b INT, c STRING) + +statement ok +INSERT INTO b VALUES (0, 1, 'a'), (2, 1, 'b'), (0, 2, 'c'), (0, 1, 'd') + +statement ok +CREATE TABLE c (a INT, b STRING) + +statement ok +INSERT INTO c VALUES (1, 'a'), (1, 'b'), (2, 'c') + +# Not supported by Materialize. +onlyif cockroach +query IIII +SELECT * FROM t1 INNER HASH JOIN t2 ON t1.k = t2.x ORDER BY 1 +---- +0 4 0 5 +3 4 3 2 + +query IIII +SELECT * FROM a AS a1 JOIN a AS a2 ON a1.k = a2.v ORDER BY 1 +---- +0 1 2 0 +1 2 0 1 +2 0 1 2 + +query IIII +SELECT * FROM a AS a2 JOIN a AS a1 ON a1.k = a2.v ORDER BY 1 +---- +0 1 1 2 +1 2 2 0 +2 0 0 1 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT t2.y, t1.v FROM t1 INNER HASH JOIN t2 ON t1.k = t2.x ORDER BY 1 DESC +---- +5 4 +2 4 + +query IIII +SELECT * FROM t1 JOIN t2 ON t1.v = t2.x ORDER BY 1 +---- +0 4 4 6 +2 1 1 3 +3 4 4 6 +5 4 4 6 + +query IIII +SELECT * FROM t1 LEFT JOIN t2 ON t1.v = t2.x ORDER BY 1 +---- +-1 -1 NULL NULL +0 4 4 6 +2 1 1 3 +3 4 4 6 +5 4 4 6 + +query IIII rowsort +SELECT * FROM t1 RIGHT JOIN t2 ON t1.v = t2.x +---- +0 4 4 6 +2 1 1 3 +3 4 4 6 +5 4 4 6 +NULL NULL 0 5 +NULL NULL 3 2 + +query IIII rowsort +SELECT * FROM t1 FULL JOIN t2 ON t1.v = t2.x +---- +-1 -1 NULL NULL +0 4 4 6 +2 1 1 3 +3 4 4 6 +5 4 4 6 +NULL NULL 3 2 +NULL NULL 0 5 + +query IIT +SELECT b.a, b.b, b.c FROM b JOIN a ON b.a = a.k AND a.v = b.b ORDER BY 3 +---- +0 1 a +0 1 d + +query ITI +SELECT b.a, b.c, c.a FROM b JOIN c ON b.b = c.a AND b.c = c.b ORDER BY 2 +---- +0 a 1 +2 b 1 +0 c 2 + +# Test hash join with an empty build table. +statement ok +CREATE TABLE empty (x INT) + +statement ok +CREATE TABLE onecolumn (x INT); INSERT INTO onecolumn(x) VALUES (44), (NULL), (42) + +query II colnames +SELECT * FROM empty AS a(x) FULL OUTER JOIN onecolumn AS b(y) ON a.x = b.y ORDER BY b.y +---- +x y +NULL 42 +NULL 44 +NULL NULL + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #41407. +statement ok +CREATE TABLE t41407 AS + SELECT + g AS _float8, + g % 0 = 0 AS _bool, + g AS _decimal, + g AS _string, + g AS _bytes + FROM + generate_series(NULL, NULL) AS g; + +# Not supported by Materialize. +onlyif cockroach +query TRTTRRBR +SELECT + tab_1688._bytes, + tab_1688._float8, + tab_1689._string, + tab_1689._string, + tab_1688._float8, + tab_1688._float8, + tab_1689._bool, + tab_1690._decimal +FROM + t41407 AS tab_1688 + JOIN t41407 AS tab_1689 + JOIN t41407 AS tab_1690 ON + tab_1689._bool = tab_1690._bool ON + tab_1688._float8 = tab_1690._float8 + AND tab_1688._bool = tab_1689._bool; +---- + +# Regression test for empty equality columns with one of the tables having only +# UNIQUE columns. +statement ok +CREATE TABLE t44207_0(c0 INT UNIQUE); CREATE TABLE t44207_1(c0 INT) + +statement ok +INSERT INTO t44207_0(c0) VALUES (NULL), (NULL); INSERT INTO t44207_1(c0) VALUES (0) + +query II +SELECT * FROM t44207_0, t44207_1 WHERE t44207_0.c0 IS NULL +---- +NULL 0 +NULL 0 + +# Regression test for the inputs that have comparable but different types (see +# issues #44547 and #44797). +statement ok +CREATE TABLE t44547_0(c0 INT4); CREATE TABLE t44547_1(c0 INT8) + +statement ok +INSERT INTO t44547_0(c0) VALUES(0); INSERT INTO t44547_1(c0) VALUES(0) + +# Note that integers of different width are still considered equal. +query I +SELECT * FROM t44547_0 NATURAL JOIN t44547_1 +---- +0 + +statement ok +CREATE TABLE t44797_0(a FLOAT, b DECIMAL); CREATE TABLE t44797_1(c INT2, d INT4) + +statement ok +INSERT INTO t44797_0 VALUES (1.0, 1.0), (2.0, 2.0); INSERT INTO t44797_1 VALUES (1, 1), (2, 2) + +# Note that mixed-type comparisons - of what appears to be "same" values - do +# not consider those values equal. +query RRII rowsort +SELECT * FROM t44797_0 NATURAL JOIN t44797_1 +---- +1 1 1 1 +1 1 2 2 +2 2 1 1 +2 2 2 2 + +statement ok +CREATE TABLE t44797_2(a FLOAT); CREATE TABLE t44797_3(b DECIMAL) + +statement ok +INSERT INTO t44797_2 VALUES (1.0), (2.0); INSERT INTO t44797_3 VALUES (1.0), (2.0) + +query RR rowsort +SELECT * FROM t44797_2 NATURAL JOIN t44797_3 +---- +1 1 +1 2 +2 1 +2 2 + +# Check that non-inner join with mixed-type equality considers the "same" +# values of different types as equal. +query R rowsort +SELECT * FROM t44797_2 WHERE EXISTS (SELECT * FROM t44797_2 AS l, t44797_3 AS r WHERE l.a = r.b) +---- +1 +2 + +# Regression test for incorrectly propagating an error in the vectorized engine. +statement ok +CREATE TABLE table57696(col_table TIME NOT NULL) + +statement error Expected a data type name, found colon +WITH cte (col_cte) AS ( SELECT * FROM ( VALUES ( ( 'false':::JSONB, '1970-01-05 16:57:40.000665+00:00':::TIMESTAMPTZ ) ) ) EXCEPT ALL SELECT * FROM ( VALUES ( ( ' [ [[true], [], {}, "b", {}], {"a": []}, {"c": 2.05750813403415} ] ':::JSONB, '1970-01-10 05:23:26.000428+00:00':::TIMESTAMPTZ ) ) ) ) SELECT * FROM cte, table57696 diff --git a/test/sqllogictest/cockroach/hidden_columns.slt b/test/sqllogictest/cockroach/hidden_columns.slt new file mode 100644 index 0000000000000..7272dd4b0ea8c --- /dev/null +++ b/test/sqllogictest/cockroach/hidden_columns.slt @@ -0,0 +1,194 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/hidden_columns +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t (x INT NOT VISIBLE); +CREATE TABLE kv ( + k INT PRIMARY KEY NOT VISIBLE, + v INT NOT VISIBLE + ) + +# Verify that hidden columns can be explicitly inserted into. + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t(x) VALUES (123) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO kv(k,v) VALUES (123,456); + +# Verify that hidden columns cannot be implicitly inserted into + +statement error unknown catalog item 't' +INSERT INTO t VALUES (123) + +statement error unknown catalog item 'kv' +INSERT INTO kv VALUES (111, 222) + +# Verify the right columns are hidden. + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE t +---- +t CREATE TABLE public.t ( + x INT8 NOT VISIBLE NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) + ) + +# Check that stars expand to no columns. + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 42, * FROM t +---- +42 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 42, * FROM kv +---- +42 + +# Check that the hidden column can be selected explicitly. + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT 42, x FROM t +---- +42 123 + +# Check that the hidden column can be renamed + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE kv RENAME COLUMN v to x; + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT x FROM t +---- +123 + +# Verify indexes can be created on hidden columns + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX ON kv(x); + +# Check that the hidden column can be droped + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE kv DROP COLUMN x; + +statement error unknown catalog item 'kv' +SELECT x FROM kv; + +# adding a foreign key constraint on a hidden column + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t1(a INT, b INT, c INT NOT VISIBLE , PRIMARY KEY(b)); +CREATE TABLE t2(b INT NOT VISIBLE, c INT, d INT, PRIMARY KEY (d)); +CREATE TABLE t5(b INT NOT VISIBLE, c INT, d INT, PRIMARY KEY (d), FOREIGN KEY(b) REFERENCES t1(b)); + +# Not supported by Materialize. +onlyif cockroach +query TTTTB +SHOW CONSTRAINTS FROM t2 +---- +t2 t2_pkey PRIMARY KEY PRIMARY KEY (d ASC) true + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t2 ADD FOREIGN KEY (b) REFERENCES t2 + +# Not supported by Materialize. +onlyif cockroach +query TTTTB +SHOW CONSTRAINTS FROM t2 +---- +t2 t2_b_fkey FOREIGN KEY FOREIGN KEY (b) REFERENCES t2(d) true +t2 t2_pkey PRIMARY KEY PRIMARY KEY (d ASC) true + +# adding a foreign key constraint that references a hidden column + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t3(a INT, b INT NOT NULL, c INT NOT VISIBLE, PRIMARY KEY(c)); +CREATE TABLE t4(c INT, d INT, e INT NOT NULL NOT VISIBLE, PRIMARY KEY(d)); +CREATE TABLE t6(c INT, d INT, e INT NOT NULL NOT VISIBLE, PRIMARY KEY(d), FOREIGN KEY(c) REFERENCES t3(c)); + +# ALTER PRIMARY KEY on a primary key with hidden columns + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t3 ALTER PRIMARY KEY USING COLUMNS(b); + +# Not supported by Materialize. +onlyif cockroach +query TTTTB +SHOW CONSTRAINTS FROM t3 +---- +t3 t3_c_key UNIQUE UNIQUE (c ASC) true +t3 t3_pkey PRIMARY KEY PRIMARY KEY (b ASC) true + +# Not supported by Materialize. +onlyif cockroach +query TTTTB +SHOW CONSTRAINTS FROM t4 +---- +t4 t4_pkey PRIMARY KEY PRIMARY KEY (d ASC) true + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t4 ALTER PRIMARY KEY USING COLUMNS(e); + +# Not supported by Materialize. +onlyif cockroach +query TTTTB +SHOW CONSTRAINTS FROM t4 +---- +t4 t4_d_key UNIQUE UNIQUE (d ASC) true +t4 t4_pkey PRIMARY KEY PRIMARY KEY (e ASC) true diff --git a/test/sqllogictest/cockroach/impure.slt b/test/sqllogictest/cockroach/impure.slt new file mode 100644 index 0000000000000..7318fee8be9d2 --- /dev/null +++ b/test/sqllogictest/cockroach/impure.slt @@ -0,0 +1,133 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/impure +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# This file contains tests for handling of duplicate impure projections. See +# #44865. + +# Not supported by Materialize. +onlyif cockroach +query I +WITH cte (a, b) AS (SELECT random(), random()) +SELECT count(*) FROM cte WHERE a = b +---- +0 + +# Not supported by Materialize. +onlyif cockroach +query I +WITH cte (x, a, b) AS (SELECT x, random(), random() FROM (VALUES (1), (2), (3)) AS v(x)) +SELECT count(*) FROM cte WHERE a = b +---- +0 + +statement ok +CREATE TABLE kab (k INT PRIMARY KEY, a UUID, b UUID) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO kab VALUES (1, gen_random_uuid(), gen_random_uuid()) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO kab VALUES (2, gen_random_uuid(), gen_random_uuid()) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO kab VALUES (3, gen_random_uuid(), gen_random_uuid()), + (4, gen_random_uuid(), gen_random_uuid()), + (5, gen_random_uuid(), gen_random_uuid()), + (6, gen_random_uuid(), gen_random_uuid()) + +query I +SELECT count(*) FROM kab WHERE a=b +---- +0 + +statement ok +CREATE TABLE kabc (k INT PRIMARY KEY, a UUID, b UUID) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO kabc VALUES (1, uuid_generate_v4(), uuid_generate_v4()) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO kabc VALUES (2, uuid_generate_v4(), uuid_generate_v4()) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO kabc VALUES (3, uuid_generate_v4(), uuid_generate_v4()), + (4, uuid_generate_v4(), uuid_generate_v4()), + (5, uuid_generate_v4(), uuid_generate_v4()), + (6, uuid_generate_v4(), uuid_generate_v4()) + +query I +SELECT count(*) FROM kabc WHERE a=b +---- +0 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE kabcd ( + k INT PRIMARY KEY, + a UUID, + b UUID, + c UUID DEFAULT gen_random_uuid(), + d UUID DEFAULT gen_random_uuid(), + e UUID DEFAULT uuid_generate_v4(), + f UUID DEFAULT uuid_generate_v4() +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO kabcd VALUES (1, gen_random_uuid(), uuid_generate_v4()) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO kabcd VALUES (2, gen_random_uuid(), uuid_generate_v4()) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO kabcd VALUES (3, gen_random_uuid(), uuid_generate_v4()), + (4, gen_random_uuid(), uuid_generate_v4()), + (5, gen_random_uuid(), uuid_generate_v4()), + (6, gen_random_uuid(), uuid_generate_v4()) + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT count(*) FROM kabcd WHERE a=b OR a=c OR a=d OR a=e OR a=f +OR b=c OR b=d OR b=e OR b=f OR c=d OR c=e OR c=f OR d=e OR d=f OR e=f +---- +0 diff --git a/test/sqllogictest/cockroach/inet.slt b/test/sqllogictest/cockroach/inet.slt index fb2fcaa1e4b50..84658ce5fe6fd 100644 --- a/test/sqllogictest/cockroach/inet.slt +++ b/test/sqllogictest/cockroach/inet.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,46 +9,58 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/inet +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/inet # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach # Basic IPv4 tests +# Not supported by Materialize. +onlyif cockroach query T SELECT '192.168.1.2/24':::INET; ---- 192.168.1.2/24 +# Not supported by Materialize. +onlyif cockroach query T SELECT '192.168.1.2/32':::INET; ---- 192.168.1.2 +# Not supported by Materialize. +onlyif cockroach query T SELECT '192.168.1.2':::INET; ---- 192.168.1.2 +# Not supported by Materialize. +onlyif cockroach query T SELECT '192.168.1.2/24':::INET; ---- 192.168.1.2/24 +# Not supported by Materialize. +onlyif cockroach query T SELECT '0.0.0.0':::INET; ---- 0.0.0.0 +# Not supported by Materialize. +onlyif cockroach query T SELECT '::/0'::inet::text::inet; ---- @@ -56,26 +68,36 @@ SELECT '::/0'::inet::text::inet; # Basic IPv6 tests +# Not supported by Materialize. +onlyif cockroach query T SELECT '::ffff:192.168.1.2':::INET; ---- ::ffff:192.168.1.2 +# Not supported by Materialize. +onlyif cockroach query T SELECT '::ffff:192.168.1.2/120':::INET; ---- ::ffff:192.168.1.2/120 +# Not supported by Materialize. +onlyif cockroach query T SELECT '::ffff':::INET; ---- ::ffff +# Not supported by Materialize. +onlyif cockroach query T SELECT '2001:4f8:3:ba:2e0:81ff:fe22:d1f1/120':::INET; ---- 2001:4f8:3:ba:2e0:81ff:fe22:d1f1/120 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2001:4f8:3:ba:2e0:81ff:fe22:d1f1':::INET; ---- @@ -83,12 +105,16 @@ SELECT '2001:4f8:3:ba:2e0:81ff:fe22:d1f1':::INET; # Test casting +# Not supported by Materialize. +onlyif cockroach query T SELECT '192.168.1.2/24'::INET; ---- 192.168.1.2/24 +# Not supported by Materialize. +onlyif cockroach query T SELECT '192.168.1.200/10':::INET ---- @@ -96,16 +122,22 @@ SELECT '192.168.1.200/10':::INET # Test for less than 4 octets with mask +# Not supported by Materialize. +onlyif cockroach query T SELECT '192.168.1/10':::INET ---- 192.168.1.0/10 +# Not supported by Materialize. +onlyif cockroach query T SELECT '192.168/10':::INET ---- 192.168.0.0/10 +# Not supported by Materialize. +onlyif cockroach query T SELECT '192/10':::INET ---- @@ -113,6 +145,8 @@ SELECT '192/10':::INET # Test for preservation of masked bits +# Not supported by Materialize. +onlyif cockroach query T SELECT '255/10':::INET ---- @@ -120,23 +154,25 @@ SELECT '255/10':::INET # Test that less than 4 octets requires a mask -statement error could not parse +statement error Expected a data type name, found colon SELECT '192':::INET -statement error could not parse +statement error Expected a data type name, found colon SELECT '19.0':::INET # Test that the mask can't be larger than the provided octet bits -statement error could not parse +statement error Expected a data type name, found colon SELECT '19.0/32':::INET -statement error could not parse +statement error Expected a data type name, found colon SELECT '19/32':::INET -statement error could not parse +statement error Expected a data type name, found colon SELECT '19/16':::INET +# Not supported by Materialize. +onlyif cockroach query T SELECT '19/15':::INET ---- @@ -144,15 +180,17 @@ SELECT '19/15':::INET # Misc tests -statement error could not parse +statement error Expected a data type name, found colon SELECT '192.168/24/1':::INET -statement error could not parse +statement error Expected a data type name, found colon SELECT '':::INET -statement error could not parse +statement error Expected a data type name, found colon SELECT '0':::INET +# Not supported by Materialize. +onlyif cockroach query T SELECT '0.0.0.0':::INET ---- @@ -160,21 +198,29 @@ SELECT '0.0.0.0':::INET # Testing equivilance +# Not supported by Materialize. +onlyif cockroach query B SELECT '::ffff:192.168.0.1/24'::INET = '::ffff:192.168.0.1/24'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '::ffff:192.168.0.1/24'::INET = '::ffff:192.168.0.1/25'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '::ffff:192.168.0.1/24'::INET = '::ffff:192.168.0.1'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '::ffff:192.168.0.1'::INET = '::ffff:192.168.0.1'::INET ---- @@ -182,26 +228,36 @@ true # Ensure IPv4-mapped IPv6 is not equal to its mapped IPv4 +# Not supported by Materialize. +onlyif cockroach query B SELECT '::ffff:192.168.0.1'::INET = '192.168.0.1'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.0.1'::INET = '192.168.0.1'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.0.1/0'::INET = '192.168.0.1'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.0.1/0'::INET = '192.168.0.1/0'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.0.1/0'::INET = '192.168.0.1/0'::INET ---- @@ -209,26 +265,36 @@ true # Testing basic comparisons +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.0.2/24'::INET < '192.168.0.1/25'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '1.2.3.4':::INET < '1.2.3.5':::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.0.1/0'::INET > '192.168.0.1/0'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.0.0'::INET > '192.168.0.1/0'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '::ffff:1.2.3.4':::INET > '1.2.3.4':::INET ---- @@ -236,156 +302,218 @@ true # Testing contains/contained by logic +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.200.95/17'::INET >> '192.168.162.1'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.200.95/8'::INET >> '192.168.2.1/8'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0000:0000:0500:5000:0000:0001/50'::INET >> '2001:0db8:0000:0000:0500:5000:0000:0001/50'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET >> '2001:0db8:0000:0000:0000:0000:0000:0001/100'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.200.95/8'::INET >>= '192.168.2.1/8'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.200.95/17'::INET >>= '192.168.2.1/24'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.200.95/8'::INET >>= '192.168.2.1/8'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET >>= '2001:0db8:0000:0000:0000:0000:0000:0001/100'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0000:0000:0500:5000:0000:0001/50'::INET >>= '2001:0db8:0000:0000:0500:5000:0000:0001/50'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.200.95'::INET << '192.168.2.1/8'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.200.95/8'::INET << '192.168.2.1/8'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.200.95'::INET <<= '192.168.2.1/8'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.200.95/8'::INET <<= '192.168.2.1/8'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0000:0000:0500:5000:0000:0001/50'::INET << '2001:0db8:0000:0000:0000:0000:0000:0001/100'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0000:0000:0500:5000:0000:0001/50'::INET << '2001:0db8:0000:0000:0500:5000:0000:0001/50'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0000:0000:0500:5000:0000:0001/50'::INET <<= '2001:0db8:0000:0000:0000:0000:0000:0001/100'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0000:0000:0500:5000:0000:0001/50'::INET <<= '2001:0db8:0000:0000:0500:5000:0000:0001/50'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.200.95/16'::INET && '192.168.2.1/24'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.200.95/17'::INET && '192.168.2.1/24'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET && '2001:0db8:0000:0000:0000:0000:0000:0001/100'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0000:0000:0500:5000:0000:0001/50'::INET && '2001:0db8:0000:0000:0000:0000:0000:0001/100'::INET ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET >> '192.168.2.1/8'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET >>= '192.168.2.1/8'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET << '192.168.2.1/8'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET <<= '192.168.2.1/8'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET && '192.168.2.1/8'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.2.1/8'::INET >> '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.2.1/8'::INET >>= '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.2.1/8'::INET << '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.2.1/8'::INET <<= '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '192.168.2.1/8'::INET && '2001:0db8:0500:0000:0500:5000:0000:0001/50'::INET ---- @@ -393,157 +521,213 @@ false # Binary operations +# Not supported by Materialize. +onlyif cockroach query T SELECT ~'192.168.1.2/10':::INET ---- 63.87.254.253/10 +# Not supported by Materialize. +onlyif cockroach query T SELECT ~'192.168.1.2/0':::INET ---- 63.87.254.253/0 +# Not supported by Materialize. +onlyif cockroach query T SELECT ~'2001:4f8:3:ba::/64':::INET ---- dffe:fb07:fffc:ff45:ffff:ffff:ffff:ffff/64 +# Not supported by Materialize. +onlyif cockroach query T SELECT '255.255.255.250/2':::INET & '0.5.0.5/17':::INET ---- 0.5.0.0/17 +# Not supported by Materialize. +onlyif cockroach query T SELECT '0000:0564:0000:0aab:0000:0000:0060:0005/23':::INET & 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0005/123':::INET ---- 0:564:0:aab::60:5/123 +# Not supported by Materialize. +onlyif cockroach query T SELECT '192.168.1.2/1':::INET | '192.168.1.3/17':::INET ---- 192.168.1.3/17 +# Not supported by Materialize. +onlyif cockroach query T SELECT '6e32:8a01:373b:c9ce:8ed5:9f7f:dc7e:5cfc/99':::INET | 'c33e:9867:5c98:f0a2:2b2:abf9:c7a5:67d':::INET ---- ef3e:9a67:7fbb:f9ee:8ef7:bfff:dfff:5efd -statement error pq: cannot AND inet values of different sizes +statement error Expected a data type name, found colon SELECT '0000:0564:0000:0aab:0000:0000:0060:0005/23':::INET & '192.168.1.2/1':::INET -statement error pq: cannot OR inet values of different sizes +statement error Expected a data type name, found colon SELECT '0000:0564:0000:0aab:0000:0000:0060:0005/23':::INET | '192.168.1.2/1':::INET # Addition and Subtraction +# Not supported by Materialize. +onlyif cockroach query T SELECT '192.168.1.2':::INET + 184836468 ---- 203.172.98.118 +# Not supported by Materialize. +onlyif cockroach query T SELECT '0.0.0.5':::INET - 5 ---- 0.0.0.0 +# Not supported by Materialize. +onlyif cockroach query T SELECT '203.172.98.118/23':::INET - 184836468 ---- 192.168.1.2/23 +# Not supported by Materialize. +onlyif cockroach query T SELECT '0.0.0.5':::INET - -5 ---- 0.0.0.10 +# Not supported by Materialize. +onlyif cockroach query T SELECT '::4104:4066:5de7:b1fa':::INET - 4684658846864486648 ---- ::ffff:192.168.1.2 +# Not supported by Materialize. +onlyif cockroach query T SELECT '::4104:4066:5de7:b1fa/121':::INET + -4684658846864486648 ---- ::ffff:192.168.1.2/121 +# Not supported by Materialize. +onlyif cockroach query T SELECT '::4104:4066:5de7:b1fa/101':::INET + 2 ---- ::4104:4066:5de7:b1fc/101 +# Not supported by Materialize. +onlyif cockroach query T SELECT '::5/128':::INET - -2 ---- ::7 +# Not supported by Materialize. +onlyif cockroach query I SELECT '203.172.98.118/17':::INET - '192.168.1.2/1':::INET ---- 184836468 +# Not supported by Materialize. +onlyif cockroach query I SELECT '::4104:4066:5de7:b1fa/79':::INET - '::ffff:192.168.1.2/44':::INET ---- 4684658846864486648 -statement error pq: result out of range +statement error Expected a data type name, found colon SELECT '255.255.0.5':::INET + 2000000000 -statement error pq: result out of range +statement error Expected a data type name, found colon SELECT '0.0.0.5':::INET - 10 -statement error pq: result out of range +statement error Expected a data type name, found colon SELECT '::5/128':::INET - 10 -statement error pq: result out of range +statement error Expected a data type name, found colon SELECT 'ff00:5::/128':::INET - '::ff00:5/128':::INET # Edge case: postgres compatibility +# Not supported by Materialize. +onlyif cockroach query T SELECT '0.0.0.0.':::INET ---- 0.0.0.0 -statement error could not parse +statement error Expected a data type name, found colon SELECT '.0.0.0.0.':::INET -statement error could not parse +statement error Expected a data type name, found colon SELECT '0.0.0.0.0':::INET # Test storage round-trip +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE u (ip inet PRIMARY KEY, ip2 inet) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u VALUES ('192.168.0.1', '192.168.0.1') -statement error duplicate key value +statement error unknown catalog item 'u' INSERT INTO u VALUES ('192.168.0.1', '192.168.0.2') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u VALUES ('192.168.0.2', '192.168.0.2') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u VALUES ('192.168.0.5/24', '192.168.0.5') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u VALUES ('192.168.0.1/31', '192.168.0.1') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u VALUES ('192.168.0.0', '192.168.0.1') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u VALUES ('192.0.0.0', '127.0.0.1') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u (ip) VALUES ('::1') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u (ip) VALUES ('::ffff:1.2.3.4') +# Not supported by Materialize. +onlyif cockroach query TT SELECT * FROM u ORDER BY ip ---- @@ -556,15 +740,21 @@ SELECT * FROM u ORDER BY ip ::1 NULL ::ffff:1.2.3.4 NULL +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE arrays (ips INET[]) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO arrays VALUES (ARRAY[]), (ARRAY['192.168.0.1/10', '::1']), (ARRAY['192.168.0.1', '192.168.0.1/10', '::1', '::ffff:1.2.3.4']) +# Not supported by Materialize. +onlyif cockroach query T rowsort SELECT * FROM arrays ---- @@ -580,36 +770,50 @@ SELECT * FROM arrays # CIDR. The input string is not always equal to the output string, e.g. # abbrev('10.0/16'::inet) => '10.0.0.0/16' +# Not supported by Materialize. +onlyif cockroach query T SELECT abbrev('10.1.0.0/16'::INET) ---- 10.1.0.0/16 +# Not supported by Materialize. +onlyif cockroach query T SELECT abbrev('192.168.0.1/16'::INET) ---- 192.168.0.1/16 +# Not supported by Materialize. +onlyif cockroach query T SELECT abbrev('192.168.0.1'::INET) ---- 192.168.0.1 +# Not supported by Materialize. +onlyif cockroach query T SELECT abbrev('192.168.0.1/32'::INET) ---- 192.168.0.1 +# Not supported by Materialize. +onlyif cockroach query T SELECT abbrev('10.0/16'::INET) ---- 10.0.0.0/16 +# Not supported by Materialize. +onlyif cockroach query T SELECT abbrev('::ffff:192.168.0.1'::INET) ---- ::ffff:192.168.0.1 +# Not supported by Materialize. +onlyif cockroach query T SELECT abbrev('::ffff:192.168.0.1/24'::INET) ---- @@ -617,36 +821,50 @@ SELECT abbrev('::ffff:192.168.0.1/24'::INET) # Test broadcast +# Not supported by Materialize. +onlyif cockroach query T SELECT broadcast('10.1.0.0/16'::INET) ---- 10.1.255.255/16 +# Not supported by Materialize. +onlyif cockroach query T SELECT broadcast('192.168.0.1/16'::INET) ---- 192.168.255.255/16 +# Not supported by Materialize. +onlyif cockroach query T SELECT broadcast('192.168.0.1'::INET) ---- 192.168.0.1 +# Not supported by Materialize. +onlyif cockroach query T SELECT broadcast('192.168.0.1/32'::INET) ---- 192.168.0.1 +# Not supported by Materialize. +onlyif cockroach query T SELECT broadcast('::ffff:192.168.0.1'::INET) ---- ::ffff:192.168.0.1 +# Not supported by Materialize. +onlyif cockroach query T SELECT broadcast('::ffff:1.2.3.1/20'::INET) ---- 0:fff:ffff:ffff:ffff:ffff:ffff:ffff/20 +# Not supported by Materialize. +onlyif cockroach query T SELECT broadcast('2001:4f8:3:ba::/64'::INET) ---- @@ -654,31 +872,43 @@ SELECT broadcast('2001:4f8:3:ba::/64'::INET) # Test family +# Not supported by Materialize. +onlyif cockroach query I SELECT family('10.1.0.0/16'::INET) ---- 4 +# Not supported by Materialize. +onlyif cockroach query I SELECT family('192.168.0.1/16'::INET) ---- 4 +# Not supported by Materialize. +onlyif cockroach query I SELECT family('192.168.0.1'::INET) ---- 4 +# Not supported by Materialize. +onlyif cockroach query I SELECT family('::ffff:192.168.0.1'::INET) ---- 6 +# Not supported by Materialize. +onlyif cockroach query I SELECT family('::ffff:1.2.3.1/20'::INET) ---- 6 +# Not supported by Materialize. +onlyif cockroach query I SELECT family('2001:4f8:3:ba::/64'::INET) ---- @@ -686,31 +916,43 @@ SELECT family('2001:4f8:3:ba::/64'::INET) # Test host +# Not supported by Materialize. +onlyif cockroach query T SELECT host('10.1.0.0/16'::INET) ---- 10.1.0.0 +# Not supported by Materialize. +onlyif cockroach query T SELECT host('192.168.0.1/16'::INET) ---- 192.168.0.1 +# Not supported by Materialize. +onlyif cockroach query T SELECT host('192.168.0.1'::INET) ---- 192.168.0.1 +# Not supported by Materialize. +onlyif cockroach query T SELECT host('192.168.0.1/32'::INET) ---- 192.168.0.1 +# Not supported by Materialize. +onlyif cockroach query T SELECT host('::ffff:192.168.0.1'::INET) ---- ::ffff:192.168.0.1 +# Not supported by Materialize. +onlyif cockroach query T SELECT host('::ffff:192.168.0.1/24'::INET) ---- @@ -718,21 +960,29 @@ SELECT host('::ffff:192.168.0.1/24'::INET) # Test hostmask +# Not supported by Materialize. +onlyif cockroach query T SELECT hostmask('192.168.1.2'::INET) ---- 0.0.0.0 +# Not supported by Materialize. +onlyif cockroach query T SELECT hostmask('192.168.1.2/16'::INET) ---- 0.0.255.255 +# Not supported by Materialize. +onlyif cockroach query T SELECT hostmask('192.168.1.2/10'::INET) ---- 0.63.255.255 +# Not supported by Materialize. +onlyif cockroach query T SELECT hostmask('2001:4f8:3:ba::/64'::INET) ---- @@ -740,26 +990,36 @@ SELECT hostmask('2001:4f8:3:ba::/64'::INET) # Test masklen +# Not supported by Materialize. +onlyif cockroach query I SELECT masklen('192.168.1.2'::INET) ---- 32 +# Not supported by Materialize. +onlyif cockroach query I SELECT masklen('192.168.1.2/16'::INET) ---- 16 +# Not supported by Materialize. +onlyif cockroach query I SELECT masklen('192.168.1.2/10'::INET) ---- 10 +# Not supported by Materialize. +onlyif cockroach query I SELECT masklen('2001:4f8:3:ba::/64'::INET) ---- 64 +# Not supported by Materialize. +onlyif cockroach query I SELECT masklen('2001:4f8:3:ba::'::INET) ---- @@ -767,46 +1027,64 @@ SELECT masklen('2001:4f8:3:ba::'::INET) # Test netmask +# Not supported by Materialize. +onlyif cockroach query T SELECT netmask('192.168.1.2'::INET) ---- 255.255.255.255 +# Not supported by Materialize. +onlyif cockroach query T SELECT netmask('192.168.1.2/16'::INET) ---- 255.255.0.0 +# Not supported by Materialize. +onlyif cockroach query T SELECT netmask('192.168.1.2/10'::INET) ---- 255.192.0.0 +# Not supported by Materialize. +onlyif cockroach query T SELECT netmask('192.168.1.2/0'::INET) ---- 0.0.0.0 +# Not supported by Materialize. +onlyif cockroach query T SELECT netmask('2001:4f8:3:ba::/64'::INET) ---- ffff:ffff:ffff:ffff:: +# Not supported by Materialize. +onlyif cockroach query T SELECT netmask('2001:4f8:3:ba::/0'::INET) ---- :: +# Not supported by Materialize. +onlyif cockroach query T SELECT netmask('2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128'::INET) ---- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff +# Not supported by Materialize. +onlyif cockroach query T SELECT netmask('::ffff:1.2.3.1/120'::INET) ---- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00 +# Not supported by Materialize. +onlyif cockroach query T SELECT netmask('::ffff:1.2.3.1/20'::INET) ---- @@ -814,41 +1092,51 @@ ffff:f000:: # Test set_masklen +# Not supported by Materialize. +onlyif cockroach query T SELECT set_masklen('10.1.0.0/16'::INET, 10) ---- 10.1.0.0/10 +# Not supported by Materialize. +onlyif cockroach query T SELECT set_masklen('192.168.0.1/16'::INET, 32) ---- 192.168.0.1 -statement error invalid mask length +statement error function "set_masklen" does not exist SELECT set_masklen('192.168.0.1'::INET, 100) -statement error invalid mask length +statement error function "set_masklen" does not exist SELECT set_masklen('192.168.0.1'::INET, 33) -statement error invalid mask length +statement error function "set_masklen" does not exist SELECT set_masklen('192.168.0.1'::INET, -1) +# Not supported by Materialize. +onlyif cockroach query T SELECT set_masklen('192.168.0.1'::INET, 0) ---- 192.168.0.1/0 +# Not supported by Materialize. +onlyif cockroach query T SELECT set_masklen('::ffff:192.168.0.1'::INET, 100) ---- ::ffff:192.168.0.1/100 -statement error invalid mask length +statement error function "set_masklen" does not exist SELECT set_masklen('::ffff:192.168.0.1'::INET, -1) -statement error invalid mask length +statement error function "set_masklen" does not exist SELECT set_masklen('::ffff:192.168.0.1'::INET, 129) +# Not supported by Materialize. +onlyif cockroach query T SELECT set_masklen('::ffff:192.168.0.1/24'::INET, 0) ---- @@ -859,31 +1147,57 @@ SELECT set_masklen('::ffff:192.168.0.1/24'::INET, 0) # the prefix length, whereas abbrev omit it when the prefix length is the # total bits size (32 for IPv4, 128 for IPv6). +# Not supported by Materialize. +onlyif cockroach query T SELECT text('10.1.0.0/16'::INET) ---- 10.1.0.0/16 +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '192.168.0.1'::INET::TEXT +---- +192.168.0.1/32 + +# Not supported by Materialize. +onlyif cockroach query T SELECT text('192.168.0.1/16'::INET) ---- 192.168.0.1/16 +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '192.168.0.1/16'::INET::TEXT +---- +192.168.0.1/16 + +# Not supported by Materialize. +onlyif cockroach query T SELECT text('192.168.0.1'::INET) ---- 192.168.0.1/32 +# Not supported by Materialize. +onlyif cockroach query T SELECT text('192.168.0.1/32'::INET) ---- 192.168.0.1/32 +# Not supported by Materialize. +onlyif cockroach query T SELECT text('::ffff:192.168.0.1'::INET) ---- ::ffff:192.168.0.1/128 +# Not supported by Materialize. +onlyif cockroach query T SELECT text('::ffff:192.168.0.1/24'::INET) ---- @@ -891,13 +1205,56 @@ SELECT text('::ffff:192.168.0.1/24'::INET) # Test inet_same_family +# Not supported by Materialize. +onlyif cockroach query T SELECT text('::ffff:192.168.0.1/24'::INET) ---- ::ffff:192.168.0.1/24 +# Not supported by Materialize. +onlyif cockroach # Verify the inet datum gets serialized correctly for distsql. query T SELECT host(max('192.168.0.2/24'::INET)) FROM (VALUES (1)) AS t(x) ---- 192.168.0.2 + +subtest regression_68578 + +# Not supported by Materialize. +onlyif cockroach +# These address formats are valid in pg, even though they are not valid in Go. +# This test ensures that they remain recognized even when Go does not support them any more. +query TTT +SELECT '127.001.002.003'::INET, '127.001.002.003/016'::INET, '010.001.002.003'::INET +---- +127.1.2.3 127.1.2.3/16 10.1.2.3 + +subtest end + +# Test inet + +query error function "inet" does not exist +SELECT inet('some_invalid_value') + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT inet('::111') +---- +::111 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT inet('192.168.0.2') +---- +192.168.0.2 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT inet('::ffff:192.168.0.1/24') +---- +::ffff:192.168.0.1/24 diff --git a/test/sqllogictest/cockroach/information_schema.slt b/test/sqllogictest/cockroach/information_schema.slt deleted file mode 100644 index 20b557ac53096..0000000000000 --- a/test/sqllogictest/cockroach/information_schema.slt +++ /dev/null @@ -1,2088 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/information_schema -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -# Verify information_schema database handles mutation statements correctly. - -query error database "information_schema" does not exist -ALTER DATABASE information_schema RENAME TO not_information_schema - -statement error schema cannot be modified: "information_schema" -CREATE TABLE information_schema.t (x INT) - -query error database "information_schema" does not exist -DROP DATABASE information_schema - -query T -SHOW TABLES FROM information_schema ----- -administrable_role_authorizations -applicable_roles -character_sets -column_privileges -columns -constraint_column_usage -enabled_roles -key_column_usage -parameters -referential_constraints -role_table_grants -routines -schema_privileges -schemata -sequences -statistics -table_constraints -table_privileges -tables -user_privileges -views - -# Verify that the name is not special for databases. - -statement ok -CREATE DATABASE other_db - -statement ok -ALTER DATABASE other_db RENAME TO information_schema - -statement error database "information_schema" already exists -CREATE DATABASE information_schema - -statement ok -DROP DATABASE information_schema CASCADE - - -# Verify information_schema tables handle mutation statements correctly. - -statement error user root does not have DROP privilege on relation tables -ALTER TABLE information_schema.tables RENAME TO information_schema.bad - -statement error user root does not have CREATE privilege on relation tables -ALTER TABLE information_schema.tables RENAME COLUMN x TO y - -statement error user root does not have CREATE privilege on relation tables -ALTER TABLE information_schema.tables ADD COLUMN x DECIMAL - -statement error user root does not have CREATE privilege on relation tables -ALTER TABLE information_schema.tables DROP COLUMN x - -statement error user root does not have CREATE privilege on relation tables -ALTER TABLE information_schema.tables ADD CONSTRAINT foo UNIQUE (b) - -statement error user root does not have CREATE privilege on relation tables -ALTER TABLE information_schema.tables DROP CONSTRAINT bar - -statement error user root does not have CREATE privilege on relation tables -ALTER TABLE information_schema.tables ALTER COLUMN x SET DEFAULT 'foo' - -statement error user root does not have CREATE privilege on relation tables -ALTER TABLE information_schema.tables ALTER x DROP NOT NULL - -statement error user root does not have CREATE privilege on relation tables -CREATE INDEX i on information_schema.tables (x) - -statement error user root does not have DROP privilege on relation tables -DROP TABLE information_schema.tables - -statement error user root does not have CREATE privilege on relation tables -DROP INDEX information_schema.tables@i - -statement error user root does not have GRANT privilege on relation tables -GRANT CREATE ON information_schema.tables TO root - -statement error user root does not have GRANT privilege on relation tables -REVOKE CREATE ON information_schema.tables FROM root - - -# Verify information_schema tables handles read-only property correctly. - -query error user root does not have DELETE privilege on relation tables -DELETE FROM information_schema.tables - -query error user root does not have INSERT privilege on relation tables -INSERT INTO information_schema.tables VALUES ('abc') - -statement error user root does not have UPDATE privilege on relation tables -UPDATE information_schema.tables SET a = 'abc' - -statement error user root does not have DROP privilege on relation tables -TRUNCATE TABLE information_schema.tables - - -# Verify information_schema handles reflection correctly. - -query T -SHOW DATABASES ----- -materialize -postgres -system -test - -query T -SHOW TABLES FROM test.information_schema ----- -administrable_role_authorizations -applicable_roles -character_sets -column_privileges -columns -constraint_column_usage -enabled_roles -key_column_usage -parameters -referential_constraints -role_table_grants -routines -schema_privileges -schemata -sequences -statistics -table_constraints -table_privileges -tables -user_privileges -views - -query TT colnames -SHOW CREATE TABLE information_schema.tables ----- -table_name create_statement -information_schema.tables CREATE TABLE tables ( - table_catalog STRING NOT NULL, - table_schema STRING NOT NULL, - table_name STRING NOT NULL, - table_type STRING NOT NULL, - is_insertable_into STRING NOT NULL, - version INT8 NULL -) - -query TTBTTTB colnames -SHOW COLUMNS FROM information_schema.tables ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -table_catalog STRING false NULL · {} false -table_schema STRING false NULL · {} false -table_name STRING false NULL · {} false -table_type STRING false NULL · {} false -is_insertable_into STRING false NULL · {} false -version INT8 true NULL · {} false - -query TTBITTBB colnames -SHOW INDEXES ON information_schema.tables ----- -table_name index_name non_unique seq_in_index column_name direction storing implicit - -query TTTTB colnames -SHOW CONSTRAINTS FROM information_schema.tables ----- -table_name constraint_name constraint_type details validated - -query TTTTT colnames -SHOW GRANTS ON information_schema.tables ----- -database_name schema_name table_name grantee privilege_type -test information_schema tables public SELECT - - -# Verify selecting from information_schema. - -## information_schema.schemata - -query TTTT colnames -SELECT * FROM information_schema.schemata ----- -catalog_name schema_name default_character_set_name sql_path -test crdb_internal NULL NULL -test information_schema NULL NULL -test pg_catalog NULL NULL -test public NULL NULL - -query TTTT colnames -SELECT * FROM INFormaTION_SCHEMa.schemata ----- -catalog_name schema_name default_character_set_name sql_path -test crdb_internal NULL NULL -test information_schema NULL NULL -test pg_catalog NULL NULL -test public NULL NULL - -## information_schema.tables - -# Check the default contents of information_schema.tables (incl. the -# special system tables) -query TT rowsort -select table_schema, table_name FROM information_schema.tables ----- -crdb_internal backward_dependencies -crdb_internal builtin_functions -crdb_internal cluster_queries -crdb_internal cluster_sessions -crdb_internal cluster_settings -crdb_internal create_statements -crdb_internal feature_usage -crdb_internal forward_dependencies -crdb_internal gossip_alerts -crdb_internal gossip_liveness -crdb_internal gossip_network -crdb_internal gossip_nodes -crdb_internal index_columns -crdb_internal jobs -crdb_internal kv_node_status -crdb_internal kv_store_status -crdb_internal leases -crdb_internal node_build_info -crdb_internal node_metrics -crdb_internal node_queries -crdb_internal node_runtime_info -crdb_internal node_sessions -crdb_internal node_statement_statistics -crdb_internal partitions -crdb_internal predefined_comments -crdb_internal ranges -crdb_internal ranges_no_leases -crdb_internal schema_changes -crdb_internal session_trace -crdb_internal session_variables -crdb_internal table_columns -crdb_internal table_indexes -crdb_internal tables -crdb_internal zones -information_schema administrable_role_authorizations -information_schema applicable_roles -information_schema column_privileges -information_schema columns -information_schema constraint_column_usage -information_schema enabled_roles -information_schema key_column_usage -information_schema parameters -information_schema referential_constraints -information_schema role_table_grants -information_schema routines -information_schema schema_privileges -information_schema schemata -information_schema sequences -information_schema statistics -information_schema table_constraints -information_schema table_privileges -information_schema tables -information_schema user_privileges -information_schema views -pg_catalog pg_am -pg_catalog pg_attrdef -pg_catalog pg_attribute -pg_catalog pg_auth_members -pg_catalog pg_class -pg_catalog pg_collation -pg_catalog pg_constraint -pg_catalog pg_database -pg_catalog pg_depend -pg_catalog pg_description -pg_catalog pg_enum -pg_catalog pg_extension -pg_catalog pg_foreign_data_wrapper -pg_catalog pg_foreign_server -pg_catalog pg_foreign_table -pg_catalog pg_index -pg_catalog pg_indexes -pg_catalog pg_inherits -pg_catalog pg_language -pg_catalog pg_namespace -pg_catalog pg_operator -pg_catalog pg_proc -pg_catalog pg_range -pg_catalog pg_rewrite -pg_catalog pg_roles -pg_catalog pg_seclabel -pg_catalog pg_sequence -pg_catalog pg_settings -pg_catalog pg_shdescription -pg_catalog pg_shseclabel -pg_catalog pg_stat_activity -pg_catalog pg_tables -pg_catalog pg_tablespace -pg_catalog pg_trigger -pg_catalog pg_type -pg_catalog pg_user -pg_catalog pg_user_mapping -pg_catalog pg_views - -statement ok -CREATE DATABASE other_db - -statement ok -CREATE TABLE other_db.xyz (i INT) - -statement ok -CREATE SEQUENCE other_db.seq - -statement ok -CREATE VIEW other_db.abc AS SELECT i from other_db.xyz - -statement ok -GRANT UPDATE ON other_db.xyz TO testuser - -user testuser - -# Check the output with the current database set to 'test' (the -# defaults in tests). This will make the tables in other_db invisible to -# a non-root user. -query T -SELECT table_name FROM information_schema.tables WHERE table_catalog = 'other_db' ----- - -# Check that the other_db tables become visible when a prefix is specified -query T -SELECT table_name FROM other_db.information_schema.tables WHERE table_catalog = 'other_db' AND table_schema = 'public' ----- -xyz - -# Check that one can see all tables with the empty prefix. -query T rowsort -SELECT table_name FROM "".information_schema.tables WHERE table_catalog = 'other_db' ----- -backward_dependencies -builtin_functions -cluster_queries -cluster_sessions -cluster_settings -create_statements -feature_usage -forward_dependencies -gossip_alerts -gossip_liveness -gossip_network -gossip_nodes -index_columns -jobs -kv_node_status -kv_store_status -leases -node_build_info -node_metrics -node_queries -node_runtime_info -node_sessions -node_statement_statistics -partitions -predefined_comments -ranges -ranges_no_leases -schema_changes -session_trace -session_variables -table_columns -table_indexes -tables -zones -administrable_role_authorizations -applicable_roles -column_privileges -columns -constraint_column_usage -enabled_roles -key_column_usage -parameters -referential_constraints -role_table_grants -routines -schema_privileges -schemata -sequences -statistics -table_constraints -table_privileges -tables -user_privileges -views -pg_am -pg_attrdef -pg_attribute -pg_auth_members -pg_class -pg_collation -pg_constraint -pg_database -pg_depend -pg_description -pg_enum -pg_extension -pg_foreign_data_wrapper -pg_foreign_server -pg_foreign_table -pg_index -pg_indexes -pg_inherits -pg_language -pg_namespace -pg_operator -pg_proc -pg_range -pg_rewrite -pg_roles -pg_seclabel -pg_sequence -pg_settings -pg_shdescription -pg_shseclabel -pg_stat_activity -pg_tables -pg_tablespace -pg_trigger -pg_type -pg_user -pg_user_mapping -pg_views -xyz - -# Check that the other_db tables become visible to non-root when the current database is changed. -query T -SET DATABASE = other_db; SELECT table_name FROM information_schema.tables WHERE table_catalog = 'other_db' AND table_schema = 'public' ----- -xyz - -user root - -# Check that root sees everything when there is no current database -query T -SET DATABASE = ''; SELECT table_name FROM information_schema.tables WHERE table_catalog = 'other_db' AND table_schema = 'public' ----- -xyz -abc - -# Check that root doesn't see other things when there is a current database -query T -SET DATABASE = test; SELECT table_name FROM information_schema.tables WHERE table_schema = 'other_db' ----- - -# Check that filtering works. -query T -SELECT table_name FROM other_db.information_schema.tables WHERE table_name > 't' ORDER BY 1 DESC ----- -zones -xyz -views -user_privileges -tables -tables -table_privileges -table_indexes -table_constraints -table_columns - -# Check that the metadata is reported properly. -query TTTTTI colnames -SELECT * FROM system.information_schema.tables ----- -table_catalog table_schema table_name table_type is_insertable_into version -system crdb_internal backward_dependencies SYSTEM VIEW NO 1 -system crdb_internal builtin_functions SYSTEM VIEW NO 1 -system crdb_internal cluster_queries SYSTEM VIEW NO 1 -system crdb_internal cluster_sessions SYSTEM VIEW NO 1 -system crdb_internal cluster_settings SYSTEM VIEW NO 1 -system crdb_internal create_statements SYSTEM VIEW NO 1 -system crdb_internal feature_usage SYSTEM VIEW NO 1 -system crdb_internal forward_dependencies SYSTEM VIEW NO 1 -system crdb_internal gossip_alerts SYSTEM VIEW NO 1 -system crdb_internal gossip_liveness SYSTEM VIEW NO 1 -system crdb_internal gossip_network SYSTEM VIEW NO 1 -system crdb_internal gossip_nodes SYSTEM VIEW NO 1 -system crdb_internal index_columns SYSTEM VIEW NO 1 -system crdb_internal jobs SYSTEM VIEW NO 1 -system crdb_internal kv_node_status SYSTEM VIEW NO 1 -system crdb_internal kv_store_status SYSTEM VIEW NO 1 -system crdb_internal leases SYSTEM VIEW NO 1 -system crdb_internal node_build_info SYSTEM VIEW NO 1 -system crdb_internal node_metrics SYSTEM VIEW NO 1 -system crdb_internal node_queries SYSTEM VIEW NO 1 -system crdb_internal node_runtime_info SYSTEM VIEW NO 1 -system crdb_internal node_sessions SYSTEM VIEW NO 1 -system crdb_internal node_statement_statistics SYSTEM VIEW NO 1 -system crdb_internal partitions SYSTEM VIEW NO 1 -system crdb_internal predefined_comments SYSTEM VIEW NO 1 -system crdb_internal ranges SYSTEM VIEW NO 1 -system crdb_internal ranges_no_leases SYSTEM VIEW NO 1 -system crdb_internal schema_changes SYSTEM VIEW NO 1 -system crdb_internal session_trace SYSTEM VIEW NO 1 -system crdb_internal session_variables SYSTEM VIEW NO 1 -system crdb_internal table_columns SYSTEM VIEW NO 1 -system crdb_internal table_indexes SYSTEM VIEW NO 1 -system crdb_internal tables SYSTEM VIEW NO 1 -system crdb_internal zones SYSTEM VIEW NO 1 -system information_schema administrable_role_authorizations SYSTEM VIEW NO 1 -system information_schema applicable_roles SYSTEM VIEW NO 1 -system information_schema column_privileges SYSTEM VIEW NO 1 -system information_schema columns SYSTEM VIEW NO 1 -system information_schema constraint_column_usage SYSTEM VIEW NO 1 -system information_schema enabled_roles SYSTEM VIEW NO 1 -system information_schema key_column_usage SYSTEM VIEW NO 1 -system information_schema parameters SYSTEM VIEW NO 1 -system information_schema referential_constraints SYSTEM VIEW NO 1 -system information_schema role_table_grants SYSTEM VIEW NO 1 -system information_schema routines SYSTEM VIEW NO 1 -system information_schema schema_privileges SYSTEM VIEW NO 1 -system information_schema schemata SYSTEM VIEW NO 1 -system information_schema sequences SYSTEM VIEW NO 1 -system information_schema statistics SYSTEM VIEW NO 1 -system information_schema table_constraints SYSTEM VIEW NO 1 -system information_schema table_privileges SYSTEM VIEW NO 1 -system information_schema tables SYSTEM VIEW NO 1 -system information_schema user_privileges SYSTEM VIEW NO 1 -system information_schema views SYSTEM VIEW NO 1 -system pg_catalog pg_am SYSTEM VIEW NO 1 -system pg_catalog pg_attrdef SYSTEM VIEW NO 1 -system pg_catalog pg_attribute SYSTEM VIEW NO 1 -system pg_catalog pg_auth_members SYSTEM VIEW NO 1 -system pg_catalog pg_class SYSTEM VIEW NO 1 -system pg_catalog pg_collation SYSTEM VIEW NO 1 -system pg_catalog pg_constraint SYSTEM VIEW NO 1 -system pg_catalog pg_database SYSTEM VIEW NO 1 -system pg_catalog pg_depend SYSTEM VIEW NO 1 -system pg_catalog pg_description SYSTEM VIEW NO 1 -system pg_catalog pg_enum SYSTEM VIEW NO 1 -system pg_catalog pg_extension SYSTEM VIEW NO 1 -system pg_catalog pg_foreign_data_wrapper SYSTEM VIEW NO 1 -system pg_catalog pg_foreign_server SYSTEM VIEW NO 1 -system pg_catalog pg_foreign_table SYSTEM VIEW NO 1 -system pg_catalog pg_index SYSTEM VIEW NO 1 -system pg_catalog pg_indexes SYSTEM VIEW NO 1 -system pg_catalog pg_inherits SYSTEM VIEW NO 1 -system pg_catalog pg_language SYSTEM VIEW NO 1 -system pg_catalog pg_namespace SYSTEM VIEW NO 1 -system pg_catalog pg_operator SYSTEM VIEW NO 1 -system pg_catalog pg_proc SYSTEM VIEW NO 1 -system pg_catalog pg_range SYSTEM VIEW NO 1 -system pg_catalog pg_rewrite SYSTEM VIEW NO 1 -system pg_catalog pg_roles SYSTEM VIEW NO 1 -system pg_catalog pg_seclabel SYSTEM VIEW NO 1 -system pg_catalog pg_sequence SYSTEM VIEW NO 1 -system pg_catalog pg_settings SYSTEM VIEW NO 1 -system pg_catalog pg_shdescription SYSTEM VIEW NO 1 -system pg_catalog pg_shseclabel SYSTEM VIEW NO 1 -system pg_catalog pg_stat_activity SYSTEM VIEW NO 1 -system pg_catalog pg_tables SYSTEM VIEW NO 1 -system pg_catalog pg_tablespace SYSTEM VIEW NO 1 -system pg_catalog pg_trigger SYSTEM VIEW NO 1 -system pg_catalog pg_type SYSTEM VIEW NO 1 -system pg_catalog pg_user SYSTEM VIEW NO 1 -system pg_catalog pg_user_mapping SYSTEM VIEW NO 1 -system pg_catalog pg_views SYSTEM VIEW NO 1 -system public namespace BASE TABLE YES 1 -system public descriptor BASE TABLE YES 1 -system public users BASE TABLE YES 1 -system public zones BASE TABLE YES 1 -system public settings BASE TABLE YES 1 -system public lease BASE TABLE YES 1 -system public eventlog BASE TABLE YES 1 -system public rangelog BASE TABLE YES 1 -system public ui BASE TABLE YES 1 -system public jobs BASE TABLE YES 1 -system public web_sessions BASE TABLE YES 1 -system public table_statistics BASE TABLE YES 1 -system public locations BASE TABLE YES 1 -system public role_members BASE TABLE YES 1 -system public comments BASE TABLE YES 1 - -statement ok -ALTER TABLE other_db.xyz ADD COLUMN j INT - -query TTI colnames -SELECT TABLE_CATALOG, TABLE_NAME, VERSION FROM "".information_schema.tables WHERE version > 1 AND TABLE_SCHEMA = 'public' ORDER BY 1,2 ----- -table_catalog table_name version -other_db xyz 6 - -user testuser - -# Check that another user cannot see other_db.adbc any more because they -# don't have privileges on it. -query TTTTTI colnames -SELECT * FROM other_db.information_schema.tables WHERE table_catalog = 'other_db' AND table_schema = 'public' ----- -table_catalog table_schema table_name table_type is_insertable_into version -other_db public xyz BASE TABLE YES 6 - - -user root - -statement ok -GRANT SELECT ON other_db.abc TO testuser - -user testuser - -# Check the user can see the tables now that they have privilege. -query TTTTTI colnames -SELECT * FROM other_db.information_schema.tables WHERE table_catalog = 'other_db' AND table_schema = 'public' ORDER BY 1, 3 ----- -table_catalog table_schema table_name table_type is_insertable_into version -other_db public abc VIEW NO 2 -other_db public xyz BASE TABLE YES 6 - -user root - -statement ok -DROP DATABASE other_db CASCADE - -statement ok -SET DATABASE = test - -## information_schema.table_constraints -## information_schema.constraint_column_usage - -query TTTTTTTTT colnames -SELECT * -FROM system.information_schema.table_constraints -ORDER BY TABLE_NAME, CONSTRAINT_TYPE, CONSTRAINT_NAME ----- -constraint_catalog constraint_schema constraint_name table_catalog table_schema table_name constraint_type is_deferrable initially_deferred -system public primary system public comments PRIMARY KEY NO NO -system public primary system public descriptor PRIMARY KEY NO NO -system public primary system public eventlog PRIMARY KEY NO NO -system public primary system public jobs PRIMARY KEY NO NO -system public primary system public lease PRIMARY KEY NO NO -system public primary system public locations PRIMARY KEY NO NO -system public primary system public namespace PRIMARY KEY NO NO -system public primary system public rangelog PRIMARY KEY NO NO -system public primary system public role_members PRIMARY KEY NO NO -system public primary system public settings PRIMARY KEY NO NO -system public primary system public table_statistics PRIMARY KEY NO NO -system public primary system public ui PRIMARY KEY NO NO -system public primary system public users PRIMARY KEY NO NO -system public primary system public web_sessions PRIMARY KEY NO NO -system public primary system public zones PRIMARY KEY NO NO - -query TTTTTTT colnames -SELECT * -FROM system.information_schema.constraint_column_usage -ORDER BY TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME ----- -table_catalog table_schema table_name column_name constraint_catalog constraint_schema constraint_name -system public comments object_id system public primary -system public comments sub_id system public primary -system public comments type system public primary -system public descriptor id system public primary -system public eventlog timestamp system public primary -system public eventlog uniqueID system public primary -system public jobs id system public primary -system public lease descID system public primary -system public lease expiration system public primary -system public lease nodeID system public primary -system public lease version system public primary -system public locations localityKey system public primary -system public locations localityValue system public primary -system public namespace name system public primary -system public namespace parentID system public primary -system public rangelog timestamp system public primary -system public rangelog uniqueID system public primary -system public role_members member system public primary -system public role_members role system public primary -system public settings name system public primary -system public table_statistics statisticID system public primary -system public table_statistics tableID system public primary -system public ui key system public primary -system public users username system public primary -system public web_sessions id system public primary -system public zones id system public primary - -statement ok -CREATE DATABASE constraint_db - -statement ok -CREATE TABLE constraint_db.t1 ( - p FLOAT PRIMARY KEY, - a INT UNIQUE CHECK (a > 4), - CONSTRAINT c2 CHECK (a < 99) -) - -statement ok -CREATE TABLE constraint_db.t2 ( - t1_ID INT, - CONSTRAINT fk FOREIGN KEY (t1_ID) REFERENCES constraint_db.t1(a), - INDEX (t1_ID) -) - -statement ok -SET DATABASE = constraint_db - -query TTTTTTTTT colnames -SELECT * -FROM information_schema.table_constraints -ORDER BY TABLE_NAME, CONSTRAINT_TYPE, CONSTRAINT_NAME ----- -constraint_catalog constraint_schema constraint_name table_catalog table_schema table_name constraint_type is_deferrable initially_deferred -constraint_db public c2 constraint_db public t1 CHECK NO NO -constraint_db public check_a constraint_db public t1 CHECK NO NO -constraint_db public primary constraint_db public t1 PRIMARY KEY NO NO -constraint_db public t1_a_key constraint_db public t1 UNIQUE NO NO -constraint_db public fk constraint_db public t2 FOREIGN KEY NO NO - -query TTTTTTT colnames -SELECT * -FROM information_schema.constraint_column_usage -WHERE constraint_catalog = 'constraint_db' -ORDER BY TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME ----- -table_catalog table_schema table_name column_name constraint_catalog constraint_schema constraint_name -constraint_db public t1 a constraint_db public c2 -constraint_db public t1 a constraint_db public check_a -constraint_db public t1 a constraint_db public fk -constraint_db public t1 a constraint_db public t1_a_key -constraint_db public t1 p constraint_db public primary - -statement ok -DROP DATABASE constraint_db CASCADE - -## information_schema.columns - -query TTTTI colnames -SELECT table_catalog, table_schema, table_name, column_name, ordinal_position -FROM system.information_schema.columns -WHERE table_schema != 'information_schema' AND table_schema != 'pg_catalog' AND table_schema != 'crdb_internal' -ORDER BY 3,4 ----- -table_catalog table_schema table_name column_name ordinal_position -system public comments comment 4 -system public comments object_id 2 -system public comments sub_id 3 -system public comments type 1 -system public descriptor descriptor 2 -system public descriptor id 1 -system public eventlog eventType 2 -system public eventlog info 5 -system public eventlog reportingID 4 -system public eventlog targetID 3 -system public eventlog timestamp 1 -system public eventlog uniqueID 6 -system public jobs created 3 -system public jobs id 1 -system public jobs payload 4 -system public jobs progress 5 -system public jobs status 2 -system public lease descID 1 -system public lease expiration 4 -system public lease nodeID 3 -system public lease version 2 -system public locations latitude 3 -system public locations localityKey 1 -system public locations localityValue 2 -system public locations longitude 4 -system public namespace id 3 -system public namespace name 2 -system public namespace parentID 1 -system public rangelog eventType 4 -system public rangelog info 6 -system public rangelog otherRangeID 5 -system public rangelog rangeID 2 -system public rangelog storeID 3 -system public rangelog timestamp 1 -system public rangelog uniqueID 7 -system public role_members isAdmin 3 -system public role_members member 2 -system public role_members role 1 -system public settings lastUpdated 3 -system public settings name 1 -system public settings value 2 -system public settings valueType 4 -system public table_statistics columnIDs 4 -system public table_statistics createdAt 5 -system public table_statistics distinctCount 7 -system public table_statistics histogram 9 -system public table_statistics name 3 -system public table_statistics nullCount 8 -system public table_statistics rowCount 6 -system public table_statistics statisticID 2 -system public table_statistics tableID 1 -system public ui key 1 -system public ui lastUpdated 3 -system public ui value 2 -system public users hashedPassword 2 -system public users isRole 3 -system public users username 1 -system public web_sessions auditInfo 8 -system public web_sessions createdAt 4 -system public web_sessions expiresAt 5 -system public web_sessions hashedSecret 2 -system public web_sessions id 1 -system public web_sessions lastUsedAt 7 -system public web_sessions revokedAt 6 -system public web_sessions username 3 -system public zones config 2 -system public zones id 1 - -statement ok -SET DATABASE = test - -statement ok -CREATE TABLE with_defaults (a INT DEFAULT 9, b STRING DEFAULT 'default', c INT, d STRING) - -query TTT colnames -SELECT table_name, column_name, column_default -FROM information_schema.columns -WHERE table_schema = 'public' AND table_name = 'with_defaults' ----- -table_name column_name column_default -with_defaults a 9:::INT8 -with_defaults b 'default':::STRING -with_defaults c NULL -with_defaults d NULL -with_defaults rowid unique_rowid() - -statement ok -DROP TABLE with_defaults - -statement ok -CREATE TABLE nullability (a INT NOT NULL, b STRING NOT NULL, c INT, d STRING) - -query TTT colnames -SELECT table_name, column_name, is_nullable -FROM information_schema.columns -WHERE table_schema = 'public' AND table_name = 'nullability' ----- -table_name column_name is_nullable -nullability a NO -nullability b NO -nullability c YES -nullability d YES -nullability rowid NO - -statement ok -DROP TABLE nullability - -statement ok -CREATE TABLE data_types ( - a INT, - a2 INT2, - a4 INT4, - a8 INT8, - b FLOAT, - b4 FLOAT4, - br REAL, - c DECIMAL, - cp DECIMAL(3), - cps DECIMAL(3,2), - d STRING, - dl STRING COLLATE en, - dc CHAR, - dc2 CHAR(2), - dv VARCHAR, - dv2 VARCHAR(2), - dq "char", - e BYTES, - f TIMESTAMP, - f6 TIMESTAMP(6), - g TIMESTAMPTZ, - g6 TIMESTAMPTZ(6), - h BIT, - h2 BIT(2), - hv VARBIT, - hv2 VARBIT(2), - i INTERVAL, - j BOOL, - k OID, - k2 REGCLASS, - k3 REGNAMESPACE, - k4 REGPROC, - k5 REGPROCEDURE, - k6 REGTYPE, - l UUID, - m INT2[], - m2 STRING[], - m3 DECIMAL(3, 2)[], - m4 VARCHAR(2)[] COLLATE en, - n INET, - o TIME, - o6 TIME(6), - p JSONB, - q NAME -) - -query TTTTTTTTTT colnames -SELECT table_name, column_name, data_type, crdb_sql_type, udt_catalog, udt_schema, udt_name, collation_catalog, collation_schema, collation_name -FROM information_schema.columns -WHERE table_schema = 'public' AND table_name = 'data_types' ----- -table_name column_name data_type crdb_sql_type udt_catalog udt_schema udt_name collation_catalog collation_schema collation_name -data_types a bigint INT8 test pg_catalog int8 NULL NULL NULL -data_types a2 smallint INT2 test pg_catalog int2 NULL NULL NULL -data_types a4 integer INT4 test pg_catalog int4 NULL NULL NULL -data_types a8 bigint INT8 test pg_catalog int8 NULL NULL NULL -data_types b double precision FLOAT8 test pg_catalog float8 NULL NULL NULL -data_types b4 real FLOAT4 test pg_catalog float4 NULL NULL NULL -data_types br real FLOAT4 test pg_catalog float4 NULL NULL NULL -data_types c numeric DECIMAL test pg_catalog numeric NULL NULL NULL -data_types cp numeric DECIMAL(3) test pg_catalog numeric NULL NULL NULL -data_types cps numeric DECIMAL(3,2) test pg_catalog numeric NULL NULL NULL -data_types d text STRING test pg_catalog text NULL NULL NULL -data_types dl text STRING COLLATE en test pg_catalog text test pg_catalog en -data_types dc character CHAR test pg_catalog bpchar NULL NULL NULL -data_types dc2 character CHAR(2) test pg_catalog bpchar NULL NULL NULL -data_types dv character varying VARCHAR test pg_catalog varchar NULL NULL NULL -data_types dv2 character varying VARCHAR(2) test pg_catalog varchar NULL NULL NULL -data_types dq "char" "char" test pg_catalog char NULL NULL NULL -data_types e bytea BYTES test pg_catalog bytea NULL NULL NULL -data_types f timestamp without time zone TIMESTAMP test pg_catalog timestamp NULL NULL NULL -data_types f6 timestamp without time zone TIMESTAMP(6) test pg_catalog timestamp NULL NULL NULL -data_types g timestamp with time zone TIMESTAMPTZ test pg_catalog timestamptz NULL NULL NULL -data_types g6 timestamp with time zone TIMESTAMPTZ(6) test pg_catalog timestamptz NULL NULL NULL -data_types h bit BIT test pg_catalog bit NULL NULL NULL -data_types h2 bit BIT(2) test pg_catalog bit NULL NULL NULL -data_types hv bit varying VARBIT test pg_catalog varbit NULL NULL NULL -data_types hv2 bit varying VARBIT(2) test pg_catalog varbit NULL NULL NULL -data_types i interval INTERVAL test pg_catalog interval NULL NULL NULL -data_types j boolean BOOL test pg_catalog bool NULL NULL NULL -data_types k oid OID test pg_catalog oid NULL NULL NULL -data_types k2 regclass REGCLASS test pg_catalog regclass NULL NULL NULL -data_types k3 regnamespace REGNAMESPACE test pg_catalog regnamespace NULL NULL NULL -data_types k4 regproc REGPROC test pg_catalog regproc NULL NULL NULL -data_types k5 regprocedure REGPROCEDURE test pg_catalog regprocedure NULL NULL NULL -data_types k6 regtype REGTYPE test pg_catalog regtype NULL NULL NULL -data_types l uuid UUID test pg_catalog uuid NULL NULL NULL -data_types m ARRAY INT2[] test pg_catalog _int2 NULL NULL NULL -data_types m2 ARRAY STRING[] test pg_catalog _text NULL NULL NULL -data_types m3 ARRAY DECIMAL(3,2)[] test pg_catalog _numeric NULL NULL NULL -data_types m4 ARRAY VARCHAR(2)[] COLLATE en test pg_catalog _varchar NULL NULL NULL -data_types n inet INET test pg_catalog inet NULL NULL NULL -data_types o time without time zone TIME test pg_catalog time NULL NULL NULL -data_types o6 time without time zone TIME(6) test pg_catalog time NULL NULL NULL -data_types p jsonb JSONB test pg_catalog jsonb NULL NULL NULL -data_types q name NAME test pg_catalog name NULL NULL NULL -data_types rowid bigint INT8 test pg_catalog int8 NULL NULL NULL - -statement ok -DROP TABLE data_types - -statement ok -CREATE TABLE computed (a INT, b INT AS (a + 1) STORED) - -query TTTT colnames -SELECT column_name, is_generated, generation_expression, is_updatable -FROM information_schema.columns -WHERE table_schema = 'public' AND table_name = 'computed' ----- -column_name is_generated generation_expression is_updatable -a NO · YES -b YES a + 1 NO -rowid NO · YES - -statement ok -CREATE TABLE char_len ( - a INT, b INT2, c INT4, - d STRING, e STRING(12), - dc CHAR, ec CHAR(12), - dv VARCHAR, ev VARCHAR(12), - dq "char", - f FLOAT, - g BIT, h BIT(12), - i VARBIT, j VARBIT(12)) - -query TTII colnames -SELECT table_name, column_name, character_maximum_length, character_octet_length -FROM information_schema.columns -WHERE table_schema = 'public' AND table_name = 'char_len' ----- -table_name column_name character_maximum_length character_octet_length -char_len a NULL NULL -char_len b NULL NULL -char_len c NULL NULL -char_len d NULL NULL -char_len e 12 48 -char_len dc 1 4 -char_len ec 12 48 -char_len dv NULL NULL -char_len ev 12 48 -char_len dq NULL NULL -char_len f NULL NULL -char_len g 1 NULL -char_len h 12 NULL -char_len i NULL NULL -char_len j 12 NULL -char_len rowid NULL NULL - -statement ok -DROP TABLE char_len - -statement ok -CREATE TABLE num_prec (a INT, b FLOAT, c FLOAT(23), d DECIMAL, e DECIMAL(12), f DECIMAL(12, 6), g BOOLEAN) - -query TTIIII colnames -SELECT table_name, column_name, numeric_precision, numeric_precision_radix, numeric_scale, datetime_precision -FROM information_schema.columns -WHERE table_schema = 'public' AND table_name = 'num_prec' ----- -table_name column_name numeric_precision numeric_precision_radix numeric_scale datetime_precision -num_prec a 64 2 0 NULL -num_prec b 53 2 NULL NULL -num_prec c 24 2 NULL NULL -num_prec d NULL 10 NULL NULL -num_prec e 12 10 0 NULL -num_prec f 12 10 6 NULL -num_prec g NULL NULL NULL NULL -num_prec rowid 64 2 0 NULL - -statement ok -DROP TABLE num_prec - -## information_schema.key_column_usage -## information_schema.referential_constraints - -statement ok -CREATE DATABASE constraint_column - -statement ok -CREATE TABLE constraint_column.t1 ( - p FLOAT PRIMARY KEY, - a INT UNIQUE, - b INT, - c INT CHECK(c > 0), - UNIQUE INDEX index_key(b, c) -) - -statement ok -CREATE TABLE constraint_column.t2 ( - t1_ID INT PRIMARY KEY, - CONSTRAINT fk FOREIGN KEY (t1_ID) REFERENCES constraint_column.t1(a) ON DELETE RESTRICT -) - -statement ok -CREATE TABLE constraint_column.t3 ( - a INT, - b INT, - CONSTRAINT fk2 FOREIGN KEY (a, b) REFERENCES constraint_column.t1(b, c) ON UPDATE CASCADE, - INDEX (a, b) -) - -statement ok -SET DATABASE = constraint_column - -query TTTTTTTII colnames -SELECT * FROM information_schema.key_column_usage WHERE constraint_schema = 'public' ORDER BY TABLE_NAME, CONSTRAINT_NAME, ORDINAL_POSITION ----- -constraint_catalog constraint_schema constraint_name table_catalog table_schema table_name column_name ordinal_position position_in_unique_constraint -constraint_column public index_key constraint_column public t1 b 1 NULL -constraint_column public index_key constraint_column public t1 c 2 NULL -constraint_column public primary constraint_column public t1 p 1 NULL -constraint_column public t1_a_key constraint_column public t1 a 1 NULL -constraint_column public fk constraint_column public t2 t1_id 1 1 -constraint_column public primary constraint_column public t2 t1_id 1 NULL -constraint_column public fk2 constraint_column public t3 a 1 1 -constraint_column public fk2 constraint_column public t3 b 2 2 - -query TTTTTTTTTTT colnames -SELECT * FROM information_schema.referential_constraints WHERE constraint_schema = 'public' ORDER BY TABLE_NAME, CONSTRAINT_NAME ----- -constraint_catalog constraint_schema constraint_name unique_constraint_catalog unique_constraint_schema unique_constraint_name match_option update_rule delete_rule table_name referenced_table_name -constraint_column public fk constraint_column public t1_a_key NONE NO ACTION RESTRICT t2 t1 -constraint_column public fk2 constraint_column public index_key NONE CASCADE NO ACTION t3 t1 - -statement ok -DROP DATABASE constraint_column CASCADE - -## information_schema.schema_privileges - -statement ok -CREATE DATABASE other_db; SET DATABASE = other_db - -query TTTTT colnames -SELECT * FROM information_schema.schema_privileges ----- -grantee table_catalog table_schema privilege_type is_grantable -admin other_db crdb_internal ALL NULL -root other_db crdb_internal ALL NULL -admin other_db information_schema ALL NULL -root other_db information_schema ALL NULL -admin other_db pg_catalog ALL NULL -root other_db pg_catalog ALL NULL -admin other_db public ALL NULL -root other_db public ALL NULL - -statement ok -GRANT SELECT ON DATABASE other_db TO testuser - -query TTTTT colnames -SELECT * FROM information_schema.schema_privileges ----- -grantee table_catalog table_schema privilege_type is_grantable -admin other_db crdb_internal ALL NULL -root other_db crdb_internal ALL NULL -testuser other_db crdb_internal SELECT NULL -admin other_db information_schema ALL NULL -root other_db information_schema ALL NULL -testuser other_db information_schema SELECT NULL -admin other_db pg_catalog ALL NULL -root other_db pg_catalog ALL NULL -testuser other_db pg_catalog SELECT NULL -admin other_db public ALL NULL -root other_db public ALL NULL -testuser other_db public SELECT NULL - -## information_schema.table_privileges and information_schema.role_table_grants - -# root can see everything -query TTTTTTTT colnames,rowsort -SELECT * FROM system.information_schema.table_privileges ORDER BY table_schema, table_name, table_schema, grantee, privilege_type ----- -grantor grantee table_catalog table_schema table_name privilege_type is_grantable with_hierarchy -NULL public system crdb_internal backward_dependencies SELECT NULL YES -NULL public system crdb_internal builtin_functions SELECT NULL YES -NULL public system crdb_internal cluster_queries SELECT NULL YES -NULL public system crdb_internal cluster_sessions SELECT NULL YES -NULL public system crdb_internal cluster_settings SELECT NULL YES -NULL public system crdb_internal create_statements SELECT NULL YES -NULL public system crdb_internal feature_usage SELECT NULL YES -NULL public system crdb_internal forward_dependencies SELECT NULL YES -NULL public system crdb_internal gossip_alerts SELECT NULL YES -NULL public system crdb_internal gossip_liveness SELECT NULL YES -NULL public system crdb_internal gossip_network SELECT NULL YES -NULL public system crdb_internal gossip_nodes SELECT NULL YES -NULL public system crdb_internal index_columns SELECT NULL YES -NULL public system crdb_internal jobs SELECT NULL YES -NULL public system crdb_internal kv_node_status SELECT NULL YES -NULL public system crdb_internal kv_store_status SELECT NULL YES -NULL public system crdb_internal leases SELECT NULL YES -NULL public system crdb_internal node_build_info SELECT NULL YES -NULL public system crdb_internal node_metrics SELECT NULL YES -NULL public system crdb_internal node_queries SELECT NULL YES -NULL public system crdb_internal node_runtime_info SELECT NULL YES -NULL public system crdb_internal node_sessions SELECT NULL YES -NULL public system crdb_internal node_statement_statistics SELECT NULL YES -NULL public system crdb_internal partitions SELECT NULL YES -NULL public system crdb_internal predefined_comments SELECT NULL YES -NULL public system crdb_internal ranges SELECT NULL YES -NULL public system crdb_internal ranges_no_leases SELECT NULL YES -NULL public system crdb_internal schema_changes SELECT NULL YES -NULL public system crdb_internal session_trace SELECT NULL YES -NULL public system crdb_internal session_variables SELECT NULL YES -NULL public system crdb_internal table_columns SELECT NULL YES -NULL public system crdb_internal table_indexes SELECT NULL YES -NULL public system crdb_internal tables SELECT NULL YES -NULL public system crdb_internal zones SELECT NULL YES -NULL public system information_schema administrable_role_authorizations SELECT NULL YES -NULL public system information_schema applicable_roles SELECT NULL YES -NULL public system information_schema column_privileges SELECT NULL YES -NULL public system information_schema columns SELECT NULL YES -NULL public system information_schema constraint_column_usage SELECT NULL YES -NULL public system information_schema enabled_roles SELECT NULL YES -NULL public system information_schema key_column_usage SELECT NULL YES -NULL public system information_schema parameters SELECT NULL YES -NULL public system information_schema referential_constraints SELECT NULL YES -NULL public system information_schema role_table_grants SELECT NULL YES -NULL public system information_schema routines SELECT NULL YES -NULL public system information_schema schema_privileges SELECT NULL YES -NULL public system information_schema schemata SELECT NULL YES -NULL public system information_schema sequences SELECT NULL YES -NULL public system information_schema statistics SELECT NULL YES -NULL public system information_schema table_constraints SELECT NULL YES -NULL public system information_schema table_privileges SELECT NULL YES -NULL public system information_schema tables SELECT NULL YES -NULL public system information_schema user_privileges SELECT NULL YES -NULL public system information_schema views SELECT NULL YES -NULL public system pg_catalog pg_am SELECT NULL YES -NULL public system pg_catalog pg_attrdef SELECT NULL YES -NULL public system pg_catalog pg_attribute SELECT NULL YES -NULL public system pg_catalog pg_auth_members SELECT NULL YES -NULL public system pg_catalog pg_class SELECT NULL YES -NULL public system pg_catalog pg_collation SELECT NULL YES -NULL public system pg_catalog pg_constraint SELECT NULL YES -NULL public system pg_catalog pg_database SELECT NULL YES -NULL public system pg_catalog pg_depend SELECT NULL YES -NULL public system pg_catalog pg_description SELECT NULL YES -NULL public system pg_catalog pg_enum SELECT NULL YES -NULL public system pg_catalog pg_extension SELECT NULL YES -NULL public system pg_catalog pg_foreign_data_wrapper SELECT NULL YES -NULL public system pg_catalog pg_foreign_server SELECT NULL YES -NULL public system pg_catalog pg_foreign_table SELECT NULL YES -NULL public system pg_catalog pg_index SELECT NULL YES -NULL public system pg_catalog pg_indexes SELECT NULL YES -NULL public system pg_catalog pg_inherits SELECT NULL YES -NULL public system pg_catalog pg_language SELECT NULL YES -NULL public system pg_catalog pg_namespace SELECT NULL YES -NULL public system pg_catalog pg_operator SELECT NULL YES -NULL public system pg_catalog pg_proc SELECT NULL YES -NULL public system pg_catalog pg_range SELECT NULL YES -NULL public system pg_catalog pg_rewrite SELECT NULL YES -NULL public system pg_catalog pg_roles SELECT NULL YES -NULL public system pg_catalog pg_seclabel SELECT NULL YES -NULL public system pg_catalog pg_sequence SELECT NULL YES -NULL public system pg_catalog pg_settings SELECT NULL YES -NULL public system pg_catalog pg_shdescription SELECT NULL YES -NULL public system pg_catalog pg_shseclabel SELECT NULL YES -NULL public system pg_catalog pg_stat_activity SELECT NULL YES -NULL public system pg_catalog pg_tables SELECT NULL YES -NULL public system pg_catalog pg_tablespace SELECT NULL YES -NULL public system pg_catalog pg_trigger SELECT NULL YES -NULL public system pg_catalog pg_type SELECT NULL YES -NULL public system pg_catalog pg_user SELECT NULL YES -NULL public system pg_catalog pg_user_mapping SELECT NULL YES -NULL public system pg_catalog pg_views SELECT NULL YES -NULL admin system public comments DELETE NULL NO -NULL admin system public comments GRANT NULL NO -NULL admin system public comments INSERT NULL NO -NULL admin system public comments SELECT NULL YES -NULL admin system public comments UPDATE NULL NO -NULL public system public comments DELETE NULL NO -NULL public system public comments GRANT NULL NO -NULL public system public comments INSERT NULL NO -NULL public system public comments SELECT NULL YES -NULL public system public comments UPDATE NULL NO -NULL root system public comments DELETE NULL NO -NULL root system public comments GRANT NULL NO -NULL root system public comments INSERT NULL NO -NULL root system public comments SELECT NULL YES -NULL root system public comments UPDATE NULL NO -NULL admin system public descriptor GRANT NULL NO -NULL admin system public descriptor SELECT NULL YES -NULL root system public descriptor GRANT NULL NO -NULL root system public descriptor SELECT NULL YES -NULL admin system public eventlog DELETE NULL NO -NULL admin system public eventlog GRANT NULL NO -NULL admin system public eventlog INSERT NULL NO -NULL admin system public eventlog SELECT NULL YES -NULL admin system public eventlog UPDATE NULL NO -NULL root system public eventlog DELETE NULL NO -NULL root system public eventlog GRANT NULL NO -NULL root system public eventlog INSERT NULL NO -NULL root system public eventlog SELECT NULL YES -NULL root system public eventlog UPDATE NULL NO -NULL admin system public jobs DELETE NULL NO -NULL admin system public jobs GRANT NULL NO -NULL admin system public jobs INSERT NULL NO -NULL admin system public jobs SELECT NULL YES -NULL admin system public jobs UPDATE NULL NO -NULL root system public jobs DELETE NULL NO -NULL root system public jobs GRANT NULL NO -NULL root system public jobs INSERT NULL NO -NULL root system public jobs SELECT NULL YES -NULL root system public jobs UPDATE NULL NO -NULL admin system public lease DELETE NULL NO -NULL admin system public lease GRANT NULL NO -NULL admin system public lease INSERT NULL NO -NULL admin system public lease SELECT NULL YES -NULL admin system public lease UPDATE NULL NO -NULL root system public lease DELETE NULL NO -NULL root system public lease GRANT NULL NO -NULL root system public lease INSERT NULL NO -NULL root system public lease SELECT NULL YES -NULL root system public lease UPDATE NULL NO -NULL admin system public locations DELETE NULL NO -NULL admin system public locations GRANT NULL NO -NULL admin system public locations INSERT NULL NO -NULL admin system public locations SELECT NULL YES -NULL admin system public locations UPDATE NULL NO -NULL root system public locations DELETE NULL NO -NULL root system public locations GRANT NULL NO -NULL root system public locations INSERT NULL NO -NULL root system public locations SELECT NULL YES -NULL root system public locations UPDATE NULL NO -NULL admin system public namespace GRANT NULL NO -NULL admin system public namespace SELECT NULL YES -NULL root system public namespace GRANT NULL NO -NULL root system public namespace SELECT NULL YES -NULL admin system public rangelog DELETE NULL NO -NULL admin system public rangelog GRANT NULL NO -NULL admin system public rangelog INSERT NULL NO -NULL admin system public rangelog SELECT NULL YES -NULL admin system public rangelog UPDATE NULL NO -NULL root system public rangelog DELETE NULL NO -NULL root system public rangelog GRANT NULL NO -NULL root system public rangelog INSERT NULL NO -NULL root system public rangelog SELECT NULL YES -NULL root system public rangelog UPDATE NULL NO -NULL admin system public role_members DELETE NULL NO -NULL admin system public role_members GRANT NULL NO -NULL admin system public role_members INSERT NULL NO -NULL admin system public role_members SELECT NULL YES -NULL admin system public role_members UPDATE NULL NO -NULL root system public role_members DELETE NULL NO -NULL root system public role_members GRANT NULL NO -NULL root system public role_members INSERT NULL NO -NULL root system public role_members SELECT NULL YES -NULL root system public role_members UPDATE NULL NO -NULL admin system public settings DELETE NULL NO -NULL admin system public settings GRANT NULL NO -NULL admin system public settings INSERT NULL NO -NULL admin system public settings SELECT NULL YES -NULL admin system public settings UPDATE NULL NO -NULL root system public settings DELETE NULL NO -NULL root system public settings GRANT NULL NO -NULL root system public settings INSERT NULL NO -NULL root system public settings SELECT NULL YES -NULL root system public settings UPDATE NULL NO -NULL admin system public table_statistics DELETE NULL NO -NULL admin system public table_statistics GRANT NULL NO -NULL admin system public table_statistics INSERT NULL NO -NULL admin system public table_statistics SELECT NULL YES -NULL admin system public table_statistics UPDATE NULL NO -NULL root system public table_statistics DELETE NULL NO -NULL root system public table_statistics GRANT NULL NO -NULL root system public table_statistics INSERT NULL NO -NULL root system public table_statistics SELECT NULL YES -NULL root system public table_statistics UPDATE NULL NO -NULL admin system public ui DELETE NULL NO -NULL admin system public ui GRANT NULL NO -NULL admin system public ui INSERT NULL NO -NULL admin system public ui SELECT NULL YES -NULL admin system public ui UPDATE NULL NO -NULL root system public ui DELETE NULL NO -NULL root system public ui GRANT NULL NO -NULL root system public ui INSERT NULL NO -NULL root system public ui SELECT NULL YES -NULL root system public ui UPDATE NULL NO -NULL admin system public users DELETE NULL NO -NULL admin system public users GRANT NULL NO -NULL admin system public users INSERT NULL NO -NULL admin system public users SELECT NULL YES -NULL admin system public users UPDATE NULL NO -NULL root system public users DELETE NULL NO -NULL root system public users GRANT NULL NO -NULL root system public users INSERT NULL NO -NULL root system public users SELECT NULL YES -NULL root system public users UPDATE NULL NO -NULL admin system public web_sessions DELETE NULL NO -NULL admin system public web_sessions GRANT NULL NO -NULL admin system public web_sessions INSERT NULL NO -NULL admin system public web_sessions SELECT NULL YES -NULL admin system public web_sessions UPDATE NULL NO -NULL root system public web_sessions DELETE NULL NO -NULL root system public web_sessions GRANT NULL NO -NULL root system public web_sessions INSERT NULL NO -NULL root system public web_sessions SELECT NULL YES -NULL root system public web_sessions UPDATE NULL NO -NULL admin system public zones DELETE NULL NO -NULL admin system public zones GRANT NULL NO -NULL admin system public zones INSERT NULL NO -NULL admin system public zones SELECT NULL YES -NULL admin system public zones UPDATE NULL NO -NULL root system public zones DELETE NULL NO -NULL root system public zones GRANT NULL NO -NULL root system public zones INSERT NULL NO -NULL root system public zones SELECT NULL YES -NULL root system public zones UPDATE NULL NO - -query TTTTTTTT colnames -SELECT * FROM system.information_schema.role_table_grants ----- -grantor grantee table_catalog table_schema table_name privilege_type is_grantable with_hierarchy -NULL public system crdb_internal backward_dependencies SELECT NULL YES -NULL public system crdb_internal builtin_functions SELECT NULL YES -NULL public system crdb_internal cluster_queries SELECT NULL YES -NULL public system crdb_internal cluster_sessions SELECT NULL YES -NULL public system crdb_internal cluster_settings SELECT NULL YES -NULL public system crdb_internal create_statements SELECT NULL YES -NULL public system crdb_internal feature_usage SELECT NULL YES -NULL public system crdb_internal forward_dependencies SELECT NULL YES -NULL public system crdb_internal gossip_alerts SELECT NULL YES -NULL public system crdb_internal gossip_liveness SELECT NULL YES -NULL public system crdb_internal gossip_network SELECT NULL YES -NULL public system crdb_internal gossip_nodes SELECT NULL YES -NULL public system crdb_internal index_columns SELECT NULL YES -NULL public system crdb_internal jobs SELECT NULL YES -NULL public system crdb_internal kv_node_status SELECT NULL YES -NULL public system crdb_internal kv_store_status SELECT NULL YES -NULL public system crdb_internal leases SELECT NULL YES -NULL public system crdb_internal node_build_info SELECT NULL YES -NULL public system crdb_internal node_metrics SELECT NULL YES -NULL public system crdb_internal node_queries SELECT NULL YES -NULL public system crdb_internal node_runtime_info SELECT NULL YES -NULL public system crdb_internal node_sessions SELECT NULL YES -NULL public system crdb_internal node_statement_statistics SELECT NULL YES -NULL public system crdb_internal partitions SELECT NULL YES -NULL public system crdb_internal predefined_comments SELECT NULL YES -NULL public system crdb_internal ranges SELECT NULL YES -NULL public system crdb_internal ranges_no_leases SELECT NULL YES -NULL public system crdb_internal schema_changes SELECT NULL YES -NULL public system crdb_internal session_trace SELECT NULL YES -NULL public system crdb_internal session_variables SELECT NULL YES -NULL public system crdb_internal table_columns SELECT NULL YES -NULL public system crdb_internal table_indexes SELECT NULL YES -NULL public system crdb_internal tables SELECT NULL YES -NULL public system crdb_internal zones SELECT NULL YES -NULL public system information_schema administrable_role_authorizations SELECT NULL YES -NULL public system information_schema applicable_roles SELECT NULL YES -NULL public system information_schema column_privileges SELECT NULL YES -NULL public system information_schema columns SELECT NULL YES -NULL public system information_schema constraint_column_usage SELECT NULL YES -NULL public system information_schema enabled_roles SELECT NULL YES -NULL public system information_schema key_column_usage SELECT NULL YES -NULL public system information_schema parameters SELECT NULL YES -NULL public system information_schema referential_constraints SELECT NULL YES -NULL public system information_schema role_table_grants SELECT NULL YES -NULL public system information_schema routines SELECT NULL YES -NULL public system information_schema schema_privileges SELECT NULL YES -NULL public system information_schema schemata SELECT NULL YES -NULL public system information_schema sequences SELECT NULL YES -NULL public system information_schema statistics SELECT NULL YES -NULL public system information_schema table_constraints SELECT NULL YES -NULL public system information_schema table_privileges SELECT NULL YES -NULL public system information_schema tables SELECT NULL YES -NULL public system information_schema user_privileges SELECT NULL YES -NULL public system information_schema views SELECT NULL YES -NULL public system pg_catalog pg_am SELECT NULL YES -NULL public system pg_catalog pg_attrdef SELECT NULL YES -NULL public system pg_catalog pg_attribute SELECT NULL YES -NULL public system pg_catalog pg_auth_members SELECT NULL YES -NULL public system pg_catalog pg_class SELECT NULL YES -NULL public system pg_catalog pg_collation SELECT NULL YES -NULL public system pg_catalog pg_constraint SELECT NULL YES -NULL public system pg_catalog pg_database SELECT NULL YES -NULL public system pg_catalog pg_depend SELECT NULL YES -NULL public system pg_catalog pg_description SELECT NULL YES -NULL public system pg_catalog pg_enum SELECT NULL YES -NULL public system pg_catalog pg_extension SELECT NULL YES -NULL public system pg_catalog pg_foreign_data_wrapper SELECT NULL YES -NULL public system pg_catalog pg_foreign_server SELECT NULL YES -NULL public system pg_catalog pg_foreign_table SELECT NULL YES -NULL public system pg_catalog pg_index SELECT NULL YES -NULL public system pg_catalog pg_indexes SELECT NULL YES -NULL public system pg_catalog pg_inherits SELECT NULL YES -NULL public system pg_catalog pg_language SELECT NULL YES -NULL public system pg_catalog pg_namespace SELECT NULL YES -NULL public system pg_catalog pg_operator SELECT NULL YES -NULL public system pg_catalog pg_proc SELECT NULL YES -NULL public system pg_catalog pg_range SELECT NULL YES -NULL public system pg_catalog pg_rewrite SELECT NULL YES -NULL public system pg_catalog pg_roles SELECT NULL YES -NULL public system pg_catalog pg_seclabel SELECT NULL YES -NULL public system pg_catalog pg_sequence SELECT NULL YES -NULL public system pg_catalog pg_settings SELECT NULL YES -NULL public system pg_catalog pg_shdescription SELECT NULL YES -NULL public system pg_catalog pg_shseclabel SELECT NULL YES -NULL public system pg_catalog pg_stat_activity SELECT NULL YES -NULL public system pg_catalog pg_tables SELECT NULL YES -NULL public system pg_catalog pg_tablespace SELECT NULL YES -NULL public system pg_catalog pg_trigger SELECT NULL YES -NULL public system pg_catalog pg_type SELECT NULL YES -NULL public system pg_catalog pg_user SELECT NULL YES -NULL public system pg_catalog pg_user_mapping SELECT NULL YES -NULL public system pg_catalog pg_views SELECT NULL YES -NULL admin system public namespace GRANT NULL NO -NULL admin system public namespace SELECT NULL YES -NULL root system public namespace GRANT NULL NO -NULL root system public namespace SELECT NULL YES -NULL admin system public descriptor GRANT NULL NO -NULL admin system public descriptor SELECT NULL YES -NULL root system public descriptor GRANT NULL NO -NULL root system public descriptor SELECT NULL YES -NULL admin system public users DELETE NULL NO -NULL admin system public users GRANT NULL NO -NULL admin system public users INSERT NULL NO -NULL admin system public users SELECT NULL YES -NULL admin system public users UPDATE NULL NO -NULL root system public users DELETE NULL NO -NULL root system public users GRANT NULL NO -NULL root system public users INSERT NULL NO -NULL root system public users SELECT NULL YES -NULL root system public users UPDATE NULL NO -NULL admin system public zones DELETE NULL NO -NULL admin system public zones GRANT NULL NO -NULL admin system public zones INSERT NULL NO -NULL admin system public zones SELECT NULL YES -NULL admin system public zones UPDATE NULL NO -NULL root system public zones DELETE NULL NO -NULL root system public zones GRANT NULL NO -NULL root system public zones INSERT NULL NO -NULL root system public zones SELECT NULL YES -NULL root system public zones UPDATE NULL NO -NULL admin system public settings DELETE NULL NO -NULL admin system public settings GRANT NULL NO -NULL admin system public settings INSERT NULL NO -NULL admin system public settings SELECT NULL YES -NULL admin system public settings UPDATE NULL NO -NULL root system public settings DELETE NULL NO -NULL root system public settings GRANT NULL NO -NULL root system public settings INSERT NULL NO -NULL root system public settings SELECT NULL YES -NULL root system public settings UPDATE NULL NO -NULL admin system public lease DELETE NULL NO -NULL admin system public lease GRANT NULL NO -NULL admin system public lease INSERT NULL NO -NULL admin system public lease SELECT NULL YES -NULL admin system public lease UPDATE NULL NO -NULL root system public lease DELETE NULL NO -NULL root system public lease GRANT NULL NO -NULL root system public lease INSERT NULL NO -NULL root system public lease SELECT NULL YES -NULL root system public lease UPDATE NULL NO -NULL admin system public eventlog DELETE NULL NO -NULL admin system public eventlog GRANT NULL NO -NULL admin system public eventlog INSERT NULL NO -NULL admin system public eventlog SELECT NULL YES -NULL admin system public eventlog UPDATE NULL NO -NULL root system public eventlog DELETE NULL NO -NULL root system public eventlog GRANT NULL NO -NULL root system public eventlog INSERT NULL NO -NULL root system public eventlog SELECT NULL YES -NULL root system public eventlog UPDATE NULL NO -NULL admin system public rangelog DELETE NULL NO -NULL admin system public rangelog GRANT NULL NO -NULL admin system public rangelog INSERT NULL NO -NULL admin system public rangelog SELECT NULL YES -NULL admin system public rangelog UPDATE NULL NO -NULL root system public rangelog DELETE NULL NO -NULL root system public rangelog GRANT NULL NO -NULL root system public rangelog INSERT NULL NO -NULL root system public rangelog SELECT NULL YES -NULL root system public rangelog UPDATE NULL NO -NULL admin system public ui DELETE NULL NO -NULL admin system public ui GRANT NULL NO -NULL admin system public ui INSERT NULL NO -NULL admin system public ui SELECT NULL YES -NULL admin system public ui UPDATE NULL NO -NULL root system public ui DELETE NULL NO -NULL root system public ui GRANT NULL NO -NULL root system public ui INSERT NULL NO -NULL root system public ui SELECT NULL YES -NULL root system public ui UPDATE NULL NO -NULL admin system public jobs DELETE NULL NO -NULL admin system public jobs GRANT NULL NO -NULL admin system public jobs INSERT NULL NO -NULL admin system public jobs SELECT NULL YES -NULL admin system public jobs UPDATE NULL NO -NULL root system public jobs DELETE NULL NO -NULL root system public jobs GRANT NULL NO -NULL root system public jobs INSERT NULL NO -NULL root system public jobs SELECT NULL YES -NULL root system public jobs UPDATE NULL NO -NULL admin system public web_sessions DELETE NULL NO -NULL admin system public web_sessions GRANT NULL NO -NULL admin system public web_sessions INSERT NULL NO -NULL admin system public web_sessions SELECT NULL YES -NULL admin system public web_sessions UPDATE NULL NO -NULL root system public web_sessions DELETE NULL NO -NULL root system public web_sessions GRANT NULL NO -NULL root system public web_sessions INSERT NULL NO -NULL root system public web_sessions SELECT NULL YES -NULL root system public web_sessions UPDATE NULL NO -NULL admin system public table_statistics DELETE NULL NO -NULL admin system public table_statistics GRANT NULL NO -NULL admin system public table_statistics INSERT NULL NO -NULL admin system public table_statistics SELECT NULL YES -NULL admin system public table_statistics UPDATE NULL NO -NULL root system public table_statistics DELETE NULL NO -NULL root system public table_statistics GRANT NULL NO -NULL root system public table_statistics INSERT NULL NO -NULL root system public table_statistics SELECT NULL YES -NULL root system public table_statistics UPDATE NULL NO -NULL admin system public locations DELETE NULL NO -NULL admin system public locations GRANT NULL NO -NULL admin system public locations INSERT NULL NO -NULL admin system public locations SELECT NULL YES -NULL admin system public locations UPDATE NULL NO -NULL root system public locations DELETE NULL NO -NULL root system public locations GRANT NULL NO -NULL root system public locations INSERT NULL NO -NULL root system public locations SELECT NULL YES -NULL root system public locations UPDATE NULL NO -NULL admin system public role_members DELETE NULL NO -NULL admin system public role_members GRANT NULL NO -NULL admin system public role_members INSERT NULL NO -NULL admin system public role_members SELECT NULL YES -NULL admin system public role_members UPDATE NULL NO -NULL root system public role_members DELETE NULL NO -NULL root system public role_members GRANT NULL NO -NULL root system public role_members INSERT NULL NO -NULL root system public role_members SELECT NULL YES -NULL root system public role_members UPDATE NULL NO -NULL admin system public comments DELETE NULL NO -NULL admin system public comments GRANT NULL NO -NULL admin system public comments INSERT NULL NO -NULL admin system public comments SELECT NULL YES -NULL admin system public comments UPDATE NULL NO -NULL public system public comments DELETE NULL NO -NULL public system public comments GRANT NULL NO -NULL public system public comments INSERT NULL NO -NULL public system public comments SELECT NULL YES -NULL public system public comments UPDATE NULL NO -NULL root system public comments DELETE NULL NO -NULL root system public comments GRANT NULL NO -NULL root system public comments INSERT NULL NO -NULL root system public comments SELECT NULL YES -NULL root system public comments UPDATE NULL NO - -statement ok -CREATE TABLE other_db.xyz (i INT) - -statement ok -CREATE VIEW other_db.abc AS SELECT i from other_db.xyz - -query TTTTTTTT colnames -SELECT * FROM other_db.information_schema.table_privileges WHERE TABLE_SCHEMA = 'public' ----- -grantor grantee table_catalog table_schema table_name privilege_type is_grantable with_hierarchy -NULL admin other_db public xyz ALL NULL NO -NULL root other_db public xyz ALL NULL NO -NULL testuser other_db public xyz SELECT NULL YES -NULL admin other_db public abc ALL NULL NO -NULL root other_db public abc ALL NULL NO -NULL testuser other_db public abc SELECT NULL YES - -query TTTTTTTT colnames -SELECT * FROM other_db.information_schema.role_table_grants WHERE TABLE_SCHEMA = 'public' ----- -grantor grantee table_catalog table_schema table_name privilege_type is_grantable with_hierarchy -NULL admin other_db public xyz ALL NULL NO -NULL root other_db public xyz ALL NULL NO -NULL testuser other_db public xyz SELECT NULL YES -NULL admin other_db public abc ALL NULL NO -NULL root other_db public abc ALL NULL NO -NULL testuser other_db public abc SELECT NULL YES - -statement ok -GRANT UPDATE ON other_db.xyz TO testuser - -query TTTTTTTT colnames -SELECT * FROM other_db.information_schema.table_privileges WHERE TABLE_SCHEMA = 'public' ----- -grantor grantee table_catalog table_schema table_name privilege_type is_grantable with_hierarchy -NULL admin other_db public xyz ALL NULL NO -NULL root other_db public xyz ALL NULL NO -NULL testuser other_db public xyz SELECT NULL YES -NULL testuser other_db public xyz UPDATE NULL NO -NULL admin other_db public abc ALL NULL NO -NULL root other_db public abc ALL NULL NO -NULL testuser other_db public abc SELECT NULL YES - -query TTTTTTTT colnames -SELECT * FROM other_db.information_schema.role_table_grants WHERE TABLE_SCHEMA = 'public' ----- -grantor grantee table_catalog table_schema table_name privilege_type is_grantable with_hierarchy -NULL admin other_db public xyz ALL NULL NO -NULL root other_db public xyz ALL NULL NO -NULL testuser other_db public xyz SELECT NULL YES -NULL testuser other_db public xyz UPDATE NULL NO -NULL admin other_db public abc ALL NULL NO -NULL root other_db public abc ALL NULL NO -NULL testuser other_db public abc SELECT NULL YES - -# testuser can read permissions as well -user testuser - -statement ok -SET DATABASE = other_db - -query TTTTTTTT colnames -SELECT * FROM information_schema.table_privileges WHERE TABLE_SCHEMA = 'public' ----- -grantor grantee table_catalog table_schema table_name privilege_type is_grantable with_hierarchy -NULL admin other_db public xyz ALL NULL NO -NULL root other_db public xyz ALL NULL NO -NULL testuser other_db public xyz SELECT NULL YES -NULL testuser other_db public xyz UPDATE NULL NO -NULL admin other_db public abc ALL NULL NO -NULL root other_db public abc ALL NULL NO -NULL testuser other_db public abc SELECT NULL YES - -query TTTTTTTT colnames -SELECT * FROM information_schema.role_table_grants WHERE TABLE_SCHEMA = 'public' ----- -grantor grantee table_catalog table_schema table_name privilege_type is_grantable with_hierarchy -NULL admin other_db public xyz ALL NULL NO -NULL root other_db public xyz ALL NULL NO -NULL testuser other_db public xyz SELECT NULL YES -NULL testuser other_db public xyz UPDATE NULL NO -NULL admin other_db public abc ALL NULL NO -NULL root other_db public abc ALL NULL NO -NULL testuser other_db public abc SELECT NULL YES - -statement ok -SET DATABASE = test - -user root - -## information_schema.statistics - -statement ok -CREATE TABLE other_db.teststatics(id INT PRIMARY KEY, c INT, d INT, e STRING, INDEX idx_c(c), UNIQUE INDEX idx_cd(c,d)) - -query TTTTTTITIITTT colnames -SELECT * FROM other_db.information_schema.statistics WHERE table_schema='public' AND table_name='teststatics' ORDER BY INDEX_SCHEMA,INDEX_NAME,SEQ_IN_INDEX ----- -table_catalog table_schema table_name non_unique index_schema index_name seq_in_index column_name COLLATION cardinality direction storing implicit -other_db public teststatics YES public idx_c 1 c NULL NULL ASC NO NO -other_db public teststatics YES public idx_c 2 id NULL NULL ASC NO YES -other_db public teststatics NO public idx_cd 1 c NULL NULL ASC NO NO -other_db public teststatics NO public idx_cd 2 d NULL NULL ASC NO NO -other_db public teststatics NO public idx_cd 3 id NULL NULL ASC NO YES -other_db public teststatics NO public primary 1 id NULL NULL ASC NO NO - -# Verify information_schema.views -statement ok -CREATE VIEW other_db.v_xyz AS SELECT i FROM other_db.xyz - -query TTTTT colnames -SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, VIEW_DEFINITION, CHECK_OPTION -FROM other_db.information_schema.views -WHERE TABLE_NAME='v_xyz' ----- -table_catalog table_schema table_name view_definition check_option -other_db public v_xyz SELECT i FROM other_db.public.xyz NULL - -query TTTTT colnames -SELECT IS_UPDATABLE, IS_INSERTABLE_INTO, IS_TRIGGER_UPDATABLE, IS_TRIGGER_DELETABLE, IS_TRIGGER_INSERTABLE_INTO -FROM other_db.information_schema.views -WHERE TABLE_NAME='v_xyz' ----- -is_updatable is_insertable_into is_trigger_updatable is_trigger_deletable is_trigger_insertable_into -NO NO NO NO NO - -statement ok -SET DATABASE = 'test' - -statement ok -DROP DATABASE other_db CASCADE - -#Verify information_schema.user_privileges - -query TTTT colnames,rowsort -SELECT * FROM information_schema.user_privileges ORDER BY grantee,privilege_type ----- -grantee table_catalog privilege_type is_grantable -admin test ALL NULL -admin test CREATE NULL -admin test DELETE NULL -admin test DROP NULL -admin test GRANT NULL -admin test INSERT NULL -admin test SELECT NULL -admin test UPDATE NULL -root test ALL NULL -root test CREATE NULL -root test DELETE NULL -root test DROP NULL -root test GRANT NULL -root test INSERT NULL -root test SELECT NULL -root test UPDATE NULL - -# information_schema.sequences - -statement ok -SET DATABASE = test - -query TTTTIIITTTTT -SELECT * FROM information_schema.sequences ----- - -statement ok -CREATE SEQUENCE test_seq - -statement ok -CREATE SEQUENCE test_seq_2 INCREMENT -1 MINVALUE 5 MAXVALUE 1000 START WITH 15 - - -query TTTTIIITTTTT colnames -SELECT * FROM information_schema.sequences ----- -sequence_catalog sequence_schema sequence_name data_type numeric_precision numeric_precision_radix numeric_scale start_value minimum_value maximum_value increment cycle_option -test public test_seq bigint 64 2 0 1 1 9223372036854775807 1 NO -test public test_seq_2 bigint 64 2 0 15 5 1000 -1 NO - -statement ok -CREATE DATABASE other_db - -statement ok -SET DATABASE = other_db - -# Sequences in one database can't be seen from another database. - -query TTTTIIITTTTT -SELECT * FROM information_schema.sequences ----- - -statement ok -SET DATABASE = test - -statement ok -DROP DATABASE other_db CASCADE - -# test information_schema.column_privileges -query TTBTTTB colnames -SHOW COLUMNS FROM information_schema.column_privileges ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -grantor STRING true NULL · {} false -grantee STRING false NULL · {} false -table_catalog STRING false NULL · {} false -table_schema STRING false NULL · {} false -table_name STRING false NULL · {} false -column_name STRING false NULL · {} false -privilege_type STRING false NULL · {} false -is_grantable STRING true NULL · {} false - - -# test information_schema.routines -query TTBTTTB colnames -SHOW COLUMNS FROM information_schema.routines ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -specific_catalog STRING true NULL · {} false -specific_schema STRING true NULL · {} false -specific_name STRING true NULL · {} false -routine_catalog STRING true NULL · {} false -routine_schema STRING true NULL · {} false -routine_name STRING true NULL · {} false -routine_type STRING true NULL · {} false -module_catalog STRING true NULL · {} false -module_schema STRING true NULL · {} false -module_name STRING true NULL · {} false -udt_catalog STRING true NULL · {} false -udt_schema STRING true NULL · {} false -udt_name STRING true NULL · {} false -data_type STRING true NULL · {} false -character_maximum_length INT8 true NULL · {} false -character_octet_length INT8 true NULL · {} false -character_set_catalog STRING true NULL · {} false -character_set_schema STRING true NULL · {} false -character_set_name STRING true NULL · {} false -collation_catalog STRING true NULL · {} false -collation_schema STRING true NULL · {} false -collation_name STRING true NULL · {} false -numeric_precision INT8 true NULL · {} false -numeric_precision_radix INT8 true NULL · {} false -numeric_scale INT8 true NULL · {} false -datetime_precision INT8 true NULL · {} false -interval_type STRING true NULL · {} false -interval_precision STRING true NULL · {} false -type_udt_catalog STRING true NULL · {} false -type_udt_schema STRING true NULL · {} false -type_udt_name STRING true NULL · {} false -scope_catalog STRING true NULL · {} false -scope_name STRING true NULL · {} false -maximum_cardinality INT8 true NULL · {} false -dtd_identifier STRING true NULL · {} false -routine_body STRING true NULL · {} false -routine_definition STRING true NULL · {} false -external_name STRING true NULL · {} false -external_language STRING true NULL · {} false -parameter_style STRING true NULL · {} false -is_deterministic STRING true NULL · {} false -sql_data_access STRING true NULL · {} false -is_null_call STRING true NULL · {} false -sql_path STRING true NULL · {} false -schema_level_routine STRING true NULL · {} false -max_dynamic_result_sets INT8 true NULL · {} false -is_user_defined_cast STRING true NULL · {} false -is_implicitly_invocable STRING true NULL · {} false -security_type STRING true NULL · {} false -to_sql_specific_catalog STRING true NULL · {} false -to_sql_specific_schema STRING true NULL · {} false -to_sql_specific_name STRING true NULL · {} false -as_locator STRING true NULL · {} false -created TIMESTAMPTZ true NULL · {} false -last_altered TIMESTAMPTZ true NULL · {} false -new_savepoint_level STRING true NULL · {} false -is_udt_dependent STRING true NULL · {} false -result_cast_from_data_type STRING true NULL · {} false -result_cast_as_locator STRING true NULL · {} false -result_cast_char_max_length INT8 true NULL · {} false -result_cast_char_octet_length STRING true NULL · {} false -result_cast_char_set_catalog STRING true NULL · {} false -result_cast_char_set_schema STRING true NULL · {} false -result_cast_char_set_name STRING true NULL · {} false -result_cast_collation_catalog STRING true NULL · {} false -result_cast_collation_schema STRING true NULL · {} false -result_cast_collation_name STRING true NULL · {} false -result_cast_numeric_precision INT8 true NULL · {} false -result_cast_numeric_precision_radix INT8 true NULL · {} false -result_cast_numeric_scale INT8 true NULL · {} false -result_cast_datetime_precision STRING true NULL · {} false -result_cast_interval_type STRING true NULL · {} false -result_cast_interval_precision INT8 true NULL · {} false -result_cast_type_udt_catalog STRING true NULL · {} false -result_cast_type_udt_schema STRING true NULL · {} false -result_cast_type_udt_name STRING true NULL · {} false -result_cast_scope_catalog STRING true NULL · {} false -result_cast_scope_schema STRING true NULL · {} false -result_cast_scope_name STRING true NULL · {} false -result_cast_maximum_cardinality INT8 true NULL · {} false -result_cast_dtd_identifier STRING true NULL · {} false - -query TTTTTTTTTTTTTTIITTTTTTIIIITTTTTTTITTTTTTTTTTTITTTTTTTTTTTTTITTTTTTTIIITTITTTTTTIT colnames -SELECT * FROM information_schema.routines ----- -specific_catalog specific_schema specific_name routine_catalog routine_schema routine_name routine_type module_catalog module_schema module_name udt_catalog udt_schema udt_name data_type character_maximum_length character_octet_length character_set_catalog character_set_schema character_set_name collation_catalog collation_schema collation_name numeric_precision numeric_precision_radix numeric_scale datetime_precision interval_type interval_precision type_udt_catalog type_udt_schema type_udt_name scope_catalog scope_name maximum_cardinality dtd_identifier routine_body routine_definition external_name external_language parameter_style is_deterministic sql_data_access is_null_call sql_path schema_level_routine max_dynamic_result_sets is_user_defined_cast is_implicitly_invocable security_type to_sql_specific_catalog to_sql_specific_schema to_sql_specific_name as_locator created last_altered new_savepoint_level is_udt_dependent result_cast_from_data_type result_cast_as_locator result_cast_char_max_length result_cast_char_octet_length result_cast_char_set_catalog result_cast_char_set_schema result_cast_char_set_name result_cast_collation_catalog result_cast_collation_schema result_cast_collation_name result_cast_numeric_precision result_cast_numeric_precision_radix result_cast_numeric_scale result_cast_datetime_precision result_cast_interval_type result_cast_interval_precision result_cast_type_udt_catalog result_cast_type_udt_schema result_cast_type_udt_name result_cast_scope_catalog result_cast_scope_schema result_cast_scope_name result_cast_maximum_cardinality result_cast_dtd_identifier - -# test information_schema.parameters -query TTBTTTB colnames -SHOW COLUMNS FROM information_schema.parameters ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -specific_catalog STRING true NULL · {} false -specific_schema STRING true NULL · {} false -specific_name STRING true NULL · {} false -ordinal_position INT8 true NULL · {} false -parameter_mode STRING true NULL · {} false -is_result STRING true NULL · {} false -as_locator STRING true NULL · {} false -parameter_name STRING true NULL · {} false -data_type STRING true NULL · {} false -character_maximum_length INT8 true NULL · {} false -character_octet_length INT8 true NULL · {} false -character_set_catalog STRING true NULL · {} false -character_set_schema STRING true NULL · {} false -character_set_name STRING true NULL · {} false -collation_catalog STRING true NULL · {} false -collation_schema STRING true NULL · {} false -collation_name STRING true NULL · {} false -numeric_precision INT8 true NULL · {} false -numeric_precision_radix INT8 true NULL · {} false -numeric_scale INT8 true NULL · {} false -datetime_precision INT8 true NULL · {} false -interval_type STRING true NULL · {} false -interval_precision INT8 true NULL · {} false -udt_catalog STRING true NULL · {} false -udt_schema STRING true NULL · {} false -udt_name STRING true NULL · {} false -scope_catalog STRING true NULL · {} false -scope_schema STRING true NULL · {} false -scope_name STRING true NULL · {} false -maximum_cardinality INT8 true NULL · {} false -dtd_identifier STRING true NULL · {} false -parameter_default STRING true NULL · {} false - -query TTTITTTTTIITTTTTTIIIITITTTTTTITT colnames -SELECT * FROM information_schema.parameters ----- -specific_catalog specific_schema specific_name ordinal_position parameter_mode is_result as_locator parameter_name data_type character_maximum_length character_octet_length character_set_catalog character_set_schema character_set_name collation_catalog collation_schema collation_name numeric_precision numeric_precision_radix numeric_scale datetime_precision interval_type interval_precision udt_catalog udt_schema udt_name scope_catalog scope_schema scope_name maximum_cardinality dtd_identifier parameter_default - -query TTTTTTTT colnames -SELECT * FROM system.information_schema.column_privileges WHERE table_name = 'eventlog' ----- -grantor grantee table_catalog table_schema table_name column_name privilege_type is_grantable -NULL admin system public eventlog timestamp SELECT NULL -NULL admin system public eventlog eventType SELECT NULL -NULL admin system public eventlog targetID SELECT NULL -NULL admin system public eventlog reportingID SELECT NULL -NULL admin system public eventlog info SELECT NULL -NULL admin system public eventlog uniqueID SELECT NULL -NULL admin system public eventlog timestamp INSERT NULL -NULL admin system public eventlog eventType INSERT NULL -NULL admin system public eventlog targetID INSERT NULL -NULL admin system public eventlog reportingID INSERT NULL -NULL admin system public eventlog info INSERT NULL -NULL admin system public eventlog uniqueID INSERT NULL -NULL admin system public eventlog timestamp UPDATE NULL -NULL admin system public eventlog eventType UPDATE NULL -NULL admin system public eventlog targetID UPDATE NULL -NULL admin system public eventlog reportingID UPDATE NULL -NULL admin system public eventlog info UPDATE NULL -NULL admin system public eventlog uniqueID UPDATE NULL -NULL root system public eventlog timestamp SELECT NULL -NULL root system public eventlog eventType SELECT NULL -NULL root system public eventlog targetID SELECT NULL -NULL root system public eventlog reportingID SELECT NULL -NULL root system public eventlog info SELECT NULL -NULL root system public eventlog uniqueID SELECT NULL -NULL root system public eventlog timestamp INSERT NULL -NULL root system public eventlog eventType INSERT NULL -NULL root system public eventlog targetID INSERT NULL -NULL root system public eventlog reportingID INSERT NULL -NULL root system public eventlog info INSERT NULL -NULL root system public eventlog uniqueID INSERT NULL -NULL root system public eventlog timestamp UPDATE NULL -NULL root system public eventlog eventType UPDATE NULL -NULL root system public eventlog targetID UPDATE NULL -NULL root system public eventlog reportingID UPDATE NULL -NULL root system public eventlog info UPDATE NULL -NULL root system public eventlog uniqueID UPDATE NULL - -# information_schema.administrable_role_authorizations - -query TTT colnames,rowsort -SELECT * FROM information_schema.administrable_role_authorizations ----- -grantee role_name is_grantable -root admin YES - -user testuser - -query TTT colnames,rowsort -SELECT * FROM information_schema.administrable_role_authorizations ----- -grantee role_name is_grantable - -user root - -# information_schema.applicable_roles - -query TTT colnames,rowsort -SELECT * FROM information_schema.applicable_roles ----- -grantee role_name is_grantable -root admin YES - -user testuser - -query TTT colnames,rowsort -SELECT * FROM information_schema.applicable_roles ----- -grantee role_name is_grantable - -user root - -# information_schema.enabled_roles - -query T colnames,rowsort -SELECT * FROM information_schema.enabled_roles ----- -role_name -admin -root - -user testuser - -query T colnames,rowsort -SELECT * FROM information_schema.enabled_roles ----- -role_name -testuser - -user root - -subtest fk_match_type - -statement ok -CREATE DATABASE dfk; SET database=dfk - -statement ok -CREATE TABLE v(x INT, y INT, UNIQUE (x,y)) - -statement ok -CREATE TABLE w( - a INT, b INT, c INT, d INT, - FOREIGN KEY (a,b) REFERENCES v(x,y) MATCH FULL, - FOREIGN KEY (c,d) REFERENCES v(x,y) MATCH SIMPLE - ); - -query TTTT -SELECT constraint_name, table_name, referenced_table_name, match_option - FROM information_schema.referential_constraints ----- -fk_a_ref_v w v FULL -fk_c_ref_v w v NONE - -statement ok -SET database = test - -statement ok -DROP DATABASE dfk CASCADE diff --git a/test/sqllogictest/cockroach/inner-join.slt b/test/sqllogictest/cockroach/inner-join.slt new file mode 100644 index 0000000000000..975da80648395 --- /dev/null +++ b/test/sqllogictest/cockroach/inner-join.slt @@ -0,0 +1,227 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/inner-join +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE abc (a INT, b INT, c INT, PRIMARY KEY (a, b)); +INSERT INTO abc VALUES (1, 1, 2), (2, 1, 1), (2, 2, NULL) + +statement ok +CREATE TABLE def (d INT, e INT, f INT, PRIMARY KEY (d, e)); +INSERT INTO def VALUES (1, 1, 2), (2, 1, 0), (1, 2, NULL) + +query III rowsort +SELECT * from abc WHERE EXISTS (SELECT * FROM def WHERE a=d) +---- +1 1 2 +2 1 1 +2 2 NULL + +# Test lookup inner joins created from semi-joins. +query III rowsort +SELECT * from abc WHERE EXISTS (SELECT * FROM def WHERE a=f) +---- +2 1 1 +2 2 NULL + +query III rowsort +SELECT * from abc WHERE EXISTS (SELECT * FROM def WHERE a=d AND c=e) +---- +1 1 2 +2 1 1 + +# Exists with primary key columns selected +query III rowsort +SELECT a, b, c FROM abc WHERE EXISTS (SELECT * FROM def WHERE a=d OR a=e) +---- +1 1 2 +2 1 1 +2 2 NULL + +# Exists with primary key columns not selected +query I rowsort +SELECT c FROM abc WHERE EXISTS (SELECT * FROM def WHERE a=d OR a=e) +---- +2 +1 +NULL + +# Not Exists with primary key columns selected +query III rowsort +SELECT a, b, c FROM abc WHERE NOT EXISTS (SELECT * FROM def WHERE a=d OR a=e) +---- + +# Not Exists with primary key columns not selected +query I rowsort +SELECT c FROM abc WHERE NOT EXISTS (SELECT * FROM def WHERE a=d OR a=e) +---- + + +# Not supported by Materialize. +onlyif cockroach +# A semi-join emits exactly one row for every matching row in the LHS. +# The following test ensures that the SemiJoin doesn't commute into an +# InnerJoin as that guarantee would be lost. +statement ok +TRUNCATE TABLE abc; TRUNCATE TABLE def; + +statement ok +INSERT INTO abc VALUES (1, 1, 1) + +statement ok +INSERT INTO def VALUES (1, 1, 1), (2, 1, 1) + +# Exists with primary key columns selected +query III rowsort +SELECT a, b, c FROM abc WHERE EXISTS (SELECT * FROM def WHERE a=d OR a=e) +---- +1 1 1 +1 1 2 +2 1 1 +2 2 NULL + +# Exists with primary key columns not selected +query I rowsort +SELECT c FROM abc WHERE EXISTS (SELECT * FROM def WHERE a=d OR a=e) +---- +1 +1 +2 +NULL + +# Not Exists with primary key columns selected +query III rowsort +SELECT a, b, c FROM abc WHERE NOT EXISTS (SELECT * FROM def WHERE a=d OR a=e) +---- + +# Not Exists with primary key columns not selected +query I rowsort +SELECT c FROM abc WHERE NOT EXISTS (SELECT * FROM def WHERE a=d OR a=e) +---- + +# Given that we know the reason the above query would fail if an InnerJoin +# was used - multiple rows emitted for each matching row in the LHS - we +# might think that adding a DistinctOn over the InnerJoin would help. +# This test shows why that wouldn't work. There are two reasons: +# +# - The columns of the LHS that are emitted aren't guaranteed to be a key. +# This means that only unique rows are returned when that is not what the +# SemiJoin should return (notice the (1, 1, 1) row is emitted twice) +# - We can't handle general filters because of composite datums (values that +# are equal but not identical). For example the decimals 1, 1.0 and 1.00 +# are equal but have different string representations. +# The DistinctOn on the RHS would omit important rows in that case. +# +# This tests that the InnerJoin commute rule for semi joins behaves sanely in +# these cases. + +# InnerJoin with primary key columns selected +query III rowsort +SELECT a, b, c FROM abc, def WHERE a=d OR a=e +---- +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 2 +1 1 2 +1 1 2 +1 1 2 +1 1 2 +2 1 1 +2 1 1 +2 1 1 +2 2 NULL +2 2 NULL +2 2 NULL + +# InnerJoin with primary key columns not selected +query I rowsort +SELECT c FROM abc, def WHERE a=d OR a=e +---- +1 +1 +1 +1 +1 +1 +1 +1 +2 +2 +2 +2 +2 +NULL +NULL +NULL + +statement ok +CREATE TABLE abc_decimal (a DECIMAL, b DECIMAL, c DECIMAL); +INSERT INTO abc_decimal VALUES (1, 1, 1), (1, 1, 1), (1.0, 1.0, 1.0), (1.00, 1.00, 1.00) + +statement ok +CREATE TABLE def_decimal (d DECIMAL, e DECIMAL, f DECIMAL); +INSERT INTO def_decimal VALUES (1, 1, 1), (1.0, 1.0, 1.0), (1.00, 1.00, 1.00) + +query RRR rowsort +SELECT a, b, c FROM abc_decimal WHERE EXISTS (SELECT * FROM def_decimal WHERE a::string=d::string) +---- +1 1 1 +1 1 1 +1 1 1 +1 1 1 + +query RRR rowsort +SELECT a, b, c FROM abc_decimal WHERE EXISTS (SELECT * FROM def_decimal WHERE a::string=d::string or a::string=e::string) +---- +1 1 1 +1 1 1 +1 1 1 +1 1 1 + +# DB-130 / DB-137 (https://linear.app/materializeinc/issue/DB-130): Materialize's +# numeric-to-text cast drops trailing-zero scale, so 1, 1.0 and 1.00 all cast to +# "1" and compare equal, making every abc/def pair match. PG and CockroachDB keep +# the scale ("1", "1.0", "1.00"), so this cross join matches only scale-aligned +# pairs and returns 4 rows (all "1 1 1"), not 12. +query RRR rowsort +SELECT a, b, c FROM abc_decimal, def_decimal WHERE a::string=d::string or a::string=e::string +---- +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 + +query RRR rowsort +SELECT a, b, c FROM abc_decimal WHERE NOT EXISTS (SELECT * FROM def_decimal WHERE a::string=d::string or a::string=e::string) +---- diff --git a/test/sqllogictest/cockroach/insert.slt b/test/sqllogictest/cockroach/insert.slt deleted file mode 100644 index 58b0583a74ee8..0000000000000 --- a/test/sqllogictest/cockroach/insert.slt +++ /dev/null @@ -1,729 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/insert -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -statement error pgcode 42P01 relation "kv" does not exist -INSERT INTO kv VALUES ('a', 'b') - -statement ok -CREATE TABLE kv ( - k VARCHAR PRIMARY KEY, - v VARCHAR, - UNIQUE INDEX a (v), - FAMILY (k), - FAMILY (v) -) - -query TT -SELECT * FROM kv ----- - -statement ok -INSERT INTO kv VALUES ('A') - -statement error missing "k" primary key column -INSERT INTO kv (v) VALUES ('a') - -statement ok -INSERT INTO kv (k) VALUES ('nil1') - -statement ok -INSERT INTO kv (k) VALUES ('nil2') - -statement ok -INSERT INTO kv VALUES ('nil3', NULL) - -statement ok -INSERT INTO kv VALUES ('nil4', NULL) - -statement ok -INSERT INTO kv (k,v) VALUES ('a', 'b'), ('c', 'd') - -query T -SELECT v || 'hello' FROM [INSERT INTO kv VALUES ('e', 'f'), ('g', '') RETURNING v] ----- -fhello -hello - -statement error pgcode 23505 duplicate key value \(v\)=\('f'\) violates unique constraint "a" -INSERT INTO kv VALUES ('h', 'f') - -statement ok -INSERT INTO kv VALUES ('f', 'g') - -statement error duplicate key value \(v\)=\('g'\) violates unique constraint "a" -INSERT INTO kv VALUES ('h', 'g') - -query TT -SELECT * FROM kv ORDER BY k ----- -A NULL -a b -c d -e f -f g -g · -nil1 NULL -nil2 NULL -nil3 NULL -nil4 NULL - -statement ok -CREATE TABLE kv2 ( - k CHAR, - v CHAR, - UNIQUE INDEX a (v), - PRIMARY KEY (k, v) -) - -statement ok -INSERT INTO kv2 VALUES ('a', 'b'), ('c', 'd'), ('e', 'f'), ('f', 'g') - -query TT rowsort -SELECT * FROM kv2 ----- -a b -c d -e f -f g - -statement ok -CREATE TABLE kv3 ( - k CHAR PRIMARY KEY, - v CHAR NOT NULL -) - -statement error null value in column "v" violates not-null constraint -INSERT INTO kv3 VALUES ('a') - -statement error null value in column "v" violates not-null constraint -INSERT INTO kv3 VALUES ('a', NULL) - -statement error null value in column "v" violates not-null constraint -INSERT INTO kv3 (k) VALUES ('a') - -query TT -SELECT * FROM kv3 ----- - -statement ok -CREATE TABLE kv4 ( - int INT PRIMARY KEY, - bit BIT, - bool BOOLEAN, - char CHAR, - float FLOAT -) - -statement error could not parse "a" as type int -INSERT INTO kv4 (int) VALUES ('a') - -statement ok -INSERT INTO kv4 (int) VALUES (1) - -statement error could not parse string as bit array: "a" is not a valid binary digit -INSERT INTO kv4 (int, bit) VALUES (2, 'a') - -statement ok -INSERT INTO kv4 (int, bit) VALUES (2, B'1') - -statement error could not parse "a" as type bool -INSERT INTO kv4 (int, bool) VALUES (3, 'a') - -statement ok -INSERT INTO kv4 (int, bool) VALUES (3, true) - -statement error value type int doesn't match type char of column "char" -INSERT INTO kv4 (int, char) VALUES (4, 1) - -statement ok -INSERT INTO kv4 (int, char) VALUES (4, 'a') - -statement error value type int doesn't match type float of column "float" -INSERT INTO kv4 (int, float) VALUES (5, 1::INT) - -statement ok -INSERT INTO kv4 (int, float) VALUES (5, 2.3) - -query ITBTR rowsort -SELECT * from kv4 ----- -1 NULL NULL NULL NULL -2 1 NULL NULL NULL -3 NULL true NULL NULL -4 NULL NULL a NULL -5 NULL NULL NULL 2.3 - -statement ok -CREATE TABLE kv5 ( - k CHAR PRIMARY KEY, - v CHAR, - UNIQUE INDEX a (v, k) -) - -statement ok -INSERT INTO kv5 VALUES ('a', NULL) - -statement error VALUES lists must all be the same length, expected 1 columns, found 2 -INSERT INTO kv5 VALUES ('b'), ('c', DEFAULT) - -query TT -SELECT v, k FROM kv5@a ----- -NULL a - -statement error INSERT has more expressions than target columns, 3 expressions for 2 targets -INSERT INTO kv SELECT 'a', 'b', 'c' - -statement error INSERT has more expressions than target columns, 2 expressions for 1 targets -INSERT INTO kv (k) SELECT 'a', 'b' - -statement error INSERT has more target columns than expressions, 1 expressions for 2 targets -INSERT INTO kv5 (k, v) SELECT 'a' - -# INSERT ... VALUES take a separate code path from INSERT ... SELECT. - -statement error INSERT has more expressions than target columns, 3 expressions for 2 targets -INSERT INTO kv VALUES ('a', 'b', 'c') - -statement error INSERT has more expressions than target columns, 2 expressions for 1 targets -INSERT INTO kv (k) VALUES ('a', 'b') - -statement error INSERT has more target columns than expressions, 1 expressions for 2 targets -INSERT INTO kv5 (k, v) VALUES ('a') - -statement ok -CREATE TABLE return (a INT DEFAULT 3, b INT) - -query III -INSERT INTO return (a) VALUES (default), (8) RETURNING a, 2, a+4 ----- -3 2 7 -8 2 12 - -query III -INSERT INTO return (b) VALUES (default), (8) RETURNING a, a+4, b ----- -3 7 NULL -3 7 8 - -# All columns returned if none specified. -query II -INSERT INTO return VALUES (default) RETURNING a, b ----- -3 NULL - -# Test column names -query III colnames -INSERT INTO return VALUES (default) RETURNING a, b AS c, 4 AS d ----- -a c d -3 NULL 4 - -# Return a qualified name -query I -INSERT INTO return VALUES (default) RETURNING return.a ----- -3 - -# Can fetch rowid -statement ok -INSERT INTO return VALUES (default) RETURNING rowid != unique_rowid() - -query I colnames -INSERT INTO return (a) VALUES (default) RETURNING b ----- -b -NULL - -query III -INSERT INTO return (b) VALUES (1) RETURNING *, a+1 ----- -3 1 4 - -query II colnames -INSERT INTO return VALUES (default) RETURNING * ----- -a b -3 NULL - -query II colnames -INSERT INTO return VALUES (1, 2), (3, 4) RETURNING return.a, b ----- -a b -1 2 -3 4 - -query II colnames -INSERT INTO return VALUES (1, 2), (3, 4) RETURNING * ----- -a b -1 2 -3 4 - -# Verify we return all columns even if we don't provide a value for all of them. -query II colnames -INSERT INTO return VALUES (1) RETURNING * ----- -a b -1 NULL - -query II colnames -INSERT INTO return (a) VALUES (1) RETURNING * ----- -a b -1 NULL - -statement error pq: "return.*" cannot be aliased -INSERT INTO return VALUES (1, 2), (3, 4) RETURNING return.* as x - -query III colnames -INSERT INTO return VALUES (1, 2), (3, 4) RETURNING return.*, a + b AS c ----- -a b c -1 2 3 -3 4 7 - -# Table alias -statement ok -INSERT INTO return AS r VALUES (5, 6) - -# TODO(knz) after cockroach#6092 is fixed -# statement ok -# INSERT INTO return AS r VALUES (5, 6) RETURNING r.a - -# materialize#17008: allow fully-qualified table names in RETURNING clauses -statement ok -INSERT INTO return VALUES (5, 6) RETURNING test.return.a - -statement error no data source matches pattern: x.\* -INSERT INTO return VALUES (1, 2) RETURNING x.*[1] - -statement error column "x" does not exist -INSERT INTO return VALUES (1, 2) RETURNING x[1] - -statement ok -CREATE VIEW kview AS VALUES ('a', 'b'), ('c', 'd') - -query TT -SELECT * FROM kview ----- -a b -c d - -statement error "kview" is not a table -INSERT INTO kview VALUES ('e', 'f') - -query TT -SELECT * FROM kview ----- -a b -c d - -statement ok -CREATE TABLE abc ( - a INT, - b INT, - c INT, - PRIMARY KEY (a, b), - INDEX a (a) -) - -statement ok -INSERT INTO abc VALUES (1, 2, 10) - -# Verify we get the correct message, even though internally the ConditionalPut -# for the index key will also fail. -statement error pgcode 23505 duplicate key value \(a,b\)=\(1,2\) violates unique constraint "primary" -INSERT INTO abc VALUES (1, 2, 20) - -statement ok -CREATE TABLE decimal ( - a DECIMAL PRIMARY KEY -) - -statement ok -INSERT INTO decimal VALUES (4) - -# Verify that the "blind" ConditionalPut optimization correctly handles a batch -# with two CPuts of the same key. -statement ok -CREATE TABLE blindcput ( - x INT, - v INT, - PRIMARY KEY (x) -) - -# The optimization thresholds at 10 k/v operations, so we need at least that -# many in one batch to trigger it. -statement error duplicate key value \(x\)=\(1\) violates unique constraint "primary" -INSERT INTO blindcput values (1, 1), (2, 2), (3, 3), (4, 4), (1, 5) - -statement ok -CREATE TABLE nocols() - -statement error INSERT has more expressions than target columns, 2 expressions for 0 targets -INSERT INTO nocols VALUES (true, default) - -statement error unimplemented at or near "k" -INSERT INTO kv (kv.k) VALUES ('hello') - -statement error unimplemented at or near "*" -INSERT INTO kv (k.*) VALUES ('hello') - -statement error unimplemented at or near "v" -INSERT INTO kv (k.v) VALUES ('hello') - - - -statement ok -CREATE TABLE insert_t (x INT, v INT) - -statement ok -CREATE TABLE select_t (x INT, v INT) - -statement ok -INSERT INTO select_t VALUES (1, 9), (8, 2), (3, 7), (6, 4) - -# Check that INSERT supports ORDER BY (MySQL extension) -query II rowsort -INSERT INTO insert_t TABLE select_t ORDER BY v DESC LIMIT 3 RETURNING x, v ----- -1 9 -3 7 -6 4 - -# Check that INSERT supports LIMIT (MySQL extension) - -statement ok -TRUNCATE TABLE insert_t - -statement ok -INSERT INTO insert_t SELECT * FROM select_t LIMIT 1 - -query II -SELECT * FROM insert_t ----- -1 9 - -statement ok -TRUNCATE TABLE insert_t - -statement ok -INSERT INTO insert_t (SELECT * FROM select_t LIMIT 1) - -query II -SELECT * FROM insert_t ----- -1 9 - -statement error pq: multiple LIMIT clauses not allowed -INSERT INTO insert_t (VALUES (1,1), (2,2) LIMIT 1) LIMIT 1 - -statement error pq: multiple ORDER BY clauses not allowed -INSERT INTO insert_t (VALUES (1,1), (2,2) ORDER BY 2) ORDER BY 2 - -statement error DEFAULT can only appear in a VALUES list within INSERT or on the right side of a SET -INSERT INTO insert_t (VALUES (1, DEFAULT), (2,'BBB') LIMIT 1) - -statement error DEFAULT can only appear in a VALUES list within INSERT or on the right side of a SET -INSERT INTO insert_t (VALUES (1, DEFAULT), (2,'BBB')) LIMIT 1 - -subtest string_bytes_conflicts - -statement ok -CREATE TABLE bytes_t ( - b BYTES PRIMARY KEY -) - -statement ok -INSERT INTO bytes_t VALUES ('byte') - -statement ok -CREATE TABLE string_t ( - s STRING PRIMARY KEY -) - -statement ok -INSERT INTO string_t VALUES ('str') - -query error value type text doesn't match type bytes of column "b" -INSERT INTO bytes_t SELECT * FROM string_t - -query error value type bytes doesn't match type text of column "s" -INSERT INTO string_t SELECT * FROM bytes_t - -subtest string_width_check - -statement ok -CREATE TABLE sw ( - a CHAR, - b CHAR(3), - c VARCHAR, - d VARCHAR(3), - e STRING, - f STRING(3), - g "char", - ac CHAR COLLATE en, - bc CHAR(3) COLLATE en, - cc VARCHAR COLLATE en, - dc VARCHAR(3) COLLATE en, - ec STRING COLLATE en, - fc STRING(3) COLLATE en -) - -query T -SELECT create_statement FROM [SHOW CREATE TABLE sw] ----- -CREATE TABLE sw ( - a CHAR NULL, - b CHAR(3) NULL, - c VARCHAR NULL, - d VARCHAR(3) NULL, - e STRING NULL, - f STRING(3) NULL, - g "char" NULL, - ac CHAR COLLATE en NULL, - bc CHAR(3) COLLATE en NULL, - cc VARCHAR COLLATE en NULL, - dc VARCHAR(3) COLLATE en NULL, - ec STRING COLLATE en NULL, - fc STRING(3) COLLATE en NULL, - FAMILY "primary" (a, b, c, d, e, f, g, ac, bc, cc, dc, ec, fc, rowid) -) - -statement ok -INSERT INTO sw VALUES ( - 'a', 'b', 'c', 'd', 'e', 'f', 'g', - 'A' COLLATE en, 'B' COLLATE en, 'C' COLLATE en, 'D' COLLATE en, 'E' COLLATE en, 'F' COLLATE en) - -statement ok -INSERT INTO sw VALUES ( - '', '', '', '', '', '', '', - '' COLLATE en, '' COLLATE en, '' COLLATE en, '' COLLATE en, '' COLLATE en, '' COLLATE en) - -statement error value too long for type CHAR \(column "a"\) -INSERT INTO sw(a) VALUES ('ab') - -statement error value too long for type CHAR COLLATE en \(column "ac"\) -INSERT INTO sw(ac) VALUES ('ab' COLLATE en) - -statement ok -INSERT INTO sw (b, c, d, e, f, g, bc, cc, dc, ec, fc) VALUES ( - 'b22', 'c22', 'd22', 'e22', 'f22', 'g22', - 'B22' COLLATE en, 'C22' COLLATE en, 'D22' COLLATE en, 'E22' COLLATE en, 'F22' COLLATE en) - -statement error value too long for type CHAR\(3\) \(column "b"\) -INSERT INTO sw(b) VALUES ('abcd') - -statement error value too long for type CHAR\(3\) COLLATE en \(column "bc"\) -INSERT INTO sw(bc) VALUES ('abcd' COLLATE en) - -statement error value too long for type VARCHAR\(3\) \(column "d"\) -INSERT INTO sw(d) VALUES ('abcd') - -statement error value too long for type VARCHAR\(3\) COLLATE en \(column "dc"\) -INSERT INTO sw(dc) VALUES ('abcd' COLLATE en) - -statement error value too long for type STRING\(3\) \(column "f"\) -INSERT INTO sw(f) VALUES ('abcd') - -statement error value too long for type STRING\(3\) COLLATE en \(column "fc"\) -INSERT INTO sw(fc) VALUES ('abcd' COLLATE en) - -subtest regression_26742 - -statement ok -CREATE TABLE ct(x INT, derived INT AS (x+1) STORED) - -statement error value type varchar doesn't match type int of column "x" -INSERT INTO ct(x) SELECT c FROM sw - -subtest contraint_check_validation_ordering - -# Verification of column constraints vs CHECK handling. The column -# constraint verification must take place first. -# -# This test requires that the error message for a CHECK constraint -# validation error be different than a column validation error. So we -# test the former first, as a sanity check. -statement ok -CREATE TABLE tn(x INT NULL CHECK(x IS NOT NULL), y CHAR(4) CHECK(length(y) < 4)); - -statement error failed to satisfy CHECK constraint -INSERT INTO tn(x) VALUES (NULL) - -statement error failed to satisfy CHECK constraint -INSERT INTO tn(y) VALUES ('abcd') - -# Now we test that the column validation occurs before the CHECK constraint. -statement ok -CREATE TABLE tn2(x INT NOT NULL CHECK(x IS NOT NULL), y CHAR(3) CHECK(length(y) < 4)); - -statement error null value in column "x" violates not-null constraint -INSERT INTO tn2(x) VALUES (NULL) - -statement error value too long for type CHAR\(3\) -INSERT INTO tn2(x, y) VALUES (123, 'abcd') - -subtest fk_contraint_check_validation_ordering - -# Verify that column constraints and CHECK handling occur before -# foreign key validation. -statement ok -CREATE TABLE src(x VARCHAR PRIMARY KEY); - INSERT INTO src(x) VALUES ('abc'); - CREATE TABLE derived(x CHAR(3) REFERENCES src(x), - y VARCHAR CHECK(length(y) < 4) REFERENCES src(x)) - -# Sanity check that the FK constraints gets actually validated -statement error foreign key violation -INSERT INTO derived(x) VALUES('xxx') - -statement error value too long for type CHAR\(3\) -INSERT INTO derived(x) VALUES('abcd') - -statement error failed to satisfy CHECK constraint -INSERT INTO derived(y) VALUES('abcd') - -subtest regression_29494 - -statement ok -CREATE TABLE t29494(x INT); INSERT INTO t29494 VALUES (12) - -statement ok -BEGIN; ALTER TABLE t29494 ADD COLUMN y INT NOT NULL DEFAULT 123 - -# Check that the new column is not visible -query T -SELECT create_statement FROM [SHOW CREATE t29494] ----- -CREATE TABLE t29494 ( - x INT8 NULL, - FAMILY "primary" (x, rowid) -) - -# Check that the new column is not usable in RETURNING. -statement error column "y" does not exist -INSERT INTO t29494(x) VALUES (123) RETURNING y - -statement ok -ROLLBACK - -statement ok -BEGIN; ALTER TABLE t29494 ADD COLUMN y INT NOT NULL DEFAULT 123 - -query I -INSERT INTO t29494(x) VALUES (123) RETURNING * ----- -123 - -statement ok -COMMIT - -subtest regression_32759_33012 - -statement ok -CREATE TABLE t32759(x INT, y STRING NOT NULL DEFAULT 'b', z INT) - -statement ok -BEGIN; ALTER TABLE t32759 DROP COLUMN y - -# Check that the dropped column is not visible -query T -SELECT create_statement FROM [SHOW CREATE t32759] ----- -CREATE TABLE t32759 ( - x INT8 NULL, - z INT8 NULL, - FAMILY "primary" (x, z, rowid) -) - -# Check that values cannot be inserted into the dropped column. -# HP and CBO return different errors, so accept both. -statement error [column "y" does not exist | column "y" is being backfilled] -INSERT INTO t32759(x, y, z) VALUES (2, 'c', 2) - -statement ok -ROLLBACK - -statement ok -BEGIN; ALTER TABLE t32759 DROP COLUMN y - -query II colnames -INSERT INTO t32759(x, z) VALUES (1, 4) RETURNING * ----- -x z -1 4 - -statement ok -COMMIT - -# Test ORDER BY with computed ordering column (requires extra column). - -statement ok -CREATE TABLE xy(x INT PRIMARY KEY, y INT); -CREATE TABLE ab(a INT PRIMARY KEY, b INT); -INSERT INTO ab VALUES (1, 1), (2, 2) - -query II rowsort -INSERT INTO xy (x, y) SELECT a, b FROM ab ORDER BY -b LIMIT 10 RETURNING *; ----- -2 2 -1 1 - -statement ok -DROP TABLE xy; DROP TABLE ab - -subtest regression_35611 - -statement ok -CREATE TABLE t35611(a INT PRIMARY KEY, CHECK (a > 0)) - -statement ok -BEGIN; ALTER TABLE t35611 ADD COLUMN b INT - -statement ok -INSERT INTO t35611 (a) VALUES (1) - -statement ok -COMMIT - -# ------------------------------------------------------------------------------ -# Regression for cockroach#35364. -# ------------------------------------------------------------------------------ -subtest regression_35364 - -statement ok -CREATE TABLE t35364(x DECIMAL(1,0) CHECK (x = 0)) - -statement ok -INSERT INTO t35364(x) VALUES (0.1) - -query T -SELECT x FROM t35364 ----- -0 - -statement ok -DROP TABLE t35364 diff --git a/test/sqllogictest/cockroach/int_size.slt b/test/sqllogictest/cockroach/int_size.slt index 32759e1d2280f..ac89d2ae1d737 100644 --- a/test/sqllogictest/cockroach/int_size.slt +++ b/test/sqllogictest/cockroach/int_size.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,23 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/int_size +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/int_size # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach subtest defaults +# Not supported by Materialize. +onlyif cockroach query T SHOW default_int_size ---- @@ -34,6 +36,8 @@ subtest set_int4 statement ok SET default_int_size=4 +# Not supported by Materialize. +onlyif cockroach query T SHOW default_int_size ---- @@ -45,16 +49,15 @@ CREATE TABLE i4 (i4 INT) query TT SHOW CREATE TABLE i4 ---- -i4 CREATE TABLE i4 ( - i4 INT4 NULL, - FAMILY "primary" (i4, rowid) -) +materialize.public.i4 CREATE␠TABLE␠materialize.public.i4␠(i4␠pg_catalog.int4); subtest set_int8 statement ok SET default_int_size=8 +# Not supported by Materialize. +onlyif cockroach query T SHOW default_int_size ---- @@ -66,10 +69,7 @@ CREATE TABLE i8 (i8 INT) query TT SHOW CREATE TABLE i8 ---- -i8 CREATE TABLE i8 ( - i8 INT8 NULL, - FAMILY "primary" (i8, rowid) -) +materialize.public.i8 CREATE␠TABLE␠materialize.public.i8␠(i8␠pg_catalog.int4); # https://github.com/cockroachdb/cockroach/issues/32846 subtest issue_32846 @@ -82,14 +82,19 @@ SET default_int_size=8 statement ok SET default_int_size=4; CREATE TABLE late4 (a INT) +# Not supported by Materialize. +onlyif cockroach query TT SHOW CREATE TABLE late4 ---- -late4 CREATE TABLE late4 ( - a INT8 NULL, - FAMILY "primary" (a, rowid) -) - +late4 CREATE TABLE public.late4 ( + a INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT late4_pkey PRIMARY KEY (rowid ASC) + ) + +# Not supported by Materialize. +onlyif cockroach query T SHOW default_int_size ---- @@ -97,7 +102,7 @@ SHOW default_int_size subtest set_bad_value -statement error pq: only 4 or 8 are supported by default_int_size +statement error unrecognized configuration parameter "default_int_size" SET default_int_size=2 # We want to check the combinations of default_int_size and @@ -108,92 +113,122 @@ subtest serial_rowid # return type of unique_rowid() statement ok -SET default_int_size=4; SET experimental_serial_normalization='rowid'; +SET default_int_size=4; SET serial_normalization='rowid'; +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE i4_rowid (a SERIAL) +# Not supported by Materialize. +onlyif cockroach query TT SHOW CREATE TABLE i4_rowid ---- -i4_rowid CREATE TABLE i4_rowid ( - a INT8 NOT NULL DEFAULT unique_rowid(), - FAMILY "primary" (a, rowid) -) +i4_rowid CREATE TABLE public.i4_rowid ( + a INT8 NOT NULL DEFAULT unique_rowid(), + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT i4_rowid_pkey PRIMARY KEY (rowid ASC) + ) statement ok -SET default_int_size=8; SET experimental_serial_normalization='rowid'; +SET default_int_size=8; SET serial_normalization='rowid'; +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE i8_rowid (a SERIAL) +# Not supported by Materialize. +onlyif cockroach query TT SHOW CREATE TABLE i8_rowid ---- -i8_rowid CREATE TABLE i8_rowid ( - a INT8 NOT NULL DEFAULT unique_rowid(), - FAMILY "primary" (a, rowid) -) +i8_rowid CREATE TABLE public.i8_rowid ( + a INT8 NOT NULL DEFAULT unique_rowid(), + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT i8_rowid_pkey PRIMARY KEY (rowid ASC) + ) subtest serial_sql_sequence # When using rowid, we should see an INTx that matches the current size setting. statement ok -SET default_int_size=4; SET experimental_serial_normalization='sql_sequence'; +SET default_int_size=4; SET serial_normalization='sql_sequence'; +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE i4_sql_sequence (a SERIAL) +# Not supported by Materialize. +onlyif cockroach query TT SHOW CREATE TABLE i4_sql_sequence ---- -i4_sql_sequence CREATE TABLE i4_sql_sequence ( - a INT4 NOT NULL DEFAULT nextval('i4_sql_sequence_a_seq':::STRING), - FAMILY "primary" (a, rowid) -) +i4_sql_sequence CREATE TABLE public.i4_sql_sequence ( + a INT4 NOT NULL DEFAULT nextval('public.i4_sql_sequence_a_seq'::REGCLASS), + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT i4_sql_sequence_pkey PRIMARY KEY (rowid ASC) + ) statement ok -SET default_int_size=8; SET experimental_serial_normalization='sql_sequence'; +SET default_int_size=8; SET serial_normalization='sql_sequence'; +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE i8_sql_sequence (a SERIAL) +# Not supported by Materialize. +onlyif cockroach query TT SHOW CREATE TABLE i8_sql_sequence ---- -i8_sql_sequence CREATE TABLE i8_sql_sequence ( - a INT8 NOT NULL DEFAULT nextval('i8_sql_sequence_a_seq':::STRING), - FAMILY "primary" (a, rowid) -) +i8_sql_sequence CREATE TABLE public.i8_sql_sequence ( + a INT8 NOT NULL DEFAULT nextval('public.i8_sql_sequence_a_seq'::REGCLASS), + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT i8_sql_sequence_pkey PRIMARY KEY (rowid ASC) + ) subtest serial_virtual_sequence # Virtual sequences are a wrapper around unique_rowid(), so they will also # return an INT8 value. statement ok -SET default_int_size=4; SET experimental_serial_normalization='virtual_sequence'; +SET default_int_size=4; SET serial_normalization='virtual_sequence'; +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE i4_virtual_sequence (a SERIAL) +# Not supported by Materialize. +onlyif cockroach query TT SHOW CREATE TABLE i4_virtual_sequence ---- -i4_virtual_sequence CREATE TABLE i4_virtual_sequence ( - a INT8 NOT NULL DEFAULT nextval('i4_virtual_sequence_a_seq':::STRING), - FAMILY "primary" (a, rowid) -) +i4_virtual_sequence CREATE TABLE public.i4_virtual_sequence ( + a INT8 NOT NULL DEFAULT nextval('public.i4_virtual_sequence_a_seq'::REGCLASS), + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT i4_virtual_sequence_pkey PRIMARY KEY (rowid ASC) + ) statement ok -SET default_int_size=8; SET experimental_serial_normalization='virtual_sequence'; +SET default_int_size=8; SET serial_normalization='virtual_sequence'; +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE i8_virtual_sequence (a SERIAL) +# Not supported by Materialize. +onlyif cockroach query TT SHOW CREATE TABLE i8_virtual_sequence ---- -i8_virtual_sequence CREATE TABLE i8_virtual_sequence ( - a INT8 NOT NULL DEFAULT nextval('i8_virtual_sequence_a_seq':::STRING), - FAMILY "primary" (a, rowid) -) +i8_virtual_sequence CREATE TABLE public.i8_virtual_sequence ( + a INT8 NOT NULL DEFAULT nextval('public.i8_virtual_sequence_a_seq'::REGCLASS), + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT i8_virtual_sequence_pkey PRIMARY KEY (rowid ASC) + ) diff --git a/test/sqllogictest/cockroach/interval.slt b/test/sqllogictest/cockroach/interval.slt new file mode 100644 index 0000000000000..b88b9aeb90939 --- /dev/null +++ b/test/sqllogictest/cockroach/interval.slt @@ -0,0 +1,919 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/interval +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# test we store various types with precision correctly. +subtest interval_type_storage + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE interval_duration_type ( + id INTEGER PRIMARY KEY, + regular INTERVAL, + regular_precision INTERVAL(3), + second INTERVAL SECOND, + second_precision INTERVAL SECOND(3), + minute INTERVAL MINUTE, + minute_to_second_precision INTERVAL MINUTE TO SECOND(3) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO interval_duration_type (id, regular, regular_precision, second, second_precision, minute, minute_to_second_precision) VALUES + (1, '12:34:56.123456', '12:34:56.123456', '12:34:56.123456', '12:34:56.123456', '12:34:56.123456', '12:34:56.123456'), + (2, '12:56.123456', '12:56.123456', '12:56.123456', '12:56.123456', '12:56.123456', '12:56.123456'), + (3, '366 12:34:56.123456', '366 12:34:56.123456', '366 12:34:56.123456', '366 12:34:56.123456', '366 12:34:56.123456', '366 12:34:56.123456'), + (4, '1-2 3.1', '1-2 3.1', '1-2 3.1', '1-2 3.1', '1-2 3.1', '1-2 3.1') + +# Not supported by Materialize. +onlyif cockroach +query ITTTTTT +select * from interval_duration_type order by id asc +---- +1 12:34:56.123456 12:34:56.123 12:34:56.123456 12:34:56.123 12:34:00 12:34:56.123 +2 00:12:56.123456 00:12:56.123 00:12:56.123456 00:12:56.123 00:12:00 00:12:56.123 +3 366 days 12:34:56.123456 366 days 12:34:56.123 366 days 12:34:56.123456 366 days 12:34:56.123 366 days 12:34:00 366 days 12:34:56.123 +4 1 year 2 mons 00:00:03.1 1 year 2 mons 00:00:03.1 1 year 2 mons 00:00:03.1 1 year 2 mons 00:00:03.1 1 year 2 mons 00:03:00 1 year 2 mons 00:00:03.1 + +subtest interval_extract_tests + +# Not supported by Materialize. +onlyif cockroach +query R +SELECT extract('second', interval '10:55:01.456') +---- +1.456 + +query R +SELECT extract(minute from interval '10:55:01.456') +---- +55 + +query R +SELECT date_part('minute', interval '10:55:01.456') +---- +55 + +# tests various typmods of intervals +# matches subset of tests in src/test/regress/expected/interval.out +subtest interval_postgres_duration_type_tests + +# oversize leading field is ok +query T +SELECT interval '999' second +---- +00:16:39 + +query T +SELECT interval '999' minute +---- +16:39:00 + +query T +SELECT interval '999' hour +---- +999:00:00 + +query T +SELECT interval '999' day +---- +999 days + +query T +SELECT interval '999' month +---- +83 years 3 months + +# test SQL-spec syntaxes for restricted field sets + +query T +SELECT interval '1' year +---- +1 year + +query T +SELECT interval '2' month +---- +2 months + +query T +SELECT interval '3' day +---- +3 days + +query T +SELECT interval '4' hour +---- +04:00:00 + +query T +SELECT interval '5' minute +---- +00:05:00 + +query T +SELECT interval '6' second +---- +00:00:06 + +query T +SELECT interval '1' year to month +---- +1 month + +query T +SELECT interval '1-2' year to month +---- +1 year 2 months + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT interval '1 2' day to hour +---- +1 day 02:00:00 + +query T +SELECT interval '1 2:03' day to hour +---- +1 day 02:00:00 + +query T +SELECT interval '1 2:03:04' day to hour +---- +1 day 02:00:00 + +query error invalid input syntax for type interval: Cannot determine format of all parts\. Add explicit time components, e\.g\. INTERVAL '1 day' or INTERVAL '1' DAY: "1 2" +SELECT interval '1 2' day to minute + +query T +SELECT interval '1 2:03' day to minute +---- +1 day 02:03:00 + +query T +SELECT interval '1 2:03:04' day to minute +---- +1 day 02:03:00 + +query error invalid input syntax for type interval: Cannot determine format of all parts\. Add explicit time components, e\.g\. INTERVAL '1 day' or INTERVAL '1' DAY: "1 2" +SELECT interval '1 2' day to second + +query T +SELECT interval '1 2:03' day to second +---- +1 day 02:03:00 + +query T +SELECT interval '1 2:03:04' day to second +---- +1 day 02:03:04 + +query error invalid input syntax for type interval: Cannot determine format of all parts\. Add explicit time components, e\.g\. INTERVAL '1 day' or INTERVAL '1' DAY: "1 2" +SELECT interval '1 2' hour to minute + +# SQL-474 (https://linear.app/materializeinc/issue/SQL-474): Materialize drops +# interval fields to the left of the range qualifier's leading unit, even when +# they were written explicitly. PG and CockroachDB keep every explicitly-written +# field and only use the qualifier to resolve ambiguity. Some inputs also change +# magnitude. The commented "PG/CRDB:" lines are the outputs to restore on fix. + +# SQL-474 PG/CRDB: 1 day 02:03:00 +query T +SELECT interval '1 2:03' hour to minute +---- +02:03:00 + +# SQL-474 PG/CRDB: 1 day 02:03:00 +query T +SELECT interval '1 2:03:04' hour to minute +---- +02:03:00 + +query error invalid input syntax for type interval: Cannot determine format of all parts\. Add explicit time components, e\.g\. INTERVAL '1 day' or INTERVAL '1' DAY: "1 2" +SELECT interval '1 2' hour to second + +# SQL-474 PG/CRDB: 1 day 02:03:00 +query T +SELECT interval '1 2:03' hour to second +---- +02:03:00 + +# SQL-474 PG/CRDB: 1 day 02:03:04 +query T +SELECT interval '1 2:03:04' hour to second +---- +02:03:04 + +query error invalid input syntax for type interval: Cannot determine format of all parts\. Add explicit time components, e\.g\. INTERVAL '1 day' or INTERVAL '1' DAY: "1 2" +SELECT interval '1 2' minute to second + +# SQL-474 PG/CRDB: 1 day 00:02:03 (MZ also mis-scales "2:03" as MM instead of MM:SS) +query T +SELECT interval '1 2:03' minute to second +---- +00:03:00 + +# SQL-474 PG/CRDB: 1 day 02:03:04 +query T +SELECT interval '1 2:03:04' minute to second +---- +00:03:04 + +# SQL-474 PG/CRDB: 1 day 00:02:03 +query T +SELECT interval '1 +2:03' minute to second +---- +00:03:00 + +# SQL-474 PG/CRDB: 1 day 02:03:04 +query T +SELECT interval '1 +2:03:04' minute to second +---- +00:03:04 + +# SQL-474 PG/CRDB: 1 day -00:02:03 +query T +SELECT interval '1 -2:03' minute to second +---- +-00:03:00 + +# SQL-474 PG/CRDB: 1 day -02:03:04 +query T +SELECT interval '1 -2:03:04' minute to second +---- +-00:03:04 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT interval '123 11' day to hour +---- +123 days 11:00:00 + +query error invalid input syntax for type interval: Cannot determine format of all parts\. Add explicit time components, e\.g\. INTERVAL '1 day' or INTERVAL '1' DAY: "123 11" +SELECT interval '123 11' day + +query error invalid input syntax for type interval: Cannot determine format of all parts\. Add explicit time components, e\.g\. INTERVAL '1 day' or INTERVAL '1' DAY: "123 11" +SELECT interval '123 11' + +# not ok, redundant hh:mm fields +query error invalid input syntax for type interval: HOUR, MINUTE, SECOND field set twice: "123 2:03 \-2:04" +SELECT interval '123 2:03 -2:04' + +# Not supported by Materialize. +onlyif cockroach +# test syntaxes for restricted precision +query T +SELECT interval(0) '1 day 01:23:45.6789' +---- +1 day 01:23:46 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT interval(2) '1 day 01:23:45.6789' +---- +1 day 01:23:45.68 + +query T +SELECT interval '12:34.5678' minute to second(2) +---- +00:12:34.57 + +query T +SELECT interval '1.234' second +---- +00:00:01.234 + +query T +SELECT interval '1.234' second(2) +---- +00:00:01.23 + +query error invalid input syntax for type interval: Cannot determine format of all parts\. Add explicit time components, e\.g\. INTERVAL '1 day' or INTERVAL '1' DAY: "1 2\.345" +SELECT interval '1 2.345' day to second(2) + +query T +SELECT interval '1 2:03' day to second(2) +---- +1 day 02:03:00 + +query T +SELECT interval '1 2:03.4567' day to second(2) +---- +1 day 00:02:03.46 + +query T +SELECT interval '1 2:03:04.5678' day to second(2) +---- +1 day 02:03:04.57 + +query error invalid input syntax for type interval: Cannot determine format of all parts\. Add explicit time components, e\.g\. INTERVAL '1 day' or INTERVAL '1' DAY: "1 2\.345" +SELECT interval '1 2.345' hour to second(2) + +# SQL-474 PG/CRDB: 1 day 00:02:03.46 +query T +SELECT interval '1 2:03.45678' hour to second(2) +---- +00:02:03.46 + +# SQL-474 PG/CRDB: 1 day 02:03:04.57 +query T +SELECT interval '1 2:03:04.5678' hour to second(2) +---- +02:03:04.57 + +query error invalid input syntax for type interval: Cannot determine format of all parts\. Add explicit time components, e\.g\. INTERVAL '1 day' or INTERVAL '1' DAY: "1 2\.3456" +SELECT interval '1 2.3456' minute to second(2) + +# SQL-474 PG/CRDB: 1 day 00:02:03.57 +query T +SELECT interval '1 2:03.5678' minute to second(2) +---- +00:02:03.57 + +# SQL-474 PG/CRDB: 1 day 02:03:04.57 +query T +SELECT interval '1 2:03:04.5678' minute to second(2) +---- +00:03:04.57 + +# Extra regression tests found when fixing this bug. +subtest regression_43074 + +query T +SELECT interval '1:02.123456' +---- +00:01:02.123456 + +query T +SELECT interval '-1:02.123456' +---- +-00:01:02.123456 + +subtest regression_43079 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT interval '1-2 3' year +---- +4 years + +# SQL-463 (https://linear.app/materializeinc/issue/SQL-463): Materialize spells +# the month unit "months" in interval text output; PG and CockroachDB print +# "mons". This differs on every interval with a month component throughout this +# file, not just here. PG/CRDB would return "1 year 2 mons 3 days". +query T +SELECT interval '1-2 3' day +---- +1 year 2 months 3 days + +query T +SELECT interval '2.1 00:' +---- +2 days 02:24:00 + +query T +SELECT interval ' 5 ' year +---- +5 years + +# Check default types and expressions get truncated on insert / update. +subtest regression_44774 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE regression_44774 ( + a interval(3) DEFAULT '1:2:3.123456' +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO regression_44774 VALUES (default), ('4:5:6.123456') + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT a FROM regression_44774 ORDER BY a +---- +01:02:03.123 +04:05:06.123 + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE regression_44774 +SET a = '13:14:15.123456'::interval + '1 sec'::interval +WHERE 1 = 1 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT a FROM regression_44774 ORDER BY a +---- +13:14:16.123 +13:14:16.123 + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE regression_44774 + +# Check error message for out of range intervals. +subtest regression_62369 + +query error invalid input syntax for type interval: Unable to parse value as a number at index 35: number too large to fit in target type: "10000000000000000000000000000000000 year" +SELECT INTERVAL '10000000000000000000000000000000000 year' + +query T +SELECT i / 2 FROM ( VALUES + ('0 days 0.253000 seconds'::interval), + (INTERVAL '0.000001'::interval), + (INTERVAL '0.000002'::interval), + (INTERVAL '0.000003'::interval), + (INTERVAL '0.000004'::interval), + (INTERVAL '0.000005'::interval), + (INTERVAL '0.000006'::interval), + (INTERVAL '0.000007'::interval), + (INTERVAL '0.000008'::interval), + (INTERVAL '0.000009'::interval) +) regression_66118(i) +---- +00:00:00 +00:00:00.000001 +00:00:00.000001 +00:00:00.000002 +00:00:00.000002 +00:00:00.000003 +00:00:00.000003 +00:00:00.000004 +00:00:00.000004 +00:00:00.1265 + +subtest interval_session + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET intervalstyle = 'iso_8601' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET intervalstyle = 'sql_standard' + +statement ok +SET intervalstyle = DEFAULT + +statement error Expected column option, found AS +CREATE TABLE invalid_table ( + invalid_col string AS ('1 hour'::interval::string) STORED +) + +statement error Expected column option, found AS +CREATE TABLE invalid_table ( + invalid_col interval AS ('1 hour'::string::interval) STORED +) + +statement ok +create table intervals ( pk INT PRIMARY KEY, i INTERVAL ) + +statement ok +INSERT INTO intervals VALUES + (1, '-2 years -11 mons 1 days 04:05:06.123'), + (2, '1 day 04:06:08.123'), + (3, '2 years 11 mons -2 days +03:25:45.678') + +query T +SELECT '-2 years 11 months 1 day 01:02:03'::interval +---- +-1 years -1 months +1 day 01:02:03 + +statement ok +create table interval_parsing ( pk INT PRIMARY KEY, i TEXT ) + +statement ok +INSERT INTO interval_parsing VALUES + (1, '-10 years 22 months 1 day 01:02:03'), + (2, '-10 years -22 months 1 day 01:02:03'), + (3, '-10 years 22 months -1 day 01:02:03'), + (4, '-10 years 22 months -1 day -01:02:03') + +query T +SELECT i FROM intervals ORDER BY pk +---- +-2 years -11 months +1 day 04:05:06.123 +1 day 04:06:08.123 +2 years 11 months -2 days +03:25:45.678 + +# Not supported by Materialize. +onlyif cockroach +query TTTTBBBB +WITH tbl(pk, i, pg, iso, sql_std, default_style) AS ( + SELECT + pk, + i, + to_char_with_style(i, 'postgres') AS pg, + to_char_with_style(i, 'iso_8601') AS iso, + to_char_with_style(i, 'sql_standard') AS sql_std, + to_char(i) AS default_style + FROM intervals +) +SELECT + pg, + iso, + sql_std, + default_style, + i = parse_interval(pg, 'postgres'), + i = parse_interval(iso, 'iso_8601'), + i = parse_interval(sql_std, 'sql_standard'), + i = parse_interval(default_style) AND pg = default_style +FROM tbl +ORDER BY pk +---- +-2 years -11 mons +1 day 04:05:06.123 P-2Y-11M1DT4H5M6.123S -2-11 +1 +4:05:06.123 -2 years -11 mons +1 day 04:05:06.123 true true true true +1 day 04:06:08.123 P1DT4H6M8.123S 1 4:06:08.123 1 day 04:06:08.123 true true true true +2 years 11 mons -2 days +03:25:45.678 P2Y11M-2DT3H25M45.678S +2-11 -2 +3:25:45.678 2 years 11 mons -2 days +03:25:45.678 true true true true + +query T +SELECT array_to_string(array_agg(i ORDER BY pk), ' ') FROM intervals +---- +-2 years -11 months +1 day 04:05:06.123 1 day 04:06:08.123 2 years 11 months -2 days +03:25:45.678 + +query T +SELECT (array_agg(i ORDER BY pk))::string FROM intervals +---- +{"-2 years -11 months +1 day 04:05:06.123","1 day 04:06:08.123","2 years 11 months -2 days +03:25:45.678"} + +query T +SELECT i::string FROM intervals ORDER BY pk +---- +-2 years -11 months +1 day 04:05:06.123 +1 day 04:06:08.123 +2 years 11 months -2 days +03:25:45.678 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT (i,) FROM intervals ORDER BY pk +---- +("-2 years -11 mons +1 day 04:05:06.123") +("1 day 04:06:08.123") +("2 years 11 mons -2 days +03:25:45.678") + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT row_to_json(intervals) FROM intervals ORDER BY pk +---- +{"i": "-2 years -11 mons +1 day 04:05:06.123", "pk": 1} +{"i": "1 day 04:06:08.123", "pk": 2} +{"i": "2 years 11 mons -2 days +03:25:45.678", "pk": 3} + +query TT +SELECT i, i::INTERVAL FROM interval_parsing ORDER BY pk +---- +-10␠years␠22␠months␠1␠day␠01:02:03 -8␠years␠-2␠months␠+1␠day␠01:02:03 +-10␠years␠-22␠months␠1␠day␠01:02:03 -11␠years␠-10␠months␠+1␠day␠01:02:03 +-10␠years␠22␠months␠-1␠day␠01:02:03 -8␠years␠-2␠months␠-1␠days␠+01:02:03 +-10␠years␠22␠months␠-1␠day␠-01:02:03 -8␠years␠-2␠months␠-1␠days␠-01:02:03 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET intervalstyle = 'iso_8601' + +query T +SELECT '-2 years 11 months 1 day 01:02:03'::interval +---- +-1 years -1 months +1 day 01:02:03 + +query T +SELECT i FROM intervals ORDER BY pk +---- +-2 years -11 months +1 day 04:05:06.123 +1 day 04:06:08.123 +2 years 11 months -2 days +03:25:45.678 + +query T +SELECT array_to_string(array_agg(i ORDER BY pk), ' ') FROM intervals +---- +-2 years -11 months +1 day 04:05:06.123 1 day 04:06:08.123 2 years 11 months -2 days +03:25:45.678 + +query T +SELECT (array_agg(i ORDER BY pk))::string FROM intervals +---- +{"-2 years -11 months +1 day 04:05:06.123","1 day 04:06:08.123","2 years 11 months -2 days +03:25:45.678"} + +query T +SELECT i::string FROM intervals ORDER BY pk +---- +-2 years -11 months +1 day 04:05:06.123 +1 day 04:06:08.123 +2 years 11 months -2 days +03:25:45.678 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT (i,) FROM intervals ORDER BY pk +---- +(P-2Y-11M1DT4H5M6.123S) +(P1DT4H6M8.123S) +(P2Y11M-2DT3H25M45.678S) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT row_to_json(intervals) FROM intervals ORDER BY pk +---- +{"i": "P-2Y-11M1DT4H5M6.123S", "pk": 1} +{"i": "P1DT4H6M8.123S", "pk": 2} +{"i": "P2Y11M-2DT3H25M45.678S", "pk": 3} + +query TT +SELECT i, i::INTERVAL FROM interval_parsing ORDER BY pk +---- +-10␠years␠22␠months␠1␠day␠01:02:03 -8␠years␠-2␠months␠+1␠day␠01:02:03 +-10␠years␠-22␠months␠1␠day␠01:02:03 -11␠years␠-10␠months␠+1␠day␠01:02:03 +-10␠years␠22␠months␠-1␠day␠01:02:03 -8␠years␠-2␠months␠-1␠days␠+01:02:03 +-10␠years␠22␠months␠-1␠day␠-01:02:03 -8␠years␠-2␠months␠-1␠days␠-01:02:03 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET intervalstyle = 'sql_standard' + +query T +SELECT '-2 years 11 months 1 day 01:02:03'::interval +---- +-1 years -1 months +1 day 01:02:03 + +query T +SELECT i FROM intervals ORDER BY pk +---- +-2 years -11 months +1 day 04:05:06.123 +1 day 04:06:08.123 +2 years 11 months -2 days +03:25:45.678 + +query T +SELECT array_to_string(array_agg(i ORDER BY pk), ' ') FROM intervals +---- +-2 years -11 months +1 day 04:05:06.123 1 day 04:06:08.123 2 years 11 months -2 days +03:25:45.678 + +query T +SELECT (array_agg(i ORDER BY pk))::string FROM intervals +---- +{"-2 years -11 months +1 day 04:05:06.123","1 day 04:06:08.123","2 years 11 months -2 days +03:25:45.678"} + +query T +SELECT i::string FROM intervals ORDER BY pk +---- +-2 years -11 months +1 day 04:05:06.123 +1 day 04:06:08.123 +2 years 11 months -2 days +03:25:45.678 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT (i,) FROM intervals ORDER BY pk +---- +("-2-11 +1 +4:05:06.123") +("1 4:06:08.123") +("+2-11 -2 +3:25:45.678") + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT row_to_json(intervals) FROM intervals ORDER BY pk +---- +{"i": "-2-11 +1 +4:05:06.123", "pk": 1} +{"i": "1 4:06:08.123", "pk": 2} +{"i": "+2-11 -2 +3:25:45.678", "pk": 3} + +query TT +SELECT i, i::INTERVAL FROM interval_parsing ORDER BY pk +---- +-10␠years␠22␠months␠1␠day␠01:02:03 -8␠years␠-2␠months␠+1␠day␠01:02:03 +-10␠years␠-22␠months␠1␠day␠01:02:03 -11␠years␠-10␠months␠+1␠day␠01:02:03 +-10␠years␠22␠months␠-1␠day␠01:02:03 -8␠years␠-2␠months␠-1␠days␠+01:02:03 +-10␠years␠22␠months␠-1␠day␠-01:02:03 -8␠years␠-2␠months␠-1␠days␠-01:02:03 + +# Not supported by Materialize. +onlyif cockroach +# Could not find any regress tests for to_char in PG, so we're making our own up! +statement ok +CREATE TABLE intvl_tbl (id SERIAL, d1 INTERVAL); +INSERT INTO intvl_tbl (d1) VALUES + ('355 months 40 days 123:45:12'), + ('-400 months -30 days -100:12:13') + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD J') + FROM intvl_tbl ORDER BY id +---- +0,029 0029 029 29 9 00 3 07 1528 10690 40 1731873 +0,-33 -0033 -033 -33 -3 00 0 -04 -1717 -12030 -30 1708823 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMJ') + FROM intvl_tbl ORDER BY id +---- +0,029 29 29 29 9 0 3 7 1528 10690 40 1731873 +0,-33 -33 -33 -33 -3 0 0 -4 -1717 -12030 -30 1708823 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'HH HH12 HH24 MI SS SSSS') + FROM intvl_tbl ORDER BY id +---- +03 03 123 45 12 445512 +-04 -04 -100 -12 -13 -360733 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, E'"HH:MI:SS is" HH:MI:SS "\\"text between quote marks\\""') + FROM intvl_tbl ORDER BY id +---- +HH:MI:SS is 03:45:12 "text between quote marks" +HH:MI:SS is -04:-12:-13 "text between quote marks" + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'HH24--text--MI--text--SS') + FROM intvl_tbl ORDER BY id +---- +123--text--45--text--12 +-100--text---12--text---13 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'YYYYTH YYYYth Jth') + FROM intvl_tbl ORDER BY id +---- +0029TH 0029th 1731873rd +-0033RD -0033rd 1708823rd + +# Test intervalstyle being respected in pg_indexes. + +statement ok +CREATE TABLE intervalstyle_in_index ( + a INT8 PRIMARY KEY, b INTERVAL, + INDEX idx (b) WHERE b > 'P3Y' +) + +query TT +SELECT indexname, indexdef +FROM pg_indexes +WHERE tablename = 'intervalstyle_in_index' +AND indexname = 'idx' +---- + + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET intervalstyle = 'iso_8601' + +query TT +SELECT indexname, indexdef +FROM pg_indexes +WHERE tablename = 'intervalstyle_in_index' +AND indexname = 'idx' +---- + + +# date_trunc +statement ok +SET intervalstyle = 'postgres' + +statement error pgcode 22023 unit 'invalid' not recognized +SELECT date_trunc('invalid', interval '1 month') + +statement error pgcode 0A000 unit 'week' not recognized +SELECT date_trunc('week', interval '1 month') + +statement error pgcode 0A000 unit 'weeks' not recognized +SELECT date_trunc('weeks', interval '1 month') + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT timespan, date_trunc(timespan, '1111 year 4 month 1 day 1 hour 1 minute 1 second 1 millisecond 1 microsecond') +FROM (VALUES + ('millennia'), + ('millennium'), + ('millenniums'), + ('century'), + ('centuries'), + ('decade'), + ('decades'), + ('quarter'), + ('month'), + ('months'), + ('day'), + ('days'), + ('hour'), + ('hours'), + ('minute'), + ('minutes'), + ('second'), + ('seconds'), + ('millisecond'), + ('milliseconds'), + ('microsecond'), + ('microseconds')) +AS t(timespan) +---- +millennia 1000 years +millennium 1000 years +millenniums 1000 years +century 1100 years +centuries 1100 years +decade 1110 years +decades 1110 years +quarter 1111 years 3 mons +month 1111 years 4 mons +months 1111 years 4 mons +day 1111 years 4 mons 1 day +days 1111 years 4 mons 1 day +hour 1111 years 4 mons 1 day 01:00:00 +hours 1111 years 4 mons 1 day 01:00:00 +minute 1111 years 4 mons 1 day 01:01:00 +minutes 1111 years 4 mons 1 day 01:01:00 +second 1111 years 4 mons 1 day 01:01:01 +seconds 1111 years 4 mons 1 day 01:01:01 +millisecond 1111 years 4 mons 1 day 01:01:01.001 +milliseconds 1111 years 4 mons 1 day 01:01:01.001 +microsecond 1111 years 4 mons 1 day 01:01:01.001001 +microseconds 1111 years 4 mons 1 day 01:01:01.001001 + +# Regression test for #83756. Interval encoding overflow should be detected +# correctly. +statement ok +CREATE TABLE t83756 (i INTERVAL PRIMARY KEY); + +# These intervals do not overflow. +statement ok +INSERT INTO t83756 VALUES ('106751 days 23:47:16.854775'); +INSERT INTO t83756 VALUES ('-106751 days -23:47:16.854775'); + +# Not supported by Materialize. +onlyif cockroach +# These intervals overflow. +# TODO(#84078): These intervals overflow due to limitations of our INTERVAL key +# encoding. All values in the range [-178000000 years, 178000000 years] should +# be allowed. +statement error overflow during Encode +INSERT INTO t83756 VALUES ('106751 days 23:47:16.854776'); + +# Not supported by Materialize. +onlyif cockroach +statement error overflow during Encode +INSERT INTO t83756 VALUES ('-106751 days -23:47:16.854776'); + +# Not supported by Materialize. +onlyif cockroach +# These intervals overflow when multiplying the days and the number of +# nanoseconds in a day, even though the total nanosecond calculation would not +# overflow. +statement error overflow during Encode +INSERT INTO t83756 VALUES ('-3558 months 106752 days'); + +# Not supported by Materialize. +onlyif cockroach +statement error overflow during Encode +INSERT INTO t83756 VALUES ('3558 months -106752 days'); diff --git a/test/sqllogictest/cockroach/join.slt b/test/sqllogictest/cockroach/join.slt index 8c1aaf1268c7f..1c0f8b53dff25 100644 --- a/test/sqllogictest/cockroach/join.slt +++ b/test/sqllogictest/cockroach/join.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/join +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/join # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - # The join condition logic is tricky to get right with NULL # values. Simple implementations can deal well with NULLs on the first # or last row but fail to handle them in the middle. So the test table @@ -31,10 +29,7 @@ COMPLETE 0 # table also contains the pair 44/42 so that a test with a non-trivial # ON condition can be written. statement ok -CREATE TABLE onecolumn (x INT) - -statement ok -INSERT INTO onecolumn(x) VALUES (44), (NULL), (42) +CREATE TABLE onecolumn (x INT); INSERT INTO onecolumn(x) VALUES (44), (NULL), (42) query II colnames,rowsort SELECT * FROM onecolumn AS a(x) CROSS JOIN onecolumn AS b(y) @@ -62,7 +57,7 @@ SELECT * FROM onecolumn AS a(x) JOIN onecolumn AS b(y) ON a.x = b.y 42 42 query I colnames -SELECT * FROM onecolumn AS a JOIN onecolumn as b USING (x) ORDER BY x +SELECT * FROM onecolumn AS a JOIN onecolumn as b USING(x) ORDER BY x ---- x 42 @@ -84,7 +79,7 @@ NULL NULL 42 42 query I colnames -SELECT * FROM onecolumn AS a LEFT OUTER JOIN onecolumn AS b USING (x) ORDER BY x +SELECT * FROM onecolumn AS a LEFT OUTER JOIN onecolumn AS b USING(x) ORDER BY x ---- x 42 @@ -92,7 +87,7 @@ x NULL # Check that ORDER BY chokes on ambiguity if no table less columns -# were introduced by USING. (materialize#12239) +# were introduced by USING. (#12239) query error column reference "x" is ambiguous SELECT * FROM onecolumn AS a, onecolumn AS b ORDER BY x @@ -113,7 +108,7 @@ SELECT * FROM onecolumn AS a(x) RIGHT OUTER JOIN onecolumn AS b(y) ON a.x = b.y NULL NULL query I colnames -SELECT * FROM onecolumn AS a RIGHT OUTER JOIN onecolumn AS b USING (x) ORDER BY x +SELECT * FROM onecolumn AS a RIGHT OUTER JOIN onecolumn AS b USING(x) ORDER BY x ---- x 42 @@ -129,10 +124,7 @@ SELECT * FROM onecolumn AS a NATURAL RIGHT OUTER JOIN onecolumn AS b NULL statement ok -CREATE TABLE onecolumn_w(w INT) - -statement ok -INSERT INTO onecolumn_w(w) VALUES (42),(43) +CREATE TABLE onecolumn_w(w INT); INSERT INTO onecolumn_w(w) VALUES (42),(43) query II colnames,rowsort SELECT * FROM onecolumn AS a NATURAL JOIN onecolumn_w as b @@ -146,10 +138,7 @@ NULL 43 42 43 statement ok -CREATE TABLE othercolumn (x INT) - -statement ok -INSERT INTO othercolumn(x) VALUES (43),(42),(16) +CREATE TABLE othercolumn (x INT); INSERT INTO othercolumn(x) VALUES (43),(42),(16) query II colnames SELECT * FROM onecolumn AS a FULL OUTER JOIN othercolumn AS b ON a.x = b.x ORDER BY a.x,b.x @@ -162,7 +151,7 @@ NULL 43 NULL NULL query I colnames -SELECT * FROM onecolumn AS a FULL OUTER JOIN othercolumn AS b USING (x) ORDER BY x +SELECT * FROM onecolumn AS a FULL OUTER JOIN othercolumn AS b USING(x) ORDER BY x ---- x 16 @@ -172,9 +161,9 @@ x NULL # Check that the source columns can be selected separately from the -# USING column (materialize#12033). +# USING column (#12033). query III colnames -SELECT x AS s, a.x, b.x FROM onecolumn AS a FULL OUTER JOIN othercolumn AS b USING (x) ORDER BY s +SELECT x AS s, a.x, b.x FROM onecolumn AS a FULL OUTER JOIN othercolumn AS b USING(x) ORDER BY s ---- s x x 16 NULL 16 @@ -217,7 +206,7 @@ SELECT * FROM onecolumn AS a(x) JOIN empty AS b(y) ON a.x = b.y ---- query I -SELECT * FROM onecolumn AS a JOIN empty AS b USING (x) +SELECT * FROM onecolumn AS a JOIN empty AS b USING(x) ---- query II @@ -225,7 +214,7 @@ SELECT * FROM empty AS a(x) JOIN onecolumn AS b(y) ON a.x = b.y ---- query I -SELECT * FROM empty AS a JOIN onecolumn AS b USING (x) +SELECT * FROM empty AS a JOIN onecolumn AS b USING(x) ---- query II colnames @@ -237,7 +226,7 @@ x y NULL NULL query I colnames -SELECT * FROM onecolumn AS a LEFT OUTER JOIN empty AS b USING (x) ORDER BY x +SELECT * FROM onecolumn AS a LEFT OUTER JOIN empty AS b USING(x) ORDER BY x ---- x 42 @@ -249,7 +238,7 @@ SELECT * FROM empty AS a(x) LEFT OUTER JOIN onecolumn AS b(y) ON a.x = b.y ---- query I -SELECT * FROM empty AS a LEFT OUTER JOIN onecolumn AS b USING (x) +SELECT * FROM empty AS a LEFT OUTER JOIN onecolumn AS b USING(x) ---- query II @@ -257,7 +246,7 @@ SELECT * FROM onecolumn AS a(x) RIGHT OUTER JOIN empty AS b(y) ON a.x = b.y ---- query I -SELECT * FROM onecolumn AS a RIGHT OUTER JOIN empty AS b USING (x) +SELECT * FROM onecolumn AS a RIGHT OUTER JOIN empty AS b USING(x) ---- query II colnames @@ -269,7 +258,7 @@ NULL 44 NULL NULL query I colnames -SELECT * FROM empty AS a FULL OUTER JOIN onecolumn AS b USING (x) ORDER BY x +SELECT * FROM empty AS a FULL OUTER JOIN onecolumn AS b USING(x) ORDER BY x ---- x 42 @@ -285,7 +274,7 @@ x y NULL NULL query I colnames -SELECT * FROM onecolumn AS a FULL OUTER JOIN empty AS b USING (x) ORDER BY x +SELECT * FROM onecolumn AS a FULL OUTER JOIN empty AS b USING(x) ORDER BY x ---- x 42 @@ -301,7 +290,7 @@ NULL 44 NULL NULL query I colnames -SELECT * FROM empty AS a FULL OUTER JOIN onecolumn AS b USING (x) ORDER BY x +SELECT * FROM empty AS a FULL OUTER JOIN onecolumn AS b USING(x) ORDER BY x ---- x 42 @@ -309,10 +298,7 @@ x NULL statement ok -CREATE TABLE twocolumn (x INT, y INT) - -statement ok -INSERT INTO twocolumn(x, y) VALUES (44,51), (NULL,52), (42,53), (45,45) +CREATE TABLE twocolumn (x INT, y INT); INSERT INTO twocolumn(x, y) VALUES (44,51), (NULL,52), (42,53), (45,45) # Natural joins with partial match query II colnames,rowsort @@ -371,16 +357,10 @@ NULL 2 NULL ## Simple test cases for inner, left, right, and outer joins statement ok -CREATE TABLE a (i int) - -statement ok -INSERT INTO a VALUES (1), (2), (3) - -statement ok -CREATE TABLE b (i int, b bool) +CREATE TABLE a (i int); INSERT INTO a VALUES (1), (2), (3) statement ok -INSERT INTO b VALUES (2, true), (3, true), (4, false) +CREATE TABLE b (i int, b bool); INSERT INTO b VALUES (2, true), (3, true), (4, false) query IIB rowsort SELECT * FROM a INNER JOIN b ON a.i = b.i @@ -458,49 +438,49 @@ x x y # Check sub-queries as data sources. query I colnames -SELECT * FROM onecolumn JOIN (VALUES (41),(42),(43)) AS a(x) USING (x) +SELECT * FROM onecolumn JOIN (VALUES (41),(42),(43)) AS a(x) USING(x) ---- x 42 query I colnames -SELECT * FROM onecolumn JOIN (SELECT x + 2 AS x FROM onecolumn) USING (x) +SELECT * FROM onecolumn JOIN (SELECT x + 2 AS x FROM onecolumn) USING(x) ---- x 44 # Check that a single column can have multiple table aliases. query IIII colnames -SELECT * FROM (twocolumn AS a JOIN twocolumn AS b USING (x) JOIN twocolumn AS c USING (x)) ORDER BY x LIMIT 1 +SELECT * FROM (twocolumn AS a JOIN twocolumn AS b USING(x) JOIN twocolumn AS c USING(x)) ORDER BY x LIMIT 1 ---- x y y y 42 53 53 53 query IIIIII colnames -SELECT a.x AS s, b.x, c.x, a.y, b.y, c.y FROM (twocolumn AS a JOIN twocolumn AS b USING (x) JOIN twocolumn AS c USING (x)) ORDER BY s +SELECT a.x AS s, b.x, c.x, a.y, b.y, c.y FROM (twocolumn AS a JOIN twocolumn AS b USING(x) JOIN twocolumn AS c USING(x)) ORDER BY s ---- s x x y y y 42 42 42 53 53 53 44 44 44 51 51 51 45 45 45 45 45 45 -query error pgcode 42703 db error: ERROR: column "y" specified in USING clause does not exist in left table -SELECT * FROM (onecolumn AS a JOIN onecolumn AS b USING (y)) +query error pgcode 42703 column "y" specified in USING clause does not exist +SELECT * FROM (onecolumn AS a JOIN onecolumn AS b USING(y)) -query error pgcode 42701 db error: ERROR: column name "x" appears more than once in USING clause not yet supported -SELECT * FROM (onecolumn AS a JOIN onecolumn AS b USING (x, x)) +query error pgcode 42701 column name "x" appears more than once in USING clause +SELECT * FROM (onecolumn AS a JOIN onecolumn AS b USING(x, x)) statement ok CREATE TABLE othertype (x TEXT) -query error pgcode 42804 db error: ERROR: NATURAL/USING join column "x" types integer and text cannot be matched -SELECT * FROM (onecolumn AS a JOIN othertype AS b USING (x)) +query error pgcode 42804 NATURAL/USING join column "x" types integer and text cannot be matched +SELECT * FROM (onecolumn AS a JOIN othertype AS b USING(x)) -query error pgcode 42712 db error: ERROR: table name "onecolumn" specified more than once -SELECT * FROM (onecolumn JOIN onecolumn USING (x)) +query error pgcode 42712 table name "onecolumn" specified more than once +SELECT * FROM (onecolumn JOIN onecolumn USING(x)) -query error pgcode 42712 db error: ERROR: table name "onecolumn" specified more than once -SELECT * FROM (onecolumn JOIN twocolumn USING (x) JOIN onecolumn USING (x)) +query error pgcode 42712 table name "onecolumn" specified more than once +SELECT * FROM (onecolumn JOIN twocolumn USING(x) JOIN onecolumn USING(x)) # Check that star expansion works across anonymous sources. query II rowsort @@ -518,7 +498,7 @@ NULL NULL # Check that anonymous sources are properly looked up without ambiguity. query I -SELECT x FROM (onecolumn JOIN othercolumn USING (x)) JOIN (onecolumn AS a JOIN othercolumn AS b USING (x)) USING (x) +SELECT x FROM (onecolumn JOIN othercolumn USING (x)) JOIN (onecolumn AS a JOIN othercolumn AS b USING(x)) USING(x) ---- 42 @@ -533,90 +513,79 @@ query error column "a.y" does not exist SELECT * FROM (onecolumn AS a JOIN onecolumn AS b ON a.y > y) statement ok -CREATE TABLE s(x INT) - -statement ok -INSERT INTO s(x) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10) +CREATE TABLE s(x INT); INSERT INTO s(x) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10) -# Ensure that large cross-joins are optimized somehow (materialize#10633) +# Not supported by Materialize. +onlyif cockroach +# Ensure that large cross-joins are optimized somehow (#10633) statement ok -CREATE TABLE customers(id INT PRIMARY KEY NOT NULL) - -# statement ok -# CREATE TABLE orders(id INT, cust INT REFERENCES customers(id)) +CREATE TABLE customers(id INT PRIMARY KEY NOT NULL); CREATE TABLE orders(id INT, cust INT REFERENCES customers(id)) + +query TTTTTTTTIIITTI +SELECT NULL::text AS pktable_cat, + pkn.nspname AS pktable_schem, + pkc.relname AS pktable_name, + pka.attname AS pkcolumn_name, + NULL::text AS fktable_cat, + fkn.nspname AS fktable_schem, + fkc.relname AS fktable_name, + fka.attname AS fkcolumn_name, + pos.n AS key_seq, + CASE con.confupdtype + WHEN 'c' THEN 0 + WHEN 'n' THEN 2 + WHEN 'd' THEN 4 + WHEN 'r' THEN 1 + WHEN 'a' THEN 3 + ELSE NULL + END AS update_rule, + CASE con.confdeltype + WHEN 'c' THEN 0 + WHEN 'n' THEN 2 + WHEN 'd' THEN 4 + WHEN 'r' THEN 1 + WHEN 'a' THEN 3 + ELSE NULL + END AS delete_rule, + con.conname AS fk_name, + pkic.relname AS pk_name, + CASE + WHEN con.condeferrable + AND con.condeferred THEN 5 + WHEN con.condeferrable THEN 6 + ELSE 7 + END AS deferrability + FROM pg_catalog.pg_namespace pkn, + pg_catalog.pg_class pkc, + pg_catalog.pg_attribute pka, + pg_catalog.pg_namespace fkn, + pg_catalog.pg_class fkc, + pg_catalog.pg_attribute fka, + pg_catalog.pg_constraint con, + pg_catalog.generate_series(1, 32) pos(n), + pg_catalog.pg_depend dep, + pg_catalog.pg_class pkic + WHERE pkn.oid = pkc.relnamespace + AND pkc.oid = pka.attrelid + AND pka.attnum = con.confkey[pos.n] + AND con.confrelid = pkc.oid + AND fkn.oid = fkc.relnamespace + AND fkc.oid = fka.attrelid + AND fka.attnum = con.conkey[pos.n] + AND con.conrelid = fkc.oid + AND con.contype = 'f' + AND con.oid = dep.objid + AND pkic.oid = dep.refobjid + AND pkic.relkind = 'i' + AND fkn.nspname = 'public' + AND fkc.relname = 'orders' + ORDER BY pkn.nspname, + pkc.relname, + con.conname, + pos.n +---- -statement ok -CREATE TABLE orders(id INT, cust INT) -# TODO(benesch): fix parse error in this query. -# -# query TTTTTTTTIIITTI -# SELECT NULL::text AS pktable_cat, -# pkn.nspname AS pktable_schem, -# pkc.relname AS pktable_name, -# pka.attname AS pkcolumn_name, -# NULL::text AS fktable_cat, -# fkn.nspname AS fktable_schem, -# fkc.relname AS fktable_name, -# fka.attname AS fkcolumn_name, -# pos.n AS key_seq, -# CASE con.confupdtype -# WHEN 'c' THEN 0 -# WHEN 'n' THEN 2 -# WHEN 'd' THEN 4 -# WHEN 'r' THEN 1 -# WHEN 'a' THEN 3 -# ELSE NULL -# END AS update_rule, -# CASE con.confdeltype -# WHEN 'c' THEN 0 -# WHEN 'n' THEN 2 -# WHEN 'd' THEN 4 -# WHEN 'r' THEN 1 -# WHEN 'a' THEN 3 -# ELSE NULL -# END AS delete_rule, -# con.conname AS fk_name, -# pkic.relname AS pk_name, -# CASE -# WHEN con.condeferrable -# AND con.condeferred THEN 5 -# WHEN con.condeferrable THEN 6 -# ELSE 7 -# END AS deferrability -# FROM pg_catalog.pg_namespace pkn, -# pg_catalog.pg_class pkc, -# pg_catalog.pg_attribute pka, -# pg_catalog.pg_namespace fkn, -# pg_catalog.pg_class fkc, -# pg_catalog.pg_attribute fka, -# pg_catalog.pg_constraint con, -# pg_catalog.generate_series(1, 32) pos(n), -# pg_catalog.pg_depend dep, -# pg_catalog.pg_class pkic -# WHERE pkn.oid = pkc.relnamespace -# AND pkc.oid = pka.attrelid -# AND pka.attnum = con.confkey[pos.n] -# AND con.confrelid = pkc.oid -# AND fkn.oid = fkc.relnamespace -# AND fkc.oid = fka.attrelid -# AND fka.attnum = con.conkey[pos.n] -# AND con.conrelid = fkc.oid -# AND con.contype = 'f' -# AND con.oid = dep.objid -# AND pkic.oid = dep.refobjid -# AND pkic.relkind = 'i' -# AND dep.classid = 'pg_constraint'::regclass::oid -# AND dep.refclassid = 'pg_class'::regclass::oid -# AND fkn.nspname = 'public' -# AND fkc.relname = 'orders' -# ORDER BY pkn.nspname, -# pkc.relname, -# con.conname, -# pos.n -# ---- -# NULL public customers id NULL public orders cust 1 3 3 fk_cust_ref_customers primary 7 -# # Tests for filter propagation through joins. @@ -658,7 +627,6 @@ SELECT * FROM pairs, square WHERE pairs.a + pairs.b = square.sq 3 6 3 9 4 5 3 9 -# Materialize and Postgres treat this division as integer division, while Cockroach and MySQL do floating point division. query IIII rowsort SELECT a, b, n, sq FROM (SELECT a, b, a * b / 2 AS div, n, sq FROM pairs, square) WHERE div = sq ---- @@ -667,14 +635,6 @@ SELECT a, b, n, sq FROM (SELECT a, b, a * b / 2 AS div, n, sq FROM pairs, square 2 4 2 4 3 6 3 9 -# Force a floating point division. -query IIII rowsort -SELECT a, b, n, sq FROM (SELECT a, b, a::float * b / 2 AS div, n, sq FROM pairs, square) WHERE div = sq ----- -1 2 1 1 -2 4 2 4 -3 6 3 9 - query IIII rowsort SELECT * FROM pairs FULL OUTER JOIN square ON pairs.a + pairs.b = square.sq ---- @@ -751,7 +711,7 @@ statement ok INSERT INTO t2 VALUES (100, 1, 1, 101), (200, 1, 201, 2), (400, 1, 401, 4) query IIIIIII -SELECT * FROM t1 JOIN t2 USING (x) +SELECT * FROM t1 JOIN t2 USING(x) ---- 1 10 11 1 100 1 101 @@ -766,7 +726,7 @@ SELECT * FROM t1 JOIN t2 ON t2.x=t1.x 10 1 11 1 100 1 1 101 query IIIIIII rowsort -SELECT * FROM t1 FULL OUTER JOIN t2 USING (x) +SELECT * FROM t1 FULL OUTER JOIN t2 USING(x) ---- 1 10 11 1 100 1 101 2 20 21 1 NULL NULL NULL @@ -792,23 +752,21 @@ SELECT * FROM t1 FULL OUTER JOIN t2 ON t1.x=t2.x NULL NULL NULL NULL 200 1 201 2 NULL NULL NULL NULL 400 1 401 4 -# not in spec -# query III -# SELECT t2.x, t1.x, x FROM t1 JOIN t2 USING (x) -# ---- -# 1 1 1 - -# not in spec -# query III rowsort -# SELECT t2.x, t1.x, x FROM t1 FULL OUTER JOIN t2 USING (x) -# ---- -# 1 1 1 -# NULL 2 2 -# NULL 3 3 -# 201 NULL 201 -# 401 NULL 401 - -# Test for materialize#19536. +query III +SELECT t2.x, t1.x, x FROM t1 JOIN t2 USING(x) +---- +1 1 1 + +query III rowsort +SELECT t2.x, t1.x, x FROM t1 FULL OUTER JOIN t2 USING(x) +---- + 1 1 1 +NULL 2 2 +NULL 3 3 + 201 NULL 201 + 401 NULL 401 + +# Test for #19536. query I SELECT x FROM t1 NATURAL JOIN (SELECT * FROM t2) ---- @@ -827,53 +785,42 @@ CREATE TABLE pkBAC (a INT, b INT, c INT, d INT, PRIMARY KEY(b,a,c)) statement ok CREATE TABLE pkBAD (a INT, b INT, c INT, d INT, PRIMARY KEY(b,a,d)) -# not supported yet -# # Tests with joins with merged columns of collated string type. -# statement ok -# CREATE TABLE str1 (a INT PRIMARY KEY, s STRING COLLATE en_u_ks_level1) -# -# statement ok -# INSERT INTO str1 VALUES (1, 'a' COLLATE en_u_ks_level1), (2, 'A' COLLATE en_u_ks_level1), (3, 'c' COLLATE en_u_ks_level1), (4, 'D' COLLATE en_u_ks_level1) -# -# statement ok -# CREATE TABLE str2 (a INT PRIMARY KEY, s STRING COLLATE en_u_ks_level1) -# -# statement ok -# INSERT INTO str2 VALUES (1, 'A' COLLATE en_u_ks_level1), (2, 'B' COLLATE en_u_ks_level1), (3, 'C' COLLATE en_u_ks_level1), (4, 'E' COLLATE en_u_ks_level1) -# -# query TTT rowsort -# SELECT s, str1.s, str2.s FROM str1 INNER JOIN str2 USING (s) -# ---- -# a a A -# A A A -# c c C -# -# query TTT rowsort -# SELECT s, str1.s, str2.s FROM str1 LEFT OUTER JOIN str2 USING (s) -# ---- -# a a A -# A A A -# c c C -# D D NULL -# -# query TTT rowsort -# SELECT s, str1.s, str2.s FROM str1 RIGHT OUTER JOIN str2 USING (s) -# ---- -# a a A -# A A A -# c c C -# B NULL B -# E NULL E -# -# query TTT rowsort -# SELECT s, str1.s, str2.s FROM str1 FULL OUTER JOIN str2 USING (s) -# ---- -# a a A -# A A A -# c c C -# D D NULL -# E NULL E -# B NULL B +# Tests with joins with merged columns of collated string type. +statement ok +CREATE TABLE str1 (a INT PRIMARY KEY, s STRING COLLATE en_u_ks_level1) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO str1 VALUES (1, 'a' COLLATE en_u_ks_level1), (2, 'A' COLLATE en_u_ks_level1), (3, 'c' COLLATE en_u_ks_level1), (4, 'D' COLLATE en_u_ks_level1) + +statement ok +CREATE TABLE str2 (a INT PRIMARY KEY, s STRING COLLATE en_u_ks_level1) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO str2 VALUES (1, 'A' COLLATE en_u_ks_level1), (2, 'B' COLLATE en_u_ks_level1), (3, 'C' COLLATE en_u_ks_level1), (4, 'E' COLLATE en_u_ks_level1) + +query TTT rowsort +SELECT s, str1.s, str2.s FROM str1 INNER JOIN str2 USING(s) +---- + + +query TTT rowsort +SELECT s, str1.s, str2.s FROM str1 LEFT OUTER JOIN str2 USING(s) +---- + + +query TTT rowsort +SELECT s, str1.s, str2.s FROM str1 RIGHT OUTER JOIN str2 USING(s) +---- + + +query TTT rowsort +SELECT s, str1.s, str2.s FROM str1 FULL OUTER JOIN str2 USING(s) +---- + statement ok @@ -889,26 +836,26 @@ statement ok INSERT INTO xyv VALUES (1, 1, 1), (2, 2, 2), (3, 1, 31), (3, 3, 33), (5, 5, 55) query IIII -SELECT * FROM xyu INNER JOIN xyv USING (x, y) WHERE x > 2 +SELECT * FROM xyu INNER JOIN xyv USING(x, y) WHERE x > 2 ---- 3 1 31 31 query IIII rowsort -SELECT * FROM xyu LEFT OUTER JOIN xyv USING (x, y) WHERE x > 2 +SELECT * FROM xyu LEFT OUTER JOIN xyv USING(x, y) WHERE x > 2 ---- 3 1 31 31 3 2 32 NULL 4 4 44 NULL query IIII rowsort -SELECT * FROM xyu RIGHT OUTER JOIN xyv USING (x, y) WHERE x > 2 +SELECT * FROM xyu RIGHT OUTER JOIN xyv USING(x, y) WHERE x > 2 ---- 3 1 31 31 3 3 NULL 33 5 5 NULL 55 query IIII rowsort -SELECT * FROM xyu FULL OUTER JOIN xyv USING (x, y) WHERE x > 2 +SELECT * FROM xyu FULL OUTER JOIN xyv USING(x, y) WHERE x > 2 ---- 3 1 31 31 3 2 32 NULL @@ -948,21 +895,21 @@ NULL NULL NULL 2 2 2 # Test OUTER joins that are run in the distSQL merge joiner query IIII rowsort -SELECT * FROM (SELECT * FROM xyu ORDER BY x, y) AS xyu LEFT OUTER JOIN (SELECT * FROM xyv ORDER BY x, y) AS xyv USING (x, y) WHERE x > 2 +SELECT * FROM (SELECT * FROM xyu ORDER BY x, y) AS xyu LEFT OUTER JOIN (SELECT * FROM xyv ORDER BY x, y) AS xyv USING(x, y) WHERE x > 2 ---- 3 1 31 31 3 2 32 NULL 4 4 44 NULL query IIII rowsort -SELECT * FROM (SELECT * FROM xyu ORDER BY x, y) AS xyu RIGHT OUTER JOIN (SELECT * FROM xyv ORDER BY x, y) AS xyv USING (x, y) WHERE x > 2 +SELECT * FROM (SELECT * FROM xyu ORDER BY x, y) AS xyu RIGHT OUTER JOIN (SELECT * FROM xyv ORDER BY x, y) AS xyv USING(x, y) WHERE x > 2 ---- 3 1 31 31 3 3 NULL 33 5 5 NULL 55 query IIII rowsort -SELECT * FROM (SELECT * FROM xyu ORDER BY x, y) AS xyu FULL OUTER JOIN (SELECT * FROM xyv ORDER BY x, y) AS xyv USING (x, y) WHERE x > 2 +SELECT * FROM (SELECT * FROM xyu ORDER BY x, y) AS xyu FULL OUTER JOIN (SELECT * FROM xyv ORDER BY x, y) AS xyv USING(x, y) WHERE x > 2 ---- 3 1 31 31 3 2 32 NULL @@ -989,42 +936,42 @@ NULL NULL NULL 5 5 55 NULL NULL NULL 2 2 2 -# Regression test for materialize#20858. +# Regression test for #20858. statement ok -CREATE TABLE l (a INT PRIMARY KEY) +CREATE TABLE l (a INT PRIMARY KEY, b1 INT) statement ok -CREATE TABLE r (a INT PRIMARY KEY) +CREATE TABLE r (a INT PRIMARY KEY, b2 INT) statement ok -INSERT INTO l VALUES (1), (2), (3) +INSERT INTO l VALUES (1, 1), (2, 1), (3, 1) statement ok -INSERT INTO r VALUES (2), (3), (4) +INSERT INTO r VALUES (2, 1), (3, 1), (4, 1) -query I -SELECT * FROM l LEFT OUTER JOIN r USING (a) WHERE a = 1 +query III +SELECT * FROM l LEFT OUTER JOIN r USING(a) WHERE a = 1 ---- -1 +1 1 NULL -query I -SELECT * FROM l LEFT OUTER JOIN r USING (a) WHERE a = 2 +query III +SELECT * FROM l LEFT OUTER JOIN r USING(a) WHERE a = 2 ---- -2 +2 1 1 -query I -SELECT * FROM l RIGHT OUTER JOIN r USING (a) WHERE a = 3 +query III +SELECT * FROM l RIGHT OUTER JOIN r USING(a) WHERE a = 3 ---- -3 +3 1 1 -query I -SELECT * FROM l RIGHT OUTER JOIN r USING (a) WHERE a = 4 +query III +SELECT * FROM l RIGHT OUTER JOIN r USING(a) WHERE a = 4 ---- -4 +4 NULL 1 -# Regression tests for mixed-type equality columns (database-issues#6807). +# Regression tests for mixed-type equality columns (#22514). statement ok CREATE TABLE foo ( a INT, @@ -1035,9 +982,9 @@ CREATE TABLE foo ( statement ok INSERT INTO foo VALUES - (1, 1, 1.0, 1.0), - (2, 2, 2.0, 2.0), - (3, 3, 3.0, 3.0) + (1, 1, 1, 1), + (2, 2, 2, 2), + (3, 3, 3, 3) statement ok CREATE TABLE bar ( @@ -1049,100 +996,186 @@ CREATE TABLE bar ( statement ok INSERT INTO bar VALUES - (1, 1.0, 1.0, 1), - (2, 2.0, 2.0, 2), - (3, 3.0, 3.0, 3) + (1, 1, 1, 1), + (2, 2, 2, 2), + (3, 3, 3, 3) -# TODO(benesch): support these mixed-type equalities. -# -# query IIRR rowsort -# SELECT * FROM foo NATURAL JOIN bar -# ---- -# 1 1 1 1 -# 2 2 2 2 -# 3 3 3 3 -# -# query IIRRIRI rowsort -# SELECT * FROM foo JOIN bar USING (b) -# ---- -# 1 1 1 1 1 1 1 -# 2 2 2 2 2 2 2 -# 3 3 3 3 3 3 3 -# -# query IIRRRI rowsort -# SELECT * FROM foo JOIN bar USING (a, b) -# ---- -# 1 1 1 1 1 1 -# 2 2 2 2 2 2 -# 3 3 3 3 3 3 -# -# query IIRRI rowsort -# SELECT * FROM foo JOIN bar USING (a, b, c) -# ---- -# 1 1 1 1 1 -# 2 2 2 2 2 -# 3 3 3 3 3 -# -# query IIRRIRRI rowsort -# SELECT * FROM foo JOIN bar ON foo.b = bar.b -# ---- -# 1 1 1 1 1 1 1 1 -# 2 2 2 2 2 2 2 2 -# 3 3 3 3 3 3 3 3 -# -# query IIRRIRRI rowsort -# SELECT * FROM foo JOIN bar ON foo.a = bar.a AND foo.b = bar.b -# ---- -# 1 1 1 1 1 1 1 1 -# 2 2 2 2 2 2 2 2 -# 3 3 3 3 3 3 3 3 -# -# query IIRRIRRI rowsort -# SELECT * FROM foo, bar WHERE foo.b = bar.b -# ---- -# 1 1 1 1 1 1 1 1 -# 2 2 2 2 2 2 2 2 -# 3 3 3 3 3 3 3 3 -# -# query IIRRIRRI rowsort -# SELECT * FROM foo, bar WHERE foo.a = bar.a AND foo.b = bar.b -# ---- -# 1 1 1 1 1 1 1 1 -# 2 2 2 2 2 2 2 2 -# 3 3 3 3 3 3 3 3 -# -# query IIRRRI rowsort -# SELECT * FROM foo JOIN bar USING (a, b) WHERE foo.c = bar.c AND foo.d = bar.d -# ---- -# 1 1 1 1 1 1 -# 2 2 2 2 2 2 -# 3 3 3 3 3 3 - -# # Regression test for 23664. -# query III rowsort -# SELECT * FROM onecolumn AS a(x) RIGHT JOIN twocolumn ON false -# ---- -# NULL 44 51 -# NULL NULL 52 -# NULL 42 53 -# NULL 45 45 - -# # Regression test for materialize#23609: make sure that the type of the merged column -# # is int (not unknown). -# query II rowsort -# SELECT column1, column1+1 -# FROM -# (SELECT * FROM -# (VALUES (NULL, NULL)) AS t -# NATURAL FULL OUTER JOIN -# (VALUES (1, 1)) AS u) -# ---- -# 1 2 -# NULL NULL - -# Regression test for materialize#28817. Do not allow special functions in ON clause. +query IIRR rowsort +SELECT * FROM foo NATURAL JOIN bar +---- +1 1 1 1 +2 2 2 2 +3 3 3 3 + +query IIRRIRI rowsort +SELECT * FROM foo JOIN bar USING (b) +---- +1 1 1 1 1 1 1 +2 2 2 2 2 2 2 +3 3 3 3 3 3 3 + +query IIRRRI rowsort +SELECT * FROM foo JOIN bar USING (a, b) +---- +1 1 1 1 1 1 +2 2 2 2 2 2 +3 3 3 3 3 3 + +query IIRRI rowsort +SELECT * FROM foo JOIN bar USING (a, b, c) +---- +1 1 1 1 1 +2 2 2 2 2 +3 3 3 3 3 + +query IIRRIRRI rowsort +SELECT * FROM foo JOIN bar ON foo.b = bar.b +---- +1 1 1 1 1 1 1 1 +2 2 2 2 2 2 2 2 +3 3 3 3 3 3 3 3 + +query IIRRIRRI rowsort +SELECT * FROM foo JOIN bar ON foo.a = bar.a AND foo.b = bar.b +---- +1 1 1 1 1 1 1 1 +2 2 2 2 2 2 2 2 +3 3 3 3 3 3 3 3 + +query IIRRIRRI rowsort +SELECT * FROM foo, bar WHERE foo.b = bar.b +---- +1 1 1 1 1 1 1 1 +2 2 2 2 2 2 2 2 +3 3 3 3 3 3 3 3 + +query IIRRIRRI rowsort +SELECT * FROM foo, bar WHERE foo.a = bar.a AND foo.b = bar.b +---- +1 1 1 1 1 1 1 1 +2 2 2 2 2 2 2 2 +3 3 3 3 3 3 3 3 + +query IIRRRI rowsort +SELECT * FROM foo JOIN bar USING (a, b) WHERE foo.c = bar.c AND foo.d = bar.d +---- +1 1 1 1 1 1 +2 2 2 2 2 2 +3 3 3 3 3 3 + +# Regression test for 23664. +query III rowsort +SELECT * FROM onecolumn AS a(x) RIGHT JOIN twocolumn ON false +---- +NULL 44 51 +NULL NULL 52 +NULL 42 53 +NULL 45 45 + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #23609: make sure that the type of the merged column +# is int (not unknown). +query II rowsort +SELECT column1, column1+1 +FROM + (SELECT * FROM + (VALUES (NULL, NULL)) AS t + NATURAL FULL OUTER JOIN + (VALUES (1, 1)) AS u) +---- +1 2 +NULL NULL + +# Regression test for #28817. Do not allow special functions in ON clause. query error table functions are not allowed in ON clause \(function pg_catalog\.generate_series\) SELECT * FROM foo JOIN bar ON generate_series(0, 1) < 2 -query error aggregate functions are not allowed in ON +query error aggregate functions are not allowed in ON clause \(function pg_catalog\.max\) SELECT * FROM foo JOIN bar ON max(foo.c) < 2 + +# Regression test for #44029 (outer join on two single-row clauses, with two +# results). +query IIII +SELECT * FROM (VALUES (1, 2)) a(a1,a2) FULL JOIN (VALUES (3, 4)) b(b1,b2) ON a1=b1 ORDER BY a2 +---- +1 2 NULL NULL +NULL NULL 3 4 + +# Regression test for #44746 (internal error for particular condition). +statement ok +CREATE TABLE t44746_0(c0 INT) + +statement ok +CREATE TABLE t44746_1(c1 INT) + +# Note: an "error parsing regexp" would also be acceptable here. +statement ok +SELECT * FROM t44746_0 FULL JOIN t44746_1 ON (SUBSTRING('', ')') = '') = (c1 > 0) + +# Regression test for #49630. +statement ok +DROP TABLE empty; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE xy (x INT PRIMARY KEY, y INT); +CREATE TABLE fk_ref (r INT NOT NULL REFERENCES xy (x)); +CREATE TABLE empty (v INT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO xy (VALUES (1, 1)); +INSERT INTO fk_ref (VALUES (1)); + +# Not supported by Materialize. +onlyif cockroach +query IIII +SELECT * FROM fk_ref LEFT JOIN (SELECT * FROM xy INNER JOIN empty ON True) ON r = x +---- +1 NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE empty; +DROP TABLE fk_ref; +DROP TABLE xy; + +statement ok +CREATE TABLE abcd (a INT, b INT, c INT, d INT) + +statement ok +INSERT INTO abcd VALUES (1, 1, 1, 1), (2, 2, 2, 2) + +statement ok +CREATE TABLE dxby (d INT, x INT, b INT, y INT) + +statement ok +INSERT INTO dxby VALUES (2, 2, 2, 2), (3, 3, 3, 3) + +query IIIIII colnames,rowsort +SELECT * FROM abcd NATURAL FULL OUTER JOIN dxby +---- +b d a c x y +1 1 1 1 NULL NULL +2 2 2 2 2 2 +3 3 NULL NULL 3 3 + +# Test that qualified stars expand to all table columns (even those that aren't +# directly visible); see #66123. +query IIIIIIII colnames,rowsort +SELECT abcd.*, dxby.* FROM abcd NATURAL FULL OUTER JOIN dxby +---- +a b c d d x b y +1 1 1 1 NULL NULL NULL NULL +2 2 2 2 2 2 2 2 +NULL NULL NULL NULL 3 3 3 3 + +query IIIIIIII colnames,rowsort +SELECT abcd.*, dxby.* FROM abcd INNER JOIN dxby USING (d, b) +---- +d b a c d x b y +2 2 2 2 2 2 2 2 diff --git a/test/sqllogictest/cockroach/json.slt b/test/sqllogictest/cockroach/json.slt index 9cac01381470f..cb792ce818718 100644 --- a/test/sqllogictest/cockroach/json.slt +++ b/test/sqllogictest/cockroach/json.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/json +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/json # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - ## Basic creation query TT @@ -44,9 +42,9 @@ jsonb query T SELECT '1.00'::JSON ---- -1.00 +1 -statement error unexpected EOF +statement error invalid input syntax for type jsonb: EOF while parsing an object at line 1 column 1: "\{" SELECT '{'::JSON query T @@ -70,17 +68,17 @@ SELECT '[]'::JSON [] query T -SELECT '[1,2,3]'::JSON +SELECT '[1, 2, 3]'::JSON ---- [1,2,3] query T -SELECT '[1,"hello",[[[true,false]]]]'::JSON +SELECT '[1, "hello", [[[true, false]]]]'::JSON ---- [1,"hello",[[[true,false]]]] query T -SELECT '[1,"hello",{"a": ["foo",{"b": 3}]}]'::JSON +SELECT '[1, "hello", {"a": ["foo", {"b": 3}]}]'::JSON ---- [1,"hello",{"a":["foo",{"b":3}]}] @@ -90,18 +88,18 @@ SELECT '{}'::JSON {} query T -SELECT '{"a":"b","c":"d"}'::JSON +SELECT '{"a": "b", "c": "d"}'::JSON ---- {"a":"b","c":"d"} query T -SELECT '{"a":1,"c":{"foo":"bar"}}'::JSON +SELECT '{"a": 1, "c": {"foo": "bar"}}'::JSON ---- {"a":1,"c":{"foo":"bar"}} # Only the final occurrence of a key in an object is kept. query T -SELECT '{"a":1,"a":2}'::JSON +SELECT '{"a": 1, "a": 2}'::JSON ---- {"a":2} @@ -110,52 +108,61 @@ SELECT NULL::JSON ---- NULL -statement error arrays of jsonb not allowed.*\nHINT:.*23468 -SELECT ARRAY['"hello"'::JSON] - -statement error arrays of jsonb not allowed.*\nHINT:.*23468 -SELECT '{}'::JSONB[] - -statement error arrays of jsonb not allowed.*\nHINT:.*23468 +# Not supported by Materialize. +onlyif cockroach +statement error arrays of JSON unsupported as column type.*\nHINT:.*\n.*23468 CREATE TABLE x (y JSONB[]) +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE foo (bar JSON) +CREATE TABLE foo (pk INT DEFAULT unique_rowid(), bar JSON) + +statement error unknown catalog item 'foo' +CREATE VIEW x AS SELECT array_agg(bar) FROM foo +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO foo VALUES - ('{"a":"b"}'), - ('[1,2,3]'), +INSERT INTO foo(bar) VALUES + ('{"a": "b"}'), + ('[1, 2, 3]'), ('"hello"'), ('1.000'), ('true'), ('false'), (NULL), - ('{"x":[1,2,3]}'), - ('{"x":{"y":"z"}}') + ('{"x": [1, 2, 3]}'), + ('{"x": {"y": "z"}}') +# Not supported by Materialize. +onlyif cockroach query T rowsort SELECT bar FROM foo ---- -{"a":"b"} -[1,2,3] +{"a": "b"} +[1, 2, 3] "hello" 1.000 true false NULL -{"x":[1,2,3]} -{"x":{"y":"z"}} +{"x": [1, 2, 3]} +{"x": {"y": "z"}} +# Not supported by Materialize. +onlyif cockroach query T SELECT bar FROM foo WHERE bar->>'a' = 'b' ---- -{"a":"b"} +{"a": "b"} +# Not supported by Materialize. +onlyif cockroach query T SELECT bar FROM foo WHERE bar ? 'a' ---- -{"a":"b"} +{"a": "b"} query BBBBBBB VALUES ( @@ -170,51 +177,70 @@ VALUES ( ---- true false false false false false false +# Not supported by Materialize. +onlyif cockroach query T SELECT bar FROM foo WHERE bar ? 'hello' ---- "hello" +# Not supported by Materialize. +onlyif cockroach query T SELECT bar FROM foo WHERE bar ? 'goodbye' ---- +# Not supported by Materialize. +onlyif cockroach query T SELECT bar FROM foo WHERE bar ?| ARRAY['a','b'] ---- -{"a":"b"} +{"a": "b"} +# Not supported by Materialize. +onlyif cockroach query T SELECT bar FROM foo WHERE bar ?& ARRAY['a','b'] ---- +# Not supported by Materialize. +onlyif cockroach # ?| and ?& ignore NULLs. query T -SELECT bar FROM foo WHERE bar ?| ARRAY['a',null] +SELECT bar FROM foo WHERE bar ?| ARRAY['a', null] ---- -{"a":"b"} +{"a": "b"} -# TODO(justin):cockroach#29355 -# query T -# SELECT bar FROM foo WHERE bar ?| ARRAY[null,null]::STRING[] -# ---- +# Not supported by Materialize. +onlyif cockroach +query T +SELECT bar FROM foo WHERE bar ?| ARRAY[null, null]::STRING[] +---- +# Not supported by Materialize. +onlyif cockroach query T -SELECT bar FROM foo WHERE bar ?& ARRAY['a',null] +SELECT bar FROM foo WHERE bar ?& ARRAY['a', null] ---- -{"a":"b"} +{"a": "b"} +# Not supported by Materialize. +onlyif cockroach query T SELECT bar FROM foo WHERE bar->'a' = '"b"'::JSON ---- -{"a":"b"} +{"a": "b"} -statement error pgcode 0A000 can't order by column type jsonb.*\nHINT.*32706 +statement error pgcode 0A000 unknown catalog item 'foo' SELECT bar FROM foo ORDER BY bar +# Not supported by Materialize. +onlyif cockroach statement error pgcode 0A000 column k is of type jsonb and thus is not indexable CREATE TABLE pk (k JSON PRIMARY KEY) +# Not supported by Materialize. +onlyif cockroach query T rowsort SELECT bar->'a' FROM foo ---- @@ -228,30 +254,47 @@ NULL NULL NULL -query T +# Not supported by Materialize. +onlyif cockroach +query IT SELECT * from foo where bar->'x' = '[1]' ---- -query T +# Not supported by Materialize. +onlyif cockroach +query IT SELECT * from foo where bar->'x' = '{}' ---- +# Not supported by Materialize. +onlyif cockroach +query T +SELECT array_agg(bar ORDER BY pk) FROM foo +---- +{"{\"a\": \"b\"}","[1, 2, 3]","\"hello\"",1.000,true,false,NULL,"{\"x\": [1, 2, 3]}","{\"x\": {\"y\": \"z\"}}"} + +# Not supported by Materialize. +onlyif cockroach statement ok DELETE FROM foo +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO foo VALUES ('{"a":{"c":"d"}}'); +INSERT INTO foo(bar) VALUES ('{"a": {"c": "d"}}'); +# Not supported by Materialize. +onlyif cockroach query TT -SELECT bar->'a'->'c',bar->'a'->>'c' FROM foo +SELECT bar->'a'->'c', bar->'a'->>'c' FROM foo ---- "d" d statement ok -CREATE TABLE multiple (a JSON,b JSON) +CREATE TABLE multiple (a JSON, b JSON) statement ok -INSERT INTO multiple VALUES ('{"a":"b"}','[1,2,3,4,"foo"]') +INSERT INTO multiple VALUES ('{"a":"b"}', '[1,2,3,4,"foo"]') query T SELECT a FROM multiple @@ -265,7 +308,7 @@ SELECT b FROM multiple ## Comparisons -# We opt to not expose <,>,<=,>= at this time,to avoid having to commit to +# We opt to not expose <, >, <=, >= at this time, to avoid having to commit to # an ordering. query B SELECT '1'::JSON = '1'::JSON @@ -288,64 +331,64 @@ SELECT '1.00'::JSON = '1'::JSON true query BB -SELECT '"hello"'::JSON = '"hello"'::JSON,'"hello"'::JSON = '"goodbye"'::JSON +SELECT '"hello"'::JSON = '"hello"'::JSON, '"hello"'::JSON = '"goodbye"'::JSON ---- true false query B -SELECT '"hello"'::JSON IN ('"hello"'::JSON,'1'::JSON,'[]'::JSON) +SELECT '"hello"'::JSON IN ('"hello"'::JSON, '1'::JSON, '[]'::JSON) ---- true query B -SELECT 'false'::JSON IN ('"hello"'::JSON,'1'::JSON,'[]'::JSON) +SELECT 'false'::JSON IN ('"hello"'::JSON, '1'::JSON, '[]'::JSON) ---- false ## Operators query T -SELECT '{"a":1}'::JSONB->'a' +SELECT '{"a": 1}'::JSONB->'a' ---- 1 query T -SELECT pg_typeof('{"a":1}'::JSONB->'a') +SELECT pg_typeof('{"a": 1}'::JSONB->'a') ---- jsonb query T -SELECT '{"a":1,"b":2}'::JSONB->'b' +SELECT '{"a": 1, "b": 2}'::JSONB->'b' ---- 2 query T -SELECT '{"a":1,"b":{"c":3}}'::JSONB->'b'->'c' +SELECT '{"a": 1, "b": {"c": 3}}'::JSONB->'b'->'c' ---- 3 query TT -SELECT '{"a":1,"b":2}'::JSONB->'c','{"c":1}'::JSONB->'a' +SELECT '{"a": 1, "b": 2}'::JSONB->'c', '{"c": 1}'::JSONB->'a' ---- NULL NULL query TT -SELECT '2'::JSONB->'b','[1,2,3]'::JSONB->'0' +SELECT '2'::JSONB->'b', '[1,2,3]'::JSONB->'0' ---- NULL NULL query T -SELECT '[1,2,3]'::JSONB->0 +SELECT '[1, 2, 3]'::JSONB->0 ---- 1 query T -SELECT '[1,2,3]'::JSONB->3 +SELECT '[1, 2, 3]'::JSONB->3 ---- NULL query T -SELECT '{"a":"b"}'::JSONB->>'a' +SELECT '{"a": "b"}'::JSONB->>'a' ---- b @@ -360,164 +403,230 @@ SELECT '{"a":null}'::JSONB->>'a' NULL query T -SELECT pg_typeof('{"a":1}'::JSONB->>'a') +SELECT pg_typeof('{"a": 1}'::JSONB->>'a') ---- -string +text query T -SELECT '{"a":1,"b":2}'::JSONB->>'b' +SELECT '{"a": 1, "b": 2}'::JSONB->>'b' ---- 2 query TT -SELECT '{"a":1,"b":2}'::JSONB->>'c','{"c":1}'::JSONB->>'a' +SELECT '{"a": 1, "b": 2}'::JSONB->>'c', '{"c": 1}'::JSONB->>'a' ---- NULL NULL query TT -SELECT '2'::JSONB->>'b','[1,2,3]'::JSONB->>'0' +SELECT '2'::JSONB->>'b', '[1,2,3]'::JSONB->>'0' ---- NULL NULL query T -SELECT '[1,2,3]'::JSONB->>0 +SELECT '[1, 2, 3]'::JSONB->>0 ---- 1 query T -SELECT '[1,2,3]'::JSONB->>3 +SELECT '[1, 2, 3]'::JSONB->>3 ---- NULL +query TTTT +SELECT 'null'::jsonb->-2, 'null'::jsonb->-1, 'null'::jsonb->0, 'null'::jsonb->1 +---- +NULL null null NULL + +query TTTT +SELECT 'true'::jsonb->-2, 'true'::jsonb->-1, 'true'::jsonb->0, 'true'::jsonb->1 +---- +NULL true true NULL + +query TTTT +SELECT 'false'::jsonb->-2, 'false'::jsonb->-1, 'false'::jsonb->0, 'false'::jsonb->1 +---- +NULL false false NULL + +query TTTT +SELECT '"foo"'::jsonb->-2, '"foo"'::jsonb->-1, '"foo"'::jsonb->0, '"foo"'::jsonb->1 +---- +NULL "foo" "foo" NULL + +query TTTT +SELECT '123'::jsonb->-2, '123'::jsonb->-1, '123'::jsonb->0, '123'::jsonb->1 +---- +NULL 123 123 NULL + +query TTTT +SELECT 'null'::jsonb->>-2, 'null'::jsonb->>-1, 'null'::jsonb->>0, 'null'::jsonb->>1 +---- +NULL NULL NULL NULL + +query TTTT +SELECT 'true'::jsonb->>-2, 'true'::jsonb->>-1, 'true'::jsonb->>0, 'true'::jsonb->>1 +---- +NULL true true NULL + +query TTTT +SELECT 'false'::jsonb->>-2, 'false'::jsonb->>-1, 'false'::jsonb->>0, 'false'::jsonb->>1 +---- +NULL false false NULL + +query TTTT +SELECT '"foo"'::jsonb->>-2, '"foo"'::jsonb->>-1, '"foo"'::jsonb->>0, '"foo"'::jsonb->>1 +---- +NULL foo foo NULL + +query TTTT +SELECT '123'::jsonb->>-2, '123'::jsonb->>-1, '123'::jsonb->>0, '123'::jsonb->>1 +---- +NULL 123 123 NULL + query T -SELECT '{"a":1}'::JSONB#>'{a}'::STRING[] +SELECT '{"a": 1}'::JSONB#>'{a}'::STRING[] ---- 1 query T -SELECT '{"a":{"b":"c"}}'::JSONB#>'{a,b}'::STRING[] +SELECT '{"a": {"b": "c"}}'::JSONB#>'{a,b}'::STRING[] ---- "c" query T -SELECT '{"a":["b"]}'::JSONB#>'{a,b}'::STRING[] +SELECT '{"a": ["b"]}'::JSONB#>'{a,b}'::STRING[] ---- NULL query T -SELECT '{"a":["b"]}'::JSONB#>'{a,0}'::STRING[] +SELECT '{"a": ["b"]}'::JSONB#>'{a,0}'::STRING[] ---- "b" query T -SELECT '{"a":1}'::JSONB#>>ARRAY['foo',null] +SELECT '{"a": 1}'::JSONB#>>ARRAY['foo', null] ---- NULL query T -SELECT '{"a":1}'::JSONB#>>'{a}'::STRING[] +SELECT '{"a": 1}'::JSONB#>>'{a}'::STRING[] ---- 1 query T -SELECT '{"a":{"b":"c"}}'::JSONB#>>'{a,b}'::STRING[] +SELECT '{"a": {"b": "c"}}'::JSONB#>>'{a,b}'::STRING[] ---- c query T -SELECT '{"a":["b"]}'::JSONB#>>'{a,b}'::STRING[] +SELECT '{"a": ["b"]}'::JSONB#>>'{a,b}'::STRING[] ---- NULL query T -SELECT '{"a":["b"]}'::JSONB#>>'{a,0}'::STRING[] +SELECT '{"a": ["b"]}'::JSONB#>>'{a,0}'::STRING[] ---- b query T -SELECT '{"a":[null]}'::JSONB#>>'{a,0}'::STRING[] +SELECT '{"a": [null]}'::JSONB#>>'{a,0}'::STRING[] ---- NULL query BB -SELECT '{"a":1}'::JSONB ? 'a','{"a":1}'::JSONB ? 'b' +SELECT '{"a": 1}'::JSONB ? 'a', '{"a": 1}'::JSONB ? 'b' ---- true false query BB -SELECT '{"a":1,"b":1}'::JSONB ? 'a','{"a":1,"b":1}'::JSONB ? 'b' +SELECT '{"a": 1, "b": 1}'::JSONB ? 'a', '{"a": 1, "b": 1}'::JSONB ? 'b' ---- true true +# Not supported by Materialize. +onlyif cockroach query BB -SELECT '{"a":1}'::JSONB ?| ARRAY['a','b'],'{"b":1}'::JSONB ?| ARRAY['a','b'] +SELECT '{"a": 1}'::JSONB ?| ARRAY['a', 'b'], '{"b": 1}'::JSONB ?| ARRAY['a', 'b'] ---- true true +# Not supported by Materialize. +onlyif cockroach query B -SELECT '{"c":1}'::JSONB ?| ARRAY['a','b'] +SELECT '{"c": 1}'::JSONB ?| ARRAY['a', 'b'] ---- false +# Not supported by Materialize. +onlyif cockroach query BB -SELECT '{"a":1}'::JSONB ?& ARRAY['a','b'],'{"b":1}'::JSONB ?& ARRAY['a','b'] +SELECT '{"a": 1}'::JSONB ?& ARRAY['a', 'b'], '{"b": 1}'::JSONB ?& ARRAY['a', 'b'] ---- false false +# Not supported by Materialize. +onlyif cockroach query B -SELECT '{"a":1,"b":1,"c":1}'::JSONB ?& ARRAY['a','b'] +SELECT '{"a": 1, "b": 1, "c": 1}'::JSONB ?& ARRAY['a', 'b'] ---- true ## Arrays do not `?` their stringified indices. query B -SELECT '[1,2,3]'::JSONB ? '0' +SELECT '[1, 2, 3]'::JSONB ? '0' ---- false ## Arrays `?` string elements. query B -SELECT '["foo","bar","baz"]'::JSONB ? 'foo' +SELECT '["foo", "bar", "baz"]'::JSONB ? 'foo' ---- true query B -SELECT '["foo","bar","baz"]'::JSONB ? 'baz' +SELECT '["foo", "bar", "baz"]'::JSONB ? 'baz' ---- true query B -SELECT '["foo","bar","baz"]'::JSONB ? 'gup' +SELECT '["foo", "bar", "baz"]'::JSONB ? 'gup' ---- false +# Not supported by Materialize. +onlyif cockroach query B -SELECT '["foo","bar","baz"]'::JSONB ?| ARRAY['foo','gup'] +SELECT '["foo", "bar", "baz"]'::JSONB ?| ARRAY['foo', 'gup'] ---- true +# Not supported by Materialize. +onlyif cockroach query B -SELECT '["foo","bar","baz"]'::JSONB ?| ARRAY['buh','gup'] +SELECT '["foo", "bar", "baz"]'::JSONB ?| ARRAY['buh', 'gup'] ---- false +# Not supported by Materialize. +onlyif cockroach query B -SELECT '["foo","bar","baz"]'::JSONB ?& ARRAY['foo','bar'] +SELECT '["foo", "bar", "baz"]'::JSONB ?& ARRAY['foo', 'bar'] ---- true +# Not supported by Materialize. +onlyif cockroach query B -SELECT '["foo","bar","baz"]'::JSONB ?& ARRAY['foo','buh'] +SELECT '["foo", "bar", "baz"]'::JSONB ?& ARRAY['foo', 'buh'] ---- false query T -SELECT '{"a":1}'::JSONB - 'a' +SELECT '{"a": 1}'::JSONB - 'a' ---- {} query T -SELECT '{"a":1}'::JSONB - 'b' +SELECT '{"a": 1}'::JSONB - 'b' ---- {"a":1} @@ -532,34 +641,38 @@ SELECT '[1,2,3]'::JSONB - 1 ---- [1,3] +# Not supported by Materialize. +onlyif cockroach statement error pgcode 22023 cannot delete from scalar SELECT '3'::JSONB - 'b' +# Not supported by Materialize. +onlyif cockroach statement error pgcode 22023 cannot delete from object using integer index SELECT '{}'::JSONB - 1 query B -SELECT '[1,2,3]'::JSONB <@ '[1,2]'::JSONB +SELECT '[1, 2, 3]'::JSONB <@ '[1, 2]'::JSONB ---- false query B -SELECT '[1,2]'::JSONB <@ '[1,2,3]'::JSONB +SELECT '[1, 2]'::JSONB <@ '[1, 2, 3]'::JSONB ---- true query B -SELECT '[1,2]'::JSONB @> '[1,2,3]'::JSONB +SELECT '[1, 2]'::JSONB @> '[1, 2, 3]'::JSONB ---- false query B -SELECT '[1,2,3]'::JSONB @> '[1,2]'::JSONB +SELECT '[1, 2, 3]'::JSONB @> '[1, 2]'::JSONB ---- true query B -SELECT '{"a":[1,2,3]}'::JSONB->'a' @> '2'::JSONB +SELECT '{"a": [1, 2, 3]}'::JSONB->'a' @> '2'::JSONB ---- true @@ -567,13 +680,15 @@ statement ok CREATE TABLE x (j JSONB) statement ok -INSERT INTO x VALUES ('{"a":[1,2,3]}') +INSERT INTO x VALUES ('{"a": [1,2,3]}') query B SELECT true FROM x WHERE j->'a' @> '2'::JSONB ---- true +# Not supported by Materialize. +onlyif cockroach statement ok CREATE INVERTED INDEX ON x (j) @@ -582,64 +697,76 @@ SELECT true FROM x WHERE j->'a' @> '2'::JSONB ---- true +# Not supported by Materialize. +onlyif cockroach query T -SELECT '{"foo":{"bar":1}}'::JSONB #- ARRAY['foo','bar'] +SELECT '{"foo": {"bar": 1}}'::JSONB #- ARRAY['foo', 'bar'] ---- -{"foo":{}} +{"foo": {}} -statement error path element at position 1 is null -SELECT '{"foo":{"bar":1}}'::JSONB #- ARRAY[null,'foo'] +statement error \[#\-\] not yet supported +SELECT '{"foo": {"bar": 1}}'::JSONB #- ARRAY[null, 'foo'] -statement error path element at position 2 is null -SELECT '{"foo":{"bar":1}}'::JSONB #- ARRAY['foo',null] +statement error \[#\-\] not yet supported +SELECT '{"foo": {"bar": 1}}'::JSONB #- ARRAY['foo', null] +# Not supported by Materialize. +onlyif cockroach query T -SELECT '{"foo":{"bar":1}}'::JSONB #- ARRAY['foo'] +SELECT '{"foo": {"bar": 1}}'::JSONB #- ARRAY['foo'] ---- {} +# Not supported by Materialize. +onlyif cockroach query T -SELECT '{"foo":{"bar":1}}'::JSONB #- ARRAY['bar'] +SELECT '{"foo": {"bar": 1}}'::JSONB #- ARRAY['bar'] ---- -{"foo":{"bar":1}} +{"foo": {"bar": 1}} +# Not supported by Materialize. +onlyif cockroach query T -SELECT '{"foo":{"bar":1},"one":1,"two":2}'::JSONB #- ARRAY['one'] +SELECT '{"foo": {"bar": 1}, "one": 1, "two": 2}'::JSONB #- ARRAY['one'] ---- -{"foo":{"bar":1},"two":2} +{"foo": {"bar": 1}, "two": 2} +# Not supported by Materialize. +onlyif cockroach query T SELECT '{}'::JSONB #- ARRAY['foo'] ---- {} +# Not supported by Materialize. +onlyif cockroach query T -SELECT '{"foo":{"bar":1}}'::JSONB #- ARRAY[''] +SELECT '{"foo": {"bar": 1}}'::JSONB #- ARRAY[''] ---- -{"foo":{"bar":1}} +{"foo": {"bar": 1}} query T -SELECT '{"a":"b"}'::JSONB::STRING +SELECT '{"a": "b"}'::JSONB::STRING ---- {"a":"b"} query T -SELECT CAST('{"a":"b"}'::JSONB AS STRING) +SELECT CAST('{"a": "b"}'::JSONB AS STRING) ---- {"a":"b"} query T -SELECT '["1","2","3"]'::JSONB - '1' +SELECT '["1", "2", "3"]'::JSONB - '1' ---- ["2","3"] query T -SELECT '["1","2","1","2","3"]'::JSONB - '2' +SELECT '["1", "2", "1", "2", "3"]'::JSONB - '2' ---- ["1","1","3"] query T -SELECT '["1","2","3"]'::JSONB - '4' +SELECT '["1", "2", "3"]'::JSONB - '4' ---- ["1","2","3"] @@ -649,86 +776,110 @@ SELECT '[]'::JSONB - '1' [] query T -SELECT '["1","2","3"]'::JSONB - '' +SELECT '["1", "2", "3"]'::JSONB - '' ---- ["1","2","3"] query T -SELECT '[1,"1",1.0]'::JSONB - '1' +SELECT '[1, "1", 1.0]'::JSONB - '1' ---- -[1,1.0] +[1,1] +# Not supported by Materialize. +onlyif cockroach query T -SELECT '[1,2,3]'::JSONB #- ARRAY['0'] +SELECT '[1, 2, 3]'::JSONB #- ARRAY['0'] ---- -[2,3] +[2, 3] +# Not supported by Materialize. +onlyif cockroach query T -SELECT '[1,2,3]'::JSONB #- ARRAY['3'] +SELECT '[1, 2, 3]'::JSONB #- ARRAY['3'] ---- -[1,2,3] +[1, 2, 3] +# Not supported by Materialize. +onlyif cockroach query T SELECT '[]'::JSONB #- ARRAY['0'] ---- [] -statement error pgcode 22P02 a path element is not an integer:foo +statement error pgcode 22P02 \[#\-\] not yet supported SELECT '["foo"]'::JSONB #- ARRAY['foo'] +# Not supported by Materialize. +onlyif cockroach query T -SELECT '{"a":["foo"]}'::JSONB #- ARRAY['a','0'] +SELECT '{"a": ["foo"]}'::JSONB #- ARRAY['a', '0'] ---- -{"a":[]} +{"a": []} +# Not supported by Materialize. +onlyif cockroach query T -SELECT '{"a":["foo","bar"]}'::JSONB #- ARRAY['a','1'] +SELECT '{"a": ["foo", "bar"]}'::JSONB #- ARRAY['a', '1'] ---- -{"a":["foo"]} +{"a": ["foo"]} +# Not supported by Materialize. +onlyif cockroach query T -SELECT '{"a":[]}'::JSONB #- ARRAY['a','0'] +SELECT '{"a": []}'::JSONB #- ARRAY['a', '0'] ---- -{"a":[]} +{"a": []} +# Not supported by Materialize. +onlyif cockroach query T SELECT '{"a":123,"b":456,"c":567}'::JSONB - array[]:::text[]; ---- -{"a":123,"b":456,"c":567} +{"a": 123, "b": 456, "c": 567} +# Not supported by Materialize. +onlyif cockroach query T SELECT '{"a":123,"b":456,"c":567}'::JSONB - array['a','c']; ---- -{"b":456} +{"b": 456} +# Not supported by Materialize. +onlyif cockroach query T SELECT '{"a":123,"c":"asdf"}'::JSONB - array['a','c']; ---- {} +# Not supported by Materialize. +onlyif cockroach query T SELECT '{}'::JSONB - array['a','c']; ---- {} +# Not supported by Materialize. +onlyif cockroach query T -SELECT '{"b":[],"c":{"a":"b"}}'::JSONB - array['a']; +SELECT '{"b": [], "c": {"a": "b"}}'::JSONB - array['a']; ---- -{"b":[],"c":{"a":"b"}} +{"b": [], "c": {"a": "b"}} -# Regression test for cockroach#34756. +# Not supported by Materialize. +onlyif cockroach +# Regression test for #34756. query T -SELECT '{"b":[],"c":{"a":"b"}}'::JSONB - array['foo',NULL] +SELECT '{"b": [], "c": {"a": "b"}}'::JSONB - array['foo', NULL] ---- -{"b":[],"c":{"a":"b"}} +{"b": [], "c": {"a": "b"}} -statement error pgcode 22P02 a path element is not an integer:foo -SELECT '{"a":{"b":["foo"]}}'::JSONB #- ARRAY['a','b','foo'] +statement error pgcode 22P02 \[#\-\] not yet supported +SELECT '{"a": {"b": ["foo"]}}'::JSONB #- ARRAY['a', 'b', 'foo'] subtest single_family_jsonb statement ok -CREATE TABLE json_family (a INT PRIMARY KEY,b JSONB,FAMILY fam0(a),FAMILY fam1(b)) +CREATE TABLE json_family (a INT PRIMARY KEY, b JSONB, FAMILY fam0(a), FAMILY fam1(b)) statement ok INSERT INTO json_family VALUES(0,'{}') @@ -737,11 +888,201 @@ statement ok INSERT INTO json_family VALUES(1,'{"a":123,"c":"asdf"}') query IT colnames -SELECT a,b FROM json_family ORDER BY a +SELECT a, b FROM json_family ORDER BY a ---- -a b +a b 0 {} 1 {"a":123,"c":"asdf"} statement ok DROP TABLE json_family + +# Regression tests for #49143. Correctly handle cases where the -> operator +# results in NULL when both arguments are non-NULL. +subtest regression_49143 + +statement ok +CREATE TABLE t49143 (k INT PRIMARY KEY, j JSON); +INSERT INTO t49143 VALUES + (0, '[]'), + (1, '[1]'), + (2, '[2]'), + (3, '[[1, 2], [3, 4]]'), + (4, '[[5, 6], [7, 8]]'), + (5, '{}'), + (6, '{"a": 1}'), + (7, '{"b": 1}'), + (8, '{"b": 2}'), + (9, '{"b": [1, 2]}'), + (10, '{"b": [3, 4]}'); + +query T +SELECT j FROM t49143 WHERE NOT (j->0 = '2') ORDER BY k +---- +[1] +[[1,2],[3,4]] +[[5,6],[7,8]] + +query T +SELECT j FROM t49143 WHERE NOT (j->'b' = '1') ORDER BY k +---- +{"b":2} +{"b":[1,2]} +{"b":[3,4]} + +query T +SELECT j FROM t49143 WHERE NOT (j -> 0 @> '[1]') ORDER BY k +---- +[1] +[2] +[[5,6],[7,8]] + +query T +SELECT j FROM t49143 WHERE NOT (j -> 'b' @> '[1]') ORDER BY k +---- +{"b":1} +{"b":2} +{"b":[3,4]} + +# Regression tests for #57165 (wrong type conversion in the vectorized engine). +subtest regression_57165 + +statement ok +CREATE TABLE t57165(j JSON, s STRING); +INSERT INTO t57165 VALUES ('{"foo": "bar"}', 'foo'), ('{"bar": "foo"}', 'bar') + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT j - 'foo' AS a, j - 'bar' AS b FROM t57165 ORDER BY rowid +---- +{} {"foo": "bar"} +{"bar": "foo"} {} + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT '{"foo": "bar"}' - s AS a, '{"bar": "foo"}' - s AS b FROM t57165 ORDER BY rowid +---- +{} {"bar": "foo"} +{"foo": "bar"} {} + +query T +SELECT j - s FROM t57165 +---- +{} +{} + +query T +SELECT ARRAY['"hello"'::JSON] +---- +{"\"hello\""} + +query T +SELECT '{}'::JSONB[] +---- +{} + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT json_valid('{"hello": {}}') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT json_valid('{"foo": {"bar": 1, "one": 1, "two": 2') +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT json_valid('[{"bar": 1}, {"bar": 2}]') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT json_valid(NULL) +---- +NULL + +# Regression tests for #81647 (false negatives for ? operator in some cases). +subtest regression_81647 + +statement ok +CREATE TABLE t81647(j JSON); +INSERT INTO t81647 VALUES ('["a", "b"]') + +query TBTB +SELECT j, j ? 'a', j-1, (j-1) ? 'a' FROM t81647 +---- +["a","b"] true ["a"] true + +# +# Test JSONB subscripting. +# + +# Constant folding. +query TTT +SELECT + ('{"a": {"b": {"c": 1}}}'::jsonb)['a'], + ('{"a": {"b": {"c": 1}}}'::jsonb)['a']['b']['c'], + ('[1, "2", null]'::jsonb)[1] +---- +{"b":{"c":1}} 1 "2" + +# Referencing subscript which does not exist. +query TTTT +SELECT + ('{"a": 1}'::jsonb)['b'], + ('{"a": {"b": {"c": 1}}}'::jsonb)['c']['b']['c'], + ('[1, "2", null]'::jsonb)[4], + ('{"a": 1}'::jsonb)[NULL] +---- +NULL NULL NULL NULL + +# Error cases. +statement error jsonb subscript type must be coercible to integer or text +SELECT ('{"a": 1}'::jsonb)[now()] + +statement error jsonb subscript does not support slices +SELECT ('{"a": 1}'::jsonb)['a':'b'] + +# Not supported by Materialize. +onlyif cockroach +# Check it works from a JSON table. +statement ok +CREATE TABLE json_subscript_test ( + id SERIAL PRIMARY KEY, + j JSONB, + extract_field TEXT, + extract_int_field INT +); +INSERT INTO json_subscript_test (j, extract_field, extract_int_field) VALUES + ('{"other_field": 2}', 'other_field', 1), + ('{"field": {"field": 2}}', 'field', 0), + ('[1, 2, 3]', 'nothing_to_fetch', 1) + +# Not supported by Materialize. +onlyif cockroach +# Test subscripts with fields using other columns. +query TTITTTT +SELECT j, extract_field, extract_int_field, j['field'], j[extract_field], j[extract_field][extract_field], j[extract_int_field] +FROM json_subscript_test ORDER BY id +---- +{"other_field": 2} other_field 1 NULL 2 NULL NULL +{"field": {"field": 2}} field 0 {"field": 2} {"field": 2} 2 NULL +[1, 2, 3] nothing_to_fetch 1 NULL NULL NULL 2 + +# Not supported by Materialize. +onlyif cockroach +# Test use in a WHERE clause. +query T +SELECT j FROM json_subscript_test WHERE j['other_field'] = '2' ORDER BY id +---- +{"other_field": 2} diff --git a/test/sqllogictest/cockroach/json_builtins.slt b/test/sqllogictest/cockroach/json_builtins.slt index c13f3dec04797..5ba2c0324700d 100644 --- a/test/sqllogictest/cockroach/json_builtins.slt +++ b/test/sqllogictest/cockroach/json_builtins.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,18 +9,23 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/json_builtins +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/json_builtins # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach ## json_typeof and jsonb_typeof +# Not supported by Materialize. +onlyif cockroach query T SELECT json_typeof('-123.4'::JSON) ---- @@ -31,6 +36,8 @@ SELECT jsonb_typeof('-123.4'::JSON) ---- number +# Not supported by Materialize. +onlyif cockroach query T SELECT json_typeof('"-123.4"'::JSON) ---- @@ -41,16 +48,20 @@ SELECT jsonb_typeof('"-123.4"'::JSON) ---- string +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_typeof('{"1":{"2":3}}'::JSON) +SELECT json_typeof('{"1": {"2": 3}}'::JSON) ---- object query T -SELECT jsonb_typeof('{"1":{"2":3}}'::JSON) +SELECT jsonb_typeof('{"1": {"2": 3}}'::JSON) ---- object +# Not supported by Materialize. +onlyif cockroach query T SELECT json_typeof('[1, 2, [3]]'::JSON) ---- @@ -61,6 +72,8 @@ SELECT jsonb_typeof('[1, 2, [3]]'::JSON) ---- array +# Not supported by Materialize. +onlyif cockroach query T SELECT json_typeof('true'::JSON) ---- @@ -71,6 +84,8 @@ SELECT jsonb_typeof('true'::JSON) ---- boolean +# Not supported by Materialize. +onlyif cockroach query T SELECT json_typeof('false'::JSON) ---- @@ -81,6 +96,8 @@ SELECT jsonb_typeof('false'::JSON) ---- boolean +# Not supported by Materialize. +onlyif cockroach query T SELECT json_typeof('null'::JSON) ---- @@ -91,149 +108,203 @@ SELECT jsonb_typeof('null'::JSON) ---- null +# Not supported by Materialize. +onlyif cockroach ## array_to_json query T -SELECT array_to_json(ARRAY[[1,2],[3,4]]) +SELECT array_to_json(ARRAY[[1, 2], [3, 4]]) ---- -[[1,2],[3,4]] +[[1, 2], [3, 4]] +# Not supported by Materialize. +onlyif cockroach query T -SELECT array_to_json('{1,2,3}'::INT[]) +SELECT array_to_json('{1, 2, 3}'::INT[]) ---- -[1,2,3] +[1, 2, 3] +# Not supported by Materialize. +onlyif cockroach query T -SELECT array_to_json('{"a","b","c"}'::STRING[]) +SELECT array_to_json('{"a", "b", "c"}'::STRING[]) ---- -["a","b","c"] +["a", "b", "c"] +# Not supported by Materialize. +onlyif cockroach query T -SELECT array_to_json('{1.0,2.0,3.0}'::DECIMAL[]) +SELECT array_to_json('{1.0, 2.0, 3.0}'::DECIMAL[]) ---- -[1.0,2.0,3.0] +[1.0, 2.0, 3.0] +# Not supported by Materialize. +onlyif cockroach query T SELECT array_to_json(NULL) ---- NULL +# Not supported by Materialize. +onlyif cockroach query T -SELECT array_to_json(ARRAY[1,2,3],NULL) +SELECT array_to_json(ARRAY[1, 2, 3], NULL) ---- NULL +# Not supported by Materialize. +onlyif cockroach query T -SELECT array_to_json(ARRAY[1,2,3],false) +SELECT array_to_json(ARRAY[1, 2, 3], false) ---- -[1,2,3] +[1, 2, 3] -query error pq:array_to_json\(\):pretty printing is not supported -SELECT array_to_json(ARRAY[1,2,3],true) +query error function "array_to_json" does not exist +SELECT array_to_json(ARRAY[1, 2, 3], true) -query error pq:unknown signature:array_to_json\(string\) +query error function "array_to_json" does not exist SELECT array_to_json('hello world') ## to_json and to_jsonb +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json(123::INT) ---- 123 +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('\a'::TEXT) ---- "\\a" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('\a'::TEXT COLLATE "fr_FR") ---- "\\a" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json(3::OID::INT::OID) ---- "3" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::UUID); ---- "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('\x0001'::BYTEA) ---- "\\x0001" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json(true::BOOL) ---- true +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json(false::BOOL) ---- false +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('"a"'::JSON) ---- "a" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json(1.234::FLOAT) ---- 1.234 +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json(1.234::DECIMAL) ---- 1.234 +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('10.1.0.0/16'::INET) ---- "10.1.0.0/16" +# Not supported by Materialize. +onlyif cockroach query T -SELECT to_json(ARRAY[[1,2],[3,4]]) +SELECT to_json(ARRAY[[1, 2], [3, 4]]) ---- -[[1,2],[3,4]] +[[1, 2], [3, 4]] +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('2014-05-28 12:22:35.614298'::TIMESTAMP) ---- "2014-05-28T12:22:35.614298" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('2014-05-28 12:22:35.614298-04'::TIMESTAMPTZ) ---- -"2014-05-28T12:22:35.614298-04:00" +"2014-05-28T16:22:35.614298Z" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('2014-05-28 12:22:35.614298-04'::TIMESTAMP) ---- "2014-05-28T12:22:35.614298" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('2014-05-28'::DATE) ---- "2014-05-28" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('00:00:00'::TIME) ---- "00:00:00" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_json('2h45m2s234ms'::INTERVAL) ---- "02:45:02.234" +# Not supported by Materialize. +onlyif cockroach query T -SELECT to_json((1,2,'hello',NULL,NULL)) +SELECT to_json((1, 2, 'hello', NULL, NULL)) ---- -{"f1":1,"f2":2,"f3":"hello","f4":null,"f5":null} +{"f1": 1, "f2": 2, "f3": "hello", "f4": null, "f5": null} query T SELECT to_jsonb(123::INT) @@ -245,6 +316,8 @@ SELECT to_jsonb('\a'::TEXT) ---- "\\a" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_jsonb('\a'::TEXT COLLATE "fr_FR") ---- @@ -290,30 +363,32 @@ SELECT to_jsonb(1.234::DECIMAL) ---- 1.234 +# Not supported by Materialize. +onlyif cockroach query T SELECT to_jsonb('10.1.0.0/16'::INET) ---- "10.1.0.0/16" query T -SELECT to_jsonb(ARRAY[[1,2],[3,4]]) +SELECT to_jsonb(ARRAY[[1, 2], [3, 4]]) ---- [[1,2],[3,4]] query T SELECT to_jsonb('2014-05-28 12:22:35.614298'::TIMESTAMP) ---- -"2014-05-28T12:22:35.614298" +"2014-05-28 12:22:35.614298" query T SELECT to_jsonb('2014-05-28 12:22:35.614298-04'::TIMESTAMPTZ) ---- -"2014-05-28T12:22:35.614298-04:00" +"2014-05-28 16:22:35.614298+00" query T SELECT to_jsonb('2014-05-28 12:22:35.614298-04'::TIMESTAMP) ---- -"2014-05-28T12:22:35.614298" +"2014-05-28 12:22:35.614298" query T SELECT to_jsonb('2014-05-28'::DATE) @@ -325,245 +400,490 @@ SELECT to_jsonb('00:00:00'::TIME) ---- "00:00:00" +# Not supported by Materialize. +onlyif cockroach query T SELECT to_jsonb('2h45m2s234ms'::INTERVAL) ---- "02:45:02.234" query T -SELECT to_jsonb((1,2,'hello',NULL,NULL)) +SELECT to_jsonb((1, 2, 'hello', NULL, NULL)) ---- {"f1":1,"f2":2,"f3":"hello","f4":null,"f5":null} -## json_array_elements and jsonb_array_elements +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_json(x.*) FROM (VALUES (1,2)) AS x(a,b); +---- +{"a": 1, "b": 2} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_json(x.*) FROM (VALUES (1,2)) AS x(a); +---- +{"a": 1, "column2": 2} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_array_elements('[1,2,3]'::JSON) +SELECT to_json(x.*) FROM (VALUES (1,2)) AS x(column2); ---- +{"column2": 2} + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #39502. +statement ok +SELECT json_agg((3808362714,)) + +## json_array_elements and jsonb_array_elements + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT json_array_elements('[1, 2, 3]'::JSON) +---- +json_array_elements 1 2 3 -query T -SELECT jsonb_array_elements('[1,2,3]'::JSON) +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT * FROM json_array_elements('[1, 2, 3]'::JSON) ---- +value 1 2 3 -query T -SELECT json_array_elements('[1,true,null,"text",-1.234,{"2":3,"4":"5"},[1,2,3]]'::JSON) +query T colnames +SELECT jsonb_array_elements('[1, 2, 3]'::JSON) ---- +jsonb_array_elements +1 +2 +3 + +query T colnames +SELECT * FROM jsonb_array_elements('[1, 2, 3]'::JSON) +---- +value +1 +2 +3 + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT json_array_elements('[1, true, null, "text", -1.234, {"2": 3, "4": "5"}, [1, 2, 3]]'::JSON) +---- +json_array_elements 1 true null "text" -1.234 -{"2":3,"4":"5"} -[1,2,3] +{"2": 3, "4": "5"} +[1, 2, 3] +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT * FROM json_array_elements('[1, true, null, "text", -1.234, {"2": 3, "4": "5"}, [1, 2, 3]]'::JSON) +---- +value +1 +true +null +"text" +-1.234 +{"2": 3, "4": "5"} +[1, 2, 3] + +# Not supported by Materialize. +onlyif cockroach query T SELECT json_array_elements('[]'::JSON) ---- -query error pq:cannot be called on a non-array -SELECT json_array_elements('{"1":2}'::JSON) +query error function "json_array_elements" does not exist +SELECT json_array_elements('{"1": 2}'::JSON) -query error pq:cannot be called on a non-array -SELECT jsonb_array_elements('{"1":2}'::JSON) +# Not supported by Materialize. +onlyif cockroach +query error pq: cannot be called on a non-array +SELECT jsonb_array_elements('{"1": 2}'::JSON) ## json_array_elements_text and jsonb_array_elements_text -query T -SELECT json_array_elements_text('[1,2,3]'::JSON) +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT json_array_elements_text('[1, 2, 3]'::JSON) ---- +json_array_elements_text 1 2 3 -query T -SELECT json_array_elements_text('[1,2,3]'::JSON) +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT * FROM json_array_elements_text('[1, 2, 3]'::JSON) +---- +value +1 +2 +3 + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT json_array_elements_text('[1, 2, 3]'::JSON) +---- +json_array_elements_text +1 +2 +3 + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT * FROM json_array_elements_text('[1, 2, 3]'::JSON) ---- +value 1 2 3 +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_array_elements_text('[1,true,null,"text",-1.234,{"2":3,"4":"5"},[1,2,3]]'::JSON) +SELECT json_array_elements_text('[1, true, null, "text", -1.234, {"2": 3, "4": "5"}, [1, 2, 3]]'::JSON) ---- 1 true NULL text -1.234 -{"2":3,"4":"5"} -[1,2,3] +{"2": 3, "4": "5"} +[1, 2, 3] +# Not supported by Materialize. +onlyif cockroach query T SELECT json_array_elements('[]'::JSON) ---- -query error pq:cannot be called on a non-array -SELECT json_array_elements_text('{"1":2}'::JSON) +query error function "json_array_elements_text" does not exist +SELECT json_array_elements_text('{"1": 2}'::JSON) -query error pq:cannot be called on a non-array -SELECT jsonb_array_elements_text('{"1":2}'::JSON) +# Not supported by Materialize. +onlyif cockroach +query error pq: cannot be called on a non-array +SELECT jsonb_array_elements_text('{"1": 2}'::JSON) ## json_object_keys and jsonb_object_keys +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_object_keys('{"1":2,"3":4}'::JSON) +SELECT json_object_keys('{"1": 2, "3": 4}'::JSON) ---- 1 3 query T -SELECT jsonb_object_keys('{"1":2,"3":4}'::JSON) +SELECT jsonb_object_keys('{"1": 2, "3": 4}'::JSON) ---- 1 3 +# Not supported by Materialize. +onlyif cockroach query T SELECT json_object_keys('{}'::JSON) ---- +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_object_keys('{"\"1\"":2}'::JSON) +SELECT json_object_keys('{"\"1\"": 2}'::JSON) ---- "1" +# Not supported by Materialize. +onlyif cockroach # Keys are sorted. -query T -SELECT json_object_keys('{"a":1,"1":2,"3":{"4":5,"6":7}}'::JSON) +query T colnames +SELECT json_object_keys('{"a": 1, "1": 2, "3": {"4": 5, "6": 7}}'::JSON) ---- +json_object_keys 1 3 a -query error pq:cannot call json_object_keys on a scalar +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT * FROM json_object_keys('{"a": 1, "1": 2, "3": {"4": 5, "6": 7}}'::JSON) +---- +json_object_keys +1 +3 +a + +query error function "json_object_keys" does not exist SELECT json_object_keys('null'::JSON) -query error pq:cannot call json_object_keys on an array -SELECT json_object_keys('[1,2,3]'::JSON) +query error function "json_object_keys" does not exist +SELECT json_object_keys('[1, 2, 3]'::JSON) ## json_build_object +# Not supported by Materialize. +onlyif cockroach query T SELECT json_build_object() ---- {} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_build_object('a',2,'b',4) +SELECT json_build_object('a', 2, 'b', 4) ---- -{"a":2,"b":4} +{"a": 2, "b": 4} +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_build_object(true,'val',1,0,1.3,2,date '2019-02-03' - date '2019-01-01',4) +SELECT jsonb_build_object(true,'val',1, 0, 1.3, 2, date '2019-02-03' - date '2019-01-01', 4, '2001-01-01 11:00+3'::timestamptz, '11:00+3'::timetz) ---- -{"1":0,"1.3":2,"33":4,"true":"val"} +{"1": 0, "1.3": 2, "2001-01-01 08:00:00+00": "11:00:00+03", "33": 4, "true": "val"} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_build_object('a',1,'b',1.2,'c',true,'d',null,'e','{"x":3,"y":[1,2,3]}'::JSON) +SELECT json_build_object('a',1,'b',1.2,'c',true,'d',null,'e','{"x": 3, "y": [1,2,3]}'::JSON) ---- -{"a":1,"b":1.2,"c":true,"d":null,"e":{"x":3,"y":[1,2,3]}} +{"a": 1, "b": 1.2, "c": true, "d": null, "e": {"x": 3, "y": [1, 2, 3]}} +# Not supported by Materialize. +onlyif cockroach query T SELECT json_build_object( - 'a',json_build_object('b',false,'c',99), - 'd',json_build_object('e',ARRAY[9,8,7]::int[]) + 'a', json_build_object('b',false,'c',99), + 'd', json_build_object('e',ARRAY[9,8,7]::int[]) ) ---- -{"a":{"b":false,"c":99},"d":{"e":[9,8,7]}} +{"a": {"b": false, "c": 99}, "d": {"e": [9, 8, 7]}} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_build_object(a,3) FROM (SELECT 1 AS a,2 AS b) r +SELECT json_build_object(a,3) FROM (SELECT 1 AS a, 2 AS b) r ---- -{"1":3} +{"1": 3} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_build_object('\a'::TEXT COLLATE "fr_FR",1) +SELECT json_build_object('\a'::TEXT COLLATE "fr_FR", 1) ---- -{"\\a":1} +{"\\a": 1} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_build_object('\a',1) +SELECT json_build_object('\a', 1) ---- -{"\\a":1} +{"\\a": 1} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_build_object(json_object_keys('{"x":3,"y":4}'::JSON),2) +SELECT json_build_object(json_object_keys('{"x":3, "y":4}'::JSON), 2) ---- -{"x":2} -{"y":2} +{"x": 2} +{"y": 2} +# Not supported by Materialize. +onlyif cockroach # Regression for panic when bit array is passed as argument. query T -SELECT json_build_object('a','0100110'::varbit) +SELECT json_build_object('a', '0100110'::varbit) +---- +{"a": "0100110"} + +# Not supported by Materialize. +onlyif cockroach +# Regression for an internal error when using an enum and void in the key. +statement ok +CREATE TYPE e AS ENUM ('e'); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT json_build_object('e'::e, 1) +---- +{"e": 1} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT json_build_object(''::void, 1) ---- -{"a":"0100110"} +{"": 1} # even number of arguments -query error pq:json_build_object\(\):argument list must have even number of elements +query error function "json_build_object" does not exist SELECT json_build_object(1,2,3) # keys must be scalar and not null -query error pq:json_build_object\(\):argument 1 cannot be null +query error function "json_build_object" does not exist SELECT json_build_object(null,2) -query error pq:json_build_object\(\):key value must be scalar,not array,tuple,or json +query error function "json_build_object" does not exist SELECT json_build_object((1,2),3) -query error pq:json_build_object\(\):key value must be scalar,not array,tuple,or json -SELECT json_build_object('{"a":1,"b":2}'::JSON,3) +query error function "json_build_object" does not exist +SELECT json_build_object('{"a":1,"b":2}'::JSON, 3) -query error pq:json_build_object\(\):key value must be scalar,not array,tuple,or json -SELECT json_build_object('{1,2,3}'::int[],3) +query error function "json_build_object" does not exist +SELECT json_build_object('{1,2,3}'::int[], 3) +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_extract_path('{"a":1}','a') +SELECT json_build_object('a'::tsvector, 1, 'b'::tsquery, 2) +---- +{"'a'": 1, "'b'": 2} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT json_extract_path('{"a": 1}', 'a') ---- 1 +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_extract_path('{"a":1}','a',NULL) +SELECT json_extract_path('{"a": 1}', 'a', NULL) ---- NULL +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_extract_path('{"a":1}') +SELECT json_extract_path('{"a": 1}') ---- -{"a":1} +{"a": 1} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_extract_path('{"a":{"b":2}}','a') +SELECT json_extract_path('{"a": {"b": 2}}', 'a') ---- -{"b":2} +{"b": 2} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_extract_path('{"a":{"b":2}}','a','b') +SELECT json_extract_path('{"a": {"b": 2}}', 'a', 'b') ---- 2 +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_extract_path('{"a":{"b":2}}','a','b') +SELECT jsonb_extract_path('{"a": {"b": 2}}', 'a', 'b') ---- 2 +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_extract_path('{"a":{"b":2}}','a','b','c') +SELECT json_extract_path('{"a": {"b": 2}}', 'a', 'b', 'c') ---- NULL +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_pretty('{"a":1}') +SELECT json_extract_path('null') ---- -{ - "a":1 -} +null + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT json_extract_path_text('{"a": 1}', 'a') +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT json_extract_path_text('{"a": 1}', 'a', NULL) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT json_extract_path_text('{"a": 1}') +---- +{"a": 1} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT json_extract_path_text('{"a": {"b": 2}}', 'a') +---- +{"b": 2} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT json_extract_path_text('{"a": {"b": 2}}', 'a', 'b') +---- +2 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT jsonb_extract_path_text('{"a": {"b": 2}}', 'a', 'b') +---- +2 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT json_extract_path_text('{"a": {"b": 2}}', 'a', 'b', 'c') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT json_extract_path_text('null') +---- +NULL + +query T +SELECT jsonb_pretty('{"a": 1}') +---- +{⏎ "a": 1⏎} query T SELECT '[1,2,3]'::JSON || '[4,5,6]'::JSON @@ -571,27 +891,35 @@ SELECT '[1,2,3]'::JSON || '[4,5,6]'::JSON [1,2,3,4,5,6] query T -SELECT '{"a":1,"b":2}'::JSON || '{"b":3,"c":4}' +SELECT '{"a": 1, "b": 2}'::JSON || '{"b": 3, "c": 4}' ---- {"a":1,"b":3,"c":4} +# Not supported by Materialize. +onlyif cockroach query error pgcode 22023 invalid concatenation of jsonb objects -SELECT '{"a":1,"b":2}'::JSON || '"c"' +SELECT '{"a": 1, "b": 2}'::JSON || '"c"' +# Not supported by Materialize. +onlyif cockroach query T SELECT json_build_array() ---- [] +# Not supported by Materialize. +onlyif cockroach query T SELECT json_build_array('\x0001'::BYTEA) ---- ["\\x0001"] +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_build_array(1,'1'::JSON,1.2,NULL,ARRAY['x','y']) +SELECT json_build_array(1, '1'::JSON, 1.2, NULL, ARRAY['x', 'y']) ---- -[1,1,1.2,null,["x","y"]] +[1, 1, 1.2, null, ["x", "y"]] query T SELECT jsonb_build_array() @@ -604,343 +932,495 @@ SELECT jsonb_build_array('\x0001'::BYTEA) ["\\x0001"] query T -SELECT jsonb_build_array(1,'1'::JSON,1.2,NULL,ARRAY['x','y']) +SELECT jsonb_build_array(1, '1'::JSON, 1.2, NULL, ARRAY['x', 'y']) ---- [1,1,1.2,null,["x","y"]] -# Regression for cockroach#37318 +# Not supported by Materialize. +onlyif cockroach +# Regression for #37318 query T -SELECT jsonb_build_array('+Inf'::FLOAT8,'NaN'::FLOAT8)::STRING::JSONB +SELECT jsonb_build_array('+Inf'::FLOAT8, 'NaN'::FLOAT8)::STRING::JSONB ---- -["Infinity","NaN"] +["Infinity", "NaN"] -query error pq:json_object\(\):array must have even number of elements +query error function "json_object" does not exist SELECT json_object('{a,b,c}'::TEXT[]) -query error pq:json_object\(\):null value not allowed for object key -SELECT json_object('{NULL,a}'::TEXT[]) +query error function "json_object" does not exist +SELECT json_object('{NULL, a}'::TEXT[]) -query error pq:json_object\(\):null value not allowed for object key +query error function "json_object" does not exist SELECT json_object('{a,b,NULL,"d e f"}'::TEXT[],'{1,2,3,"a b c"}'::TEXT[]) -query error pq:json_object\(\):mismatched array dimensions +query error function "json_object" does not exist SELECT json_object('{a,b,c,"d e f",g}'::TEXT[],'{1,2,3,"a b c"}'::TEXT[]) -query error pq:json_object\(\):mismatched array dimensions +query error function "json_object" does not exist SELECT json_object('{a,b,c,"d e f"}'::TEXT[],'{1,2,3,"a b c",g}'::TEXT[]) -query error pq:unknown signature:json_object\(collatedstring\{fr_FR\}\[\]\) +query error function "json_object" does not exist SELECT json_object(ARRAY['a'::TEXT COLLATE "fr_FR"]) +# Not supported by Materialize. +onlyif cockroach query T SELECT json_object('{}'::TEXT[]) ---- {} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_object('{}'::TEXT[],'{}'::TEXT[]) +SELECT json_object('{}'::TEXT[], '{}'::TEXT[]) ---- {} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_object('{b,3,a,1,b,4,a,2}'::TEXT[]) +SELECT json_object('{b, 3, a, 1, b, 4, a, 2}'::TEXT[]) ---- -{"a":"2","b":"4"} +{"a": "2", "b": "4"} +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_object('{b,b,a,a}'::TEXT[],'{1,2,3,4}'::TEXT[]) +SELECT json_object('{b, b, a, a}'::TEXT[], '{1, 2, 3, 4}'::TEXT[]) ---- -{"a":"4","b":"2"} +{"a": "4", "b": "2"} +# Not supported by Materialize. +onlyif cockroach query T SELECT json_object('{a,1,b,2,3,NULL,"d e f","a b c"}'::TEXT[]) ---- -{"3":null,"a":"1","b":"2","d e f":"a b c"} +{"3": null, "a": "1", "b": "2", "d e f": "a b c"} +# Not supported by Materialize. +onlyif cockroach query T SELECT json_object('{a,b,"","d e f"}'::TEXT[],'{1,2,3,"a b c"}'::TEXT[]) ---- -{"":"3","a":"1","b":"2","d e f":"a b c"} +{"": "3", "a": "1", "b": "2", "d e f": "a b c"} +# Not supported by Materialize. +onlyif cockroach query T SELECT json_object('{a,b,c,"d e f"}'::TEXT[],'{1,2,3,"a b c"}'::TEXT[]) ---- -{"a":"1","b":"2","c":"3","d e f":"a b c"} +{"a": "1", "b": "2", "c": "3", "d e f": "a b c"} -query error pq:jsonb_object\(\):array must have even number of elements +query error function "jsonb_object" does not exist SELECT jsonb_object('{a,b,c}'::TEXT[]) -query error pq:jsonb_object\(\):null value not allowed for object key -SELECT jsonb_object('{NULL,a}'::TEXT[]) +query error function "jsonb_object" does not exist +SELECT jsonb_object('{NULL, a}'::TEXT[]) -query error pq:jsonb_object\(\):null value not allowed for object key +query error function "jsonb_object" does not exist SELECT jsonb_object('{a,b,NULL,"d e f"}'::TEXT[],'{1,2,3,"a b c"}'::TEXT[]) -query error pq:jsonb_object\(\):mismatched array dimensions +query error function "jsonb_object" does not exist SELECT jsonb_object('{a,b,c,"d e f",g}'::TEXT[],'{1,2,3,"a b c"}'::TEXT[]) -query error pq:jsonb_object\(\):mismatched array dimensions +query error function "jsonb_object" does not exist SELECT jsonb_object('{a,b,c,"d e f"}'::TEXT[],'{1,2,3,"a b c",g}'::TEXT[]) -query error pq:unknown signature:jsonb_object\(collatedstring\{fr_FR\}\[\]\) +query error function "jsonb_object" does not exist SELECT jsonb_object(ARRAY['a'::TEXT COLLATE "fr_FR"]) +# Not supported by Materialize. +onlyif cockroach query T SELECT jsonb_object('{}'::TEXT[]) ---- {} +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_object('{}'::TEXT[],'{}'::TEXT[]) +SELECT jsonb_object('{}'::TEXT[], '{}'::TEXT[]) ---- {} +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_object('{b,3,a,1,b,4,a,2}'::TEXT[]) +SELECT jsonb_object('{b, 3, a, 1, b, 4, a, 2}'::TEXT[]) ---- -{"a":"2","b":"4"} +{"a": "2", "b": "4"} +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_object('{b,b,a,a}'::TEXT[],'{1,2,3,4}'::TEXT[]) +SELECT jsonb_object('{b, b, a, a}'::TEXT[], '{1, 2, 3, 4}'::TEXT[]) ---- -{"a":"4","b":"2"} +{"a": "4", "b": "2"} +# Not supported by Materialize. +onlyif cockroach query T SELECT jsonb_object('{a,1,b,2,3,NULL,"d e f","a b c"}'::TEXT[]) ---- -{"3":null,"a":"1","b":"2","d e f":"a b c"} +{"3": null, "a": "1", "b": "2", "d e f": "a b c"} +# Not supported by Materialize. +onlyif cockroach query T SELECT jsonb_object('{a,b,"","d e f"}'::TEXT[],'{1,2,3,"a b c"}'::TEXT[]) ---- -{"":"3","a":"1","b":"2","d e f":"a b c"} +{"": "3", "a": "1", "b": "2", "d e f": "a b c"} +# Not supported by Materialize. +onlyif cockroach query T SELECT jsonb_object('{a,b,c,"d e f"}'::TEXT[],'{1,2,3,"a b c"}'::TEXT[]) ---- -{"a":"1","b":"2","c":"3","d e f":"a b c"} +{"a": "1", "b": "2", "c": "3", "d e f": "a b c"} -query error pq:cannot deconstruct an array as an object +query error function "json_each" does not exist SELECT json_each('[1]'::JSON) -query error pq:cannot deconstruct a scalar +query error function "json_each" does not exist SELECT json_each('null'::JSON) +# Not supported by Materialize. +onlyif cockroach query TT -SELECT * from json_each('{}') q +SELECT * FROM json_each('{}') q +---- + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT json_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') ---- +json_each +(f1,"[1, 2, 3]") +(f2,"{""f3"": 1}") +(f4,null) +(f5,99) +(f6,"""stringy""") +# Not supported by Materialize. +onlyif cockroach query TT colnames -SELECT * from json_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q +SELECT * FROM json_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q ---- key value -f1 [1,2,3] -f2 {"f3":1} +f1 [1, 2, 3] +f2 {"f3": 1} f4 null f5 99 f6 "stringy" -query error pq:cannot deconstruct an array as an object +# Not supported by Materialize. +onlyif cockroach +query error pq: cannot deconstruct an array as an object SELECT jsonb_each('[1]'::JSON) -query error pq:cannot deconstruct a scalar +# Not supported by Materialize. +onlyif cockroach +query error pq: cannot deconstruct a scalar SELECT jsonb_each('null'::JSON) query TT -SELECT * from jsonb_each('{}') q +SELECT * FROM jsonb_each('{}') q ---- -query TT colnames -SELECT * from jsonb_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q +query T colnames +SELECT jsonb_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') ---- -key value -f1 [1,2,3] -f2 {"f3":1} -f4 null -f5 99 -f6 "stringy" +jsonb_each +(f4,null) +(f5,99) +(f6,"""stringy""") +(f2,"{""f3"":1}") +(f1,"[1,2,3]") -query error pq:cannot deconstruct an array as an object +query TT colnames +SELECT * FROM jsonb_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q +---- +key value +f4 null +f5 99 +f6 "stringy" +f2 {"f3":1} +f1 [1,2,3] + +# Not supported by Materialize. +onlyif cockroach +query error pq: cannot deconstruct an array as an object SELECT jsonb_each_text('[1]'::JSON) -query error pq:cannot deconstruct a scalar +# Not supported by Materialize. +onlyif cockroach +query error pq: cannot deconstruct a scalar SELECT jsonb_each_text('null'::JSON) query TT -SELECT * from jsonb_each_text('{}') q +SELECT * FROM jsonb_each_text('{}') q ---- -query TT -SELECT * from jsonb_each_text('{}') q +query T colnames +SELECT jsonb_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') ---- +jsonb_each_text +(f4,) +(f5,99) +(f1,"[1,2,3]") +(f6,stringy) +(f2,"{""f3"":1}") + +query T colnames +SELECT jsonb_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q +---- +q +(f4,) +(f5,99) +(f1,"[1,2,3]") +(f6,stringy) +(f2,"{""f3"":1}") query TT colnames -SELECT * from jsonb_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q +SELECT * FROM jsonb_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q ---- -key value -f1 [1,2,3] -f2 {"f3":1} -f4 NULL -f5 99 -f6 stringy +key value +f4 NULL +f5 99 +f1 [1,2,3] +f6 stringy +f2 {"f3":1} -query error pq:cannot deconstruct an array as an object +query error function "json_each_text" does not exist SELECT json_each_text('[1]'::JSON) -query error pq:cannot deconstruct a scalar +query error function "json_each_text" does not exist SELECT json_each_text('null'::JSON) +# Not supported by Materialize. +onlyif cockroach query TT -SELECT * from json_each_text('{}') q +SELECT * FROM json_each_text('{}') q ---- +# Not supported by Materialize. +onlyif cockroach query TT -SELECT * from json_each_text('{}') q ----- - +SELECT * FROM json_each_text('{}') q +---- + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT json_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') +---- +json_each_text +(f1,"[1, 2, 3]") +(f2,"{""f3"": 1}") +(f4,) +(f5,99) +(f6,stringy) + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT json_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q +---- +q +(f1,"[1, 2, 3]") +(f2,"{""f3"": 1}") +(f4,) +(f5,99) +(f6,stringy) + +# Not supported by Materialize. +onlyif cockroach query TT colnames -SELECT * from json_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q +SELECT * FROM json_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') q ---- key value -f1 [1,2,3] -f2 {"f3":1} +f1 [1, 2, 3] +f2 {"f3": 1} f4 NULL f5 99 f6 stringy +# Not supported by Materialize. +onlyif cockroach query T -SELECT json_set('{"a":1}','{a}'::STRING[],'2') +SELECT json_set('{"a":1}', '{a}'::STRING[], '2') ---- -{"a":2} +{"a": 2} +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_set('{"a":1}','{b}'::STRING[],'2') +SELECT jsonb_set('{"a":1}', '{b}'::STRING[], '2') ---- -{"a":1,"b":2} +{"a": 1, "b": 2} -statement error path element at position 1 is null -SELECT jsonb_set('{"a":1}',ARRAY[null,'foo']::STRING[],'2') +statement error function "jsonb_set" does not exist +SELECT jsonb_set('{"a":1}', ARRAY[null, 'foo']::STRING[], '2') -statement error path element at position 1 is null -SELECT jsonb_set('{"a":1}','{null,foo}'::STRING[],'2',true) +statement error function "jsonb_set" does not exist +SELECT jsonb_set('{"a":1}', '{null,foo}'::STRING[], '2', true) -statement error path element at position 2 is null -SELECT jsonb_set('{"a":1}','{foo,null}'::STRING[],'2',true) +statement error function "jsonb_set" does not exist +SELECT jsonb_set('{"a":1}', '{foo,null}'::STRING[], '2', true) +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_set('{"a":1}','{b}'::STRING[],'2',true) +SELECT jsonb_set('{"a":1}', '{b}'::STRING[], '2', true) ---- -{"a":1,"b":2} +{"a": 1, "b": 2} +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_set('{"a":1}','{b}'::STRING[],'2',false) +SELECT jsonb_set('{"a":1}', '{b}'::STRING[], '2', false) ---- -{"a":1} +{"a": 1} +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_set('[{"f1":1,"f2":null},2,null,3]','{0,f1}'::STRING[],'[2,3,4]',false) +SELECT jsonb_set('[{"f1":1,"f2":null},2,null,3]', '{0,f1}'::STRING[], '[2,3,4]', false) ---- -[{"f1":[2,3,4],"f2":null},2,null,3] +[{"f1": [2, 3, 4], "f2": null}, 2, null, 3] +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_set('[{"f1":1,"f2":null},2]','{0,f3}'::STRING[],'[2,3,4]') +SELECT jsonb_set('[{"f1":1,"f2":null},2]', '{0,f3}'::STRING[], '[2,3,4]') ---- -[{"f1":1,"f2":null,"f3":[2,3,4]},2] +[{"f1": 1, "f2": null, "f3": [2, 3, 4]}, 2] +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_insert('{"a":[0,1,2]}','{a,1}'::STRING[],'"new_value"'); +SELECT jsonb_insert('{"a": [0, 1, 2]}', '{a, 1}'::STRING[], '"new_value"'); ---- -{"a":[0,"new_value",1,2]} +{"a": [0, "new_value", 1, 2]} +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_insert('[0,1,2,{"a":["a","b","d"]},4]','{3,a,2}'::STRING[],'"c"') +SELECT jsonb_insert('[0, 1, 2, {"a": ["a", "b", "d"]}, 4]', '{3, a, 2}'::STRING[], '"c"') ---- -[0,1,2,{"a":["a","b","c","d"]},4] +[0, 1, 2, {"a": ["a", "b", "c", "d"]}, 4] +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_insert('{"a":"foo"}','{b}'::STRING[],'"bar"') +SELECT jsonb_insert('{"a": "foo"}', '{b}'::STRING[], '"bar"') ---- -{"a":"foo","b":"bar"} +{"a": "foo", "b": "bar"} +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_insert(NULL,'{a}',NULL,false) +SELECT jsonb_insert(NULL, '{a}', NULL, false) ---- NULL +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_insert('{"a":[0,1,2]}','{a,1}'::STRING[],'"new_value"',true) +SELECT jsonb_insert('{"a": [0, 1, 2]}', '{a, 1}'::STRING[], '"new_value"', true) ---- -{"a":[0,1,"new_value",2]} +{"a": [0, 1, "new_value", 2]} +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_insert('{"a":[0,1,2]}','{a,-1}'::STRING[],'"new_value"',true) +SELECT jsonb_insert('{"a": [0, 1, 2]}', '{a, -1}'::STRING[], '"new_value"', true) ---- -{"a":[0,1,2,"new_value"]} +{"a": [0, 1, 2, "new_value"]} -query error pq:jsonb_insert\(\):cannot replace existing key -SELECT jsonb_insert('{"a":"foo"}','{a}'::STRING[],'"new_value"',false) +query error function "jsonb_insert" does not exist +SELECT jsonb_insert('{"a": "foo"}', '{a}'::STRING[], '"new_value"', false) +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_insert('{"a":"foo"}','{a,0}'::STRING[],'"new_value"',false) +SELECT jsonb_insert('{"a": "foo"}', '{a, 0}'::STRING[], '"new_value"', false) ---- -{"a":"foo"} +{"a": "foo"} +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_insert('[0,1,2,3]','{3}'::STRING[],'10',true) +SELECT jsonb_insert('[0, 1, 2, 3]', '{3}'::STRING[], '10', true) ---- -[0,1,2,3,10] +[0, 1, 2, 3, 10] -statement error cannot set path in scalar -SELECT jsonb_insert('1','{a}'::STRING[],'10',true) +statement error function "jsonb_insert" does not exist +SELECT jsonb_insert('1', '{a}'::STRING[], '10', true) +# Not supported by Materialize. +onlyif cockroach query T -SELECT jsonb_insert('1',NULL,'10') +SELECT jsonb_insert('1', NULL, '10') ---- NULL -statement error path element at position 1 is null -SELECT jsonb_insert('{"a":[0,1,2],"b":"hello","c":"world"}','{NULL,a,0}'::STRING[],'"new_val"') +statement error function "jsonb_insert" does not exist +SELECT jsonb_insert('{"a": [0, 1, 2], "b": "hello", "c": "world"}', '{NULL, a, 0}'::STRING[], '"new_val"') -statement error path element at position 2 is null -SELECT jsonb_insert('{"a":[0,1,2],"b":"hello","c":"world"}','{a,NULL,0}'::STRING[],'"new_val"') +statement error function "jsonb_insert" does not exist +SELECT jsonb_insert('{"a": [0, 1, 2], "b": "hello", "c": "world"}', '{a, NULL, 0}'::STRING[], '"new_val"') query T SELECT jsonb_strip_nulls(NULL) ---- NULL +# Not supported by Materialize. +onlyif cockroach query T SELECT json_strip_nulls('1') ---- 1 +# Not supported by Materialize. +onlyif cockroach query T SELECT json_strip_nulls('"a string"') ---- "a string" +# Not supported by Materialize. +onlyif cockroach query T SELECT json_strip_nulls('null') ---- null +# Not supported by Materialize. +onlyif cockroach query T SELECT json_strip_nulls('[1,2,null,3,4]') ---- -[1,2,null,3,4] +[1, 2, null, 3, 4] +# Not supported by Materialize. +onlyif cockroach query T SELECT json_strip_nulls('{"a":1,"b":null,"c":[2,null,3],"d":{"e":4,"f":null}}') ---- -{"a":1,"c":[2,null,3],"d":{"e":4}} +{"a": 1, "c": [2, null, 3], "d": {"e": 4}} +# Not supported by Materialize. +onlyif cockroach query T SELECT json_strip_nulls('[1,{"a":1,"b":null,"c":2},3]') ---- -[1,{"a":1,"c":2},3] +[1, {"a": 1, "c": 2}, 3] query T -SELECT jsonb_strip_nulls('{"a":{"b":null,"c":null},"d":{}}') +SELECT jsonb_strip_nulls('{"a": {"b": null, "c": null}, "d": {}}') ---- {"a":{},"d":{}} @@ -980,30 +1460,38 @@ SELECT jsonb_strip_nulls('[1,{"a":1,"b":null,"c":2},3]') [1,{"a":1,"c":2},3] query T -SELECT jsonb_strip_nulls('{"a":{"b":null,"c":null},"d":{}}') +SELECT jsonb_strip_nulls('{"a": {"b": null, "c": null}, "d": {}}') ---- {"a":{},"d":{}} -query error pq:json_array_length\(\):cannot get array length of a non-array +query error function "json_array_length" does not exist SELECT json_array_length('{"f1":1,"f2":[5,6]}') -query error pq:json_array_length\(\):cannot get array length of a scalar +query error function "json_array_length" does not exist SELECT json_array_length('4') +# Not supported by Materialize. +onlyif cockroach query I SELECT json_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]') ---- 5 +# Not supported by Materialize. +onlyif cockroach query I SELECT json_array_length('[]') ---- 0 -query error pq:jsonb_array_length\(\):cannot get array length of a non-array +# Not supported by Materialize. +onlyif cockroach +query error pq: jsonb_array_length\(\): cannot get array length of a non-array SELECT jsonb_array_length('{"f1":1,"f2":[5,6]}') -query error pq:jsonb_array_length\(\):cannot get array length of a scalar +# Not supported by Materialize. +onlyif cockroach +query error pq: jsonb_array_length\(\): cannot get array length of a scalar SELECT jsonb_array_length('4') query I @@ -1015,3 +1503,388 @@ query I SELECT jsonb_array_length('[]') ---- 0 + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT row_to_json(row(1,'foo')), row_to_json(NULL), row_to_json(row()) +---- +{"f1": 1, "f2": "foo"} NULL {} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT row_to_json(x) FROM (SELECT 1 AS "OnE", 2 AS "tO_") x +---- +{"OnE": 1, "tO_": 2} + + +# Not supported by Materialize. +onlyif cockroach +# TODO(jordan,radu): this should also work without the .*. +query T +select row_to_json(t.*) +from ( + select 1 as a, 2 as b +) t +---- +{"a": 1, "b": 2} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '["a", {"b":1}]'::jsonb #- '{1,b}' +---- +["a", {}] + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBB +select + jsonb_exists_any('{"id":12,"name":"Michael","address": {"postcode":12,"state":"California"}}'::jsonb, array['id']), + jsonb_exists_any('{"id":12,"name":"Michael","address": {"postcode":12,"state":"California"}}'::jsonb->'address', array['state']), + jsonb_exists_any('{"id":12,"name":"Michael","address": {"postcode":12,"state":"California"}}'::jsonb, array[NULL,'id']), + jsonb_exists_any('{"id":12,"name":"Michael","address": {"postcode":12,"state":"California"}}'::jsonb, array[NULL,'ids']), + jsonb_exists_any('["a","b"]', array['a']), + jsonb_exists_any('["a", 10, 12]', '{"a"}'::text[]), + jsonb_exists_any('["a"]', '{"a"}'), + jsonb_exists_any('["a"]', '{}'); +---- +true true true false true true true false + +query error function "jsonb_exists_any" does not exist +select + jsonb_exists_any('{"id":12,"name":"Michael","address": {"postcode":12,"state":"California"}}'::jsonb, array[1]); + +query error function "jsonb_exists_any" does not exist +select + jsonb_exists_any('{"id":12,"name":"Michael","address": {"postcode":12,"state":"California"}}'::jsonb, array['id',1]); + +# Not supported by Materialize. +onlyif cockroach +# json_populate_record +query FIII colnames +SELECT *, c FROM json_populate_record(((1.01, 2, 3) AS d, c, a), '{"a": 3, "c": 10, "d": 11.001}') +---- +d c a c +11.001 10 3 10 + +# Not supported by Materialize. +onlyif cockroach +query BTT colnames +SELECT * FROM json_populate_record(((true, ARRAY[1], ARRAY['f']) AS a, b, c), '{"a": true, "b": [1,2], "c": ["a", "b"]}') +---- +a b c +true {1,2} {a,b} + +# Not supported by Materialize. +onlyif cockroach +query BT colnames +SELECT * FROM json_populate_record(((true, ((1, 'bar', ARRAY['a']) AS x, y, z)) AS a, b), '{"a": true, "b": {"x": "3", "y": "foo", "z": ["a", "b"]}}') +---- +a b +true (3,foo,"{a,b}") + +# Not supported by Materialize. +onlyif cockroach +query BI colnames +SELECT * FROM json_populate_record(((true, 3) AS a, b), '{"a": null, "b": null}') +---- +a b +NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT json_populate_record(((1.01, 2, 3) AS d, c, a), '{"a": 3, "c": 10, "d": 11.001}') +---- +json_populate_record +(11.001,10,3) + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT json_populate_record(((1.01, 2) AS a, b), '{"a": "1.2345", "b": "33"}') +---- +json_populate_record +(1.2345,33) + +# Not supported by Materialize. +onlyif cockroach +query F colnames +SELECT (json_populate_record(((1.01, 2, 3) AS d, c, a), '{"a": 3, "c": 10, "d": 11.001}')).d +---- +d +11.001 + +statement ok +CREATE TABLE testtab ( + i int, + ia int[], + t text, + ta text[], + ts timestamp, + j jsonb +) + +# Not supported by Materialize. +onlyif cockroach +query ITTTTT +SELECT * FROM json_populate_record(NULL::testtab, '{"i": 3, "ia": [1,2,3], "t": "foo", "ta": ["a", "b"], "ts": "2017-01-01 00:00", "j": {"a": "b", "c": 3, "d": [1,false,true,null,{"1":"2"}]}}'::JSON) +---- +3 {1,2,3} foo {a,b} 2017-01-01 00:00:00 +0000 +0000 {"a": "b", "c": 3, "d": [1, false, true, null, {"1": "2"}]} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT json_populate_record(NULL::testtab, '{"i": 3, "ia": [1,2,3], "t": "foo", "ta": ["a", "b"], "ts": "2017-01-01 00:00", "j": {"a": "b", "c": 3, "d": [1,false,true,null,{"1":"2"}]}}'::JSON) +---- +(3,"{1,2,3}",foo,"{a,b}","2017-01-01 00:00:00","{""a"": ""b"", ""c"": 3, ""d"": [1, false, true, null, {""1"": ""2""}]}") + +# Not supported by Materialize. +onlyif cockroach +query ITTTTT +SELECT * FROM json_populate_record(NULL::testtab, NULL) +---- +NULL NULL NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query error could not parse \"foo\" as type int +SELECT json_populate_record(((3,) AS a), '{"a": "foo"}') + +query error function "json_populate_record" does not exist +SELECT * FROM json_populate_record((1,2,3,4), '{"a": 3, "c": 10, "d": 11.001}') + +query error function "json_populate_record" does not exist +SELECT * FROM json_populate_record(NULL, '{"a": 3, "c": 10, "d": 11.001}') + +query error function "json_populate_record" does not exist +SELECT * FROM json_populate_record(1, '{"a": 3, "c": 10, "d": 11.001}') + +query error function "json_populate_record" does not exist +SELECT * FROM json_populate_record(NULL::INT, '{"a": 3, "c": 10, "d": 11.001}') + +query error function "json_populate_record" does not exist +SELECT * FROM json_populate_record(NULL::record, '{"a": 3, "c": 10, "d": 11.001}') + +query error function "json_populate_recordset" does not exist +SELECT * FROM json_populate_recordset(NULL, '[{"a": 3, "c": 10, "d": 11.001}, {}]') + +query error function "json_populate_recordset" does not exist +SELECT * FROM json_populate_recordset(NULL::INT, '[{"a": 3, "c": 10, "d": 11.001}, {}]') + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT * FROM json_populate_record(((3,) AS a), NULL) +---- +3 + +# Not supported by Materialize. +onlyif cockroach +query FIII colnames +SELECT *, c FROM json_populate_recordset(((1.01, 2, 3) AS d, c, a), '[{"a": 3, "c": 10, "d": 11.001}, {}]') +---- +d c a c +11.001 10 3 10 +1.01 2 3 2 + +# Not supported by Materialize. +onlyif cockroach +query FITI colnames +SELECT *, c FROM json_populate_recordset(((NULL::NUMERIC, 2::INT, 3::TEXT) AS d, c, a), '[{"a": 3, "c": 10, "d": 11.001}, {}]') +---- +d c a c +11.001 10 3 10 +NULL 2 3 2 + +# Not supported by Materialize. +onlyif cockroach +query FIT +SELECT * FROM json_populate_recordset(((NULL::NUMERIC, 2::INT, 3::TEXT) AS d, c, a), NULL) +---- + +# Not supported by Materialize. +onlyif cockroach +query FIT +SELECT * FROM json_populate_recordset(((NULL::NUMERIC, 2::INT, 3::TEXT) AS d, c, a), '[]') +---- + +# Not supported by Materialize. +onlyif cockroach +query error argument of json_populate_recordset must be an array +SELECT * FROM json_populate_recordset(((NULL::NUMERIC, 2::INT, 3::TEXT) AS d, c, a), '{"foo": "bar"}') + +# Not supported by Materialize. +onlyif cockroach +query error argument of json_populate_recordset must be an array +SELECT * FROM json_populate_recordset(((NULL::NUMERIC, 2::INT, 3::TEXT) AS d, c, a), 'true') + +# Not supported by Materialize. +onlyif cockroach +query error argument of json_populate_recordset must be an array +SELECT * FROM json_populate_recordset(((NULL::NUMERIC, 2::INT, 3::TEXT) AS d, c, a), '0') + +# Not supported by Materialize. +onlyif cockroach +query error argument of json_populate_recordset must be an array +SELECT * FROM json_populate_recordset(((NULL::NUMERIC, 2::INT, 3::TEXT) AS d, c, a), 'null') + +# Not supported by Materialize. +onlyif cockroach +query error argument of json_populate_recordset must be an array of objects +SELECT * FROM json_populate_recordset(((NULL::NUMERIC, 2::INT, 3::TEXT) AS d, c, a), '[null]') + +# Not supported by Materialize. +onlyif cockroach +query error argument of json_populate_recordset must be an array of objects +SELECT * FROM json_populate_recordset(((NULL::NUMERIC, 2::INT, 3::TEXT) AS d, c, a), '[{"foo":"bar"}, 3]') + +# Not supported by Materialize. +onlyif cockroach +query ITTTTT +SELECT * FROM json_populate_recordset(NULL::testtab, '[{"i": 3, "ia": [1,2,3], "t": "foo", "ta": ["a", "b"], "ts": "2017-01-01 00:00", "j": {"a": "b", "c": 3, "d": [1,false,true,null,{"1":"2"}]}}, {}]'::JSON) +---- +3 {1,2,3} foo {a,b} 2017-01-01 00:00:00 +0000 +0000 {"a": "b", "c": 3, "d": [1, false, true, null, {"1": "2"}]} +NULL NULL NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query error invalid non-object argument to json_to_record +SELECT * FROM json_to_record('3') AS t(a INT) + +# Not supported by Materialize. +onlyif cockroach +query error invalid non-object argument to json_to_record +SELECT * FROM json_to_record('"a"') AS t(a TEXT) + +# Not supported by Materialize. +onlyif cockroach +query error invalid non-object argument to json_to_record +SELECT * FROM json_to_record('null') AS t(a INT) + +# Not supported by Materialize. +onlyif cockroach +query error invalid non-object argument to json_to_record +SELECT * FROM json_to_record('true') AS t(a INT) + +# Not supported by Materialize. +onlyif cockroach +query error invalid non-object argument to json_to_record +SELECT * FROM json_to_record('[1,2]') AS t(a INT) + +query error function "json_to_record" does not exist +SELECT * FROM json_to_record('{"a": "b"}') AS t(a) + +query error function "json_to_record" does not exist +SELECT * FROM json_to_record('{"a": "b"}') + +# Not supported by Materialize. +onlyif cockroach +# Test that non-record generators don't permit col definition lists (with types). +query error a column definition list is only allowed for functions returning \"record\" +SELECT * FROM generate_series(1,10) g(g int) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE j (j) AS SELECT '{ + "str": "a", + "int": 1, + "bool": true, + "nul": null, + "dec": 2.45, + "arrint": [1,2], + "arrmixed": [1,2,true], + "arrstr": ["a", "b"], + "arrbool": [true, false], + "obj": {"i": 3, "t": "blah", "z": true} + }'::JSONB + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO j VALUES('{"str": "zzz"}') + +# Not supported by Materialize. +onlyif cockroach +query TIBTFTTTTT +SELECT t.* FROM j, json_to_record(j.j) AS t( + str TEXT, + int INT, + bool BOOL, + nul TEXT, + dec DECIMAL, + arrint INT[], + arrmixed TEXT, + arrstr TEXT[], + arrbool BOOL[], + obj TEXT +) ORDER BY rowid +---- +a 1 true NULL 2.45 {1,2} [1, 2, true] {a,b} {t,f} {"i": 3, "t": "blah", "z": true} +zzz NULL NULL NULL NULL NULL NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +# Test that mismatched types return an error +query error could not parse \"true\" as type int +SELECT t.bool FROM j, json_to_record(j.j) AS t(bool INT) + +# Not supported by Materialize. +onlyif cockroach +# But types can be coerced. +query TT rowsort +SELECT t.* FROM j, json_to_record(j.j) AS t(int TEXT, bool TEXT) +---- +1 true +NULL NULL + +# Not supported by Materialize. +onlyif cockroach +# Mixed type arrays +query error could not parse \"2\" as type bool +SELECT t.arrmixed FROM j, json_to_record(j.j) AS t(arrmixed BOOL[]) + +# Not supported by Materialize. +onlyif cockroach +# Record with custom type +query T rowsort +SELECT t.obj FROM j, json_to_record(j.j) AS t(obj testtab) +---- +(3,,blah,,,) +NULL + +# Not supported by Materialize. +onlyif cockroach +# Test json_to_recordset +query TIBTFTTTTT +SELECT t.* FROM j, json_to_recordset(j.j || '[]' || j.j) AS t( + str TEXT, + int INT, + bool BOOL, + nul TEXT, + dec DECIMAL, + arrint INT[], + arrmixed TEXT, + arrstr TEXT[], + arrbool BOOL[], + obj TEXT +) ORDER BY rowid +---- +a 1 true NULL 2.45 {1,2} [1, 2, true] {a,b} {t,f} {"i": 3, "t": "blah", "z": true} +a 1 true NULL 2.45 {1,2} [1, 2, true] {a,b} {t,f} {"i": 3, "t": "blah", "z": true} +zzz NULL NULL NULL NULL NULL NULL NULL NULL NULL +zzz NULL NULL NULL NULL NULL NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query TT rowsort +SELECT * FROM jsonb_to_recordset('[{"foo": "bar"}, {"foo": "bar2"}]') AS t(foo TEXT), + jsonb_to_recordset('[{"foo": "blah"}, {"foo": "blah2"}]') AS u(foo TEXT) +---- +bar blah +bar blah2 +bar2 blah +bar2 blah2 diff --git a/test/sqllogictest/cockroach/limit.slt b/test/sqllogictest/cockroach/limit.slt index 876cde3699f8e..a558a78c10806 100644 --- a/test/sqllogictest/cockroach/limit.slt +++ b/test/sqllogictest/cockroach/limit.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,26 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/limit +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/limit # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET enable_expressions_in_limit_syntax TO true; ----- -COMPLETE 0 - query I SELECT generate_series FROM generate_series(1, 100) ORDER BY generate_series LIMIT 5; ---- @@ -63,11 +56,10 @@ SELECT generate_series FROM generate_series(1, 100) FETCH NEXT ROW ONLY LIMIT 3; statement error multiple LIMIT/FETCH clauses not allowed SELECT generate_series FROM generate_series(1, 100) LIMIT 3 FETCH NEXT ROW ONLY; -query I +# Not supported by Materialize. +onlyif cockroach +statement error syntax error SELECT generate_series FROM generate_series(1, 100) FETCH NEXT 1 + 1 ROWS ONLY; ----- -1 -2 query I SELECT generate_series FROM generate_series(1, 100) ORDER BY generate_series FETCH FIRST (1 + 1) ROWS ONLY; @@ -76,7 +68,7 @@ SELECT generate_series FROM generate_series(1, 100) ORDER BY generate_series FET 2 statement ok -CREATE TABLE t (k INT PRIMARY KEY, v INT, w INT) +CREATE TABLE t (k INT PRIMARY KEY, v INT, w INT, INDEX(v)) statement ok INSERT INTO t VALUES (1, 1, 1), (2, -4, 8), (3, 9, 27), (4, -16, 94), (5, 25, 125), (6, -36, 216) @@ -102,8 +94,7 @@ SELECT k, v FROM t ORDER BY k OFFSET 5 ---- 6 -36 -# TODO(benesch): support this. -query error Expected end of statement, found number +query II SELECT k, v FROM t ORDER BY v LIMIT (1+4) OFFSET 1 ---- 4 -16 @@ -112,8 +103,7 @@ SELECT k, v FROM t ORDER BY v LIMIT (1+4) OFFSET 1 3 9 5 25 -# TODO(benesch): support this. -query error Expected end of statement, found number +query II SELECT k, v FROM t ORDER BY v DESC LIMIT (1+4) OFFSET 1 ---- 3 9 @@ -132,51 +122,324 @@ SELECT sum(w) FROM t GROUP BY k, v ORDER BY v DESC LIMIT 10 94 216 -skipif postgresql # Cockroach preserves sort ordering when not required to. query I SELECT k FROM (SELECT k, v FROM t ORDER BY v LIMIT 4) ---- -6 -4 -2 1 +2 +4 +6 -skipif postgresql # Cockroach preserves sort ordering when not required to. query I SELECT k FROM (SELECT k, v, w FROM t ORDER BY v LIMIT 4) ---- -6 -4 -2 1 +2 +4 +6 # Use expression for LIMIT/OFFSET value. -# TODO(benesch): support this. - -query error Expected end of statement, found number +query II SELECT k, v FROM t ORDER BY k LIMIT length(pg_typeof(123)) ---- 1 1 2 -4 3 9 +4 -16 +5 25 +6 -36 -query error Expected end of statement, found number +query II SELECT k, v FROM t ORDER BY k LIMIT length(pg_typeof(123)) OFFSET length(pg_typeof(123))-2 ---- -2 -4 -3 9 -4 -16 +6 -36 -query error Expected end of statement, found number +# Not supported by Materialize. +onlyif cockroach +query II SELECT k, v FROM t ORDER BY k OFFSET (SELECT count(*)-3 FROM t) ---- 4 -16 5 25 6 -36 -query error Expected end of statement, found number +# Not supported by Materialize. +onlyif cockroach +query II SELECT k, v FROM t ORDER BY k LIMIT (SELECT count(*)-3 FROM t) OFFSET (SELECT count(*)-5 FROM t) ---- 2 -4 3 9 4 -16 + +# Test sort node with both filter and limit. (https://github.com/cockroachdb/cockroach/issues/31163) +statement ok +SET TRACING = ON; SELECT 1; SET TRACING = OFF + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT SPAN FROM [SHOW TRACE FOR SESSION] WHERE span = 1 LIMIT 1 +---- +1 + +# Regression test for #38659: offset on top of limit was broken. + +query I +SELECT * FROM (select * from generate_series(1,10) a LIMIT 5) OFFSET 3 +---- +4 +5 + +query I +SELECT * FROM (select * from generate_series(1,10) a LIMIT 5) OFFSET 6 +---- + +# Regression test for #47283: scan with both hard limit and soft limit. +statement ok +CREATE TABLE t_47283(k INT PRIMARY KEY, a INT) + +statement ok +INSERT INTO t_47283 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6) + +# This should return no results; if it does, we incorrectly removed the hard +# limit in the scan. +query II +SELECT * FROM (SELECT * FROM t_47283 ORDER BY k LIMIT 4) WHERE a > 5 LIMIT 1 +---- + +# Not supported by Materialize. +onlyif cockroach +# Test various combinations of LIMIT and OFFSET with values coming from +# subqueries, including values that can cause overflows. +statement ok +CREATE TABLE vals (k STRING PRIMARY KEY, v INT); +INSERT INTO vals VALUES ('zero', 0), ('one', 1), ('large', 9223372036854775806), ('maxint64', 9223372036854775807); +CREATE TABLE probe (a INT PRIMARY KEY); +INSERT INTO probe VALUES (1), (2), (3), (4); + +# Not supported by Materialize. +onlyif cockroach +# No offset. +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'zero'); +---- + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'one'); +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'large'); +---- +1 +2 +3 +4 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'maxint64'); +---- +1 +2 +3 +4 + +# Not supported by Materialize. +onlyif cockroach +# No limit. +query I +SELECT a FROM probe ORDER BY a OFFSET (SELECT v FROM vals WHERE k = 'zero'); +---- +1 +2 +3 +4 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a OFFSET (SELECT v FROM vals WHERE k = 'one'); +---- +2 +3 +4 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a OFFSET (SELECT v FROM vals WHERE k = 'large'); +---- + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a OFFSET (SELECT v FROM vals WHERE k = 'maxint64'); +---- + + +# Not supported by Materialize. +onlyif cockroach +# Offset zero. +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'zero') OFFSET (SELECT v FROM vals WHERE k = 'zero'); +---- + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'one') OFFSET (SELECT v FROM vals WHERE k = 'zero'); +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'large') OFFSET (SELECT v FROM vals WHERE k = 'zero'); +---- +1 +2 +3 +4 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'maxint64') OFFSET (SELECT v FROM vals WHERE k = 'zero'); +---- +1 +2 +3 +4 + +# Not supported by Materialize. +onlyif cockroach +# Offset one. +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'zero') OFFSET (SELECT v FROM vals WHERE k = 'one'); +---- + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'one') OFFSET (SELECT v FROM vals WHERE k = 'one'); +---- +2 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'large') OFFSET (SELECT v FROM vals WHERE k = 'one'); +---- +2 +3 +4 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'maxint64') OFFSET (SELECT v FROM vals WHERE k = 'one'); +---- +2 +3 +4 + +# Not supported by Materialize. +onlyif cockroach +# Offset large. +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'zero') OFFSET (SELECT v FROM vals WHERE k = 'large'); +---- + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'one') OFFSET (SELECT v FROM vals WHERE k = 'large'); +---- + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'large') OFFSET (SELECT v FROM vals WHERE k = 'large'); +---- + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'maxint64') OFFSET (SELECT v FROM vals WHERE k = 'large'); +---- + +# Not supported by Materialize. +onlyif cockroach +# Offset maxint64. +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'zero') OFFSET (SELECT v FROM vals WHERE k = 'maxint64'); +---- + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'one') OFFSET (SELECT v FROM vals WHERE k = 'maxint64'); +---- + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'large') OFFSET (SELECT v FROM vals WHERE k = 'maxint64'); +---- + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM probe ORDER BY a LIMIT (SELECT v FROM vals WHERE k = 'maxint64') OFFSET (SELECT v FROM vals WHERE k = 'maxint64'); +---- + +# Regression test for incorrectly treating LIMIT query as containing full scan (Issue #60751). +statement ok +SET disallow_full_table_scans = true; + +query I +SELECT w FROM t ORDER BY k LIMIT 1; +---- +1 + +statement ok +SET disallow_full_table_scans = false; + +# Regression test for incorrectly de-duplicating rows before reaching LIMIT. (Issue #65171) +statement ok +CREATE TABLE t65171 (x INT, y INT, INDEX(x, y)) + +statement ok +INSERT INTO t65171 VALUES (1, 2), (1, 2), (2, 3) + +query II +SELECT * FROM t65171 WHERE x = 1 OR x = 2 ORDER BY y LIMIT 2 +---- +1 2 +1 2 + +query III +SELECT * FROM t ORDER BY v, w LIMIT 3; +---- +6 -36 216 +4 -16 94 +2 -4 8 + +query IT +SELECT oid::INT, typname FROM pg_type ORDER BY oid LIMIT 3 +---- +16 bool +17 bytea +18 char + +# Regression test for limit hint overflowing int64 range and becoming negative. +statement ok +SELECT * FROM t65171 WHERE x = 1 OFFSET 1 LIMIT 9223372036854775807 diff --git a/test/sqllogictest/cockroach/lock_timeout.slt b/test/sqllogictest/cockroach/lock_timeout.slt new file mode 100644 index 0000000000000..6eecaa111b392 --- /dev/null +++ b/test/sqllogictest/cockroach/lock_timeout.slt @@ -0,0 +1,133 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/lock_timeout +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Create a table, write a row, lock it, then switch users. +statement ok +CREATE TABLE t (k INT PRIMARY KEY, v int) + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON t TO testuser + +statement ok +INSERT INTO t VALUES (1, 1) + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; UPDATE t SET v = 2 WHERE k = 1 + +user testuser + +# Set a lock timeout and begin issuing queries. Those that conflict with +# the locked row should be rejected. +statement ok +SET lock_timeout = '1ms' + +statement error pgcode 55P03 permission denied for TABLE "materialize\.public\.t" +SELECT * FROM t + +statement error pgcode 55P03 Expected end of statement, found UPDATE +SELECT * FROM t FOR UPDATE + +statement error pgcode 55P03 Expected end of statement, found UPDATE +SELECT * FROM t FOR UPDATE NOWAIT + +statement error pgcode 55P03 permission denied for TABLE "materialize\.public\.t" +SELECT * FROM t WHERE k = 1 + +statement error pgcode 55P03 Expected end of statement, found FOR +SELECT * FROM t WHERE k = 1 FOR UPDATE + +statement error pgcode 55P03 Expected end of statement, found FOR +SELECT * FROM t WHERE k = 1 FOR UPDATE NOWAIT + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t WHERE k = 2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t WHERE k = 2 FOR UPDATE + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t WHERE k = 2 FOR UPDATE NOWAIT + +statement error pgcode 55P03 permission denied for TABLE "materialize\.public\.t" +SELECT * FROM t WHERE v = 9 + +statement error pgcode 55P03 Expected end of statement, found FOR +SELECT * FROM t WHERE v = 9 FOR UPDATE + +statement error pgcode 55P03 Expected end of statement, found FOR +SELECT * FROM t WHERE v = 9 FOR UPDATE NOWAIT + +statement error pgcode 55P03 permission denied for TABLE "materialize\.public\.t" +INSERT INTO t VALUES (1, 3) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t VALUES (2, 3) + +statement error pgcode 55P03 Unexpected keyword UPSERT at the beginning of a statement +UPSERT INTO t VALUES (1, 3) + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPSERT INTO t VALUES (2, 3) + +statement error pgcode 55P03 permission denied for TABLE "materialize\.public\.t" +UPDATE t SET v = 4 + +statement error pgcode 55P03 permission denied for TABLE "materialize\.public\.t" +UPDATE t SET v = 4 WHERE k = 1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE t SET v = 4 WHERE k = 2 + +statement error pgcode 55P03 permission denied for TABLE "materialize\.public\.t" +UPDATE t SET v = 4 WHERE v = 9 + +statement error pgcode 55P03 permission denied for TABLE "materialize\.public\.t" +DELETE FROM t + +statement error pgcode 55P03 permission denied for TABLE "materialize\.public\.t" +DELETE FROM t WHERE k = 1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +DELETE FROM t WHERE k = 2 + +statement error pgcode 55P03 permission denied for TABLE "materialize\.public\.t" +DELETE FROM t WHERE v = 9 diff --git a/test/sqllogictest/cockroach/lookup_join.slt b/test/sqllogictest/cockroach/lookup_join.slt index 2cdbabb1da3ab..580988cc179e2 100644 --- a/test/sqllogictest/cockroach/lookup_join.slt +++ b/test/sqllogictest/cockroach/lookup_join.slt @@ -190,6 +190,8 @@ INSERT INTO books2 VALUES ('Art of Computer Programming', 1, 2), ('Art of Computer Programming', 2, 2) +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE books INJECT STATISTICS '[ { @@ -200,6 +202,8 @@ ALTER TABLE books INJECT STATISTICS '[ } ]' +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE books2 INJECT STATISTICS '[ { @@ -223,6 +227,8 @@ INSERT INTO authors VALUES ('Clifford Stein', 'Intro to Algo'), ('Donald Knuth', 'Art of Computer Programming') +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE authors INJECT STATISTICS '[ { @@ -287,6 +293,8 @@ statement ok INSERT INTO large SELECT x, 2*x, 3*x, 4*x FROM generate_series(1, 10) AS a(x) +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE small INJECT STATISTICS '[ { @@ -297,6 +305,8 @@ ALTER TABLE small INJECT STATISTICS '[ } ]' +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE large INJECT STATISTICS '[ { @@ -427,12 +437,16 @@ SELECT small.c, large.d FROM small LEFT JOIN large ON small.c = large.b AND larg statement ok CREATE TABLE parent (a INT, b INT, PRIMARY KEY(a, b)) +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE child (a INT, b INT, c INT, PRIMARY KEY(a, b, c)) INTERLEAVE IN PARENT parent(a, b) statement ok CREATE TABLE source (a INT) +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE source INJECT STATISTICS '[ { @@ -443,6 +457,8 @@ ALTER TABLE source INJECT STATISTICS '[ } ]' +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE child INJECT STATISTICS '[ { @@ -453,12 +469,16 @@ ALTER TABLE child INJECT STATISTICS '[ } ]' +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO child VALUES(1, 2, 3) statement ok INSERT INTO source VALUES(1) +# Not supported by Materialize. +onlyif cockroach query IIII SELECT * FROM source JOIN child ON source.a = child.a ---- @@ -471,6 +491,8 @@ SELECT * FROM source JOIN child ON source.a = child.a statement ok CREATE TABLE t (a INT, b INT, c INT, d INT, e INT) +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE u (a INT, b INT, c INT, d INT, e INT, PRIMARY KEY (a DESC, b, c)) @@ -478,21 +500,29 @@ statement ok INSERT INTO t VALUES (1, 2, 3, 4, 5) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u VALUES (1, 2, 3, 4, 5), (2, 3, 4, 5, 6), (3, 4, 5, 6, 7) +# Not supported by Materialize. +onlyif cockroach # Test index with all primary key columns implicit. statement ok CREATE INDEX idx ON u (d) +# Not supported by Materialize. +onlyif cockroach query I SELECT u.a FROM t JOIN u ON t.d = u.d AND t.a = u.a WHERE t.e = 5 ---- 1 +# Not supported by Materialize. +onlyif cockroach # Test unique version of same index. (Lookup join should not use column a.) statement ok DROP INDEX u@idx @@ -500,42 +530,62 @@ DROP INDEX u@idx statement ok CREATE UNIQUE INDEX idx ON u (d) +# Not supported by Materialize. +onlyif cockroach query I SELECT u.a FROM t JOIN u ON t.d = u.d AND t.a = u.a WHERE t.e = 5 ---- 1 +# Not supported by Materialize. +onlyif cockroach # Test index with first primary key column explicit and the rest implicit. statement ok DROP INDEX u@idx CASCADE +# Not supported by Materialize. +onlyif cockroach statement ok CREATE INDEX idx ON u (d, a) +# Not supported by Materialize. +onlyif cockroach query I SELECT u.a FROM t JOIN u ON t.d = u.d AND t.a = u.a AND t.b = u.b WHERE t.e = 5 ---- 1 +# Not supported by Materialize. +onlyif cockroach # Test index with middle primary key column explicit and the rest implicit. statement ok DROP INDEX u@idx +# Not supported by Materialize. +onlyif cockroach statement ok CREATE INDEX idx ON u (d, b) +# Not supported by Materialize. +onlyif cockroach query I SELECT u.a FROM t JOIN u ON t.d = u.d AND t.a = u.a AND t.b = u.b WHERE t.e = 5 ---- 1 +# Not supported by Materialize. +onlyif cockroach # Test index with last primary key column explicit and the rest implicit. statement ok DROP INDEX u@idx +# Not supported by Materialize. +onlyif cockroach statement ok CREATE INDEX idx ON u (d, c) +# Not supported by Materialize. +onlyif cockroach query I SELECT u.a FROM t JOIN u ON t.d = u.d AND t.a = u.a AND t.d = u.d WHERE t.e = 5 ---- diff --git a/test/sqllogictest/cockroach/lookup_join_local.slt b/test/sqllogictest/cockroach/lookup_join_local.slt new file mode 100644 index 0000000000000..426e128aa09f2 --- /dev/null +++ b/test/sqllogictest/cockroach/lookup_join_local.slt @@ -0,0 +1,70 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/lookup_join_local +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: local !metamorphic-batch-sizes + +# This test verifies that the row container used by the join reader spills to +# disk in order to make room for the non-spillable internal state of the +# processor. + +# Lower the workmem limit so that less data needs to be inserted. The join +# reader overrides it to be at least 8MiB, so we cannot go lower than that. +statement ok +SET distsql_workmem = '8MiB'; + +# Not supported by Materialize. +onlyif cockroach +# Populate two tables such that there will be very large input:output lookup +# ratio. +statement ok +CREATE TABLE small (n INT PRIMARY KEY); +INSERT INTO small SELECT generate_series(0, 6); +CREATE TABLE large (n INT, v STRING, INDEX (n) STORING (v)); + +# Not supported by Materialize. +onlyif cockroach +# The data set has been carefully constructed so that the memory limit in the +# join reader is reached when accounting for some internal state and not when +# adding looked up rows into the row container. +statement ok +INSERT INTO large SELECT g % 7, repeat('a', 52) FROM generate_series(0, 69999) as g; + +# Not supported by Materialize. +onlyif cockroach +# Read from the small table and perform the lookup join into the large table. +# We want to make sure that the query succeeds and doesn't run into "budget +# exceeded" error - the row container will have to spill to disk. +query II +SELECT small.n, sum_int(length(large.v)) FROM small +INNER LOOKUP JOIN large ON small.n = large.n +GROUP BY small.n +ORDER BY small.n +---- +0 520000 +1 520000 +2 520000 +3 520000 +4 520000 +5 520000 +6 520000 diff --git a/test/sqllogictest/cockroach/materialized_view.slt b/test/sqllogictest/cockroach/materialized_view.slt new file mode 100644 index 0000000000000..e0879c198f005 --- /dev/null +++ b/test/sqllogictest/cockroach/materialized_view.slt @@ -0,0 +1,313 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/materialized_view +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE t (x INT, y INT); +INSERT INTO t VALUES (1, 2), (3, 4), (5, 6) + +statement ok +CREATE MATERIALIZED VIEW v AS SELECT x, y FROM t + +# Not supported by Materialize. +onlyif cockroach +# Ensure that materialized views show up in SHOW TABLES. +query T +SELECT table_name FROM [SHOW TABLES] WHERE type = 'materialized view' +---- +v + +query II rowsort +SELECT * FROM v +---- +1 2 +3 4 +5 6 + +# If we update t, the view shouldn't change. +statement ok +INSERT INTO t VALUES (7, 8) + +query II rowsort +SELECT * FROM v +---- +1 2 +3 4 +5 6 +7 8 + +let $orig_crdb_timestamp +SELECT max(crdb_internal_mvcc_timestamp) FROM v + +# Not supported by Materialize. +onlyif cockroach +# Now refresh the view. +statement ok +REFRESH MATERIALIZED VIEW v + +# The update should be visible now, as v has been recomputed. +query II rowsort +SELECT * FROM v +---- +1 2 +3 4 +5 6 +7 8 + +# Not supported by Materialize. +onlyif cockroach +# Verify that crdb_internal_mvcc_timestamp is updated for all rows. +query I +SELECT count(*) FROM v WHERE crdb_internal_mvcc_timestamp > $orig_crdb_timestamp +---- +4 + +# Now add an index to the view, and use it. +statement ok +CREATE INDEX i ON v (y) + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT y FROM v@i WHERE y > 4 +---- +6 +8 + +# Now update t and refresh the view -- the index should be updated as well. +statement ok +INSERT INTO t VALUES (9, 10) + +# Not supported by Materialize. +onlyif cockroach +statement ok +REFRESH MATERIALIZED VIEW v + +query I rowsort +SELECT y FROM v WHERE y > 4 +---- +6 +8 +10 + +# Not supported by Materialize. +onlyif cockroach +# Drop the index now. +statement ok +DROP INDEX v@i + +query I rowsort +SELECT y FROM v WHERE y > 4 +---- +6 +8 +10 + +# We can't refresh with an explicit txn. +statement ok +BEGIN + +statement error Unexpected keyword REFRESH at the beginning of a statement +REFRESH MATERIALIZED VIEW v + +statement ok +ROLLBACK + +statement error cannot insert into materialized view 'materialize\.public\.v' +INSERT INTO v VALUES (1, 2) + +statement error cannot mutate materialized view 'materialize\.public\.v' +UPDATE v SET x = 1 WHERE y = 1 + +statement error cannot mutate materialized view 'materialize\.public\.v' +DELETE FROM v WHERE x = 1 + +statement error Expected a keyword at the beginning of a statement, found identifier "truncate" +TRUNCATE v + +# Test that a materialized view with a unique index errors out if the refresh +# runs into a uniqueness constraint violation. +statement ok +CREATE TABLE dup (x INT); + +statement ok +CREATE MATERIALIZED VIEW v_dup AS SELECT x FROM dup; + +statement ok +CREATE UNIQUE INDEX i ON v_dup (x); + +statement ok +INSERT INTO dup VALUES (1), (1); + +statement error Unexpected keyword REFRESH at the beginning of a statement +REFRESH MATERIALIZED VIEW v_dup + +# We shouldn't be able to mix materialized and non materialized views in DDLs. +statement ok +CREATE VIEW normal_view AS SELECT 1; +CREATE MATERIALIZED VIEW materialized_view AS SELECT 1; + +statement error materialized_view is not a view +ALTER VIEW materialized_view RENAME TO newname + +statement error normal_view is a view not a materialized view +ALTER MATERIALIZED VIEW normal_view RENAME TO newname + +statement error Expected left parenthesis, found SCHEMA +ALTER VIEW materialized_view SET SCHEMA public + +statement error Expected left parenthesis, found SCHEMA +ALTER MATERIALIZED VIEW normal_view SET SCHEMA public + +statement error materialized_view is not a view +DROP VIEW materialized_view + +statement error normal_view is a view not a materialized view +DROP MATERIALIZED VIEW normal_view + +# Using REFRESH MATERIALIZED VIEW ... WITH NO DATA should result in +# an empty view. +statement ok +CREATE MATERIALIZED VIEW with_options AS SELECT 1; + +# Not supported by Materialize. +onlyif cockroach +statement ok +REFRESH MATERIALIZED VIEW with_options WITH DATA + +query I +SELECT * FROM with_options +---- +1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +REFRESH MATERIALIZED VIEW with_options WITH NO DATA + +query I +SELECT * FROM with_options +---- +1 + +# Regression test for null data in materialized views. +statement ok +CREATE TABLE t57108 (id INT PRIMARY KEY, a INT); +INSERT INTO t57108 VALUES(1, 1), (2, NULL); +CREATE MATERIALIZED VIEW t57108_v AS SELECT t57108.a from t57108; + +query I rowsort +SELECT * FROM t57108_v +---- +NULL +1 + +user testuser + +# testuser should not be able to refresh the materialized view without +# ownership. +statement error Unexpected keyword REFRESH at the beginning of a statement +REFRESH MATERIALIZED VIEW with_options WITH NO DATA + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT root TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +# testuser should now be able to refresh the materialized view as a member of +# root. +statement ok +REFRESH MATERIALIZED VIEW with_options WITH NO DATA + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE root FROM testuser + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON DATABASE test TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER MATERIALIZED VIEW with_options OWNER TO testuser + +# Not supported by Materialize. +onlyif cockroach +# root should still be able to refresh the view. +statement ok +REFRESH MATERIALIZED VIEW with_options WITH NO DATA + +user testuser + +# Not supported by Materialize. +onlyif cockroach +# testuser should now be able to refresh the materialized view as the owner. +statement ok +REFRESH MATERIALIZED VIEW with_options WITH NO DATA + +# Not supported by Materialize. +onlyif cockroach +# Test CREATE MATERIALIZED VIEW referring to a sequence. +statement ok +CREATE SEQUENCE seq; +CREATE MATERIALIZED VIEW view_from_seq AS (SELECT nextval('seq')) + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT * FROM view_from_seq +---- +1 + +# Regression test for #79015. +user testuser + +statement ok +BEGIN + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM system.descriptor; + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE seq_2; +CREATE MATERIALIZED VIEW view_from_seq_2 AS (SELECT nextval('seq_2')); +COMMIT diff --git a/test/sqllogictest/cockroach/merge_join.slt b/test/sqllogictest/cockroach/merge_join.slt new file mode 100644 index 0000000000000..06b8391f49a0e --- /dev/null +++ b/test/sqllogictest/cockroach/merge_join.slt @@ -0,0 +1,99 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/merge_join +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Basic tables, no nulls + +statement ok +CREATE TABLE t1 (k INT PRIMARY KEY, v INT) + +statement ok +INSERT INTO t1 VALUES (-1, -1), (0, 4), (2, 1), (3, 4), (5, 4) + +statement ok +CREATE TABLE t2 (x INT, y INT, INDEX x (x)) + +statement ok +INSERT INTO t2 VALUES (0, 5), (1, 3), (1, 4), (3, 2), (3, 3), (4, 6) + +# Not supported by Materialize. +onlyif cockroach +query IIII rowsort +SELECT k, v, x, y FROM t1 INNER MERGE JOIN t2 ON k = x +---- +0 4 0 5 +3 4 3 2 +3 4 3 3 + +statement ok +DROP TABLE t1 + +statement ok +DROP TABLE t2 + +# Basic tables with nulls + +statement ok +CREATE TABLE t1 (k INT, INDEX k(k)) + +statement ok +INSERT INTO t1 VALUES (0), (null) + +statement ok +CREATE TABLE t2 (x INT, INDEX x (x)) + +statement ok +INSERT INTO t2 VALUES (0), (null) + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT k, x FROM t1 INNER MERGE JOIN t2 ON k = x +---- +0 0 + +# Regression test for the inputs that have comparable but different types (see +# issue #44798). +statement ok +CREATE TABLE t44798_0(c0 INT4 PRIMARY KEY); CREATE TABLE t44798_1(c0 INT8 PRIMARY KEY) + +statement ok +INSERT INTO t44798_0(c0) VALUES(0), (1), (2); INSERT INTO t44798_1(c0) VALUES(0), (2), (4) + +# Note that integers of different width are still considered equal. +query I rowsort +SELECT * FROM t44798_0 NATURAL JOIN t44798_1 +---- +0 +2 + +# Regression test for batch type schema prefix mismatch after LEFT ANTI join +# (48622). +statement ok +CREATE TABLE l (l INT PRIMARY KEY); INSERT INTO l VALUES (1), (2); +CREATE TABLE r (r INT PRIMARY KEY); INSERT INTO r VALUES (1) + +query IB +SELECT *, true FROM (SELECT l FROM l WHERE l NOT IN (SELECT r FROM r)) +---- +2 true diff --git a/test/sqllogictest/cockroach/multi_statement.slt b/test/sqllogictest/cockroach/multi_statement.slt new file mode 100644 index 0000000000000..da5fd2e2ea3ce --- /dev/null +++ b/test/sqllogictest/cockroach/multi_statement.slt @@ -0,0 +1,91 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/multi_statement +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE kv ( + k CHAR PRIMARY KEY, + v CHAR +) + +query TT +SELECT * FROM kv +---- + +statement ok +INSERT INTO kv (k,v) VALUES ('a', 'b'); INSERT INTO kv (k,v) VALUES ('c', 'd') + +query TT rowsort +SELECT * FROM kv +---- +a b +c d + +# Not supported by Materialize. +onlyif cockroach +# error if either statement returns an error +# first statement returns an error. Second stmt shouldn't execute. +statement error duplicate key value violates unique constraint "kv_pkey"\nDETAIL: Key \(k\)=\('a'\) already exists\. +INSERT INTO kv (k,v) VALUES ('a', 'b'); INSERT INTO kv (k,v) VALUES ('e', 'f') + +query TT rowsort +SELECT * FROM kv +---- +a b +c d + +# Not supported by Materialize. +onlyif cockroach +# second statement returns an error, and causes the whole batch to rollbacl +statement error duplicate key value violates unique constraint "kv_pkey"\nDETAIL: Key \(k\)=\('a'\) already exists\. +INSERT INTO kv (k,v) VALUES ('g', 'h'); INSERT INTO kv (k,v) VALUES ('a', 'b') + +query TT rowsort +SELECT * FROM kv +---- +a b +c d + +# parse error runs nothing +statement error Expected identifier, found string literal "k" +INSERT INTO kv (k,v) VALUES ('i', 'j'); INSERT INTO VALUES ('k', 'l') + +query TT rowsort +SELECT * FROM kv +---- +a b +c d + +statement error Unexpected keyword END at the beginning of a statement +BEGIN; INSERT INTO x.y(a) VALUES (1); END + +# Not supported by Materialize. +onlyif cockroach +statement error pq: current transaction is aborted, commands ignored until end of transaction block +SELECT * from kv; ROLLBACK + +statement ok +ROLLBACK + +statement error pgcode 42P01 unknown schema 'system' +BEGIN TRANSACTION; SELECT * FROM system.t; INSERT INTO t(a) VALUES (1) diff --git a/test/sqllogictest/cockroach/namespace.slt b/test/sqllogictest/cockroach/namespace.slt index a4924ed48da6e..2151d60987c75 100644 --- a/test/sqllogictest/cockroach/namespace.slt +++ b/test/sqllogictest/cockroach/namespace.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/namespace +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/namespace # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach statement ok @@ -28,28 +28,34 @@ CREATE TABLE a(a INT) statement ok CREATE DATABASE public; CREATE TABLE public.public.t(a INT) +# Not supported by Materialize. +onlyif cockroach # "public" with the current database designates the public schema -query T +query TTTTIT SHOW TABLES FROM public ---- -a +public a table root 0 NULL +# Not supported by Materialize. +onlyif cockroach # To access all tables in database "public", one must specify # its public schema explicitly. -query T +query TTTTIT SHOW TABLES FROM public.public ---- -t +public t table root 0 NULL # Of course one can also list the tables in "public" by making it the # current database. statement ok SET database = public -query T +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES ---- -t +public t table root 0 NULL statement ok SET database = test; DROP DATABASE public @@ -64,31 +70,43 @@ date statement ok SET search_path=public,pg_catalog +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE pg_type(x INT); INSERT INTO pg_type VALUES(42) +# Not supported by Materialize. +onlyif cockroach query I SELECT x FROM pg_type ---- 42 +# Not supported by Materialize. +onlyif cockroach # Leave database, check name resolves to default. # The expected error can only occur on the virtual pg_type, not the physical one. query error cannot access virtual schema in anonymous database SET database = ''; SELECT * FROM pg_type +# Not supported by Materialize. +onlyif cockroach # Go to different database, check name still resolves to default. query T CREATE DATABASE foo; SET database = foo; SELECT typname FROM pg_type WHERE typname = 'date' ---- date +# Not supported by Materialize. +onlyif cockroach # Verify that pg_catalog at the beginning of the search path takes precedence. query T SET database = test; SET search_path = pg_catalog,public; SELECT typname FROM pg_type WHERE typname = 'date' ---- date +# Not supported by Materialize. +onlyif cockroach # Now set the search path to the testdb, placing pg_catalog explicitly # at the end. query I @@ -96,17 +114,25 @@ SET search_path = public,pg_catalog; SELECT x FROM pg_type ---- 42 +# Not supported by Materialize. +onlyif cockroach statement ok DROP TABLE pg_type; RESET search_path; SET database = test +# Not supported by Materialize. +onlyif cockroach # Unqualified index name resolution. statement ok -ALTER INDEX "primary" RENAME TO a_pk +ALTER INDEX a_pkey RENAME TO a_pk +# Not supported by Materialize. +onlyif cockroach # Schema-qualified index name resolution. statement ok ALTER INDEX public.a_pk RENAME TO a_pk2 +# Not supported by Materialize. +onlyif cockroach # DB-qualified index name resolution (CRDB 1.x compat). statement ok ALTER INDEX test.a_pk2 RENAME TO a_pk3 @@ -115,20 +141,24 @@ statement ok CREATE DATABASE public; CREATE TABLE public.public.t(a INT) # We can't see the DB "public" with DB-qualified index name resolution. -statement error index "primary" does not exist -ALTER INDEX public."primary" RENAME TO t_pk +statement error unknown schema 'public' +ALTER INDEX public.t_pkey RENAME TO t_pk +# Not supported by Materialize. +onlyif cockroach # But we can see it with sufficient qualification. statement ok -ALTER INDEX public.public."primary" RENAME TO t_pk +ALTER INDEX public.public.t_pkey RENAME TO t_pk # If the search path is invalid, we get a special error. statement ok SET search_path = invalid -statement error schema or database was not found while searching index: "a_pk3" +statement error unknown catalog item 'a_pk3' ALTER INDEX a_pk3 RENAME TO a_pk4 +# Not supported by Materialize. +onlyif cockroach # But qualification resolves the problem. statement ok ALTER INDEX public.a_pk3 RENAME TO a_pk4 diff --git a/test/sqllogictest/cockroach/no_primary_key.slt b/test/sqllogictest/cockroach/no_primary_key.slt index b6251666a9855..6a222fe7ab4a7 100644 --- a/test/sqllogictest/cockroach/no_primary_key.slt +++ b/test/sqllogictest/cockroach/no_primary_key.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,22 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/no_primary_key +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/no_primary_key # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -# we don't support rowid -# query error duplicate column name: "rowid" -# CREATE TABLE t ( -# rowid INT -#) - statement ok CREATE TABLE t ( a INT, @@ -47,6 +44,8 @@ SELECT a, b FROM t 1 2 3 4 +# Not supported by Materialize. +onlyif cockroach query I SELECT count(rowid) FROM t ---- @@ -54,12 +53,18 @@ SELECT count(rowid) FROM t # Make sure column order for insertion is not affected by the rowid column. +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE t ADD c STRING +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO t VALUES (5, 6, '7') +# Not supported by Materialize. +onlyif cockroach query IIT rowsort select * from t ---- @@ -68,24 +73,32 @@ select * from t 3 4 NULL 5 6 7 +# Not supported by Materialize. +onlyif cockroach statement ok SELECT a, b, c, rowid FROM t +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO t (a, rowid) VALUES (10, 11) +# Not supported by Materialize. +onlyif cockroach query I SELECT rowid FROM t WHERE a = 10 ---- 11 +# Not supported by Materialize. +onlyif cockroach query TTBTTTB SHOW COLUMNS FROM t ---- -a INT8 true NULL · {} false -b INT8 true NULL · {} false -rowid INT8 false unique_rowid() · {primary} true -c STRING true NULL · {} false +a INT8 true NULL · {t_pkey} false +b INT8 true NULL · {t_pkey} false +rowid INT8 false unique_rowid() · {t_pkey} true +c STRING true NULL · {t_pkey} false statement ok CREATE INDEX a_idx ON t (a) @@ -93,5 +106,5 @@ CREATE INDEX a_idx ON t (a) statement ok INSERT INTO t DEFAULT VALUES -statement error syntax error +statement error INSERT has more target columns than expressions INSERT INTO t (a, b) DEFAULT VALUES diff --git a/test/sqllogictest/cockroach/notice.slt b/test/sqllogictest/cockroach/notice.slt new file mode 100644 index 0000000000000..b671456f1810c --- /dev/null +++ b/test/sqllogictest/cockroach/notice.slt @@ -0,0 +1,90 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/notice +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Test multiple notices all display at once. +query T noticetrace +SELECT crdb_internal.notice('hi'), crdb_internal.notice('i am....'), crdb_internal.notice('otan!!!') +---- +NOTICE: hi +NOTICE: i am.... +NOTICE: otan!!! + +subtest test_notice_severity + +query T noticetrace +SELECT crdb_internal.notice('debug1', 'do not see this'), crdb_internal.notice('warning', 'but you see this'), crdb_internal.notice('debug2', 'and never this') +---- +WARNING: but you see this + +statement ok +SET client_min_messages = 'debug1' + +query T noticetrace +SELECT crdb_internal.notice('debug1', 'now you see this'), crdb_internal.notice('warning', 'and you see this'), crdb_internal.notice('debug2', 'and never this') +---- +DEBUG1: now you see this +WARNING: and you see this + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE DATABASE d; +CREATE TABLE d.t (x int) + +query T noticetrace +ALTER TABLE d.t RENAME TO d.t2 +---- +NOTICE: renaming tables with a qualification is deprecated +HINT: use ALTER TABLE d.t RENAME TO t2 instead + +# Not supported by Materialize. +onlyif cockroach +# Start off with an empty enum, and add values to it. +statement ok +CREATE TYPE color AS ENUM () + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TYPE color ADD VALUE 'black' + +query T noticetrace +ALTER TYPE color ADD VALUE IF NOT EXISTS 'black' +---- +NOTICE: enum value "black" already exists, skipping + +statement ok +CREATE MATERIALIZED VIEW v AS SELECT 1 + +query T noticetrace +REFRESH MATERIALIZED VIEW CONCURRENTLY v +---- +NOTICE: CONCURRENTLY is not required as views are refreshed concurrently + +query T noticetrace +UNLISTEN temp +---- +NOTICE: unimplemented: CRDB does not support LISTEN, making UNLISTEN a no-op +HINT: You have attempted to use a feature that is not yet implemented. +See: https://go.crdb.dev/issue-v/41522/* diff --git a/test/sqllogictest/cockroach/numeric_references.slt b/test/sqllogictest/cockroach/numeric_references.slt new file mode 100644 index 0000000000000..4ad5a7703eccf --- /dev/null +++ b/test/sqllogictest/cockroach/numeric_references.slt @@ -0,0 +1,315 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/numeric_references +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE x (a INT PRIMARY KEY, xx INT, b INT, c INT, INDEX bc (b,c)) + +statement ok +INSERT INTO x VALUES (1), (2), (3) + +statement ok +CREATE VIEW view_ref AS SELECT a, 1 FROM x + +let $v_id +SELECT id FROM system.namespace WHERE name='view_ref' + +statement error unterminated dollar\-quoted string +SELECT * FROM [$v_id(1) AS _] + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT * FROM [$v_id AS _] +---- +1 1 +2 1 +3 1 + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT foo.a FROM [$v_id AS foo] +---- +1 +2 +3 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE seq + +let $seq_id +SELECT id FROM system.namespace WHERE name='seq' + +# Not supported by Materialize. +onlyif cockroach +query IIB +SELECT * FROM [$seq_id AS _] +---- +0 0 true + +# Not supported by Materialize. +onlyif cockroach +# Col refs in sequences are ignored. +query IIB +SELECT * FROM [$seq_id(1) AS _] +---- +0 0 true + +# Not supported by Materialize. +onlyif cockroach +query IIB +SELECT * FROM [$seq_id(1, 2) AS _] +---- +0 0 true + +statement ok +CREATE TABLE num_ref (a INT PRIMARY KEY, xx INT, b INT, c INT, INDEX bc (b,c)) + +statement ok +CREATE TABLE num_ref_hidden (a INT, b INT) + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE num_ref RENAME COLUMN b TO d + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE num_ref RENAME COLUMN a TO p + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE num_ref DROP COLUMN xx + +statement ok +INSERT INTO num_ref VALUES (1, 10, 101), (2, 20, 200), (3, 30, 300) + +statement ok +INSERT INTO num_ref_hidden VALUES (1, 10), (2, 20), (3, 30) + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT * FROM num_ref +---- +1 10 101 +2 20 200 +3 30 300 + +let $num_ref_id +SELECT id FROM system.namespace WHERE name='num_ref' + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT * FROM [$num_ref_id as num_ref_alias] +---- +1 10 101 +2 20 200 +3 30 300 + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT * FROM [$num_ref_id(4,3,1) AS num_ref_alias] +---- +101 10 1 +200 20 2 +300 30 3 + +let $num_ref_bc +SELECT index_id + FROM crdb_internal.table_indexes + WHERE descriptor_id = $num_ref_id + AND index_name = 'bc'; + +let $num_ref_pkey +SELECT index_id + FROM crdb_internal.table_indexes + WHERE descriptor_id = $num_ref_id + AND index_name = 'num_ref_pkey'; + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT * FROM [$num_ref_id(4) AS num_ref_alias]@[$num_ref_bc] +---- +101 +200 +300 + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT * FROM [$num_ref_id(1) AS num_ref_alias]@[$num_ref_pkey] +---- +1 +2 +3 + +# Not supported by Materialize. +onlyif cockroach +query III colnames,rowsort +SELECT * FROM [$num_ref_id(1,3,4) AS num_ref_alias(col1,col2,col3)] +---- +col1 col2 col3 +1 10 101 +2 20 200 +3 30 300 + +# Not supported by Materialize. +onlyif cockroach +statement OK +UPSERT INTO [$num_ref_id AS num_ref_alias] VALUES (4, 40, 400) + +# Not supported by Materialize. +onlyif cockroach +statement OK +INSERT INTO [$num_ref_id(1) AS num_ref_alias] VALUES (5) + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT * FROM [$num_ref_id as num_ref_alias] +---- +1 10 101 +2 20 200 +3 30 300 +4 40 400 +5 NULL NULL + +# Not supported by Materialize. +onlyif cockroach +statement OK +DELETE FROM [$num_ref_id AS num_ref_alias]@bc WHERE p=5 + +# Not supported by Materialize. +onlyif cockroach +query I +DELETE FROM [$num_ref_id AS num_ref_alias] WHERE d=40 RETURNING num_ref_alias.c +---- +400 + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT * FROM [$num_ref_id AS num_ref_alias] +---- +1 10 101 +2 20 200 +3 30 300 + +# Not supported by Materialize. +onlyif cockroach +statement OK +INSERT INTO [$num_ref_id AS num_ref_alias] (p, c) VALUES (4, 400) + +# Not supported by Materialize. +onlyif cockroach +query I +INSERT INTO [$num_ref_id(1,4) AS num_ref_alias] VALUES (5, 500) RETURNING num_ref_alias.d +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT * FROM [$num_ref_id AS num_ref_alias] +---- +1 10 101 +2 20 200 +3 30 300 +4 NULL 400 +5 NULL 500 + +# Not supported by Materialize. +onlyif cockroach +query I +UPDATE [$num_ref_id AS num_ref_alias] SET d=40 WHERE p=4 RETURNING num_ref_alias.c +---- +400 + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT * FROM [$num_ref_id AS num_ref_alias] +---- +1 10 101 +2 20 200 +3 30 300 +4 40 400 +5 NULL 500 + +statement error unterminated dollar\-quoted string +INSERT INTO [$num_ref_id(1,4) AS num_ref_alias] (p,c) VALUES (6, 600) + +statement error unterminated dollar\-quoted string +DELETE FROM [$num_ref_id(1) AS num_ref_alias] + +statement error unterminated dollar\-quoted string +UPDATE [$num_ref_id(1) AS num_ref_alias] SET d=10 + +let $num_ref_hidden_id +SELECT id FROM system.namespace WHERE name='num_ref_hidden' + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT * FROM [$num_ref_hidden_id(1,3) AS num_ref_hidden] +---- +1 +2 +3 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT count(rowid) FROM [$num_ref_hidden_id(3) AS num_ref_hidden] +---- +3 + +# Ensure that privileges are checked when using numeric references. +user testuser + +statement error unterminated dollar\-quoted string +SELECT * FROM [$num_ref_id AS t] + +statement error unterminated dollar\-quoted string +INSERT INTO [$num_ref_id AS t] VALUES (1) + +statement error unterminated dollar\-quoted string +DELETE FROM [$num_ref_id AS t] + +statement error unterminated dollar\-quoted string +UPDATE [$num_ref_id AS t] SET d=1 + +# The @ reference is by type OID, which is +# type desc ID + oid.CockroachPredefinedOIDMax. This error reports that the +# type desc with ID 15210 is not found, hence the slightly different error message. +statement error Expected a data type name, found operator "@" +SELECT 1::@115210 diff --git a/test/sqllogictest/cockroach/operator.slt b/test/sqllogictest/cockroach/operator.slt new file mode 100644 index 0000000000000..388ef3b2221a8 --- /dev/null +++ b/test/sqllogictest/cockroach/operator.slt @@ -0,0 +1,83 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/operator +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +query error cannot take square root of a negative number +SELECT |/ -1.0::float + +# Not supported by Materialize. +onlyif cockroach +query error cannot take square root of a negative number +SELECT |/ -1.0::decimal + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT ~-1; +---- +0 + +query I +SELECT ~0; +---- +-1 + +query I +SELECT ~1; +---- +-2 + +query I +SELECT ~2; +---- +-3 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT ~B'0'; +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT ~B'1'; +---- +0 + +statement error type "b" does not exist +SELECT ~B'2'; + +statement error operator is not unique: \~ unknown +SELECT ~'0'; + +statement error operator is not unique: \~ unknown +SELECT ~'1'; + +query I +SELECT ~2; +---- +-3 diff --git a/test/sqllogictest/cockroach/optimizer_timeout.slt b/test/sqllogictest/cockroach/optimizer_timeout.slt new file mode 100644 index 0000000000000..f373aa4bbd124 --- /dev/null +++ b/test/sqllogictest/cockroach/optimizer_timeout.slt @@ -0,0 +1,84 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/optimizer_timeout +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE table1 +( + col1_0 INT NULL, + col1_1 BYTES[] NOT NULL, + col1_2 INT NULL, + col1_3 INT NOT NULL, + col1_4 INT NOT NULL, + col1_5 FLOAT8, + col1_6 TIMETZ NOT NULL, + col1_7 UUID, + col1_8 int NOT NULL, + col2 int as (col1_0 + 1) virtual, + col3 int as (col1_2 + 1) virtual, + PRIMARY KEY (col1_3 DESC, col1_6), + INVERTED INDEX (col1_5 ASC, col1_1 ASC), + UNIQUE (col1_4 DESC, col1_3 ASC, col1_7, col1_8 ASC, col1_6) STORING (col1_1), + INDEX (col1_0 ASC, col1_2 ASC) WHERE ((((table1.col1_6 = '24:00:00-15:59:00':::TIMETZ) AND (table1.col1_5 <= '-Inf':::FLOAT8)) OR (table1.col1_4 < 0)) AND (table1.col1_3 >= 0)), + INDEX table1_col1_2_col1_8_col1_0_expr_col1_4_idx (col1_2 DESC, col1_8, col1_0 DESC, col2 ASC, col1_4 DESC) STORING (col1_1, col1_5, col1_7) WHERE table1.col1_3 = 1, + INDEX table1_expr_idx (col3 DESC) STORING (col1_1, col1_2, col1_4, col1_5, col1_7) WHERE table1.col1_5 < '+Inf':::FLOAT8 +); + +# Not supported by Materialize. +onlyif cockroach +# The following query takes on the order of 1s to optimize, so we set the +# timeout to a much shorter duration and verify that the optimization is +# canceled accordingly. +statement ok +SET statement_timeout='0.1s'; + +statement error Expected end of statement, found operator "@" +SELECT + tab_124176.col1_4 AS col_298240, tab_124184.col1_8 AS col_298241 +FROM + table1@[0] AS tab_124176, + table1@[0] AS tab_124177 + JOIN table1 AS tab_124178 + JOIN table1 AS tab_124179 + JOIN table1 AS tab_124180 + JOIN table1 AS tab_124181 ON + (tab_124180.col1_0) = (tab_124181.col1_0) + AND (tab_124180.col1_6) = (tab_124181.col1_6) + AND (tab_124180.col1_3) = (tab_124181.col1_3) + AND (tab_124180.col1_2) = (tab_124181.col1_2) + JOIN table1@[0] AS tab_124182 ON (tab_124181.col1_2) = (tab_124182.col1_8) AND (tab_124180.col1_2) = (tab_124182.tableoid) ON + (tab_124179.col1_2) = (tab_124180.col1_2) + JOIN table1@[0] AS tab_124183 ON (tab_124182.col3) = (tab_124183.col1_4) AND (tab_124182.col1_3) = (tab_124183.col3) + JOIN table1 AS tab_124184 + JOIN table1 AS tab_124185 ON + (tab_124184.col1_2) = (tab_124185.col1_2) + AND (tab_124184.col1_6) = (tab_124185.col1_6) + AND (tab_124184.col1_3) = (tab_124185.col1_3) + AND (tab_124184.col1_4) = (tab_124185.col1_4) ON (tab_124183.col1_8) = (tab_124184.col1_8) ON + (tab_124178.col1_2) = (tab_124180.col1_2) AND (tab_124178.col1_2) = (tab_124185.col1_8) AND (tab_124178.col2) = (tab_124182.col3) ON + (tab_124177.col1_8) = (tab_124181.col1_2) AND (tab_124177.col3) = (tab_124178.col2) AND (tab_124177.col3) = (tab_124183.col1_3); + +statement ok +RESET statement_timeout diff --git a/test/sqllogictest/cockroach/order_by.slt b/test/sqllogictest/cockroach/order_by.slt index 8dfab8d429d61..f19a0dcd8a2ab 100644 --- a/test/sqllogictest/cockroach/order_by.slt +++ b/test/sqllogictest/cockroach/order_by.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/order_by +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/order_by # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - statement ok CREATE TABLE t ( a INT PRIMARY KEY, @@ -34,7 +32,6 @@ CREATE TABLE t ( statement ok INSERT INTO t VALUES (1, 9, true), (2, 8, false), (3, 7, NULL) -# Note: Result differs from Cockroach but matches Postgres. query B SELECT c FROM t ORDER BY c ---- @@ -51,7 +48,6 @@ false NULL true -# Note: Result differs from Cockroach but matches Postgres. query B SELECT c FROM t ORDER BY c DESC ---- @@ -197,13 +193,26 @@ query error pgcode 42601 multiple ORDER BY clauses not allowed query error CASE types integer and boolean cannot be matched SELECT CASE a WHEN 1 THEN b ELSE c END as val FROM t ORDER BY val -query error pgcode 42P10 column reference 0 in ORDER BY clause is out of range \(1 - 3\) +query error pgcode 42P10 column reference 0 in ORDER BY clause is out of range \(1 \- 3\) SELECT * FROM t ORDER BY 0 +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42601 non-integer constant in ORDER BY: true +SELECT * FROM t ORDER BY true + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42601 non-integer constant in ORDER BY: 'a' +SELECT * FROM t ORDER BY 'a' + +query error pgcode 42601 unable to parse column reference in ORDER BY clause: 2\.5: invalid digit found in string +SELECT * FROM t ORDER BY 2.5 + query error column "foo" does not exist SELECT * FROM t ORDER BY foo -query error column "a.b" does not exist +query error column "a\.b" does not exist SELECT a FROM t ORDER BY a.b query IT @@ -227,7 +236,11 @@ CREATE TABLE abc ( b INT, c INT, d VARCHAR, - PRIMARY KEY (a, b, c) + PRIMARY KEY (a, b, c), + UNIQUE INDEX bc (b, c), + INDEX ba (b, a), + FAMILY (a, b, c), + FAMILY (d) ) statement ok @@ -256,7 +269,7 @@ SELECT a FROM abc ORDER BY a DESC OFFSET 1 1 statement ok -CREATE TABLE bar (id INT PRIMARY KEY, baz STRING) +CREATE TABLE bar (id INT PRIMARY KEY, baz STRING, UNIQUE INDEX i_bar (baz)) statement ok INSERT INTO bar VALUES (0, NULL), (1, NULL) @@ -276,7 +289,8 @@ CREATE TABLE abcd ( a INT PRIMARY KEY, b INT, c INT, - d INT + d INT, + INDEX abc (a, b, c) ) statement ok @@ -309,15 +323,13 @@ CREATE TABLE nan (id INT PRIMARY KEY, x REAL) statement ok INSERT INTO nan VALUES (1, 'NaN'), (2, -1), (3, 1), (4, 'NaN') -# TODO(benesch): NaN sorts backwards in Materialize, it seems. -skipif postgresql query R SELECT x FROM nan ORDER BY x ---- -NaN -NaN -1 1 +NaN +NaN statement ok CREATE TABLE blocks ( @@ -333,7 +345,8 @@ statement ok CREATE TABLE store ( id INT PRIMARY KEY, baz STRING, - extra INT + extra INT, + UNIQUE INDEX i_store (baz) STORING (extra) ) statement ok @@ -352,38 +365,36 @@ SELECT * FROM store ORDER BY baz, extra # ------------------------------------------------------------------------------ subtest order_by_index -# NOTE(benesch): this is Cockroach-specific syntax we're unlikely to support. -halt - -statement ok -CREATE TABLE kv(k INT PRIMARY KEY, v INT) - statement ok -CREATE INDEX foo ON kv(v DESC) +CREATE TABLE kv(k INT PRIMARY KEY, v INT); CREATE INDEX foo ON kv(v DESC) # Check the extended syntax cannot be used in case of renames. -statement error no data source matches prefix: test.public.kv +statement error Expected end of statement, found KEY SELECT * FROM kv AS a, kv AS b ORDER BY PRIMARY KEY kv # The INDEX/PRIMARY syntax can only be used when the data source # is a real table, not an alias. # -statement error no data source matches prefix: test.public.kv -SELECT k FROM (SELECT @1, @1 FROM generate_series(1,10)) AS kv(k,v) ORDER BY PRIMARY KEY kv +statement error Expected end of statement, found KEY +SELECT k FROM (SELECT i, i FROM generate_series(1,10) g(i)) AS kv(k,v) ORDER BY PRIMARY KEY kv -statement error no data source matches prefix: test.public.kv +statement error Expected end of statement, found KEY CREATE TABLE unrelated(x INT); SELECT * FROM unrelated ORDER BY PRIMARY KEY kv -# Check that prepare doesn't crash on ORDER BY PK clauses materialize#17312 +# Not supported by Materialize. +onlyif cockroach +# Check that prepare doesn't crash on ORDER BY PK clauses #17312 statement ok PREPARE a AS (TABLE kv) ORDER BY PRIMARY KEY kv -statement error ORDER BY INDEX in window definition is not supported +statement error Expected one of ROWS or RANGE or GROUPS, found KEY SELECT avg(k) OVER (ORDER BY PRIMARY KEY kv) FROM kv statement ok INSERT INTO kv VALUES (1, 1), (2, 1), (3, 1), (4, 1), (5, 1) +# Not supported by Materialize. +onlyif cockroach query I SELECT k FROM kv ORDER BY INDEX kv@foo ---- @@ -406,6 +417,8 @@ CREATE TABLE abc2 ( statement ok INSERT INTO abc2 VALUES (2, 30, 400), (1, 30, 500), (3, 30, 300) +# Not supported by Materialize. +onlyif cockroach query III SELECT a, b, c FROM abc2 ORDER BY PRIMARY KEY abc2 ---- @@ -413,6 +426,8 @@ SELECT a, b, c FROM abc2 ORDER BY PRIMARY KEY abc2 2 30 400 3 30 300 +# Not supported by Materialize. +onlyif cockroach query III SELECT a, b, c FROM abc2 ORDER BY PRIMARY KEY abc2 DESC ---- @@ -420,6 +435,8 @@ SELECT a, b, c FROM abc2 ORDER BY PRIMARY KEY abc2 DESC 2 30 400 1 30 500 +# Not supported by Materialize. +onlyif cockroach query III SELECT a, b, c FROM abc2 ORDER BY INDEX abc2@bc ---- @@ -427,6 +444,8 @@ SELECT a, b, c FROM abc2 ORDER BY INDEX abc2@bc 2 30 400 1 30 500 +# Not supported by Materialize. +onlyif cockroach query III SELECT a, b, c FROM abc2 ORDER BY INDEX abc2@bc DESC ---- @@ -434,6 +453,8 @@ SELECT a, b, c FROM abc2 ORDER BY INDEX abc2@bc DESC 2 30 400 3 30 300 +# Not supported by Materialize. +onlyif cockroach query III SELECT a, b, c FROM abc2 ORDER BY INDEX abc2@ba ---- @@ -441,6 +462,8 @@ SELECT a, b, c FROM abc2 ORDER BY INDEX abc2@ba 2 30 400 3 30 300 +# Not supported by Materialize. +onlyif cockroach query III SELECT a, b, c FROM abc2 ORDER BY INDEX abc2@ba DESC ---- @@ -448,8 +471,183 @@ SELECT a, b, c FROM abc2 ORDER BY INDEX abc2@ba DESC 2 30 400 1 30 500 -statement error relation \"x\" does not exist +statement error Expected end of statement, found identifier "x" SELECT a, b, c FROM abc2 AS x ORDER BY INDEX x@bc -statement error no data source matches prefix: test.public.abc2 +statement error Expected end of statement, found identifier "abc2" SELECT a, b, c FROM abc2 AS x ORDER BY INDEX abc2@bc + +# Not supported by Materialize. +onlyif cockroach +# Check that telemetry is being collected on the usage of ORDER BY. +query B +SELECT usage_count > 0 FROM crdb_internal.feature_usage WHERE feature_name = 'sql.plan.opt.node.sort' +---- +true + +# ------------------------------------------------------------------------------ +# NULLS FIRST, NULLS LAST test cases. +# ------------------------------------------------------------------------------ +subtest nulls_ordering + +statement ok +CREATE TABLE xy(x INT, y INT) + +statement ok +INSERT INTO xy VALUES (2, NULL), (NULL, 6), (2, 5), (4, 8) + +query II +SELECT x, y FROM xy ORDER BY y NULLS FIRST +---- +2 NULL +2 5 +NULL 6 +4 8 + +query II +SELECT x, y FROM xy ORDER BY y NULLS LAST +---- +2 5 +NULL 6 +4 8 +2 NULL + +query II +SELECT x, y FROM xy ORDER BY y DESC NULLS FIRST +---- +2 NULL +4 8 +NULL 6 +2 5 + +query II +SELECT x, y FROM xy ORDER BY y DESC NULLS LAST +---- +4 8 +NULL 6 +2 5 +2 NULL + +statement ok +CREATE INDEX y_idx ON xy(y); + +query II +SELECT x, y FROM xy ORDER BY y NULLS LAST +---- +2 5 +NULL 6 +4 8 +2 NULL + +statement ok +INSERT INTO xy VALUES (NULL, NULL) + +query II +SELECT x, y FROM xy ORDER BY x NULLS FIRST, y NULLS LAST +---- +NULL 6 +NULL NULL +2 5 +2 NULL +4 8 + +query II +SELECT x, y FROM xy ORDER BY x NULLS LAST, y DESC NULLS FIRST +---- +2 NULL +2 5 +4 8 +NULL NULL +NULL 6 + +# Ensure null_ordered_last works by default, but respects NULLS FIRST +# if it is explicitly mentioned. +statement ok +SET null_ordered_last = true + +query II +SELECT x, y FROM xy ORDER BY x, y +---- +2 5 +2 NULL +4 8 +NULL 6 +NULL NULL + +query II +SELECT x, y FROM xy ORDER BY x, y DESC NULLS FIRST +---- +2 NULL +2 5 +4 8 +NULL NULL +NULL 6 + +query II +SELECT x, y FROM xy ORDER BY x NULLS LAST, y DESC NULLS FIRST +---- +2 NULL +2 5 +4 8 +NULL NULL +NULL 6 + +query II +SELECT x, y FROM xy ORDER BY x NULLS FIRST, y DESC NULLS LAST +---- +NULL 6 +NULL NULL +2 5 +2 NULL +4 8 + +query II +SELECT x, y FROM xy ORDER BY x NULLS FIRST, y DESC +---- +NULL NULL +NULL 6 +2 NULL +2 5 +4 8 + +query II +SELECT x, y FROM xy ORDER BY x NULLS FIRST, y DESC NULLS FIRST +---- +NULL NULL +NULL 6 +2 NULL +2 5 +4 8 + +# Not supported by Materialize. +onlyif cockroach +# Using the session variable, we should get results that match Postgres. +# TODO(#93558): This test case is broken and shows the limit of our +# approach to using an optimizer-based approach for NULLS LAST. +# Postgres returns: +# x | y +# -------+--- +# (1,1) | 1 +# (1,) | 3 +# (,) | 4 +# | 2 +# +query TI +WITH t (x, y) AS ( + VALUES + ((1, 1), 1), + ((NULL::RECORD), 2), + ((1, NULL::INT), 3), + ((NULL::INT, NULL::INT), 4) +) +SELECT * +FROM t +ORDER BY x; +---- +(1,) 3 +(1,1) 1 +NULL 2 +(,) 4 + +statement ok +RESET null_ordered_last diff --git a/test/sqllogictest/cockroach/ordinal_references.slt b/test/sqllogictest/cockroach/ordinal_references.slt index 477b828092f13..c4f628a7d90d9 100644 --- a/test/sqllogictest/cockroach/ordinal_references.slt +++ b/test/sqllogictest/cockroach/ordinal_references.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,22 +9,27 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/ordinal_references +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/ordinal_references # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach +statement ok +SET allow_ordinal_column_references=true + statement ok CREATE TABLE foo(a INT, b CHAR) +# Not supported by Materialize. +onlyif cockroach query I INSERT INTO foo(a, b) VALUES (1,'c'), (2,'b'), (3,'a') RETURNING @1 ---- @@ -32,12 +37,14 @@ INSERT INTO foo(a, b) VALUES (1,'c'), (2,'b'), (3,'a') RETURNING @1 2 3 -query error invalid column ordinal +query error Expected an expression, found operator "@" SELECT @0 FROM foo -query error invalid column ordinal +query error Expected an expression, found operator "@" SELECT @42 FROM foo +# Not supported by Materialize. +onlyif cockroach query TI rowsort SELECT @2, @1 FROM foo ---- @@ -49,10 +56,10 @@ a 3 query TI SELECT b, a FROM foo ORDER BY 1 ---- -a 3 -b 2 -c 1 + +# Not supported by Materialize. +onlyif cockroach # CockroachDB column ordinals refer to the data source. query TI SELECT b, a FROM foo ORDER BY @1 @@ -61,6 +68,8 @@ c 1 b 2 a 3 +# Not supported by Materialize. +onlyif cockroach query TI SELECT b, a FROM foo ORDER BY @1 % 2, a ---- @@ -71,6 +80,8 @@ a 3 statement ok INSERT INTO foo(a, b) VALUES (4, 'c'), (5, 'c'), (6, 'c') +# Not supported by Materialize. +onlyif cockroach query R SELECT sum(a) AS s FROM foo GROUP BY @1 ORDER BY s ---- @@ -81,6 +92,8 @@ SELECT sum(a) AS s FROM foo GROUP BY @1 ORDER BY s 5 6 +# Not supported by Materialize. +onlyif cockroach query R SELECT sum(a) AS s FROM foo GROUP BY @2 ORDER BY s ---- @@ -88,14 +101,14 @@ SELECT sum(a) AS s FROM foo GROUP BY @2 ORDER BY s 3 16 -statement error column reference @1 not allowed in this context +statement error Expected an expression, found operator "@" INSERT INTO foo(a, b) VALUES (@1, @2) -query error column reference @485 not allowed in this context +query error Expected an expression, found operator "@" VALUES (@485) -query error column reference @1 not allowed in this context +query error Expected an expression, found operator "@" SELECT * FROM foo LIMIT @1 -query error column reference @1 not allowed in this context +query error Expected an expression, found operator "@" SELECT * FROM foo OFFSET @1 diff --git a/test/sqllogictest/cockroach/ordinality.slt b/test/sqllogictest/cockroach/ordinality.slt index 47c7f4d59335a..4030ddf2dd82e 100644 --- a/test/sqllogictest/cockroach/ordinality.slt +++ b/test/sqllogictest/cockroach/ordinality.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,19 +9,21 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/ordinality +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/ordinality # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach +# Not supported by Materialize. +onlyif cockroach query TI colnames SELECT * FROM (VALUES ('a'), ('b')) WITH ORDINALITY AS x(name, i) ---- @@ -29,6 +31,8 @@ name i a 1 b 2 +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT ordinality FROM (VALUES ('a'), ('b')) WITH ORDINALITY ---- @@ -37,27 +41,32 @@ ordinality 2 statement ok -CREATE TABLE foo (x CHAR PRIMARY KEY) - -statement ok -INSERT INTO foo(x) VALUES ('a'), ('b') +CREATE TABLE foo (x CHAR PRIMARY KEY); INSERT INTO foo(x) VALUES ('a'), ('b') +# Not supported by Materialize. +onlyif cockroach query TI SELECT * FROM foo WITH ORDINALITY ---- a 1 b 2 +# Not supported by Materialize. +onlyif cockroach query TI SELECT * FROM foo WITH ORDINALITY LIMIT 1 ---- a 1 +# Not supported by Materialize. +onlyif cockroach query I SELECT max(ordinality) FROM foo WITH ORDINALITY ---- 2 +# Not supported by Materialize. +onlyif cockroach query TITI rowsort SELECT * FROM foo WITH ORDINALITY AS a, foo WITH ORDINALITY AS b ---- @@ -66,39 +75,72 @@ a 1 b 2 b 2 a 1 b 2 b 2 +# Not supported by Materialize. +onlyif cockroach query TI SELECT * FROM (SELECT x||x FROM foo) WITH ORDINALITY ---- aa 1 bb 2 -query TII -SELECT * FROM (SELECT x, ordinality*2 FROM foo WITH ORDINALITY AS a) JOIN foo WITH ORDINALITY AS b USING (x) +# Not supported by Materialize. +onlyif cockroach +query TII rowsort +SELECT * FROM (SELECT x, ordinality*2 FROM foo WITH ORDINALITY AS a) JOIN foo WITH ORDINALITY AS b USING(x) ---- a 2 1 b 4 2 +# Not supported by Materialize. +onlyif cockroach +query TI +SELECT * FROM (SELECT * FROM foo ORDER BY x DESC) WITH ORDINALITY LIMIT 1 +---- +b 1 + +# Not supported by Materialize. +onlyif cockroach +query TI +SELECT * FROM (SELECT * FROM foo ORDER BY x) WITH ORDINALITY ORDER BY x DESC LIMIT 1 +---- +b 2 + +# Not supported by Materialize. +onlyif cockroach +query TI +SELECT * FROM (SELECT * FROM foo ORDER BY x) WITH ORDINALITY ORDER BY ordinality DESC LIMIT 1 +---- +b 2 + statement ok INSERT INTO foo(x) VALUES ('c') +# Not supported by Materialize. +onlyif cockroach query TI SELECT * FROM foo WITH ORDINALITY WHERE x > 'a' ---- b 2 c 3 +# Not supported by Materialize. +onlyif cockroach query TI SELECT * FROM foo WITH ORDINALITY WHERE ordinality > 1 ORDER BY ordinality DESC ---- c 3 b 2 +# Not supported by Materialize. +onlyif cockroach query TI SELECT * FROM (SELECT * FROM foo WHERE x > 'a') WITH ORDINALITY ---- b 1 c 2 +# Not supported by Materialize. +onlyif cockroach query B SELECT ordinality = row_number() OVER () FROM foo WITH ORDINALITY ---- @@ -106,6 +148,16 @@ true true true -# Regression test for cockroach#33659 +# Not supported by Materialize. +onlyif cockroach +# Regression test for #33659 statement ok TABLE [SHOW ZONE CONFIGURATIONS] WITH ORDINALITY + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #41760 +query TI +SELECT * FROM (SELECT * FROM foo LIMIT 1) WITH ORDINALITY +---- +a 1 diff --git a/test/sqllogictest/cockroach/orms-opt.slt b/test/sqllogictest/cockroach/orms-opt.slt deleted file mode 100644 index a671fe73b903e..0000000000000 --- a/test/sqllogictest/cockroach/orms-opt.slt +++ /dev/null @@ -1,112 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/orms-opt -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -## This test file contains various complex queries that ORMs issue during -## startup or general use, that pre-CBO code can't handle. This file should be -## merged with the orms test file once the heuristic planner is gone. - -statement ok -CREATE TABLE a (a INT PRIMARY KEY) - -# ActiveRecord query that needs apply join. -query TTTBTITT -SELECT a.attname, - format_type(a.atttypid, a.atttypmod), - pg_get_expr(d.adbin, d.adrelid), - a.attnotnull, - a.atttypid, - a.atttypmod, - (SELECT c.collname - FROM pg_collation c, pg_type t - WHERE c.oid = a.attcollation - AND t.oid = a.atttypid - AND a.attcollation <> t.typcollation), - col_description(a.attrelid, a.attnum) AS comment -FROM pg_attribute a LEFT JOIN pg_attrdef d -ON a.attrelid = d.adrelid AND a.attnum = d.adnum -WHERE a.attrelid = '"a"'::regclass -AND a.attnum > 0 AND NOT a.attisdropped -ORDER BY a.attnum ----- -a bigint NULL true 20 -1 NULL NULL - -# Navicat metadata query. - -query TTBBB -SELECT - attname AS name, - attrelid AS tid, - COALESCE( - ( - SELECT - attnum = ANY conkey - FROM - pg_constraint - WHERE - contype = 'p' AND conrelid = attrelid - ), - false - ) - AS primarykey, - NOT (attnotnull) AS allownull, - ( - SELECT - seq.oid - FROM - pg_class AS seq - LEFT JOIN pg_depend AS dep - ON seq.oid = dep.objid - WHERE - ( - seq.relkind = 'S'::CHAR - AND dep.refobjsubid = attnum - ) - AND dep.refobjid = attrelid - ) - IS NOT NULL - AS autoincrement -FROM - pg_attribute -WHERE - ( - attisdropped = false - AND attrelid - = ( - SELECT - tbl.oid - FROM - pg_class AS tbl - LEFT JOIN pg_namespace AS sch - ON tbl.relnamespace = sch.oid - WHERE - ( - tbl.relkind = 'r'::"char" - AND tbl.relname = 'a' - ) - AND sch.nspname = 'public' - ) - ) - AND attname = 'a'; ----- -a 53 true false false diff --git a/test/sqllogictest/cockroach/orms.slt b/test/sqllogictest/cockroach/orms.slt index 7bbad06ae1f5e..d375afebcad1b 100644 --- a/test/sqllogictest/cockroach/orms.slt +++ b/test/sqllogictest/cockroach/orms.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,19 +9,23 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/orms +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/orms # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach +# TODO(mjibson): The fakedist-disk config produces an error. When fixed, +# remove this config line. See #38985. +# LogicTest: local fakedist 3node-tenant + ## This test file contains various complex queries that ORMs issue during ## startup or general use. @@ -39,21 +43,20 @@ SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.a AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum ---- -id bigint NULL false 20 -1 -name text NULL false 25 -1 -rowid bigint unique_rowid() true 20 -1 +id integer NULL false 23 -1 +name text NULL false 25 -1 -# materialize#12115 -# Skipped until database-issues#7510 is solved -#query TT -#SELECT t.typname enum_name, array_agg(e.enumlabel ORDER BY enumsortorder) enum_value -# FROM pg_type t -# JOIN pg_enum e ON t.oid = e.enumtypid -# JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace -# WHERE n.nspname = 'public' -# GROUP BY 1 -#---- +# Ordered aggregations are possible. +# #12115 +query TT +SELECT t.typname enum_name, array_agg(e.enumlabel ORDER BY enumsortorder) enum_value + FROM pg_type t + JOIN pg_enum e ON t.oid = e.enumtypid + JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace + WHERE n.nspname = 'public' + GROUP BY 1 +---- ## 12207 @@ -91,9 +94,8 @@ GROUP BY i.relname, ix.indkey ORDER BY i.relname ---- -name primary unique indkey column_indexes column_names definition -customers_id_idx false false 2 {1,2} {name,id} CREATE INDEX customers_id_idx ON test.public.customers (id ASC) -primary true true 1 {1,2} {name,id} CREATE UNIQUE INDEX "primary" ON test.public.customers (name ASC) +name primary unique indkey column_indexes column_names definition + query TT colnames @@ -104,9 +106,11 @@ JOIN pg_attribute a ON a.attrelid = i.indrelid WHERE i.indrelid = '"a"'::regclass AND i.indisprimary ---- -attname data_type -rowid bigint +attname data_type + +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE b (id INT, a_id INT, FOREIGN KEY (a_id) REFERENCES a (id)) @@ -125,14 +129,18 @@ AND t1.relname ='b' AND t3.nspname = ANY (current_schemas(false)) ORDER BY c.conname ---- -a a_id id fk_a_id_ref_a a a + +# Not supported by Materialize. +onlyif cockroach # Default value columns in Rails produce these kinds of queries: query O SELECT 'decimal(18,2)'::regtype::oid ---- 1700 +# Not supported by Materialize. +onlyif cockroach # NOTE: Before 19.2, this returned 25 (oid.T_text), but due to updates to the # type system to more correctly handle OIDs, this now returns 1043 # (oid.T_varchar), which is what PG returns. @@ -141,6 +149,8 @@ SELECT 'character varying'::regtype::oid ---- 1043 +# Not supported by Materialize. +onlyif cockroach statement ok CREATE INDEX b_idx ON b(a_id); @@ -156,4 +166,253 @@ AND i.relname = 'b_idx' AND t.relname = 'b' AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false))) ---- -1 +0 + +statement ok +CREATE TABLE c (a INT, b INT, PRIMARY KEY (a, b)) + +# ActiveRecord query for determining primary key cols. +query T +SELECT + a.attname +FROM + ( + SELECT + indrelid, indkey, generate_subscripts(indkey, 1) AS idx + FROM + pg_index + WHERE + indrelid = '"c"'::REGCLASS AND indisprimary + ) + AS i + JOIN pg_attribute AS a ON + a.attrelid = i.indrelid AND a.attnum = i.indkey[i.idx] +ORDER BY + i.idx +---- + + +statement ok +CREATE TABLE metatest (a INT PRIMARY KEY) + +# ActiveRecord query that needs apply join. +query TTTBTITT +SELECT a.attname, + format_type(a.atttypid, a.atttypmod), + pg_get_expr(d.adbin, d.adrelid), + a.attnotnull, + a.atttypid, + a.atttypmod, + (SELECT c.collname + FROM pg_collation c, pg_type t + WHERE c.oid = a.attcollation + AND t.oid = a.atttypid + AND a.attcollation <> t.typcollation), + col_description(a.attrelid, a.attnum) AS comment +FROM pg_attribute a LEFT JOIN pg_attrdef d +ON a.attrelid = d.adrelid AND a.attnum = d.adnum +WHERE a.attrelid = '"metatest"'::regclass +AND a.attnum > 0 AND NOT a.attisdropped +ORDER BY a.attnum +---- +a integer NULL true 23 -1 NULL NULL + +# Navicat metadata query. + +# Not supported by Materialize. +onlyif cockroach +query TTBBB +SELECT + attname AS name, + attrelid AS tid, + COALESCE( + ( + SELECT + attnum = ANY conkey + FROM + pg_constraint + WHERE + contype = 'p' AND conrelid = attrelid + ), + false + ) + AS primarykey, + NOT (attnotnull) AS allownull, + ( + SELECT + seq.oid + FROM + pg_class AS seq + LEFT JOIN pg_depend AS dep + ON seq.oid = dep.objid + WHERE + ( + seq.relkind = 'S'::CHAR + AND dep.refobjsubid = attnum + ) + AND dep.refobjid = attrelid + ) + IS NOT NULL + AS autoincrement +FROM + pg_attribute +WHERE + ( + attisdropped = false + AND attrelid + = ( + SELECT + tbl.oid + FROM + pg_class AS tbl + LEFT JOIN pg_namespace AS sch + ON tbl.relnamespace = sch.oid + WHERE + ( + tbl.relkind = 'r'::"char" + AND tbl.relname = 'metatest' + ) + AND sch.nspname = 'public' + ) + ) + AND attname = 'a'; +---- +a 110 true false false + +# Hibernate query. + +query TTTOBIIITTOT rowsort +SELECT * FROM (SELECT n.nspname, c.relname, a.attname, a.atttypid, a.attnotnull OR ((t.typtype = 'd') AND t.typnotnull) AS attnotnull, a.atttypmod, a.attlen, row_number() OVER (PARTITION BY a.attrelid ORDER BY a.attnum) AS attnum, pg_get_expr(def.adbin, def.adrelid) AS adsrc, dsc.description, t.typbasetype, t.typtype FROM pg_catalog.pg_namespace AS n JOIN pg_catalog.pg_class AS c ON (c.relnamespace = n.oid) JOIN pg_catalog.pg_attribute AS a ON (a.attrelid = c.oid) JOIN pg_catalog.pg_type AS t ON (a.atttypid = t.oid) LEFT JOIN pg_catalog.pg_attrdef AS def ON ((a.attrelid = def.adrelid) AND (a.attnum = def.adnum)) LEFT JOIN pg_catalog.pg_description AS dsc ON ((c.oid = dsc.objoid) AND (a.attnum = dsc.objsubid)) LEFT JOIN pg_catalog.pg_class AS dc ON ((dc.oid = dsc.classoid) AND (dc.relname = 'pg_class')) LEFT JOIN pg_catalog.pg_namespace AS dn ON ((dc.relnamespace = dn.oid) AND (dn.nspname = 'pg_catalog')) WHERE (((c.relkind IN ('r', 'v', 'f', 'm')) AND (a.attnum > 0)) AND (NOT a.attisdropped)) AND (n.nspname LIKE 'public')) AS c; +---- +public a id 23 false -1 NULL 1 NULL NULL 0 b +public a name 25 false -1 NULL 2 NULL NULL 0 b +public c a 23 true -1 NULL 1 NULL NULL 0 b +public c b 23 true -1 NULL 2 NULL NULL 0 b +public customers id 23 false -1 NULL 2 NULL NULL 0 b +public customers name 25 true -1 NULL 1 NULL NULL 0 b +public metatest a 23 true -1 NULL 1 NULL NULL 0 b + + +# Not supported by Materialize. +onlyif cockroach +# Regression test for windower not using EncDatum.Fingerprint. +statement ok +SELECT + array_agg(t_pk.table_name ORDER BY t_pk.table_name) +FROM + information_schema.statistics AS i + LEFT JOIN ( + SELECT + array_agg(c.column_name) AS table_primary_key_columns, + c.table_name + FROM + information_schema.columns AS c + GROUP BY + c.table_name + ) + AS t_pk ON i.table_name = t_pk.table_name +GROUP BY + t_pk.table_primary_key_columns + +# Regression test for pgcli's foreign key query. +query TTTTTT +SELECT + s_p.nspname AS parentschema, + t_p.relname AS parenttable, + unnest( + ( + SELECT + array_agg(attname ORDER BY i) + FROM + ( + SELECT + unnest(confkey) AS attnum, + generate_subscripts(confkey, 1) AS i + ) + AS x + JOIN pg_catalog.pg_attribute AS c USING (attnum) + WHERE + c.attrelid = fk.confrelid + ) + ) + AS parentcolumn, + s_c.nspname AS childschema, + t_c.relname AS childtable, + unnest( + ( + SELECT + array_agg(attname ORDER BY i) + FROM + ( + SELECT + unnest(conkey) AS attnum, + generate_subscripts(conkey, 1) AS i + ) + AS x + JOIN pg_catalog.pg_attribute AS c USING (attnum) + WHERE + c.attrelid = fk.conrelid + ) + ) + AS childcolumn +FROM + pg_catalog.pg_constraint AS fk + JOIN pg_catalog.pg_class AS t_p ON t_p.oid = fk.confrelid + JOIN pg_catalog.pg_namespace AS s_p ON + s_p.oid = t_p.relnamespace + JOIN pg_catalog.pg_class AS t_c ON t_c.oid = fk.conrelid + JOIN pg_catalog.pg_namespace AS s_c ON + s_c.oid = t_c.relnamespace +WHERE + fk.contype = 'f'; +---- + + +# Regression test for #66576 + +statement ok +CREATE TABLE regression_66576 () + +# Not supported by Materialize. +onlyif cockroach +query TOTTBTITIT +SELECT + typname, + typnamespace, + typtype, + typcategory, + typnotnull, + typelem, + typlen, + typbasetype, + typtypmod, + typdefaultbin +FROM pg_type WHERE typname = 'regression_66576' +---- +regression_66576 105 c C false 0 -1 0 -1 NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT reltype FROM pg_class WHERE relname = 'regression_65576' +---- + +let $oid +SELECT reltype FROM pg_class WHERE relname = 'regression_66576' + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT typname FROM pg_type WHERE oid = $oid +---- +regression_66576 + +let $oid +SELECT typrelid FROM pg_type WHERE typname = 'regression_66576' + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT relname FROM pg_class WHERE oid = $oid +---- +regression_66576 diff --git a/test/sqllogictest/cockroach/overflow.slt b/test/sqllogictest/cockroach/overflow.slt new file mode 100644 index 0000000000000..078f6e1ebcec9 --- /dev/null +++ b/test/sqllogictest/cockroach/overflow.slt @@ -0,0 +1,83 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/overflow +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Test for overflow handling in sum aggregate. + +statement ok +CREATE TABLE large_numbers (a INT8) + +statement ok +INSERT INTO large_numbers VALUES (9223372036854775807),(1) + +statement error function "sum_int" does not exist +SELECT sum_int(a) FROM large_numbers + +statement ok +DELETE FROM large_numbers + +statement ok +INSERT INTO large_numbers VALUES (-9223372036854775808),(-1) + +statement error function "sum_int" does not exist +SELECT sum_int(a) FROM large_numbers + +subtest regression_88128 + +statement ok +CREATE TABLE t88128 (i INT) + +statement ok +INSERT INTO t88128 VALUES (100000) + +# Ensure that the optimizer does not simplify the filter by adding the constant +# subtrahend to the right side of the comparison when the addition would +# overflow. +query B +SELECT i - 1000 < 9223372036854775800 FROM t88128 +---- +true + +# Ensure that the optimizer does not simplify the filter by adding the constant +# subtrahend to the right side of the comparison when the addition would +# underflow. +query B +SELECT i - (-1000) > -9223372036854775800 FROM t88128 +---- +true + +# Ensure that the optimizer does not simplify the filter by subtracting the +# constant addend to the right side of the comparison when the subtraction would +# underflow. +query B +SELECT i + 1000 > -9223372036854775800 FROM t88128 +---- +true + +# Ensure that the optimizer does not simplify the filter by subtracting the +# constant addend to the right side of the comparison when the subtraction would +# overflow. +query B +SELECT i + (-1000) < 9223372036854775800 FROM t88128 +---- +true diff --git a/test/sqllogictest/cockroach/partitioning.slt b/test/sqllogictest/cockroach/partitioning.slt new file mode 100644 index 0000000000000..1c86cb546ac45 --- /dev/null +++ b/test/sqllogictest/cockroach/partitioning.slt @@ -0,0 +1,43 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/partitioning +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# 3node-tenant is blocked from running this file because the config runs with +# a CCL binary, so the expected failures from using a non-CCL binary don't occur. +# LogicTest: !3node-tenant-default-configs + +statement error pgcode XXC01 Expected end of statement, found PARTITION +CREATE TABLE t (a INT, b INT, c INT, PRIMARY KEY (a, b)) PARTITION BY LIST (a) ( + PARTITION p1 VALUES IN (1), + PARTITION p2 VALUES IN (2) +) + +# Not supported by Materialize. +onlyif cockroach +statement error pgcode XXC01 creating or manipulating partitions requires a CCL binary +CREATE TABLE t ( + a INT PRIMARY KEY, b INT, + INDEX (b) PARTITION BY LIST (b) ( + PARTITION p1 VALUES IN (1) + ) +) diff --git a/test/sqllogictest/cockroach/pg_builtins.slt b/test/sqllogictest/cockroach/pg_builtins.slt new file mode 100644 index 0000000000000..b26d1ae09da33 --- /dev/null +++ b/test/sqllogictest/cockroach/pg_builtins.slt @@ -0,0 +1,1034 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/pg_builtins +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +query T +SELECT aclexplode(NULL) +---- + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT aclexplode(ARRAY[]::text[]) +---- + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT aclexplode(ARRAY['foo']) +---- + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #43166. +statement ok +SELECT has_table_privilege('root'::NAME, 0, 'select') + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #53684. +statement ok +CREATE TYPE typ AS ENUM ('hello') + +query T +SELECT format_type(oid, 0) FROM pg_catalog.pg_type WHERE typname = 'typ' +---- + + +# Nothing breaks if we put a non-existing oid into format_type. +query T +SELECT format_type(152100, 0) +---- +??? + +subtest pg_column_size + +query I +SELECT pg_column_size(1::float) +---- +9 + +query I +SELECT pg_column_size(1::int) +---- +2 + +query I +SELECT pg_column_size((1, 1)) +---- +13 + +query I +SELECT pg_column_size('{}'::json) +---- +9 + +query I +SELECT pg_column_size('') +---- +2 + +query I +SELECT pg_column_size('a') +---- +3 + +query I +SELECT pg_column_size((1,'a')) +---- +14 + +query I +SELECT pg_column_size(true) +---- +1 + +query I +SELECT pg_column_size(NULL::int) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE is_visible(a int primary key); +CREATE TYPE visible_type AS ENUM('a'); +CREATE FUNCTION visible_func() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$; +CREATE SCHEMA other; +CREATE TABLE other.not_visible(a int primary key); +CREATE TYPE other.not_visible_type AS ENUM('b'); +CREATE FUNCTION other.not_visible_func() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$; +CREATE DATABASE db2; +SET DATABASE = db2; +CREATE TABLE table_in_db2(a int primary key); +CREATE TYPE type_in_db2 AS ENUM('c'); +CREATE FUNCTION func_in_db2() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$; + +let $table_in_db2_id +SELECT c.oid FROM pg_class c WHERE c.relname = 'table_in_db2'; + +let $type_in_db2_id +SELECT t.oid FROM pg_type t WHERE t.typname = 'type_in_db2'; + +let $func_in_db2_id +SELECT p.oid FROM pg_proc p WHERE p.proname = 'func_in_db2'; + +statement ok +SET DATABASE = test; + +query TB rowsort +SELECT c.relname, pg_table_is_visible(c.oid) +FROM pg_class c +WHERE c.relname IN ('is_visible', 'not_visible', 'is_visible_pkey', 'not_visible_pkey') +---- + + +# Not supported by Materialize. +onlyif cockroach +# Looking up a table in a different database should return NULL. +query B +SELECT pg_table_is_visible($table_in_db2_id) +---- +NULL + +# Looking up a non-existent OID should return NULL. +query B +SELECT pg_table_is_visible(1010101010) +---- +NULL + +query B +SELECT pg_table_is_visible(NULL) +---- +NULL + +query TB rowsort +SELECT t.typname, pg_type_is_visible(t.oid) +FROM pg_type t +WHERE t.typname IN ('int8', '_date', 'visible_type', 'not_visible_type') +---- +_date true +int8 true + +# Not supported by Materialize. +onlyif cockroach +# Looking up a table in a different database should return NULL. +query B +SELECT pg_type_is_visible($type_in_db2_id) +---- +NULL + +# Looking up a non-existent OID should return NULL. +query B +SELECT pg_type_is_visible(1010101010) +---- +NULL + +query B +SELECT pg_type_is_visible(NULL) +---- +NULL + +query TB rowsort +SELECT p.proname, pg_function_is_visible(p.oid) +FROM pg_proc p +WHERE p.proname IN ('array_length', 'visible_func', 'not_visible_func') +---- +array_length true + +# Not supported by Materialize. +onlyif cockroach +# Looking up a function in a different database should return NULL. +query B +SELECT pg_function_is_visible($func_in_db2_id) +---- +NULL + +# Looking up a non-existent OID should return NULL. +query B +SELECT pg_function_is_visible(1010101010) +---- +NULL + +query B +SELECT pg_function_is_visible(NULL) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT pg_get_partkeydef(1), pg_get_partkeydef(NULL) +---- +NULL NULL + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE is_updatable(a INT PRIMARY KEY, b INT, c INT AS (b * 10) STORED); +CREATE VIEW is_updatable_view AS SELECT a, b FROM is_updatable + +# Not supported by Materialize. +onlyif cockroach +query TTOIIB colnames +SELECT + c.relname, + a.attname, + c.oid, + a.attnum, + pg_relation_is_updatable(c.oid, false), + pg_column_is_updatable(c.oid, a.attnum, false) +FROM pg_class c +JOIN pg_attribute a ON a.attrelid = c.oid +WHERE c.relname IN ('is_updatable', 'is_updatable_view', 'pg_class') +ORDER BY c.oid, a.attnum +---- +relname attname oid attnum pg_relation_is_updatable pg_column_is_updatable +is_updatable a 123 1 28 true +is_updatable b 123 2 28 true +is_updatable c 123 3 28 false +is_updatable_view a 124 1 0 false +is_updatable_view b 124 2 0 false +pg_class oid 4294967106 1 0 false +pg_class relname 4294967106 2 0 false +pg_class relnamespace 4294967106 3 0 false +pg_class reltype 4294967106 4 0 false +pg_class reloftype 4294967106 5 0 false +pg_class relowner 4294967106 6 0 false +pg_class relam 4294967106 7 0 false +pg_class relfilenode 4294967106 8 0 false +pg_class reltablespace 4294967106 9 0 false +pg_class relpages 4294967106 10 0 false +pg_class reltuples 4294967106 11 0 false +pg_class relallvisible 4294967106 12 0 false +pg_class reltoastrelid 4294967106 13 0 false +pg_class relhasindex 4294967106 14 0 false +pg_class relisshared 4294967106 15 0 false +pg_class relpersistence 4294967106 16 0 false +pg_class relistemp 4294967106 17 0 false +pg_class relkind 4294967106 18 0 false +pg_class relnatts 4294967106 19 0 false +pg_class relchecks 4294967106 20 0 false +pg_class relhasoids 4294967106 21 0 false +pg_class relhaspkey 4294967106 22 0 false +pg_class relhasrules 4294967106 23 0 false +pg_class relhastriggers 4294967106 24 0 false +pg_class relhassubclass 4294967106 25 0 false +pg_class relfrozenxid 4294967106 26 0 false +pg_class relacl 4294967106 27 0 false +pg_class reloptions 4294967106 28 0 false +pg_class relforcerowsecurity 4294967106 29 0 false +pg_class relispartition 4294967106 30 0 false +pg_class relispopulated 4294967106 31 0 false +pg_class relreplident 4294967106 32 0 false +pg_class relrewrite 4294967106 33 0 false +pg_class relrowsecurity 4294967106 34 0 false +pg_class relpartbound 4294967106 35 0 false +pg_class relminmxid 4294967106 36 0 false + + +# Check that the oid does not exist. If this test fail, change the oid here and in +# the next test at 'relation does not exist' value. +query I +SELECT count(1) FROM pg_class WHERE oid = 1 +---- +0 + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT * FROM (VALUES + ('system column', (SELECT CAST(pg_column_is_updatable(oid, -1, true) AS TEXT) FROM pg_class WHERE relname = 'is_updatable')), + ('relation does not exist', CAST(pg_relation_is_updatable(1, true) AS TEXT)), + ('relation does not exist', CAST(pg_column_is_updatable(1, 1, true) AS TEXT)), + ('relation exists, but column does not', (SELECT CAST(pg_column_is_updatable(oid, 15, true) AS TEXT) FROM pg_class WHERE relname = 'is_updatable')) + ) AS tbl(description, value) +ORDER BY 1 +---- +relation does not exist 0 +relation does not exist false +relation exists, but column does not true +system column false + +query T +SELECT current_setting('statement_timeout') +---- +1 min + +query T +SELECT current_setting('statement_timeout', false) +---- +1 min + +# Not supported by Materialize. +onlyif cockroach +# check returns null on unsupported session var. +query T +SELECT IFNULL(current_setting('woo', true), 'OK') +---- +OK + +# Not supported by Materialize. +onlyif cockroach +# check that current_setting handles null. +query T +SELECT current_setting(NULL, false) +---- +NULL + +# check that multiple settings can be queried at once. +query TT +SELECT current_setting('statement_timeout'), current_setting('search_path') +---- +1␠min public + +# check error on nonexistent session var. +query error unrecognized configuration parameter +SELECT pg_catalog.current_setting('woo', false) + +# Check that current_setting handles custom settings correctly. +query T +SELECT current_setting('my.custom', true) +---- +NULL + +statement ok +PREPARE check_custom AS SELECT current_setting('my.custom', true) + +query T +EXECUTE check_custom +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +SET LOCAL my.custom = 'foo' + +# Check that the existence of my.custom is checked depending on the execution +# context, and not at PREPARE time. +query T +EXECUTE check_custom +---- +NULL + +statement ok +COMMIT + +# check error on unsupported session var. +query error unrecognized configuration parameter +SELECT current_setting('vacuum_cost_delay', false) + +query T +SHOW application_name +---- +(empty) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT set_config('application_name', 'woo', false) +---- +woo + +query T +SHOW application_name +---- +(empty) + +# Not supported by Materialize. +onlyif cockroach +# check that multiple settings can be set at once +query TTT +SELECT + set_config('application_name', 'foo', false), + set_config('statement_timeout', '60s', false), + set_config(NULL, 'foo', false) +---- +foo 60000 NULL + +# Not supported by Materialize. +onlyif cockroach +# check that the value doesn't change with isLocal=true outside of a +# transaction. Note: in Postgres, set_config returns 'woo' here even though +# the value doesn't change. This difference doesn't seem too important. +query T +SELECT set_config('application_name', 'woo', true) +---- +foo + +query T +SELECT current_setting('application_name') +---- +(empty) + +# verify that the setting change is scoped to the transaction with isLocal=true. +statement ok +BEGIN + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT set_config('application_name', 'woo', true) +---- +woo + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT current_setting('application_name'), current_setting('statement_timeout') +---- +woo 60000 + +statement ok +COMMIT + +query T +SELECT current_setting('application_name') +---- +(empty) + +query error function "pg_catalog\.set_config" does not exist +SELECT pg_catalog.set_config('woo', 'woo', false) + +query error function "set_config" does not exist +SELECT set_config('vacuum_cost_delay', '0', false) + +# pg_my_temp_schema +# +# Before a temporary schema is created, it returns 0. Afterwards, it returns the +# OID of session's temporary schema. + +# Not supported by Materialize. +onlyif cockroach +query O +SELECT pg_my_temp_schema() +---- +0 + +statement ok +SET experimental_enable_temp_tables = true; + +statement ok +CREATE TEMP TABLE temp1 (a int); + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT pg_my_temp_schema()::TEXT LIKE 'pg_temp_%' +---- +true + +# If the user changes databases, it no longer has access to its temp tables. +# pg_my_temp_schema reverts to returning 0 again. + +statement ok +SET DATABASE = db2; + +# Not supported by Materialize. +onlyif cockroach +query O +SELECT pg_my_temp_schema() +---- +0 + +statement ok +CREATE TEMP TABLE temp2 (a int); + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT pg_my_temp_schema()::TEXT LIKE 'pg_temp_%' +---- +true + +statement ok +SET DATABASE = test; + +# pg_is_other_temp_schema +# +# Returns true if the provided OID meets the following conditions: +# - is a reference to a schema +# - that is temporary +# - and is owned by a different session + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT pg_is_other_temp_schema((SELECT oid FROM pg_type LIMIT 1)) +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT pg_is_other_temp_schema((SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')) +---- +false + +# Not supported by Materialize. +onlyif cockroach +query TB +SELECT user, pg_is_other_temp_schema((SELECT oid FROM pg_namespace WHERE nspname LIKE 'pg_temp_%')) +---- +root false + +# Switch users as a means of switching sessions. GRANT to ensure visibility. + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT root TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +query TB +SELECT user, pg_is_other_temp_schema((SELECT oid FROM pg_namespace WHERE nspname LIKE 'pg_temp_%')) +---- +testuser true + +user root + +# information_schema._pg_truetypid and information_schema._pg_truetypmod +# +# We can't exhaustively test these until we support domain types. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE types ( + a TEXT PRIMARY KEY, + b FLOAT, + c BPCHAR, + d VARCHAR(64), + e BIT, + f VARBIT(16), + g DECIMAL(12, 2) +); + +# Not supported by Materialize. +onlyif cockroach +query TOI +SELECT typname, + information_schema._pg_truetypid(a.*, t.*), + information_schema._pg_truetypmod(a.*, t.*) +FROM pg_attribute a +JOIN pg_type t +ON a.atttypid = t.oid +WHERE attrelid = 'types'::regclass +ORDER BY t.oid +---- +text 25 -1 +float8 701 -1 +bpchar 1042 5 +varchar 1043 68 +bit 1560 1 +varbit 1562 16 +numeric 1700 786438 + +# information_schema._pg_char_max_length + +# Not supported by Materialize. +onlyif cockroach +query TI +SELECT typname, information_schema._pg_char_max_length(a.atttypid, a.atttypmod) +FROM pg_attribute a +JOIN pg_type t +ON a.atttypid = t.oid +WHERE attrelid = 'types'::regclass +ORDER BY t.oid +---- +text NULL +float8 NULL +bpchar 1 +varchar 64 +bit 1 +varbit 16 +numeric NULL + +# Not supported by Materialize. +onlyif cockroach +query TI +SELECT typname, information_schema._pg_char_max_length( + information_schema._pg_truetypid(a.*, t.*), + information_schema._pg_truetypmod(a.*, t.*) +) +FROM pg_attribute a +JOIN pg_type t +ON a.atttypid = t.oid +WHERE attrelid = 'types'::regclass +ORDER BY t.oid +---- +text NULL +float8 NULL +bpchar 1 +varchar 64 +bit 1 +varbit 16 +numeric NULL + +# information_schema._pg_index_position + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE indexed ( + a INT PRIMARY KEY, + b INT, + c INT, + d INT, + INDEX (b, d), + INDEX (c, a) +); + +# NOTE, we cast indkey to an INT2[], because an INT2VECTOR's formatting appears +# to be dependent on whether the result set spilled to disk or not. It was being +# formatted differently with the "local" test config (and others) than with the +# "fakedist-disk" test config. +statement ok +CREATE TEMPORARY VIEW indexes AS + SELECT i.relname, indkey::INT2[], indexrelid + FROM pg_catalog.pg_index + JOIN pg_catalog.pg_class AS t ON indrelid = t.oid + JOIN pg_catalog.pg_class AS i ON indexrelid = i.oid + WHERE t.relname = 'indexed' +ORDER BY i.relname + +query TT +SELECT relname, indkey FROM indexes ORDER BY relname DESC +---- + + +# Not supported by Materialize. +onlyif cockroach +query TTII +SELECT relname, + indkey, + generate_series(1, 4) input, + information_schema._pg_index_position(indexrelid, generate_series(1, 4)) +FROM indexes +ORDER BY relname DESC, input +---- +indexed_pkey {1} 1 1 +indexed_pkey {1} 2 NULL +indexed_pkey {1} 3 NULL +indexed_pkey {1} 4 NULL +indexed_c_a_idx {3,1} 1 2 +indexed_c_a_idx {3,1} 2 NULL +indexed_c_a_idx {3,1} 3 1 +indexed_c_a_idx {3,1} 4 NULL +indexed_b_d_idx {2,4} 1 NULL +indexed_b_d_idx {2,4} 2 1 +indexed_b_d_idx {2,4} 3 NULL +indexed_b_d_idx {2,4} 4 2 + +# information_schema._pg_numeric_precision and information_schema._pg_numeric_precision_radix +# and information_schema._pg_numeric_scale + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE numeric ( + a SMALLINT, + b INT4, + c BIGINT, + d FLOAT(1), + e FLOAT4, + f FLOAT8, + g FLOAT(40), + h FLOAT, + i DECIMAL(12,2), + j DECIMAL(4,4) +); + +# Not supported by Materialize. +onlyif cockroach +query TTIII +SELECT a.attname, + t.typname, + information_schema._pg_numeric_precision(a.atttypid,a.atttypmod), + information_schema._pg_numeric_precision_radix(a.atttypid,a.atttypmod), + information_schema._pg_numeric_scale(a.atttypid,a.atttypmod) +FROM pg_attribute a +JOIN pg_type t +ON a.atttypid = t.oid +WHERE a.attrelid = 'numeric'::regclass +ORDER BY a.attname +---- +a int2 16 2 0 +b int4 32 2 0 +c int8 64 2 0 +d float4 24 2 NULL +e float4 24 2 NULL +f float8 53 2 NULL +g float8 53 2 NULL +h float8 53 2 NULL +i numeric 12 10 2 +j numeric 4 10 4 +rowid int8 64 2 0 + +statement error function "pg_options_to_table" does not exist +SELECT * FROM pg_options_to_table(array['b', NULL, 'a']::text[]) + +# Not supported by Materialize. +onlyif cockroach +query TT colnames +SELECT * FROM pg_options_to_table(array[]::text[]); +---- +option_name option_value + +# Not supported by Materialize. +onlyif cockroach +query TT colnames +SELECT * FROM pg_options_to_table(array['a', 'b=c', '=d', 'e=f=g']::text[]); +---- +option_name option_value +a NULL +b c +· d +e f=g + +# Not supported by Materialize. +onlyif cockroach +query TT colnames +SELECT * FROM pg_options_to_table(null) +---- +option_name option_value + +# Not supported by Materialize. +onlyif cockroach +query TT colnames +SELECT * FROM pg_options_to_table('{a, b=c, =d, e=f=g}') +---- +option_name option_value +a NULL +b c +· d +e f=g + + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE test_type AS ENUM ('open', 'closed', 'inactive'); + +statement ok +CREATE ROLE test_role LOGIN; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t1 (a int); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regclass('pg_roles') +---- +pg_roles + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regclass('4294967230') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regclass('pg_policy') +---- +pg_policy + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regclass('t1') +---- +t1 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regnamespace('crdb_internal') +---- +crdb_internal + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regnamespace('public') +---- +public + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regnamespace('1330834471') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regnamespace(' 1330834471') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regproc('_st_contains') +---- +_st_contains + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regproc('version') +---- +version + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regproc('bit_in') +---- +bit_in + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regprocedure('bit_in') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regprocedure('bit_in(int)') +---- +bit_in + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regprocedure('version') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regprocedure('version()') +---- +version + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regprocedure('961893967') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regrole('admin') +---- +admin + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regrole('test_role') +---- +test_role + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regrole('foo') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regrole('1546506610') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regtype('interval') +---- +interval + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regtype('integer') +---- +bigint + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regtype('int_4') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regtype('string') +---- +text + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regtype('1186') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_regtype('test_type') +---- +test_type + +# Not supported by Materialize. +onlyif cockroach +# Test that pg_get_indexdef works for expression indexes. +statement ok +CREATE TABLE expr_idx_tbl (id string PRIMARY key, json JSON) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX expr_idx ON expr_idx_tbl (id, (json->>'bar'), (length(id))) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_get_indexdef('expr_idx'::regclass::oid) +---- +CREATE INDEX expr_idx ON test.public.expr_idx_tbl USING btree (id ASC, (json->>'bar'::STRING) ASC, length(id) ASC) + +# Not supported by Materialize. +onlyif cockroach +query IT +SELECT k, pg_get_indexdef('expr_idx'::regclass::oid, k, true) FROM generate_series(0,4) k ORDER BY k +---- +0 CREATE INDEX expr_idx ON test.public.expr_idx_tbl USING btree (id ASC, (json->>'bar'::STRING) ASC, length(id) ASC) +1 id +2 (json->>'bar'::STRING) +3 (length(id)) +4 · + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #101357. The SQL implementations of pg_get_indexdef and +# col_description should not have unqualified table names that can conflict with +# a user tables. +statement ok +CREATE TABLE pg_indexes (i INT PRIMARY KEY); +CREATE TABLE pg_attribute (i INT PRIMARY KEY) + +statement ok +SET search_path TO public,pg_catalog + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT i, pg_get_indexdef(0, 1, true) FROM pg_indexes + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE pg_indexes; +DROP TABLE pg_attribute; +RESET search_path + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA system; +CREATE TABLE system.comments (i INT) + +statement ok +SELECT col_description(0, 0) + +# Not supported by Materialize. +onlyif cockroach +statement +DROP TABLE system.comments; +DROP SCHEMA system diff --git a/test/sqllogictest/cockroach/pg_catalog.slt b/test/sqllogictest/cockroach/pg_catalog.slt deleted file mode 100644 index 0bf27eb8c8c86..0000000000000 --- a/test/sqllogictest/cockroach/pg_catalog.slt +++ /dev/null @@ -1,2024 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/pg_catalog -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -mode cockroach - -# We are not currently trying to be this PostgreSQL compatible. Perhaps someday. -halt - -statement ok -SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false - -# Verify pg_catalog database handles mutation statements correctly. - -query error database "pg_catalog" does not exist -ALTER DATABASE pg_catalog RENAME TO not_pg_catalog - -statement error schema cannot be modified: "pg_catalog" -CREATE TABLE pg_catalog.t (x INT) - -query error database "pg_catalog" does not exist -DROP DATABASE pg_catalog - -query T -SHOW TABLES FROM pg_catalog ----- -pg_am -pg_attrdef -pg_attribute -pg_auth_members -pg_class -pg_collation -pg_constraint -pg_database -pg_depend -pg_description -pg_enum -pg_extension -pg_foreign_data_wrapper -pg_foreign_server -pg_foreign_table -pg_index -pg_indexes -pg_inherits -pg_language -pg_namespace -pg_operator -pg_proc -pg_range -pg_rewrite -pg_roles -pg_seclabel -pg_sequence -pg_settings -pg_shdescription -pg_shseclabel -pg_stat_activity -pg_tables -pg_tablespace -pg_trigger -pg_type -pg_user -pg_user_mapping -pg_views - -# Verify "pg_catalog" is a regular db name - -statement ok -CREATE DATABASE other_db - -statement ok -ALTER DATABASE other_db RENAME TO pg_catalog - -statement error database "pg_catalog" already exists -CREATE DATABASE pg_catalog - -statement ok -DROP DATABASE pg_catalog - -# the following query checks that the planDataSource instantiated from -# a virtual table in the FROM clause is properly deallocated even when -# query preparation causes an error. database-issues#2980 -query error unknown function -SELECT * FROM pg_catalog.pg_class c WHERE nonexistent_function() - -# Verify pg_catalog handles reflection correctly. - -query T -SHOW TABLES FROM test.pg_catalog ----- -pg_am -pg_attrdef -pg_attribute -pg_auth_members -pg_class -pg_collation -pg_constraint -pg_database -pg_depend -pg_description -pg_enum -pg_extension -pg_foreign_data_wrapper -pg_foreign_server -pg_foreign_table -pg_index -pg_indexes -pg_inherits -pg_language -pg_namespace -pg_operator -pg_proc -pg_range -pg_rewrite -pg_roles -pg_seclabel -pg_sequence -pg_settings -pg_shdescription -pg_shseclabel -pg_stat_activity -pg_tables -pg_tablespace -pg_trigger -pg_type -pg_user -pg_user_mapping -pg_views - -query TT colnames -SHOW CREATE TABLE pg_catalog.pg_namespace ----- -table_name create_statement -pg_catalog.pg_namespace CREATE TABLE pg_namespace ( - oid OID NULL, - nspname NAME NOT NULL, - nspowner OID NULL, - nspacl STRING[] NULL -) - -query TTBTTTB colnames -SHOW COLUMNS FROM pg_catalog.pg_namespace ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -oid OID true NULL · {} false -nspname NAME false NULL · {} false -nspowner OID true NULL · {} false -nspacl STRING[] true NULL · {} false - -query TTBITTBB colnames -SHOW INDEXES ON pg_catalog.pg_namespace ----- -table_name index_name non_unique seq_in_index column_name direction storing implicit - -query TTTTB colnames -SHOW CONSTRAINTS FROM pg_catalog.pg_namespace ----- -table_name constraint_name constraint_type details validated - -query TTTTT colnames -SHOW GRANTS ON pg_catalog.pg_namespace ----- -database_name schema_name table_name grantee privilege_type -test pg_catalog pg_namespace public SELECT - - -# Verify selecting from pg_catalog. - -statement ok -CREATE DATABASE constraint_db - -statement ok -CREATE TABLE constraint_db.t1 ( - p FLOAT PRIMARY KEY, - a INT UNIQUE, - b INT, - c INT DEFAULT 12, - d VARCHAR(5), - e BIT(5), - f DECIMAL(10,7), - UNIQUE INDEX index_key(b, c) -) - -statement ok -CREATE TABLE constraint_db.t2 ( - t1_ID INT, - CONSTRAINT fk FOREIGN KEY (t1_ID) REFERENCES constraint_db.t1(a), - INDEX (t1_ID) -) - -statement ok -CREATE TABLE constraint_db.t3 ( - a INT, - b INT CHECK (b > 11), - c STRING DEFAULT 'FOO', - CONSTRAINT fk FOREIGN KEY (a, b) REFERENCES constraint_db.t1(b, c), - INDEX (a, b DESC) STORING (c) -) - -statement ok -CREATE VIEW constraint_db.v1 AS SELECT p,a,b,c FROM constraint_db.t1 - -## pg_catalog.pg_namespace - -query OTOT colnames -SELECT * FROM pg_catalog.pg_namespace ----- -oid nspname nspowner nspacl -3604332469 crdb_internal NULL NULL -3672231114 information_schema NULL NULL -2508829085 pg_catalog NULL NULL -3426283741 public NULL NULL - -## pg_catalog.pg_database - -query OTOITTBB colnames -SELECT oid, datname, datdba, encoding, datcollate, datctype, datistemplate, datallowconn -FROM pg_catalog.pg_database -ORDER BY oid ----- -oid datname datdba encoding datcollate datctype datistemplate datallowconn -1 system NULL 6 en_US.utf8 en_US.utf8 false true -50 materialize NULL 6 en_US.utf8 en_US.utf8 false true -51 postgres NULL 6 en_US.utf8 en_US.utf8 false true -52 test NULL 6 en_US.utf8 en_US.utf8 false true -54 constraint_db NULL 6 en_US.utf8 en_US.utf8 false true - -query OTIOIIOT colnames -SELECT oid, datname, datconnlimit, datlastsysoid, datfrozenxid, datminmxid, dattablespace, datacl -FROM pg_catalog.pg_database -ORDER BY oid ----- -oid datname datconnlimit datlastsysoid datfrozenxid datminmxid dattablespace datacl -1 system -1 NULL NULL NULL 0 NULL -50 materialize -1 NULL NULL NULL 0 NULL -51 postgres -1 NULL NULL NULL 0 NULL -52 test -1 NULL NULL NULL 0 NULL -54 constraint_db -1 NULL NULL NULL 0 NULL - -## pg_catalog.pg_tables - -statement ok -SET DATABASE = constraint_db - -query TTTTBBBB colnames -SELECT * FROM constraint_db.pg_catalog.pg_tables WHERE schemaname = 'public' ----- -schemaname tablename tableowner tablespace hasindexes hasrules hastriggers rowsecurity -public t1 NULL NULL true false false false -public t2 NULL NULL true false false false -public t3 NULL NULL true false false false - -query TB colnames -SELECT tablename, hasindexes FROM pg_catalog.pg_tables WHERE schemaname = 'information_schema' AND tablename LIKE '%table%' ----- -tablename hasindexes -role_table_grants false -table_constraints false -table_privileges false -tables false - -## pg_catalog.pg_tablespace - -query OTOTT colnames -SELECT oid, spcname, spcowner, spcacl, spcoptions FROM pg_tablespace ----- -oid spcname spcowner spcacl spcoptions -0 pg_default NULL NULL NULL - -## pg_catalog.pg_views - -query TTTT colnames -SELECT * FROM pg_catalog.pg_views ----- -schemaname viewname viewowner definition -public v1 NULL SELECT p, a, b, c FROM constraint_db.public.t1 - -## pg_catalog.pg_class - -query OTOOOOOO colnames -SELECT c.oid, relname, relnamespace, reltype, relowner, relam, relfilenode, reltablespace -FROM pg_catalog.pg_class c -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE n.nspname = 'public' ----- -oid relname relnamespace reltype relowner relam relfilenode reltablespace -55 t1 2332901747 0 NULL NULL 0 0 -450499963 primary 2332901747 0 NULL NULL 0 0 -450499960 t1_a_key 2332901747 0 NULL NULL 0 0 -450499961 index_key 2332901747 0 NULL NULL 0 0 -56 t2 2332901747 0 NULL NULL 0 0 -2315049508 primary 2332901747 0 NULL NULL 0 0 -2315049511 t2_t1_id_idx 2332901747 0 NULL NULL 0 0 -57 t3 2332901747 0 NULL NULL 0 0 -969972501 primary 2332901747 0 NULL NULL 0 0 -969972502 t3_a_b_idx 2332901747 0 NULL NULL 0 0 -58 v1 2332901747 0 NULL NULL 0 0 - -query TIRIOBBT colnames -SELECT relname, relpages, reltuples, relallvisible, reltoastrelid, relhasindex, relisshared, relpersistence -FROM pg_catalog.pg_class c -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE n.nspname = 'public' ----- -relname relpages reltuples relallvisible reltoastrelid relhasindex relisshared relpersistence -t1 NULL NULL 0 0 true false p -primary NULL NULL 0 0 false false p -t1_a_key NULL NULL 0 0 false false p -index_key NULL NULL 0 0 false false p -t2 NULL NULL 0 0 true false p -primary NULL NULL 0 0 false false p -t2_t1_id_idx NULL NULL 0 0 false false p -t3 NULL NULL 0 0 true false p -primary NULL NULL 0 0 false false p -t3_a_b_idx NULL NULL 0 0 false false p -v1 NULL NULL 0 0 false false p - -query TBTIIBB colnames -SELECT relname, relistemp, relkind, relnatts, relchecks, relhasoids, relhaspkey -FROM pg_catalog.pg_class c -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE n.nspname = 'public' ----- -relname relistemp relkind relnatts relchecks relhasoids relhaspkey -t1 false r 7 0 false true -primary false i 1 0 false false -t1_a_key false i 1 0 false false -index_key false i 2 0 false false -t2 false r 2 0 false true -primary false i 1 0 false false -t2_t1_id_idx false i 1 0 false false -t3 false r 4 1 false true -primary false i 1 0 false false -t3_a_b_idx false i 2 0 false false -v1 false v 4 0 false false - -query TBBBITT colnames -SELECT relname, relhasrules, relhastriggers, relhassubclass, relfrozenxid, relacl, reloptions -FROM pg_catalog.pg_class c -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE n.nspname = 'public' ----- -relname relhasrules relhastriggers relhassubclass relfrozenxid relacl reloptions -t1 false false false 0 NULL NULL -primary false false false 0 NULL NULL -t1_a_key false false false 0 NULL NULL -index_key false false false 0 NULL NULL -t2 false false false 0 NULL NULL -primary false false false 0 NULL NULL -t2_t1_id_idx false false false 0 NULL NULL -t3 false false false 0 NULL NULL -primary false false false 0 NULL NULL -t3_a_b_idx false false false 0 NULL NULL -v1 false false false 0 NULL NULL - -## pg_catalog.pg_attribute - -query OTTOIIIII colnames -SELECT attrelid, c.relname, attname, atttypid, attstattarget, attlen, attnum, attndims, attcacheoff -FROM pg_catalog.pg_attribute a -JOIN pg_catalog.pg_class c ON a.attrelid = c.oid -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE n.nspname = 'public' ----- -attrelid relname attname atttypid attstattarget attlen attnum attndims attcacheoff -55 t1 p 701 0 8 1 0 -1 -55 t1 a 20 0 8 2 0 -1 -55 t1 b 20 0 8 3 0 -1 -55 t1 c 20 0 8 4 0 -1 -55 t1 d 1043 0 -1 5 0 -1 -55 t1 e 1560 0 -1 6 0 -1 -55 t1 f 1700 0 -1 7 0 -1 -450499963 primary p 701 0 8 1 0 -1 -450499960 t1_a_key a 20 0 8 2 0 -1 -450499961 index_key b 20 0 8 3 0 -1 -450499961 index_key c 20 0 8 4 0 -1 -56 t2 t1_id 20 0 8 1 0 -1 -56 t2 rowid 20 0 8 2 0 -1 -2315049508 primary rowid 20 0 8 2 0 -1 -2315049511 t2_t1_id_idx t1_id 20 0 8 1 0 -1 -57 t3 a 20 0 8 1 0 -1 -57 t3 b 20 0 8 2 0 -1 -57 t3 c 25 0 -1 3 0 -1 -57 t3 rowid 20 0 8 4 0 -1 -969972501 primary rowid 20 0 8 4 0 -1 -969972502 t3_a_b_idx a 20 0 8 1 0 -1 -969972502 t3_a_b_idx b 20 0 8 2 0 -1 -58 v1 p 701 0 8 1 0 -1 -58 v1 a 20 0 8 2 0 -1 -58 v1 b 20 0 8 3 0 -1 -58 v1 c 20 0 8 4 0 -1 - -query TTIBTTBB colnames -SELECT c.relname, attname, atttypmod, attbyval, attstorage, attalign, attnotnull, atthasdef -FROM pg_catalog.pg_attribute a -JOIN pg_catalog.pg_class c ON a.attrelid = c.oid -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE n.nspname = 'public' ----- -relname attname atttypmod attbyval attstorage attalign attnotnull atthasdef -t1 p -1 NULL NULL NULL true false -t1 a -1 NULL NULL NULL false false -t1 b -1 NULL NULL NULL false false -t1 c -1 NULL NULL NULL false true -t1 d 9 NULL NULL NULL false false -t1 e 5 NULL NULL NULL false false -t1 f 655371 NULL NULL NULL false false -primary p -1 NULL NULL NULL true false -t1_a_key a -1 NULL NULL NULL false false -index_key b -1 NULL NULL NULL false false -index_key c -1 NULL NULL NULL false true -t2 t1_id -1 NULL NULL NULL false false -t2 rowid -1 NULL NULL NULL true true -primary rowid -1 NULL NULL NULL true true -t2_t1_id_idx t1_id -1 NULL NULL NULL false false -t3 a -1 NULL NULL NULL false false -t3 b -1 NULL NULL NULL false false -t3 c -1 NULL NULL NULL false true -t3 rowid -1 NULL NULL NULL true true -primary rowid -1 NULL NULL NULL true true -t3_a_b_idx a -1 NULL NULL NULL false false -t3_a_b_idx b -1 NULL NULL NULL false false -v1 p -1 NULL NULL NULL true false -v1 a -1 NULL NULL NULL true false -v1 b -1 NULL NULL NULL true false -v1 c -1 NULL NULL NULL true false - -query TTBBITTT colnames -SELECT c.relname, attname, attisdropped, attislocal, attinhcount, attacl, attoptions, attfdwoptions -FROM pg_catalog.pg_attribute a -JOIN pg_catalog.pg_class c ON a.attrelid = c.oid -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE n.nspname = 'public' ----- -relname attname attisdropped attislocal attinhcount attacl attoptions attfdwoptions -t1 p false true 0 NULL NULL NULL -t1 a false true 0 NULL NULL NULL -t1 b false true 0 NULL NULL NULL -t1 c false true 0 NULL NULL NULL -t1 d false true 0 NULL NULL NULL -t1 e false true 0 NULL NULL NULL -t1 f false true 0 NULL NULL NULL -primary p false true 0 NULL NULL NULL -t1_a_key a false true 0 NULL NULL NULL -index_key b false true 0 NULL NULL NULL -index_key c false true 0 NULL NULL NULL -t2 t1_id false true 0 NULL NULL NULL -t2 rowid false true 0 NULL NULL NULL -primary rowid false true 0 NULL NULL NULL -t2_t1_id_idx t1_id false true 0 NULL NULL NULL -t3 a false true 0 NULL NULL NULL -t3 b false true 0 NULL NULL NULL -t3 c false true 0 NULL NULL NULL -t3 rowid false true 0 NULL NULL NULL -primary rowid false true 0 NULL NULL NULL -t3_a_b_idx a false true 0 NULL NULL NULL -t3_a_b_idx b false true 0 NULL NULL NULL -v1 p false true 0 NULL NULL NULL -v1 a false true 0 NULL NULL NULL -v1 b false true 0 NULL NULL NULL -v1 c false true 0 NULL NULL NULL - -# Check relkind codes. -statement ok -CREATE DATABASE relkinds - -statement ok -SET DATABASE = relkinds - -statement ok -CREATE TABLE tbl_test (k int primary key, v int) - -statement ok -CREATE INDEX tbl_test_v_idx ON tbl_test (v) - -statement ok -CREATE VIEW view_test AS SELECT k, v FROM tbl_test ORDER BY v - -statement ok -CREATE SEQUENCE seq_test - -query TT -SELECT relname, relkind -FROM pg_catalog.pg_class c -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE n.nspname = 'public' -ORDER BY relname ----- -primary i -seq_test S -tbl_test r -tbl_test_v_idx i -view_test v - -statement ok -DROP DATABASE relkinds - -statement ok -SET DATABASE = constraint_db - -# Select all columns with collations. -query TTTOT colnames -SELECT c.relname, attname, t.typname, attcollation, k.collname -FROM pg_catalog.pg_attribute a -JOIN pg_catalog.pg_class c ON a.attrelid = c.oid -JOIN pg_catalog.pg_type t ON a.atttypid = t.oid -JOIN pg_catalog.pg_collation k ON a.attcollation = k.oid -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE n.nspname = 'public' ----- -relname attname typname attcollation collname -t1 d varchar 3903121477 en-US -t3 c text 3903121477 en-US - - -## pg_catalog.pg_am - -query OTIIBBBBBBBBBBBOOOOOOOOOOOOOOOOOT colnames -SELECT * -FROM pg_catalog.pg_am ----- -oid amname amstrategies amsupport amcanorder amcanorderbyop amcanbackward amcanunique amcanmulticol amoptionalkey amsearcharray amsearchnulls amstorage amclusterable ampredlocks amkeytype aminsert ambeginscan amgettuple amgetbitmap amrescan amendscan ammarkpos amrestrpos ambuild ambuildempty ambulkdelete amvacuumcleanup amcanreturn amcostestimate amoptions amhandler amtype -2631952481 prefix 0 0 true false true true true true true true false false false 0 NULL NULL 0 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL i - -## pg_catalog.pg_attrdef - -query OTOITT colnames -SELECT ad.oid, c.relname, adrelid, adnum, adbin, adsrc -FROM pg_catalog.pg_attrdef ad -JOIN pg_catalog.pg_class c ON ad.adrelid = c.oid -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE n.nspname = 'public' ----- -oid relname adrelid adnum adbin adsrc -1666782879 t1 55 4 12:::INT8 12:::INT8 -841178406 t2 56 2 unique_rowid() unique_rowid() -2186255414 t3 57 3 'FOO':::STRING 'FOO':::STRING -2186255409 t3 57 4 unique_rowid() unique_rowid() - -## pg_catalog.pg_indexes - -query OTTTT colnames -SELECT crdb_oid, schemaname, tablename, indexname, tablespace -FROM pg_catalog.pg_indexes -WHERE schemaname = 'public' ----- -crdb_oid schemaname tablename indexname tablespace -450499963 public t1 primary NULL -450499960 public t1 t1_a_key NULL -450499961 public t1 index_key NULL -2315049508 public t2 primary NULL -2315049511 public t2 t2_t1_id_idx NULL -969972501 public t3 primary NULL -969972502 public t3 t3_a_b_idx NULL - -query OTTT colnames -SELECT crdb_oid, tablename, indexname, indexdef -FROM pg_catalog.pg_indexes -WHERE schemaname = 'public' ----- -crdb_oid tablename indexname indexdef -450499963 t1 primary CREATE UNIQUE INDEX "primary" ON constraint_db.public.t1 (p ASC) -450499960 t1 t1_a_key CREATE UNIQUE INDEX t1_a_key ON constraint_db.public.t1 (a ASC) -450499961 t1 index_key CREATE UNIQUE INDEX index_key ON constraint_db.public.t1 (b ASC, c ASC) -2315049508 t2 primary CREATE UNIQUE INDEX "primary" ON constraint_db.public.t2 (rowid ASC) -2315049511 t2 t2_t1_id_idx CREATE INDEX t2_t1_id_idx ON constraint_db.public.t2 (t1_id ASC) -969972501 t3 primary CREATE UNIQUE INDEX "primary" ON constraint_db.public.t3 (rowid ASC) -969972502 t3 t3_a_b_idx CREATE INDEX t3_a_b_idx ON constraint_db.public.t3 (a ASC, b DESC) STORING (c) - -## pg_catalog.pg_index - -query OOIBBB colnames -SELECT indexrelid, indrelid, indnatts, indisunique, indisprimary, indisexclusion -FROM pg_catalog.pg_index -WHERE indnatts = 2 ----- -indexrelid indrelid indnatts indisunique indisprimary indisexclusion -450499961 55 2 true false false -969972502 57 2 false false false - -query OBBBBB colnames -SELECT indexrelid, indimmediate, indisclustered, indisvalid, indcheckxmin, indisready -FROM pg_catalog.pg_index -WHERE indnatts = 2 ----- -indexrelid indimmediate indisclustered indisvalid indcheckxmin indisready -450499961 true false true false false -969972502 false false true false false - -query OOBBTTTTTT colnames -SELECT indexrelid, indrelid, indislive, indisreplident, indkey, indcollation, indclass, indoption, indexprs, indpred -FROM pg_catalog.pg_index -WHERE indnatts = 2 ----- -indexrelid indrelid indislive indisreplident indkey indcollation indclass indoption indexprs indpred -450499961 55 true false 3 4 0 0 0 0 0 0 NULL NULL -969972502 57 true false 1 2 0 0 0 0 0 0 NULL NULL - -statement ok -SET DATABASE = system - -query OOIBBBBBBBBBBTTTTTT colnames -SELECT * -FROM pg_catalog.pg_index -ORDER BY indexrelid ----- -indexrelid indrelid indnatts indisunique indisprimary indisexclusion indimmediate indisclustered indisvalid indcheckxmin indisready indislive indisreplident indkey indcollation indclass indoption indexprs indpred -543291288 23 1 false false false false false true false false true false 1 3903121477 0 0 NULL NULL -543291289 23 1 false false false false false true false false true false 2 3903121477 0 0 NULL NULL -543291291 23 2 true true false true false true false false true false 1 2 3903121477 3903121477 0 0 0 0 NULL NULL -1276104432 12 2 true true false true false true false false true false 1 6 0 0 0 0 0 0 NULL NULL -1582236367 3 1 true true false true false true false false true false 1 0 0 0 NULL NULL -1628632028 19 1 false false false false false true false false true false 5 0 0 0 NULL NULL -1628632029 19 1 false false false false false true false false true false 4 0 0 0 NULL NULL -1628632031 19 1 true true false true false true false false true false 1 0 0 0 NULL NULL -1841972634 6 1 true true false true false true false false true false 1 3903121477 0 0 NULL NULL -2101708905 5 1 true true false true false true false false true false 1 0 0 0 NULL NULL -2148104569 21 2 true true false true false true false false true false 1 2 3903121477 3903121477 0 0 0 0 NULL NULL -2407840836 24 3 true true false true false true false false true false 1 2 3 0 0 0 0 0 0 0 0 0 NULL NULL -2621181440 15 2 false false false false false true false false true false 2 3 3903121477 0 0 0 0 0 NULL NULL -2621181443 15 1 true true false true false true false false true false 1 0 0 0 NULL NULL -2927313374 2 2 true true false true false true false false true false 1 2 0 3903121477 0 0 0 0 NULL NULL -3446785912 4 1 true true false true false true false false true false 1 3903121477 0 0 NULL NULL -3493181576 20 2 true true false true false true false false true false 1 2 0 0 0 0 0 0 NULL NULL -3706522183 11 4 true true false true false true false false true false 1 2 4 3 0 0 0 0 0 0 0 0 0 0 0 0 NULL NULL -3966258450 14 1 true true false true false true false false true false 1 3903121477 0 0 NULL NULL -4225994721 13 2 true true false true false true false false true false 1 7 0 0 0 0 0 0 NULL NULL - -# From materialize#26504 -query OOI colnames -SELECT indexrelid, - (information_schema._pg_expandarray(indclass)).x AS operator_argument_type_oid, - (information_schema._pg_expandarray(indclass)).n AS operator_argument_position -FROM pg_index -ORDER BY indexrelid, operator_argument_position ----- -indexrelid operator_argument_type_oid operator_argument_position -543291288 0 1 -543291289 0 1 -543291291 0 1 -543291291 0 2 -1276104432 0 1 -1276104432 0 2 -1582236367 0 1 -1628632028 0 1 -1628632029 0 1 -1628632031 0 1 -1841972634 0 1 -2101708905 0 1 -2148104569 0 1 -2148104569 0 2 -2407840836 0 1 -2407840836 0 2 -2407840836 0 3 -2621181440 0 1 -2621181440 0 2 -2621181443 0 1 -2927313374 0 1 -2927313374 0 2 -3446785912 0 1 -3493181576 0 1 -3493181576 0 2 -3706522183 0 1 -3706522183 0 2 -3706522183 0 3 -3706522183 0 4 -3966258450 0 1 -4225994721 0 1 -4225994721 0 2 - -## pg_catalog.pg_collation - -statement ok -SET DATABASE = constraint_db - -query OTOOITT colnames -SELECT * FROM pg_collation -WHERE collname='en-US' ----- -oid collname collnamespace collowner collencoding collcollate collctype -3903121477 en-US 2332901747 NULL 6 NULL NULL - -## pg_catalog.pg_constraint -## -## These order of this virtual table is non-deterministic, so all queries must -## explicitly add an ORDER BY clause. - -query OTOT colnames -SELECT con.oid, conname, connamespace, contype -FROM pg_catalog.pg_constraint con -JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid -WHERE n.nspname = 'public' -ORDER BY con.oid ----- -oid conname connamespace contype -178791267 fk 2332901747 f -3236224800 check_b 2332901747 c -3318155331 fk 2332901747 f -3572320190 primary 2332901747 p -4243354484 t1_a_key 2332901747 u -4243354485 index_key 2332901747 u - -query TTBBBOOO colnames -SELECT conname, contype, condeferrable, condeferred, convalidated, conrelid, contypid, conindid -FROM pg_catalog.pg_constraint con -JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid -WHERE n.nspname = 'public' -ORDER BY con.oid ----- -conname contype condeferrable condeferred convalidated conrelid contypid conindid -fk f false false true 57 0 450499961 -check_b c false false true 57 0 0 -fk f false false true 56 0 450499960 -primary p false false true 55 0 450499963 -t1_a_key u false false true 55 0 450499960 -index_key u false false true 55 0 450499961 - -query T -SELECT conname -FROM pg_catalog.pg_constraint con -JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid -WHERE n.nspname = 'public' AND contype NOT IN ('c', 'f', 'p', 'u') -ORDER BY con.oid ----- - -query TOTTT colnames -SELECT conname, confrelid, confupdtype, confdeltype, confmatchtype -FROM pg_catalog.pg_constraint con -JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid -WHERE n.nspname = 'public' AND contype IN ('c', 'p', 'u') -ORDER BY con.oid ----- -conname confrelid confupdtype confdeltype confmatchtype -check_b 0 NULL NULL NULL -primary 0 NULL NULL NULL -t1_a_key 0 NULL NULL NULL -index_key 0 NULL NULL NULL - -query TOTTT colnames -SELECT conname, confrelid, confupdtype, confdeltype, confmatchtype -FROM pg_catalog.pg_constraint con -JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid -WHERE n.nspname = 'public' AND contype = 'f' -ORDER BY con.oid ----- -conname confrelid confupdtype confdeltype confmatchtype -fk 55 a a s -fk 55 a a s - -query TBIBT colnames -SELECT conname, conislocal, coninhcount, connoinherit, conkey -FROM pg_catalog.pg_constraint con -JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid -WHERE n.nspname = 'public' -ORDER BY con.oid ----- -conname conislocal coninhcount connoinherit conkey -fk true 0 true {1,2} -check_b true 0 true {2} -fk true 0 true {1} -primary true 0 true {1} -t1_a_key true 0 true {2} -index_key true 0 true {3,4} - -query TTTTTTTT colnames -SELECT conname, confkey, conpfeqop, conppeqop, conffeqop, conexclop, conbin, consrc -FROM pg_catalog.pg_constraint con -JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid -WHERE n.nspname = 'public' AND contype IN ('c', 'p', 'u') -ORDER BY con.oid ----- -conname confkey conpfeqop conppeqop conffeqop conexclop conbin consrc -check_b NULL NULL NULL NULL NULL b > 11 b > 11 -primary NULL NULL NULL NULL NULL NULL NULL -t1_a_key NULL NULL NULL NULL NULL NULL NULL -index_key NULL NULL NULL NULL NULL NULL NULL - -query TTTTTTTT colnames -SELECT conname, confkey, conpfeqop, conppeqop, conffeqop, conexclop, conbin, consrc -FROM pg_catalog.pg_constraint con -JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid -WHERE n.nspname = 'public' AND contype = 'f' -ORDER BY con.oid ----- -conname confkey conpfeqop conppeqop conffeqop conexclop conbin consrc -fk {3,4} NULL NULL NULL NULL NULL NULL -fk {2} NULL NULL NULL NULL NULL NULL - -## pg_catalog.pg_depend - -query OOIOOIT colnames -SELECT classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype -FROM pg_catalog.pg_depend -ORDER BY objid ----- -classid objid objsubid refclassid refobjid refobjsubid deptype -4294967232 178791267 0 4294967234 450499961 0 n -4294967232 3318155331 0 4294967234 450499960 0 n - -# All entries in pg_depend are dependency links from the pg_constraint system -# table to the pg_class system table. - -query OOTT colnames -SELECT DISTINCT classid, refclassid, cla.relname AS tablename, refcla.relname AS reftablename -FROM pg_catalog.pg_depend -JOIN pg_class cla ON classid=cla.oid -JOIN pg_class refcla ON refclassid=refcla.oid ----- -classid refclassid tablename reftablename -4294967232 4294967234 pg_constraint pg_class - -# All entries in pg_depend are foreign key constraints that reference an index -# in pg_class. - -query TT colnames -SELECT relname, relkind -FROM pg_depend -JOIN pg_class ON refobjid=pg_class.oid -ORDER BY relname ----- -relname relkind -index_key i -t1_a_key i - - -# All entries are pg_depend are linked to a foreign key constraint whose -# supporting index is the referenced object id. - -query T colnames -SELECT DISTINCT pg_constraint.contype -FROM pg_depend -JOIN pg_constraint ON objid=pg_constraint.oid AND refobjid=pg_constraint.conindid ----- -contype -f - -## pg_catalog.pg_type - -query OTOOIBT colnames -SELECT oid, typname, typnamespace, typowner, typlen, typbyval, typtype -FROM pg_catalog.pg_type -ORDER BY oid ----- -oid typname typnamespace typowner typlen typbyval typtype -16 bool 1307062959 NULL 1 true b -17 bytea 1307062959 NULL -1 false b -18 char 1307062959 NULL -1 false b -19 name 1307062959 NULL -1 false b -20 int8 1307062959 NULL 8 true b -21 int2 1307062959 NULL 8 true b -22 int2vector 1307062959 NULL -1 false b -23 int4 1307062959 NULL 8 true b -24 regproc 1307062959 NULL 8 true b -25 text 1307062959 NULL -1 false b -26 oid 1307062959 NULL 8 true b -30 oidvector 1307062959 NULL -1 false b -700 float4 1307062959 NULL 8 true b -701 float8 1307062959 NULL 8 true b -705 unknown 1307062959 NULL 0 true b -869 inet 1307062959 NULL 24 true b -1000 _bool 1307062959 NULL -1 false b -1001 _bytea 1307062959 NULL -1 false b -1002 _char 1307062959 NULL -1 false b -1003 _name 1307062959 NULL -1 false b -1005 _int2 1307062959 NULL -1 false b -1006 _int2vector 1307062959 NULL -1 false b -1007 _int4 1307062959 NULL -1 false b -1008 _regproc 1307062959 NULL -1 false b -1009 _text 1307062959 NULL -1 false b -1013 _oidvector 1307062959 NULL -1 false b -1014 _bpchar 1307062959 NULL -1 false b -1015 _varchar 1307062959 NULL -1 false b -1016 _int8 1307062959 NULL -1 false b -1021 _float4 1307062959 NULL -1 false b -1022 _float8 1307062959 NULL -1 false b -1028 _oid 1307062959 NULL -1 false b -1041 _inet 1307062959 NULL -1 false b -1042 bpchar 1307062959 NULL -1 false b -1043 varchar 1307062959 NULL -1 false b -1082 date 1307062959 NULL 16 true b -1083 time 1307062959 NULL 8 true b -1114 timestamp 1307062959 NULL 24 true b -1115 _timestamp 1307062959 NULL -1 false b -1182 _date 1307062959 NULL -1 false b -1183 _time 1307062959 NULL -1 false b -1184 timestamptz 1307062959 NULL 24 true b -1185 _timestamptz 1307062959 NULL -1 false b -1186 interval 1307062959 NULL 24 true b -1187 _interval 1307062959 NULL -1 false b -1231 _numeric 1307062959 NULL -1 false b -1560 bit 1307062959 NULL -1 false b -1561 _bit 1307062959 NULL -1 false b -1562 varbit 1307062959 NULL -1 false b -1563 _varbit 1307062959 NULL -1 false b -1700 numeric 1307062959 NULL -1 false b -2202 regprocedure 1307062959 NULL 8 true b -2205 regclass 1307062959 NULL 8 true b -2206 regtype 1307062959 NULL 8 true b -2207 _regprocedure 1307062959 NULL -1 false b -2210 _regclass 1307062959 NULL -1 false b -2211 _regtype 1307062959 NULL -1 false b -2249 record 1307062959 NULL 0 true p -2277 anyarray 1307062959 NULL -1 false p -2283 anyelement 1307062959 NULL -1 false p -2287 _record 1307062959 NULL -1 false b -2950 uuid 1307062959 NULL 16 true b -2951 _uuid 1307062959 NULL -1 false b -3802 jsonb 1307062959 NULL -1 false b -3807 _jsonb 1307062959 NULL -1 false b -4089 regnamespace 1307062959 NULL 8 true b -4090 _regnamespace 1307062959 NULL -1 false b - -query OTTBBTOOO colnames -SELECT oid, typname, typcategory, typispreferred, typisdefined, typdelim, typrelid, typelem, typarray -FROM pg_catalog.pg_type -ORDER BY oid ----- -oid typname typcategory typispreferred typisdefined typdelim typrelid typelem typarray -16 bool B false true , 0 0 1000 -17 bytea U false true , 0 0 1001 -18 char S false true , 0 0 1002 -19 name S false true , 0 0 1003 -20 int8 N false true , 0 0 1016 -21 int2 N false true , 0 0 1005 -22 int2vector A false true , 0 21 1006 -23 int4 N false true , 0 0 1007 -24 regproc N false true , 0 0 1008 -25 text S false true , 0 0 1009 -26 oid N false true , 0 0 1028 -30 oidvector A false true , 0 26 1013 -700 float4 N false true , 0 0 1021 -701 float8 N false true , 0 0 1022 -705 unknown X false true , 0 0 0 -869 inet I false true , 0 0 1041 -1000 _bool A false true , 0 16 0 -1001 _bytea A false true , 0 17 0 -1002 _char A false true , 0 18 0 -1003 _name A false true , 0 19 0 -1005 _int2 A false true , 0 21 0 -1006 _int2vector A false true , 0 22 0 -1007 _int4 A false true , 0 23 0 -1008 _regproc A false true , 0 24 0 -1009 _text A false true , 0 25 0 -1013 _oidvector A false true , 0 30 0 -1014 _bpchar A false true , 0 1042 0 -1015 _varchar A false true , 0 1043 0 -1016 _int8 A false true , 0 20 0 -1021 _float4 A false true , 0 700 0 -1022 _float8 A false true , 0 701 0 -1028 _oid A false true , 0 26 0 -1041 _inet A false true , 0 869 0 -1042 bpchar S false true , 0 0 1014 -1043 varchar S false true , 0 0 1015 -1082 date D false true , 0 0 1182 -1083 time D false true , 0 0 1183 -1114 timestamp D false true , 0 0 1115 -1115 _timestamp A false true , 0 1114 0 -1182 _date A false true , 0 1082 0 -1183 _time A false true , 0 1083 0 -1184 timestamptz D false true , 0 0 1185 -1185 _timestamptz A false true , 0 1184 0 -1186 interval T false true , 0 0 1187 -1187 _interval A false true , 0 1186 0 -1231 _numeric A false true , 0 1700 0 -1560 bit V false true , 0 0 1561 -1561 _bit A false true , 0 1560 0 -1562 varbit V false true , 0 0 1563 -1563 _varbit A false true , 0 1562 0 -1700 numeric N false true , 0 0 1231 -2202 regprocedure N false true , 0 0 2207 -2205 regclass N false true , 0 0 2210 -2206 regtype N false true , 0 0 2211 -2207 _regprocedure A false true , 0 2202 0 -2210 _regclass A false true , 0 2205 0 -2211 _regtype A false true , 0 2206 0 -2249 record P false true , 0 0 2287 -2277 anyarray P false true , 0 0 0 -2283 anyelement P false true , 0 0 2277 -2287 _record A false true , 0 2249 0 -2950 uuid U false true , 0 0 2951 -2951 _uuid A false true , 0 2950 0 -3802 jsonb U false true , 0 0 3807 -3807 _jsonb A false true , 0 3802 0 -4089 regnamespace N false true , 0 0 4090 -4090 _regnamespace A false true , 0 4089 0 - -query OTOOOOOOO colnames -SELECT oid, typname, typinput, typoutput, typreceive, typsend, typmodin, typmodout, typanalyze -FROM pg_catalog.pg_type -ORDER BY oid ----- -oid typname typinput typoutput typreceive typsend typmodin typmodout typanalyze -16 bool boolin boolout boolrecv boolsend 0 0 0 -17 bytea byteain byteaout bytearecv byteasend 0 0 0 -18 char charin charout charrecv charsend 0 0 0 -19 name namein nameout namerecv namesend 0 0 0 -20 int8 int8in int8out int8recv int8send 0 0 0 -21 int2 int2in int2out int2recv int2send 0 0 0 -22 int2vector int2vectorin int2vectorout int2vectorrecv int2vectorsend 0 0 0 -23 int4 int4in int4out int4recv int4send 0 0 0 -24 regproc regprocin regprocout regprocrecv regprocsend 0 0 0 -25 text textin textout textrecv textsend 0 0 0 -26 oid oidin oidout oidrecv oidsend 0 0 0 -30 oidvector oidvectorin oidvectorout oidvectorrecv oidvectorsend 0 0 0 -700 float4 float4in float4out float4recv float4send 0 0 0 -701 float8 float8in float8out float8recv float8send 0 0 0 -705 unknown unknownin unknownout unknownrecv unknownsend 0 0 0 -869 inet inetin inetout inetrecv inetsend 0 0 0 -1000 _bool array_in array_out array_recv array_send 0 0 0 -1001 _bytea array_in array_out array_recv array_send 0 0 0 -1002 _char array_in array_out array_recv array_send 0 0 0 -1003 _name array_in array_out array_recv array_send 0 0 0 -1005 _int2 array_in array_out array_recv array_send 0 0 0 -1006 _int2vector array_in array_out array_recv array_send 0 0 0 -1007 _int4 array_in array_out array_recv array_send 0 0 0 -1008 _regproc array_in array_out array_recv array_send 0 0 0 -1009 _text array_in array_out array_recv array_send 0 0 0 -1013 _oidvector array_in array_out array_recv array_send 0 0 0 -1014 _bpchar array_in array_out array_recv array_send 0 0 0 -1015 _varchar array_in array_out array_recv array_send 0 0 0 -1016 _int8 array_in array_out array_recv array_send 0 0 0 -1021 _float4 array_in array_out array_recv array_send 0 0 0 -1022 _float8 array_in array_out array_recv array_send 0 0 0 -1028 _oid array_in array_out array_recv array_send 0 0 0 -1041 _inet array_in array_out array_recv array_send 0 0 0 -1042 bpchar bpcharin bpcharout bpcharrecv bpcharsend 0 0 0 -1043 varchar varcharin varcharout varcharrecv varcharsend 0 0 0 -1082 date date_in date_out date_recv date_send 0 0 0 -1083 time time_in time_out time_recv time_send 0 0 0 -1114 timestamp timestamp_in timestamp_out timestamp_recv timestamp_send 0 0 0 -1115 _timestamp array_in array_out array_recv array_send 0 0 0 -1182 _date array_in array_out array_recv array_send 0 0 0 -1183 _time array_in array_out array_recv array_send 0 0 0 -1184 timestamptz timestamptz_in timestamptz_out timestamptz_recv timestamptz_send 0 0 0 -1185 _timestamptz array_in array_out array_recv array_send 0 0 0 -1186 interval interval_in interval_out interval_recv interval_send 0 0 0 -1187 _interval array_in array_out array_recv array_send 0 0 0 -1231 _numeric array_in array_out array_recv array_send 0 0 0 -1560 bit bit_in bit_out bit_recv bit_send 0 0 0 -1561 _bit array_in array_out array_recv array_send 0 0 0 -1562 varbit varbit_in varbit_out varbit_recv varbit_send 0 0 0 -1563 _varbit array_in array_out array_recv array_send 0 0 0 -1700 numeric numeric_in numeric_out numeric_recv numeric_send 0 0 0 -2202 regprocedure regprocedurein regprocedureout regprocedurerecv regproceduresend 0 0 0 -2205 regclass regclassin regclassout regclassrecv regclasssend 0 0 0 -2206 regtype regtypein regtypeout regtyperecv regtypesend 0 0 0 -2207 _regprocedure array_in array_out array_recv array_send 0 0 0 -2210 _regclass array_in array_out array_recv array_send 0 0 0 -2211 _regtype array_in array_out array_recv array_send 0 0 0 -2249 record record_in record_out record_recv record_send 0 0 0 -2277 anyarray anyarray_in anyarray_out anyarray_recv anyarray_send 0 0 0 -2283 anyelement anyelement_in anyelement_out anyelement_recv anyelement_send 0 0 0 -2287 _record array_in array_out array_recv array_send 0 0 0 -2950 uuid uuid_in uuid_out uuid_recv uuid_send 0 0 0 -2951 _uuid array_in array_out array_recv array_send 0 0 0 -3802 jsonb jsonb_in jsonb_out jsonb_recv jsonb_send 0 0 0 -3807 _jsonb array_in array_out array_recv array_send 0 0 0 -4089 regnamespace regnamespacein regnamespaceout regnamespacerecv regnamespacesend 0 0 0 -4090 _regnamespace array_in array_out array_recv array_send 0 0 0 - -query OTTTBOI colnames -SELECT oid, typname, typalign, typstorage, typnotnull, typbasetype, typtypmod -FROM pg_catalog.pg_type -ORDER BY oid ----- -oid typname typalign typstorage typnotnull typbasetype typtypmod -16 bool NULL NULL false 0 -1 -17 bytea NULL NULL false 0 -1 -18 char NULL NULL false 0 -1 -19 name NULL NULL false 0 -1 -20 int8 NULL NULL false 0 -1 -21 int2 NULL NULL false 0 -1 -22 int2vector NULL NULL false 0 -1 -23 int4 NULL NULL false 0 -1 -24 regproc NULL NULL false 0 -1 -25 text NULL NULL false 0 -1 -26 oid NULL NULL false 0 -1 -30 oidvector NULL NULL false 0 -1 -700 float4 NULL NULL false 0 -1 -701 float8 NULL NULL false 0 -1 -705 unknown NULL NULL false 0 -1 -869 inet NULL NULL false 0 -1 -1000 _bool NULL NULL false 0 -1 -1001 _bytea NULL NULL false 0 -1 -1002 _char NULL NULL false 0 -1 -1003 _name NULL NULL false 0 -1 -1005 _int2 NULL NULL false 0 -1 -1006 _int2vector NULL NULL false 0 -1 -1007 _int4 NULL NULL false 0 -1 -1008 _regproc NULL NULL false 0 -1 -1009 _text NULL NULL false 0 -1 -1013 _oidvector NULL NULL false 0 -1 -1014 _bpchar NULL NULL false 0 -1 -1015 _varchar NULL NULL false 0 -1 -1016 _int8 NULL NULL false 0 -1 -1021 _float4 NULL NULL false 0 -1 -1022 _float8 NULL NULL false 0 -1 -1028 _oid NULL NULL false 0 -1 -1041 _inet NULL NULL false 0 -1 -1042 bpchar NULL NULL false 0 -1 -1043 varchar NULL NULL false 0 -1 -1082 date NULL NULL false 0 -1 -1083 time NULL NULL false 0 -1 -1114 timestamp NULL NULL false 0 -1 -1115 _timestamp NULL NULL false 0 -1 -1182 _date NULL NULL false 0 -1 -1183 _time NULL NULL false 0 -1 -1184 timestamptz NULL NULL false 0 -1 -1185 _timestamptz NULL NULL false 0 -1 -1186 interval NULL NULL false 0 -1 -1187 _interval NULL NULL false 0 -1 -1231 _numeric NULL NULL false 0 -1 -1560 bit NULL NULL false 0 -1 -1561 _bit NULL NULL false 0 -1 -1562 varbit NULL NULL false 0 -1 -1563 _varbit NULL NULL false 0 -1 -1700 numeric NULL NULL false 0 -1 -2202 regprocedure NULL NULL false 0 -1 -2205 regclass NULL NULL false 0 -1 -2206 regtype NULL NULL false 0 -1 -2207 _regprocedure NULL NULL false 0 -1 -2210 _regclass NULL NULL false 0 -1 -2211 _regtype NULL NULL false 0 -1 -2249 record NULL NULL false 0 -1 -2277 anyarray NULL NULL false 0 -1 -2283 anyelement NULL NULL false 0 -1 -2287 _record NULL NULL false 0 -1 -2950 uuid NULL NULL false 0 -1 -2951 _uuid NULL NULL false 0 -1 -3802 jsonb NULL NULL false 0 -1 -3807 _jsonb NULL NULL false 0 -1 -4089 regnamespace NULL NULL false 0 -1 -4090 _regnamespace NULL NULL false 0 -1 - -query OTIOTTT colnames -SELECT oid, typname, typndims, typcollation, typdefaultbin, typdefault, typacl -FROM pg_catalog.pg_type -ORDER BY oid ----- -oid typname typndims typcollation typdefaultbin typdefault typacl -16 bool 0 0 NULL NULL NULL -17 bytea 0 0 NULL NULL NULL -18 char 0 3903121477 NULL NULL NULL -19 name 0 3903121477 NULL NULL NULL -20 int8 0 0 NULL NULL NULL -21 int2 0 0 NULL NULL NULL -22 int2vector 0 0 NULL NULL NULL -23 int4 0 0 NULL NULL NULL -24 regproc 0 0 NULL NULL NULL -25 text 0 3903121477 NULL NULL NULL -26 oid 0 0 NULL NULL NULL -30 oidvector 0 0 NULL NULL NULL -700 float4 0 0 NULL NULL NULL -701 float8 0 0 NULL NULL NULL -705 unknown 0 0 NULL NULL NULL -869 inet 0 0 NULL NULL NULL -1000 _bool 0 0 NULL NULL NULL -1001 _bytea 0 0 NULL NULL NULL -1002 _char 0 3903121477 NULL NULL NULL -1003 _name 0 3903121477 NULL NULL NULL -1005 _int2 0 0 NULL NULL NULL -1006 _int2vector 0 0 NULL NULL NULL -1007 _int4 0 0 NULL NULL NULL -1008 _regproc 0 0 NULL NULL NULL -1009 _text 0 3903121477 NULL NULL NULL -1013 _oidvector 0 0 NULL NULL NULL -1014 _bpchar 0 3903121477 NULL NULL NULL -1015 _varchar 0 3903121477 NULL NULL NULL -1016 _int8 0 0 NULL NULL NULL -1021 _float4 0 0 NULL NULL NULL -1022 _float8 0 0 NULL NULL NULL -1028 _oid 0 0 NULL NULL NULL -1041 _inet 0 0 NULL NULL NULL -1042 bpchar 0 3903121477 NULL NULL NULL -1043 varchar 0 3903121477 NULL NULL NULL -1082 date 0 0 NULL NULL NULL -1083 time 0 0 NULL NULL NULL -1114 timestamp 0 0 NULL NULL NULL -1115 _timestamp 0 0 NULL NULL NULL -1182 _date 0 0 NULL NULL NULL -1183 _time 0 0 NULL NULL NULL -1184 timestamptz 0 0 NULL NULL NULL -1185 _timestamptz 0 0 NULL NULL NULL -1186 interval 0 0 NULL NULL NULL -1187 _interval 0 0 NULL NULL NULL -1231 _numeric 0 0 NULL NULL NULL -1560 bit 0 0 NULL NULL NULL -1561 _bit 0 0 NULL NULL NULL -1562 varbit 0 0 NULL NULL NULL -1563 _varbit 0 0 NULL NULL NULL -1700 numeric 0 0 NULL NULL NULL -2202 regprocedure 0 0 NULL NULL NULL -2205 regclass 0 0 NULL NULL NULL -2206 regtype 0 0 NULL NULL NULL -2207 _regprocedure 0 0 NULL NULL NULL -2210 _regclass 0 0 NULL NULL NULL -2211 _regtype 0 0 NULL NULL NULL -2249 record 0 0 NULL NULL NULL -2277 anyarray 0 3903121477 NULL NULL NULL -2283 anyelement 0 0 NULL NULL NULL -2287 _record 0 0 NULL NULL NULL -2950 uuid 0 0 NULL NULL NULL -2951 _uuid 0 0 NULL NULL NULL -3802 jsonb 0 0 NULL NULL NULL -3807 _jsonb 0 0 NULL NULL NULL -4089 regnamespace 0 0 NULL NULL NULL -4090 _regnamespace 0 0 NULL NULL NULL - -## pg_catalog.pg_proc - -query TOOOTTO colnames -SELECT proname, pronamespace, proowner, prolang, procost, prorows, provariadic -FROM pg_catalog.pg_proc -WHERE proname='substring' ----- -proname pronamespace proowner prolang procost prorows provariadic -substring 1307062959 NULL 0 NULL NULL 0 -substring 1307062959 NULL 0 NULL NULL 0 -substring 1307062959 NULL 0 NULL NULL 0 -substring 1307062959 NULL 0 NULL NULL 0 - -query TTBBBB colnames -SELECT proname, protransform, proisagg, proiswindow, prosecdef, proleakproof -FROM pg_catalog.pg_proc -WHERE proname='substring' ----- -proname protransform proisagg proiswindow prosecdef proleakproof -substring NULL false false false true -substring NULL false false false true -substring NULL false false false true -substring NULL false false false true - -query TBBTT colnames -SELECT proname, proisstrict, proretset, provolatile, proparallel -FROM pg_catalog.pg_proc -WHERE proname='substring' ----- -proname proisstrict proretset provolatile proparallel -substring false false NULL NULL -substring false false NULL NULL -substring false false NULL NULL -substring false false NULL NULL - -query TIIOTTTT colnames -SELECT proname, pronargs, pronargdefaults, prorettype, proargtypes, proallargtypes, proargmodes, proargdefaults -FROM pg_catalog.pg_proc -WHERE proname='substring' ----- -proname pronargs pronargdefaults prorettype proargtypes proallargtypes proargmodes proargdefaults -substring 2 0 25 25 20 NULL NULL NULL -substring 3 0 25 25 20 20 NULL NULL NULL -substring 2 0 25 25 25 NULL NULL NULL -substring 3 0 25 25 25 25 NULL NULL NULL - -query TTTTTT colnames -SELECT proname, protrftypes, prosrc, probin, proconfig, proacl -FROM pg_catalog.pg_proc -WHERE proname='substring' ----- -proname protrftypes prosrc probin proconfig proacl -substring NULL substring NULL NULL NULL -substring NULL substring NULL NULL NULL -substring NULL substring NULL NULL NULL -substring NULL substring NULL NULL NULL - -query TOIOTT colnames -SELECT proname, provariadic, pronargs, prorettype, proargtypes, proargmodes -FROM pg_catalog.pg_proc -WHERE proname='least' ----- -proname provariadic pronargs prorettype proargtypes proargmodes -least 2283 1 2283 2283 {v} - -query TOIOTT colnames -SELECT proname, provariadic, pronargs, prorettype, proargtypes, proargmodes -FROM pg_catalog.pg_proc -WHERE proname='json_extract_path' ----- -proname provariadic pronargs prorettype proargtypes proargmodes -json_extract_path 25 2 3802 3802 25 {i,v} - -## pg_catalog.pg_range -query IIIIII colnames -SELECT * from pg_catalog.pg_range ----- -rngtypid rngsubtype rngcollation rngsubopc rngcanonical rngsubdiff - -## pg_catalog.pg_roles - -query OTBBBBBBB colnames -SELECT oid, rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcatupdate, rolcanlogin, rolreplication -FROM pg_catalog.pg_roles -ORDER BY rolname ----- -oid rolname rolsuper rolinherit rolcreaterole rolcreatedb rolcatupdate rolcanlogin rolreplication -2310524507 admin true true true true false false false -1546506610 root true false true true false true false -2264919399 testuser false false false false false true false - -query OTITTBT colnames -SELECT oid, rolname, rolconnlimit, rolpassword, rolvaliduntil, rolbypassrls, rolconfig -FROM pg_catalog.pg_roles -ORDER BY rolname ----- -oid rolname rolconnlimit rolpassword rolvaliduntil rolbypassrls rolconfig -2310524507 admin -1 ******** NULL false NULL -1546506610 root -1 ******** NULL false NULL -2264919399 testuser -1 ******** NULL false NULL - -## pg_catalog.pg_auth_members - -query OOOB colnames -SELECT roleid, member, grantor, admin_option -FROM pg_catalog.pg_auth_members ----- -roleid member grantor admin_option -2310524507 1546506610 NULL true - -## pg_catalog.pg_user - -query TOBBBBTTA colnames -SELECT usename, usesysid, usecreatedb, usesuper, userepl, usebypassrls, passwd, valuntil, useconfig -FROM pg_catalog.pg_user -ORDER BY usename ----- -usename usesysid usecreatedb usesuper userepl usebypassrls passwd valuntil useconfig -root 1546506610 true true false false ******** NULL NULL -testuser 2264919399 false false false false ******** NULL NULL - -## pg_catalog.pg_description - -query OOIT colnames -SELECT objoid, classoid, objsubid, regexp_replace(description, e'\n.*', '') AS description - FROM pg_catalog.pg_description ----- -objoid classoid objsubid description -4294967294 4294967234 0 backward inter-descriptor dependencies starting from tables accessible by current user in current database (KV scan) -4294967292 4294967234 0 built-in functions (RAM/static) -4294967291 4294967234 0 running queries visible by current user (cluster RPC; expensive!) -4294967290 4294967234 0 running sessions visible to current user (cluster RPC; expensive!) -4294967289 4294967234 0 cluster settings (RAM) -4294967288 4294967234 0 CREATE and ALTER statements for all tables accessible by current user in current database (KV scan) -4294967287 4294967234 0 telemetry counters (RAM; local node only) -4294967286 4294967234 0 forward inter-descriptor dependencies starting from tables accessible by current user in current database (KV scan) -4294967284 4294967234 0 locally known gossiped health alerts (RAM; local node only) -4294967283 4294967234 0 locally known gossiped node liveness (RAM; local node only) -4294967282 4294967234 0 locally known edges in the gossip network (RAM; local node only) -4294967285 4294967234 0 locally known gossiped node details (RAM; local node only) -4294967281 4294967234 0 index columns for all indexes accessible by current user in current database (KV scan) -4294967280 4294967234 0 decoded job metadata from system.jobs (KV scan) -4294967279 4294967234 0 node details across the entire cluster (cluster RPC; expensive!) -4294967278 4294967234 0 store details and status (cluster RPC; expensive!) -4294967277 4294967234 0 acquired table leases (RAM; local node only) -4294967293 4294967234 0 detailed identification strings (RAM, local node only) -4294967274 4294967234 0 current values for metrics (RAM; local node only) -4294967276 4294967234 0 running queries visible by current user (RAM; local node only) -4294967269 4294967234 0 server parameters, useful to construct connection URLs (RAM, local node only) -4294967275 4294967234 0 running sessions visible by current user (RAM; local node only) -4294967265 4294967234 0 statement statistics (RAM; local node only) -4294967273 4294967234 0 defined partitions for all tables/indexes accessible by the current user in the current database (KV scan) -4294967272 4294967234 0 comments for predefined virtual tables (RAM/static) -4294967271 4294967234 0 range metadata without leaseholder details (KV join; expensive!) -4294967268 4294967234 0 ongoing schema changes, across all descriptors accessible by current user (KV scan; expensive!) -4294967267 4294967234 0 session trace accumulated so far (RAM) -4294967266 4294967234 0 session variables (RAM) -4294967264 4294967234 0 details for all columns accessible by current user in current database (KV scan) -4294967263 4294967234 0 indexes accessible by current user in current database (KV scan) -4294967262 4294967234 0 table descriptors accessible by current user, including non-public and virtual (KV scan; expensive!) -4294967261 4294967234 0 decoded zone configurations from system.zones (KV scan) -4294967259 4294967234 0 roles for which the current user has admin option -4294967258 4294967234 0 roles available to the current user -4294967257 4294967234 0 column privilege grants (incomplete) -4294967256 4294967234 0 table and view columns (incomplete) -4294967255 4294967234 0 columns usage by constraints -4294967254 4294967234 0 roles for the current user -4294967253 4294967234 0 column usage by indexes and key constraints -4294967252 4294967234 0 built-in function parameters (empty - introspection not yet supported) -4294967251 4294967234 0 foreign key constraints -4294967250 4294967234 0 privileges granted on table or views (incomplete; see also information_schema.table_privileges; may contain excess users or roles) -4294967249 4294967234 0 built-in functions (empty - introspection not yet supported) -4294967247 4294967234 0 schema privileges (incomplete; may contain excess users or roles) -4294967248 4294967234 0 database schemas (may contain schemata without permission) -4294967246 4294967234 0 sequences -4294967245 4294967234 0 index metadata and statistics (incomplete) -4294967244 4294967234 0 table constraints -4294967243 4294967234 0 privileges granted on table or views (incomplete; may contain excess users or roles) -4294967242 4294967234 0 tables and views -4294967240 4294967234 0 grantable privileges (incomplete) -4294967241 4294967234 0 views (incomplete) -4294967238 4294967234 0 index access methods (incomplete) -4294967237 4294967234 0 column default values -4294967236 4294967234 0 table columns (incomplete - see also information_schema.columns) -4294967235 4294967234 0 role membership -4294967234 4294967234 0 tables and relation-like objects (incomplete - see also information_schema.tables/sequences/views) -4294967233 4294967234 0 available collations (incomplete) -4294967232 4294967234 0 table constraints (incomplete - see also information_schema.table_constraints) -4294967231 4294967234 0 available databases (incomplete) -4294967230 4294967234 0 dependency relationships (incomplete) -4294967229 4294967234 0 object comments -4294967227 4294967234 0 enum types and labels (empty - feature does not exist) -4294967226 4294967234 0 installed extensions (empty - feature does not exist) -4294967225 4294967234 0 foreign data wrappers (empty - feature does not exist) -4294967224 4294967234 0 foreign servers (empty - feature does not exist) -4294967223 4294967234 0 foreign tables (empty - feature does not exist) -4294967222 4294967234 0 indexes (incomplete) -4294967221 4294967234 0 index creation statements -4294967220 4294967234 0 table inheritance hierarchy (empty - feature does not exist) -4294967219 4294967234 0 available languages (empty - feature does not exist) -4294967218 4294967234 0 available namespaces (incomplete; namespaces and databases are congruent in CockroachDB) -4294967217 4294967234 0 operators (incomplete) -4294967216 4294967234 0 built-in functions (incomplete) -4294967215 4294967234 0 range types (empty - feature does not exist) -4294967214 4294967234 0 rewrite rules (empty - feature does not exist) -4294967213 4294967234 0 database roles -4294967202 4294967234 0 security labels (empty - feature does not exist) -4294967212 4294967234 0 sequences (see also information_schema.sequences) -4294967211 4294967234 0 session variables (incomplete) -4294967228 4294967234 0 shared object comments -4294967201 4294967234 0 shared security labels (empty - feature not supported) -4294967203 4294967234 0 backend access statistics (empty - monitoring works differently in CockroachDB) -4294967208 4294967234 0 tables summary (see also information_schema.tables, pg_catalog.pg_class) -4294967207 4294967234 0 available tablespaces (incomplete; concept inapplicable to CockroachDB) -4294967206 4294967234 0 triggers (empty - feature does not exist) -4294967205 4294967234 0 scalar types (incomplete) -4294967210 4294967234 0 database users -4294967209 4294967234 0 local to remote user mapping (empty - feature does not exist) -4294967204 4294967234 0 view definitions (incomplete - see also information_schema.views) - -## pg_catalog.pg_shdescription - -query OOT colnames -SELECT objoid, classoid, description FROM pg_catalog.pg_shdescription ----- -objoid classoid description - -## pg_catalog.pg_enum - -query OORT colnames -SELECT * FROM pg_catalog.pg_enum ----- -oid enumtypid enumsortorder enumlabel - -## pg_catalog.pg_extension -query OTOOBTTT colnames -SELECT * FROM pg_catalog.pg_extension ----- -oid extname extowner extnamespace extrelocatable extversion extconfig extcondition - -## pg_catalog.pg_stat_activity - -query OTIOTTTTITTTTTTTIIT colnames -SELECT * FROM pg_catalog.pg_stat_activity ----- -datid datname pid usesysid username application_name client_addr client_hostname client_port backend_start xact_start query_start state_change wait_event_type wait_event state backend_xid backend_xmin query - -query TTBTTTB colnames -SHOW COLUMNS FROM pg_catalog.pg_stat_activity ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -datid OID true NULL · {} false -datname NAME true NULL · {} false -pid INT8 true NULL · {} false -usesysid OID true NULL · {} false -username NAME true NULL · {} false -application_name STRING true NULL · {} false -client_addr INET true NULL · {} false -client_hostname STRING true NULL · {} false -client_port INT8 true NULL · {} false -backend_start TIMESTAMPTZ true NULL · {} false -xact_start TIMESTAMPTZ true NULL · {} false -query_start TIMESTAMPTZ true NULL · {} false -state_change TIMESTAMPTZ true NULL · {} false -wait_event_type STRING true NULL · {} false -wait_event STRING true NULL · {} false -state STRING true NULL · {} false -backend_xid INT8 true NULL · {} false -backend_xmin INT8 true NULL · {} false -query STRING true NULL · {} false - - -## pg_catalog.pg_settings - -statement ok -SET DATABASE = test - -# We filter here because 'optimizer' will be different depending on which -# configuration this logic test is running in. -query TTTTTT colnames -SELECT - name, setting, category, short_desc, extra_desc, vartype -FROM - pg_catalog.pg_settings -WHERE - name != 'optimizer' AND name != 'crdb_version' ----- -name setting category short_desc extra_desc vartype -application_name · NULL NULL NULL string -bytea_output hex NULL NULL NULL string -client_encoding UTF8 NULL NULL NULL string -client_min_messages notice NULL NULL NULL string -database test NULL NULL NULL string -datestyle ISO, MDY NULL NULL NULL string -default_int_size 8 NULL NULL NULL string -default_tablespace · NULL NULL NULL string -default_transaction_isolation serializable NULL NULL NULL string -default_transaction_read_only off NULL NULL NULL string -distsql off NULL NULL NULL string -experimental_enable_zigzag_join on NULL NULL NULL string -experimental_force_split_at off NULL NULL NULL string -experimental_serial_normalization rowid NULL NULL NULL string -experimental_vectorize off NULL NULL NULL string -extra_float_digits 0 NULL NULL NULL string -force_savepoint_restart off NULL NULL NULL string -idle_in_transaction_session_timeout 0 NULL NULL NULL string -integer_datetimes on NULL NULL NULL string -intervalstyle postgres NULL NULL NULL string -lock_timeout 0 NULL NULL NULL string -max_index_keys 32 NULL NULL NULL string -node_id 1 NULL NULL NULL string -reorder_joins_limit 4 NULL NULL NULL string -results_buffer_size 16384 NULL NULL NULL string -row_security off NULL NULL NULL string -search_path public NULL NULL NULL string -server_encoding UTF8 NULL NULL NULL string -server_version 9.5.0 NULL NULL NULL string -server_version_num 90500 NULL NULL NULL string -session_user root NULL NULL NULL string -sql_safe_updates off NULL NULL NULL string -standard_conforming_strings on NULL NULL NULL string -statement_timeout 0 NULL NULL NULL string -synchronize_seqscans on NULL NULL NULL string -timezone UTC NULL NULL NULL string -tracing off NULL NULL NULL string -transaction_isolation serializable NULL NULL NULL string -transaction_priority normal NULL NULL NULL string -transaction_read_only off NULL NULL NULL string -transaction_status NoTxn NULL NULL NULL string - -query TTTTTTT colnames -SELECT - name, setting, unit, context, enumvals, boot_val, reset_val -FROM - pg_catalog.pg_settings -WHERE - name != 'optimizer' AND name != 'crdb_version' ----- -name setting unit context enumvals boot_val reset_val -application_name · NULL user NULL · · -bytea_output hex NULL user NULL hex hex -client_encoding UTF8 NULL user NULL UTF8 UTF8 -client_min_messages notice NULL user NULL notice notice -database test NULL user NULL · test -datestyle ISO, MDY NULL user NULL ISO, MDY ISO, MDY -default_int_size 8 NULL user NULL 8 8 -default_tablespace · NULL user NULL · · -default_transaction_isolation serializable NULL user NULL default default -default_transaction_read_only off NULL user NULL off off -distsql off NULL user NULL off off -experimental_enable_zigzag_join on NULL user NULL on on -experimental_force_split_at off NULL user NULL off off -experimental_serial_normalization rowid NULL user NULL rowid rowid -experimental_vectorize off NULL user NULL off off -extra_float_digits 0 NULL user NULL 0 2 -force_savepoint_restart off NULL user NULL off off -idle_in_transaction_session_timeout 0 NULL user NULL 0 0 -integer_datetimes on NULL user NULL on on -intervalstyle postgres NULL user NULL postgres postgres -lock_timeout 0 NULL user NULL 0 0 -max_index_keys 32 NULL user NULL 32 32 -node_id 1 NULL user NULL 1 1 -reorder_joins_limit 4 NULL user NULL 4 4 -results_buffer_size 16384 NULL user NULL 16384 16384 -row_security off NULL user NULL off off -search_path public NULL user NULL public public -server_encoding UTF8 NULL user NULL UTF8 UTF8 -server_version 9.5.0 NULL user NULL 9.5.0 9.5.0 -server_version_num 90500 NULL user NULL 90500 90500 -session_user root NULL user NULL root root -sql_safe_updates off NULL user NULL off off -standard_conforming_strings on NULL user NULL on on -statement_timeout 0 NULL user NULL 0 0 -synchronize_seqscans on NULL user NULL on on -timezone UTC NULL user NULL UTC UTC -tracing off NULL user NULL off off -transaction_isolation serializable NULL user NULL serializable serializable -transaction_priority normal NULL user NULL normal normal -transaction_read_only off NULL user NULL off off -transaction_status NoTxn NULL user NULL NoTxn NoTxn - -query TTTTTT colnames -SELECT name, source, min_val, max_val, sourcefile, sourceline FROM pg_catalog.pg_settings ----- -name source min_val max_val sourcefile sourceline -application_name NULL NULL NULL NULL NULL -bytea_output NULL NULL NULL NULL NULL -client_encoding NULL NULL NULL NULL NULL -client_min_messages NULL NULL NULL NULL NULL -crdb_version NULL NULL NULL NULL NULL -database NULL NULL NULL NULL NULL -datestyle NULL NULL NULL NULL NULL -default_int_size NULL NULL NULL NULL NULL -default_tablespace NULL NULL NULL NULL NULL -default_transaction_isolation NULL NULL NULL NULL NULL -default_transaction_read_only NULL NULL NULL NULL NULL -distsql NULL NULL NULL NULL NULL -experimental_enable_zigzag_join NULL NULL NULL NULL NULL -experimental_force_split_at NULL NULL NULL NULL NULL -experimental_serial_normalization NULL NULL NULL NULL NULL -experimental_vectorize NULL NULL NULL NULL NULL -extra_float_digits NULL NULL NULL NULL NULL -force_savepoint_restart NULL NULL NULL NULL NULL -idle_in_transaction_session_timeout NULL NULL NULL NULL NULL -integer_datetimes NULL NULL NULL NULL NULL -intervalstyle NULL NULL NULL NULL NULL -lock_timeout NULL NULL NULL NULL NULL -max_index_keys NULL NULL NULL NULL NULL -node_id NULL NULL NULL NULL NULL -optimizer NULL NULL NULL NULL NULL -reorder_joins_limit NULL NULL NULL NULL NULL -results_buffer_size NULL NULL NULL NULL NULL -row_security NULL NULL NULL NULL NULL -search_path NULL NULL NULL NULL NULL -server_encoding NULL NULL NULL NULL NULL -server_version NULL NULL NULL NULL NULL -server_version_num NULL NULL NULL NULL NULL -session_user NULL NULL NULL NULL NULL -sql_safe_updates NULL NULL NULL NULL NULL -standard_conforming_strings NULL NULL NULL NULL NULL -statement_timeout NULL NULL NULL NULL NULL -synchronize_seqscans NULL NULL NULL NULL NULL -timezone NULL NULL NULL NULL NULL -tracing NULL NULL NULL NULL NULL -transaction_isolation NULL NULL NULL NULL NULL -transaction_priority NULL NULL NULL NULL NULL -transaction_read_only NULL NULL NULL NULL NULL -transaction_status NULL NULL NULL NULL NULL - -# pg_catalog.pg_sequence - -statement ok -CREATE DATABASE seq - -query OOIIIIIB -SELECT * FROM pg_catalog.pg_sequence ----- - -statement ok -CREATE SEQUENCE foo - -statement ok -CREATE SEQUENCE bar MAXVALUE 10 MINVALUE 5 START 6 INCREMENT 2 - -query OOIIIIIB colnames -SELECT * FROM pg_catalog.pg_sequence ----- -seqrelid seqtypid seqstart seqincrement seqmax seqmin seqcache seqcycle -64 20 1 1 9223372036854775807 1 1 false -65 20 6 2 10 5 1 false - -statement ok -DROP DATABASE seq - -statement ok -SET database = constraint_db - -# Verify sequences can't be seen from another database. -query OOIIIIIB -SELECT * FROM pg_catalog.pg_sequence ----- - -## pg_catalog.pg_operator - -query OTOOTBBOOOOOOOO colnames -SELECT * FROM pg_catalog.pg_operator where oprname='+' and oprleft='float8'::regtype ----- -oid oprname oprnamespace oprowner oprkind oprcanmerge oprcanhash oprleft oprright oprresult oprcom oprnegate oprcode oprrest oprjoin -74817020 + 1307062959 NULL b false false 701 701 701 NULL NULL NULL NULL NULL - -# Verify proper functionality of system information functions. - -query TT -SELECT pg_catalog.pg_get_expr('1', 0), pg_catalog.pg_get_expr('1', 0::OID) ----- -1 1 - -query T -SELECT pg_catalog.pg_get_expr('1', 0, true) ----- -1 - -statement ok -SET DATABASE = constraint_db - -query OTT -SELECT def.oid, c.relname, pg_catalog.pg_get_expr(def.adbin, def.adrelid) -FROM pg_catalog.pg_attrdef def -JOIN pg_catalog.pg_class c ON def.adrelid = c.oid -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE n.nspname = 'public' ----- -1666782879 t1 12:::INT8 -841178406 t2 unique_rowid() -2186255414 t3 'FOO':::STRING -2186255409 t3 unique_rowid() - -# Verify that a set database shows tables from that database for a non-root -# user, when that user has permissions. - -statement ok -GRANT ALL ON constraint_db.* TO testuser - -user testuser - -statement ok -SET DATABASE = 'constraint_db' - -query I -SELECT count(*) FROM pg_catalog.pg_tables WHERE schemaname='public' ----- -3 - -user root - -# Verify that an unset database shows tables across databases. -# But only those items visible to this user are reported. -# (Tests below show that root sees more). - -statement ok -SET DATABASE = '' - -query error cannot access virtual schema in anonymous database -SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public' ORDER BY 1 - -query error cannot access virtual schema in anonymous database -SELECT viewname FROM pg_catalog.pg_views WHERE schemaname='public' ORDER BY 1 - -query error cannot access virtual schema in anonymous database -SELECT relname FROM pg_catalog.pg_class c -JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid -WHERE nspname='public' - -query error cannot access virtual schema in anonymous database -SELECT conname FROM pg_catalog.pg_constraint con -JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid -WHERE n.nspname = 'public' - -query error cannot access virtual schema in anonymous database -SELECT count(*) FROM pg_catalog.pg_depend - -query error cannot access virtual schema in anonymous database -select 'upper'::REGPROC; - -query error cannot access virtual schema in anonymous database -select 'system.namespace'::regclass - -statement ok -SET DATABASE = test - -## materialize#13567 -## regproc columns display as text but can still be joined against oid columns -query OTO -SELECT p.oid, p.proname, t.typinput -FROM pg_proc p -JOIN pg_type t ON t.typinput = p.oid -WHERE t.typname = '_int4' ----- -780513238 array_in array_in - -## materialize#16285 -## int2vectors should be 0-indexed -query I -SELECT count(*) FROM pg_catalog.pg_index WHERE indkey[0] IS NULL; ----- -0 - -## Ensure no two builtins have the same oid. -query I -SELECT c FROM (SELECT oid, count(*) as c FROM pg_catalog.pg_proc GROUP BY oid) WHERE c > 1 ----- - -## Ensure that unnest works with oid wrapper arrays - -query O -SELECT unnest((SELECT proargtypes FROM pg_proc WHERE proname='split_part')); ----- -25 -25 -20 - -## TODO(masha): cockroach#16769 -#statement ok -#CREATE TABLE types(a int8, b int2); - -#query I -#SELECT attname, atttypid, typname FROM pg_attribute a JOIN pg_type t ON a.atttypid=t.oid WHERE attrelid = 'types'::REGCLASS; -#attname atttypid typname -#a 20 int8 -#b 20 int2 - -subtest pg_catalog.pg_seclabel - -query OOOTT colnames -SELECT objoid, classoid, objsubid, provider, label FROM pg_catalog.pg_seclabel ----- -objoid classoid objsubid provider label - -subtest pg_catalog.pg_shseclabel - -query OOTT colnames -SELECT objoid, classoid, provider, label FROM pg_catalog.pg_shseclabel ----- -objoid classoid provider label - -subtest collated_string_type - -statement ok -CREATE TABLE coltab (a STRING COLLATE en) - -query OT -SELECT typ.oid, typ.typname FROM pg_attribute att JOIN pg_type typ ON atttypid=typ.oid WHERE attrelid='coltab'::regclass AND attname='a' ----- -25 text - -subtest 31545 - -# Test an index of 2 referencing an index of 2. -statement ok -CREATE TABLE a ( - id_a_1 INT UNIQUE, - id_a_2 INT, - PRIMARY KEY (id_a_1, id_a_2) -) - -statement ok -CREATE TABLE b ( - id_b_1 INT, - id_b_2 INT, - PRIMARY KEY (id_b_1, id_b_2), - CONSTRAINT my_fkey FOREIGN KEY (id_b_1, id_b_2) REFERENCES a (id_a_1, id_a_2) -) - -query TT colnames -SELECT conkey, confkey FROM pg_catalog.pg_constraint WHERE conname = 'my_fkey' ----- -conkey confkey -{1,2} {1,2} - -# Test an index of 3 referencing an index of 2. -statement ok -DROP TABLE b; -CREATE TABLE b ( - id_b_1 INT, - id_b_2 INT, - id_b_3 INT, - PRIMARY KEY (id_b_1, id_b_2, id_b_3), - CONSTRAINT my_fkey FOREIGN KEY (id_b_1, id_b_2) REFERENCES a (id_a_1, id_a_2) -) - -query TT colnames -SELECT conkey, confkey FROM pg_catalog.pg_constraint WHERE conname = 'my_fkey' ----- -conkey confkey -{1,2} {1,2} - -# Test an index of 3 referencing an index of 1. -statement ok -DROP TABLE b; -CREATE TABLE b ( - id_b_1 INT, - id_b_2 INT, - id_b_3 INT, - PRIMARY KEY (id_b_1, id_b_2, id_b_3), - CONSTRAINT my_fkey FOREIGN KEY (id_b_1) REFERENCES a (id_a_1) -) - -query TT colnames -SELECT conkey, confkey FROM pg_catalog.pg_constraint WHERE conname = 'my_fkey' ----- -conkey confkey -{1} {1} - -subtest regression_34856 - -statement ok -CREATE DATABASE d34856 - -statement ok -CREATE TABLE d34856.t(x INT); - CREATE VIEW d34856.v AS SELECT x FROM d34856.t; - CREATE SEQUENCE d34856.s - -# Check that only tables show up in pg_tables. -query T -SELECT tablename FROM d34856.pg_catalog.pg_tables WHERE schemaname = 'public' ----- -t - -statement ok -DROP DATABASE d34856 CASCADE - -subtest regression_34862 - -statement ok -CREATE DATABASE d34862; SET database=d34862 - -statement ok -CREATE TABLE t(x INT UNIQUE); - CREATE TABLE u( - a INT REFERENCES t(x) ON DELETE NO ACTION, - b INT REFERENCES t(x) ON DELETE RESTRICT, - c INT REFERENCES t(x) ON DELETE SET NULL, - d INT DEFAULT 123 REFERENCES t(x) ON DELETE SET DEFAULT, - e INT REFERENCES t(x) ON DELETE CASCADE, - f INT REFERENCES t(x) ON UPDATE NO ACTION, - g INT REFERENCES t(x) ON UPDATE RESTRICT, - h INT REFERENCES t(x) ON UPDATE SET NULL, - i INT DEFAULT 123 REFERENCES t(x) ON UPDATE SET DEFAULT, - j INT REFERENCES t(x) ON UPDATE CASCADE, - k INT REFERENCES t(x) ON DELETE RESTRICT ON UPDATE SET NULL - ); - -query TTT -SELECT conname, confupdtype, confdeltype FROM pg_constraint ORDER BY conname ----- -fk_a_ref_t a a -fk_b_ref_t a r -fk_c_ref_t a n -fk_d_ref_t a d -fk_e_ref_t a c -fk_f_ref_t a a -fk_g_ref_t r a -fk_h_ref_t n a -fk_i_ref_t d a -fk_j_ref_t c a -fk_k_ref_t n r -t_x_key NULL NULL - -statement ok -DROP TABLE u; DROP TABLE t - -statement ok -CREATE TABLE v(x INT, y INT, UNIQUE (x,y)) - -statement ok -CREATE TABLE w( - a INT, b INT, c INT, d INT, - FOREIGN KEY (a,b) REFERENCES v(x,y) MATCH FULL, - FOREIGN KEY (c,d) REFERENCES v(x,y) MATCH SIMPLE - ); - -query TT -SELECT conname, confmatchtype FROM pg_constraint ORDER BY conname ----- -fk_a_ref_v f -fk_c_ref_v s -v_x_y_key NULL - -statement ok -DROP DATABASE d34862 CASCADE; SET database=test - -subtest regression_35108 - -query T -SELECT pg_catalog.current_setting('statement_timeout') ----- -0 - -query T -SELECT pg_catalog.current_setting('statement_timeout', false) ----- -0 - -# check returns null on unsupported session var. -query T -SELECT IFNULL(pg_catalog.current_setting('woo', true), 'OK') ----- -OK - -# check error on nonexistent session var. -query error unrecognized configuration parameter -SELECT pg_catalog.current_setting('woo', false) - -# check error on unsupported session var. -query error configuration setting.*not supported -SELECT pg_catalog.current_setting('vacuum_cost_delay', false) - -query T -SHOW application_name ----- -· - -query T -SELECT pg_catalog.set_config('application_name', 'woo', false) ----- -woo - -query T -SHOW application_name ----- -woo - -query error transaction-scoped settings are not supported -SELECT pg_catalog.set_config('application_name', 'woo', true) - -query error unrecognized configuration parameter -SELECT pg_catalog.set_config('woo', 'woo', false) - -query error configuration setting.*not supported -SELECT pg_catalog.set_config('vacuum_cost_delay', '0', false) diff --git a/test/sqllogictest/cockroach/pg_catalog_pg_default_acl_with_grant_option.slt b/test/sqllogictest/cockroach/pg_catalog_pg_default_acl_with_grant_option.slt new file mode 100644 index 0000000000000..d442ed0b709f2 --- /dev/null +++ b/test/sqllogictest/cockroach/pg_catalog_pg_default_acl_with_grant_option.slt @@ -0,0 +1,273 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/pg_catalog_pg_default_acl_with_grant_option +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement error Expected FOR, found GRANT +ALTER DEFAULT PRIVILEGES GRANT SELECT ON TABLES TO PUBLIC WITH GRANT OPTION + +statement error Expected FOR, found GRANT +ALTER DEFAULT PRIVILEGES GRANT USAGE ON SCHEMAS TO PUBLIC WITH GRANT OPTION + +statement error Expected FOR, found GRANT +ALTER DEFAULT PRIVILEGES GRANT SELECT ON SEQUENCES TO PUBLIC WITH GRANT OPTION + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES GRANT SELECT ON TABLES TO PUBLIC; +ALTER DEFAULT PRIVILEGES GRANT USAGE ON SCHEMAS TO PUBLIC; +ALTER DEFAULT PRIVILEGES GRANT SELECT ON SEQUENCES TO PUBLIC; + +# Not supported by Materialize. +onlyif cockroach +# Public should appear as an empty string with privileges. +query OOOTT colnames,rowsort +SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL +---- +oid defaclrole defaclnamespace defaclobjtype defaclacl +1451375629 1546506610 0 r {=r/} +1451375629 1546506610 0 S {=r/} +1451375629 1546506610 0 n {=U/} + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER foo + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER bar + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES GRANT ALL ON TABLES TO foo, bar WITH GRANT OPTION; +ALTER DEFAULT PRIVILEGES GRANT ALL ON TYPES TO foo, bar WITH GRANT OPTION; +ALTER DEFAULT PRIVILEGES GRANT ALL ON SCHEMAS TO foo, bar WITH GRANT OPTION; +ALTER DEFAULT PRIVILEGES GRANT ALL ON SEQUENCES TO foo, bar WITH GRANT OPTION; +ALTER DEFAULT PRIVILEGES GRANT ALL ON FUNCTIONS TO foo, bar WITH GRANT OPTION; + +# Not supported by Materialize. +onlyif cockroach +query OOOTT colnames,rowsort +SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL +---- +oid defaclrole defaclnamespace defaclobjtype defaclacl +1451375629 1546506610 0 r {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/,=r/} +1451375629 1546506610 0 S {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/,=r/} +1451375629 1546506610 0 T {bar=U*/,foo=U*/} +1451375629 1546506610 0 n {bar=C*U*/,foo=C*U*/,=U/} +1451375629 1546506610 0 f {bar=X*/,foo=X*/} + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR SELECT, DELETE ON TABLES FROM foo, bar; +ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR USAGE ON TYPES FROM foo, bar; +ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR CREATE ON SCHEMAS FROM foo, bar; +ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR CREATE, UPDATE ON SEQUENCES FROM foo, bar; +ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR EXECUTE ON FUNCTIONS FROM foo, bar; + +# Not supported by Materialize. +onlyif cockroach +query OOOTT colnames,rowsort +SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL +---- +oid defaclrole defaclnamespace defaclobjtype defaclacl +1451375629 1546506610 0 r {bar=C*a*drw*/,foo=C*a*drw*/,=r/} +1451375629 1546506610 0 S {bar=Ca*d*r*w/,foo=Ca*d*r*w/,=r/} +1451375629 1546506610 0 T {bar=U/,foo=U/} +1451375629 1546506610 0 n {bar=CU*/,foo=CU*/,=U/} +1451375629 1546506610 0 f {bar=X/,foo=X/} + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR ALL ON TABLES FROM foo, bar; +ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR ALL ON TYPES FROM foo, bar; +ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR ALL ON SCHEMAS FROM foo, bar; +ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR ALL ON SEQUENCES FROM foo, bar; +ALTER DEFAULT PRIVILEGES REVOKE GRANT OPTION FOR ALL ON FUNCTIONS FROM foo, bar; + +# Not supported by Materialize. +onlyif cockroach +query OOOTT colnames,rowsort +SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL +---- +oid defaclrole defaclnamespace defaclobjtype defaclacl +1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 S {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 T {bar=U/,foo=U/} +1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/} +1451375629 1546506610 0 f {bar=X/,foo=X/} + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT foo, bar TO root; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar GRANT ALL ON TABLES TO foo, bar WITH GRANT OPTION; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar GRANT ALL ON TYPES TO foo, bar WITH GRANT OPTION; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar GRANT ALL ON SCHEMAS TO foo, bar WITH GRANT OPTION; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar GRANT ALL ON SEQUENCES TO foo, bar WITH GRANT OPTION; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar GRANT ALL ON FUNCTIONS TO foo, bar WITH GRANT OPTION; + +# Not supported by Materialize. +onlyif cockroach +# 12 rows should exist, 4 for each role, root, foo and bar. +query OOOTT colnames,rowsort +SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL +---- +oid defaclrole defaclnamespace defaclobjtype defaclacl +97389596 1791217281 0 r {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/} +97389596 1791217281 0 S {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/} +97389596 1791217281 0 T {bar=U*/,foo=U*/,=U/} +97389596 1791217281 0 n {bar=C*U*/,foo=C*U*/} +97389596 1791217281 0 f {bar=X*/,foo=X*/} +3755498903 2026795574 0 r {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/} +3755498903 2026795574 0 S {bar=C*a*d*r*w*/,foo=C*a*d*r*w*/} +3755498903 2026795574 0 T {bar=U*/,foo=U*/,=U/} +3755498903 2026795574 0 n {bar=C*U*/,foo=C*U*/} +3755498903 2026795574 0 f {bar=X*/,foo=X*/} +1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 S {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 T {bar=U/,foo=U/} +1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/} +1451375629 1546506610 0 f {bar=X/,foo=X/} + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar REVOKE ALL ON TABLES FROM foo, bar; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar REVOKE ALL ON TYPES FROM foo, bar; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar REVOKE ALL ON SCHEMAS FROM foo, bar; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar REVOKE ALL ON SEQUENCES FROM foo, bar; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar REVOKE ALL ON FUNCTIONS FROM foo, bar; + +# Not supported by Materialize. +onlyif cockroach +# Revoking all will result in rows with empty privileges since the privileges +# are revoked from the creator role. +query OOOTT colnames,rowsort +SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL +---- +oid defaclrole defaclnamespace defaclobjtype defaclacl +97389596 1791217281 0 r {} +97389596 1791217281 0 S {} +97389596 1791217281 0 T {=U/} +97389596 1791217281 0 n {} +97389596 1791217281 0 f {} +3755498903 2026795574 0 r {} +3755498903 2026795574 0 S {} +3755498903 2026795574 0 T {=U/} +3755498903 2026795574 0 n {} +3755498903 2026795574 0 f {} +1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 S {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 T {bar=U/,foo=U/} +1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/} +1451375629 1546506610 0 f {bar=X/,foo=X/} + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE foo GRANT ALL ON TABLES TO foo; +ALTER DEFAULT PRIVILEGES FOR ROLE foo GRANT ALL ON SEQUENCES TO foo; +ALTER DEFAULT PRIVILEGES FOR ROLE foo GRANT ALL ON SCHEMAS TO foo; +ALTER DEFAULT PRIVILEGES FOR ROLE foo GRANT ALL ON TYPES TO foo; +ALTER DEFAULT PRIVILEGES FOR ROLE foo GRANT ALL ON FUNCTIONS TO foo; +ALTER DEFAULT PRIVILEGES FOR ROLE bar GRANT ALL ON TABLES TO bar; +ALTER DEFAULT PRIVILEGES FOR ROLE bar GRANT ALL ON SEQUENCES TO bar; +ALTER DEFAULT PRIVILEGES FOR ROLE bar GRANT ALL ON SCHEMAS TO bar; +ALTER DEFAULT PRIVILEGES FOR ROLE bar GRANT ALL ON TYPES TO bar; +ALTER DEFAULT PRIVILEGES FOR ROLE bar GRANT ALL ON FUNCTIONS TO bar; + +# Not supported by Materialize. +onlyif cockroach +# remove this block once the GRANT privilege is removed in 22.2 +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE foo REVOKE GRANT OPTION FOR ALL ON TABLES FROM foo; +ALTER DEFAULT PRIVILEGES FOR ROLE foo REVOKE GRANT OPTION FOR ALL ON SEQUENCES FROM foo; +ALTER DEFAULT PRIVILEGES FOR ROLE foo REVOKE GRANT OPTION FOR ALL ON SCHEMAS FROM foo; +ALTER DEFAULT PRIVILEGES FOR ROLE foo REVOKE GRANT OPTION FOR ALL ON TYPES FROM foo; +ALTER DEFAULT PRIVILEGES FOR ROLE foo REVOKE GRANT OPTION FOR ALL ON FUNCTIONS FROM foo; +ALTER DEFAULT PRIVILEGES FOR ROLE bar REVOKE GRANT OPTION FOR ALL ON TABLES FROM bar; +ALTER DEFAULT PRIVILEGES FOR ROLE bar REVOKE GRANT OPTION FOR ALL ON SEQUENCES FROM bar; +ALTER DEFAULT PRIVILEGES FOR ROLE bar REVOKE GRANT OPTION FOR ALL ON SCHEMAS FROM bar; +ALTER DEFAULT PRIVILEGES FOR ROLE bar REVOKE GRANT OPTION FOR ALL ON TYPES FROM bar; +ALTER DEFAULT PRIVILEGES FOR ROLE bar REVOKE GRANT OPTION FOR ALL ON FUNCTIONS FROM bar; + +# Not supported by Materialize. +onlyif cockroach +# Entries should disappear since the previous ALTER DEFAULT PRIVILEGE commands +# revert the default privileges to the default state. +query OOOTT colnames,rowsort +SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL +---- +oid defaclrole defaclnamespace defaclobjtype defaclacl +1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 S {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 T {bar=U/,foo=U/} +1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/} +1451375629 1546506610 0 f {bar=X/,foo=X/} + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE foo GRANT USAGE ON TYPES TO foo WITH GRANT OPTION + +# Not supported by Materialize. +onlyif cockroach +# foo should show up in the table since it got modified +query OOOTT colnames,rowsort +SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL +---- +oid defaclrole defaclnamespace defaclobjtype defaclacl +3755498903 2026795574 0 T {foo=U*/,=U/} +1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 S {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 T {bar=U/,foo=U/} +1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/} +1451375629 1546506610 0 f {bar=X/,foo=X/} + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE foo REVOKE GRANT OPTION FOR USAGE ON TYPES FROM foo + +# Not supported by Materialize. +onlyif cockroach +# foo should disappear since it's back in the "default state" +query OOOTT colnames,rowsort +SELECT * FROM PG_CATALOG.PG_DEFAULT_ACL +---- +oid defaclrole defaclnamespace defaclobjtype defaclacl +1451375629 1546506610 0 r {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 S {bar=Cadrw/,foo=Cadrw/,=r/} +1451375629 1546506610 0 T {bar=U/,foo=U/} +1451375629 1546506610 0 n {bar=CU/,foo=CU/,=U/} +1451375629 1546506610 0 f {bar=X/,foo=X/} diff --git a/test/sqllogictest/cockroach/pg_extension.slt b/test/sqllogictest/cockroach/pg_extension.slt new file mode 100644 index 0000000000000..79cbcbdaf2cfe --- /dev/null +++ b/test/sqllogictest/cockroach/pg_extension.slt @@ -0,0 +1,116 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/pg_extension +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE pg_extension_test ( + a geography(point, 4326), + b geometry(polygon, 3857), + c geometry, + d geography, + az geography(pointz, 4326), + bz geometry(polygonz, 3857), + am geography(pointm, 4326), + bm geometry(polygonm, 3857), + azm geography(pointzm, 4326), + bzm geometry(polygonzm, 3857) +) + +# Not supported by Materialize. +onlyif cockroach +query TTTTIIT rowsort +SELECT * FROM pg_extension.geography_columns WHERE f_table_name = 'pg_extension_test' +---- +test public pg_extension_test a 2 4326 Point +test public pg_extension_test d NULL 0 Geometry +test public pg_extension_test az 3 4326 PointZ +test public pg_extension_test am 3 4326 PointM +test public pg_extension_test azm 4 4326 PointZM + +# Not supported by Materialize. +onlyif cockroach +query TTTTIIT rowsort +SELECT * FROM pg_extension.geometry_columns WHERE f_table_name = 'pg_extension_test' +---- +test public pg_extension_test b 2 3857 POLYGON +test public pg_extension_test c 2 0 GEOMETRY +test public pg_extension_test bz 3 3857 POLYGON +test public pg_extension_test bm 3 3857 POLYGON +test public pg_extension_test bzm 4 3857 POLYGON + +# Not supported by Materialize. +onlyif cockroach +query TTTTIIT rowsort +SELECT * FROM geography_columns WHERE f_table_name = 'pg_extension_test' +---- +test public pg_extension_test a 2 4326 Point +test public pg_extension_test d NULL 0 Geometry +test public pg_extension_test az 3 4326 PointZ +test public pg_extension_test am 3 4326 PointM +test public pg_extension_test azm 4 4326 PointZM + +# Not supported by Materialize. +onlyif cockroach +query TTTTIIT rowsort +SELECT * FROM geometry_columns WHERE f_table_name = 'pg_extension_test' +---- +test public pg_extension_test b 2 3857 POLYGON +test public pg_extension_test c 2 0 GEOMETRY +test public pg_extension_test bz 3 3857 POLYGON +test public pg_extension_test bm 3 3857 POLYGON +test public pg_extension_test bzm 4 3857 POLYGON + +# Not supported by Materialize. +onlyif cockroach +query ITITT +SELECT * FROM pg_extension.spatial_ref_sys WHERE srid IN (3857, 4326) ORDER BY srid ASC +---- +3857 EPSG 3857 PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],AUTHORITY["EPSG","3857"]] +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +4326 EPSG 4326 GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] +proj=longlat +datum=WGS84 +no_defs + +# Not supported by Materialize. +onlyif cockroach +query ITITT +SELECT * FROM spatial_ref_sys WHERE srid IN (3857, 4326) ORDER BY srid ASC +---- +3857 EPSG 3857 PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],AUTHORITY["EPSG","3857"]] +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +4326 EPSG 4326 GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] +proj=longlat +datum=WGS84 +no_defs + +# Not supported by Materialize. +onlyif cockroach +# pg_extension is explicitly disallowed for use with the anonymous database. +query error cannot access virtual schema in anonymous database +SELECT f_table_name FROM "".pg_extension.geometry_columns + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET DATABASE = ""; + +query error unknown schema 'pg_extension' +SELECT f_table_name FROM pg_extension.geometry_columns + +statement ok +SET DATABASE = test; diff --git a/test/sqllogictest/cockroach/pgcrypto_builtins.slt b/test/sqllogictest/cockroach/pgcrypto_builtins.slt new file mode 100644 index 0000000000000..07df5f8977a10 --- /dev/null +++ b/test/sqllogictest/cockroach/pgcrypto_builtins.slt @@ -0,0 +1,346 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/pgcrypto_builtins +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +subtest digest + +# Not supported by Materialize. +onlyif cockroach +# NB: CockroachDB currently differs from Postgres, since the shaX functions +# return a string in CockroachDB, while Postgres returns bytea. +query BTT +SELECT + encode(digest('abc', alg), 'hex') = expected, digest(NULL, alg), digest('abc', NULL) +FROM + ( + VALUES + ('md5', md5('abc')), + ('sha1', sha1('abc')), + ('sha224', sha224('abc')), + ('sha256', sha256('abc')), + ('sha384', sha384('abc')), + ('sha512', sha512('abc')) + ) + AS v (alg, expected); +---- +true NULL NULL +true NULL NULL +true NULL NULL +true NULL NULL +true NULL NULL +true NULL NULL + +query T +SELECT digest(NULL, 'made up alg') +---- +NULL + +statement error pgcode 22023 invalid hash algorithm 'made up alg' +SELECT digest('cat', 'made up alg') + +subtest end + +subtest hmac + +# NB: These results were manually confirmed to match the hashed values +# created by Postgres. +query T +SELECT encode(hmac('abc', 'key', alg), 'hex') +FROM (VALUES ('md5'), ('sha1'), ('sha224'), ('sha256'), ('sha384'), ('sha512')) v(alg) +---- +d2fe98063f876b03193afb49b4979591 +4fd0b215276ef12f2b3e4c8ecac2811498b656fc +f524670b7e34f31467de0aa96593861cf65117d414fb2d86158d760e +9c196e32dc0175f86f4b1cb89289d6619de6bee699e4c378e68309ed97a1a6ab +30ddb9c8f347cffbfb44e519d814f074cf4047a55d6f563324f1c6a33920e5edfb2a34bac60bdc96cd33a95623d7d638 +3926a207c8c42b0c41792cbd3e1a1aaaf5f7a25704f62dfc939c4987dd7ce060009c5bb1c2447355b3216f10b537e9afa7b64a4e5391b0d631172d07939e087a + +query TTT +SELECT hmac('abc', 'key', NULL), hmac('abc', NULL, 'made up alg'), hmac(NULL, 'key', 'sha256') +---- +NULL NULL NULL + +statement error pgcode 22023 invalid hash algorithm 'made up alg' +SELECT hmac('dog', 'key', 'made up alg') + +subtest end + +subtest gen_random_uuid + +# Not supported by Materialize. +onlyif cockroach +query IB +SELECT length(gen_random_uuid()::BYTES), gen_random_uuid() = gen_random_uuid() +---- +16 false + +subtest end + +subtest gen_salt_invalid_algo + +statement error pgcode 22023 function "gen_salt" does not exist +SELECT gen_salt('invalid') + +statement error pgcode 22023 function "gen_salt" does not exist +SELECT gen_salt('invalid', 0) + +subtest end + +subtest gen_salt_des + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT char_length(gen_salt('des')) +---- +2 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT char_length(gen_salt('des', rounds)) +FROM (VALUES (0), (25)) AS t (rounds) +---- +2 +2 + +# invalid rounds +statement error pgcode 22023 function "gen_salt" does not exist +SELECT gen_salt('des', 1) + +subtest end + +subtest gen_salt_xdes + +# Not supported by Materialize. +onlyif cockroach +query TI +SELECT substr(salt, 1, 5), char_length(salt) +FROM (SELECT gen_salt('xdes') AS salt) +---- +_J9.. 9 + +# Not supported by Materialize. +onlyif cockroach +query TI +SELECT substr(salt, 1, 5), char_length(salt) +FROM (SELECT gen_salt('xdes', rounds) AS salt FROM (VALUES (0), (1), (16777215)) AS t (rounds)) +---- +_J9.. 9 +_/... 9 +_zzzz 9 + +# invalid even rounds +statement error pgcode 22023 function "gen_salt" does not exist +SELECT gen_salt('xdes', 2) + +# invalid min rounds +statement error pgcode 22023 function "gen_salt" does not exist +SELECT gen_salt('xdes', -1) + +# invalid max rounds +statement error pgcode 22023 function "gen_salt" does not exist +SELECT gen_salt('xdes', 16777216) + +subtest end + +subtest gen_salt_md5 + +# Not supported by Materialize. +onlyif cockroach +query TI +SELECT substr(salt, 1, 3), char_length(salt) +FROM (SELECT gen_salt('md5') AS salt) +---- +$1$ 11 + +# Not supported by Materialize. +onlyif cockroach +query TI +SELECT substr(salt, 1, 3), char_length(salt) +FROM (SELECT gen_salt('md5', rounds) AS salt FROM (VALUES (0), (1000)) AS t (rounds)) +---- +$1$ 11 +$1$ 11 + +# invalid rounds +statement error pgcode 22023 function "gen_salt" does not exist +SELECT gen_salt('md5', 1) + +subtest end + +subtest gen_salt_bf + +# Not supported by Materialize. +onlyif cockroach +query TI +SELECT substr(salt, 1, 7), char_length(salt) +FROM (SELECT gen_salt('bf', rounds) AS salt FROM (VALUES (0), (4), (31)) AS t (rounds)) +---- +$2a$06$ 29 +$2a$04$ 29 +$2a$31$ 29 + +# invalid min rounds +statement error pgcode 22023 function "gen_salt" does not exist +SELECT gen_salt('bf', 3) + +# invalid max rounds +statement error pgcode 22023 function "gen_salt" does not exist +SELECT gen_salt('bf', 32) + +subtest crypt_invalid_algo + +# invalid header +statement error pgcode 22023 function "crypt" does not exist +SELECT crypt('password', '') + +# invalid header +statement error pgcode 22023 function "crypt" does not exist +SELECT crypt('password', '$') + +subtest end + +subtest crypt_md5 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crypt(password, '$1$aRnqRmeP') +FROM (VALUES + (''), + ('0'), + ('password'), + (repeat('a', 50)) +) AS t (password) +---- +$1$aRnqRmeP$.GKS2A8uOS7cKSGtb33BL0 +$1$aRnqRmeP$zSsYGTxby0DLjRezdRBT50 +$1$aRnqRmeP$79.GOqWdD1jolSFx6PGg5. +$1$aRnqRmeP$Qtrye90cHoHamBO08sQKC1 + +# Not supported by Materialize. +onlyif cockroach +# salt is truncated to 11 chars +query TB +SELECT hash1, hash1 = hash2 +FROM (SELECT + crypt('password', '$1$aRnqRmeP') as hash1, + crypt('password', '$1$aRnqRmePextra') as hash2 +) as t +---- +$1$aRnqRmeP$79.GOqWdD1jolSFx6PGg5. true + +# Not supported by Materialize. +onlyif cockroach +# random salt can be less than 8 characters +query T +SELECT crypt('password', '$1$') +---- +$1$$I2o9Z7NcvQAKp7wyCTlia0 + +subtest end + +subtest crypt_bf + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crypt(password, '$2a$06$Ukv6DxN3PpZo4YboQRrIVO') +FROM (VALUES + (''), + ('0'), + ('password'), + (repeat('a', 50)) +) AS t (password) +---- +$2a$06$Ukv6DxN3PpZo4YboQRrIVOXwHbf79QsnJ4GoQyYv5vZozGSILtNUu +$2a$06$Ukv6DxN3PpZo4YboQRrIVOBxB6sdGuSnn.PViRLXxUFUiihB30ukm +$2a$06$Ukv6DxN3PpZo4YboQRrIVO6UrBIvyPUuhsGQvYZyAvmsIjt02Ze3O +$2a$06$Ukv6DxN3PpZo4YboQRrIVO9DZGS27nWDW5eSzsL/ckOByIGwpxf0a + +# Not supported by Materialize. +onlyif cockroach +# password is truncated to 72 chars +query TBB +SELECT hash72, hash71 != hash72, hash72 = hash73 +FROM (SELECT + crypt(repeat('a', 71), salt) as hash71, + crypt(repeat('a', 72), salt) as hash72, + crypt(repeat('a', 73), salt) as hash73 + FROM (SELECT '$2a$06$Ukv6DxN3PpZo4YboQRrIVO' as salt) as s +) as t +---- +$2a$06$Ukv6DxN3PpZo4YboQRrIVOIQPDI39RHxEgW32.ICmqRFFBxkR8ddC true true + +# Not supported by Materialize. +onlyif cockroach +# salt is truncated to 29 chars +query TB +SELECT hash1, hash1 = hash2 +FROM (SELECT + crypt('password', '$2a$06$Ukv6DxN3PpZo4YboQRrIVO') as hash1, + crypt('password', '$2a$06$Ukv6DxN3PpZo4YboQRrIVOextra') as hash2 +) as t +---- +$2a$06$Ukv6DxN3PpZo4YboQRrIVO6UrBIvyPUuhsGQvYZyAvmsIjt02Ze3O true + +# Not supported by Materialize. +onlyif cockroach +# test min and average num rounds (large num rounds take too long to run for a test) +query T +SELECT crypt('password', concat('$2a$', rounds, '$Ukv6DxN3PpZo4YboQRrIVO')) +FROM (VALUES ('04'), ('10')) AS t (rounds) +---- +$2a$04$Ukv6DxN3PpZo4YboQRrIVOSgyjUD9vDt2W.RjRVhm7XC2QTQrtLSK +$2a$10$Ukv6DxN3PpZo4YboQRrIVOwLm63.TplP3REdrq258BBo3lUBnEbrm + +# invalid salt length +statement error pgcode 22023 function "crypt" does not exist +SELECT crypt('password', '$2a$06$') + +# invalid salt length +statement error pgcode 22023 function "crypt" does not exist +SELECT crypt('password', '$2a$06$Ukv6DxN3PpZo4YboQRrIV') + +# invalid round syntax +statement error pgcode 22023 function "crypt" does not exist +SELECT crypt('password', '$2a$AA$Ukv6DxN3PpZo4YboQRrIVO') + +# invalid min rounds +statement error pgcode 22023 function "crypt" does not exist +SELECT crypt('password', '$2a$03$Ukv6DxN3PpZo4YboQRrIVO') + +# invalid max rounds +statement error pgcode 22023 function "crypt" does not exist +SELECT crypt('password', '$2a$32$Ukv6DxN3PpZo4YboQRrIVO') + +# invalid salt formatting +statement error pgcode 22023 function "crypt" does not exist +SELECT crypt('password', '$2a$06AUkv6DxN3PpZo4YboQRrIVO') + +# invalid salt encoding +statement error pgcode 22023 function "crypt" does not exist +SELECT crypt('password', '$2a$06$#kv6DxN3PpZo4YboQRrIVO') + +subtest end diff --git a/test/sqllogictest/cockroach/pgoidtype.slt b/test/sqllogictest/cockroach/pgoidtype.slt index afb53ec2fdcd3..1f5434859ddb2 100644 --- a/test/sqllogictest/cockroach/pgoidtype.slt +++ b/test/sqllogictest/cockroach/pgoidtype.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/pgoidtype +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/pgoidtype # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - query OO SELECT 3::OID, '3'::OID ---- @@ -34,43 +32,68 @@ SELECT 3::OID::INT::OID ---- 3 -# The rest of this file is not yet supported. -halt - -query OOOOOO -SELECT 1::OID, 1::REGCLASS, 1::REGNAMESPACE, 1::REGPROC, 1::REGPROCEDURE, 1::REGTYPE +# Not supported by Materialize. +onlyif cockroach +query OOOOOOO +SELECT 1::OID, 1::REGCLASS, 1::REGNAMESPACE, 1::REGPROC, 1::REGPROCEDURE, 1::REGROLE, 1::REGTYPE ---- -1 1 1 1 1 1 +1 1 1 array_agg array_agg 1 1 -query OOOOO -SELECT 1::OID::REGCLASS, 1::OID::REGNAMESPACE, 1::OID::REGPROC, 1::OID::REGPROCEDURE, 1::OID::REGTYPE +# Not supported by Materialize. +onlyif cockroach +query OOOOOO +SELECT 1::OID::REGCLASS, 1::OID::REGNAMESPACE, 1::OID::REGPROC, 1::OID::REGPROCEDURE, 1::OID::REGROLE, 1::OID::REGTYPE ---- -1 1 1 1 1 +1 1 array_agg array_agg 1 1 +# Not supported by Materialize. +onlyif cockroach query TTT SELECT pg_typeof(1::OID), pg_typeof(1::REGCLASS), pg_typeof(1::REGNAMESPACE) ---- oid regclass regnamespace -query TTT -SELECT pg_typeof(1::REGPROC), pg_typeof(1::REGPROCEDURE), pg_typeof(1::REGTYPE) +# Not supported by Materialize. +onlyif cockroach +query TTTT +SELECT pg_typeof(1::REGPROC), pg_typeof(1::REGPROCEDURE), pg_typeof(1::REGROLE), pg_typeof(1::REGTYPE) ---- -regproc regprocedure regtype +regproc regprocedure regrole regtype +# Not supported by Materialize. +onlyif cockroach query TTT SELECT pg_typeof('1'::OID), pg_typeof('pg_constraint'::REGCLASS), pg_typeof('public'::REGNAMESPACE) ---- oid regclass regnamespace -query TTT -SELECT pg_typeof('upper'::REGPROC), pg_typeof('upper'::REGPROCEDURE), pg_typeof('bool'::REGTYPE) +statement error string is not a valid identifier: "upper\(string\)" +SELECT 'upper(string)'::REGPROC + +statement error type "regprocedure" does not exist +SELECT 'upper'::REGPROCEDURE + +statement error type "regprocedure" does not exist +SELECT 'upper(int)'::REGPROCEDURE + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT pg_typeof('upper'::REGPROC), pg_typeof('upper(string)'::REGPROCEDURE) ---- -regproc regprocedure regtype +regproc regprocedure + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT pg_typeof('root'::REGROLE), pg_typeof('bool'::REGTYPE) +---- +regrole regtype query OO SELECT 'pg_constraint'::REGCLASS, 'pg_catalog.pg_constraint'::REGCLASS ---- -pg_constraint pg_constraint +16846 16846 query error pgcode 42P01 relation "foo.pg_constraint" does not exist SELECT 'foo.pg_constraint'::REGCLASS @@ -78,141 +101,225 @@ SELECT 'foo.pg_constraint'::REGCLASS query OO SELECT '"pg_constraint"'::REGCLASS, ' "pg_constraint" '::REGCLASS ---- -pg_constraint pg_constraint +16846 16846 query OO SELECT 'pg_constraint '::REGCLASS, ' pg_constraint '::REGCLASS ---- -pg_constraint pg_constraint +16846 16846 +# This weird form is to avoid making the test depend on the concrete value of +# the pg_constraint table id. query OO -SELECT 'pg_constraint '::REGCLASS, '"pg_constraint"'::REGCLASS::OID +SELECT 'pg_constraint '::REGCLASS, ('"pg_constraint"'::REGCLASS::OID::INT-'"pg_constraint"'::REGCLASS::OID::INT)::OID ---- -pg_constraint 4294967232 +16846 0 query O SELECT 4061301040::REGCLASS ---- 4061301040 +# Not supported by Materialize. +onlyif cockroach query OOIOT -SELECT oid, oid::regclass, oid::regclass::int, oid::regclass::int::regclass, oid::regclass::text +SELECT (oid::int-oid::int)::oid, oid::regclass, (oid::regclass::int-oid::regclass::int), oid::regclass::int::regclass, oid::regclass::text FROM pg_class WHERE relname = 'pg_constraint' ---- -4294967232 pg_constraint 4294967232 pg_constraint pg_constraint +0 pg_constraint 0 pg_constraint pg_constraint +# Not supported by Materialize. +onlyif cockroach query OOOO -SELECT 'upper'::REGPROC, 'upper'::REGPROCEDURE, 'pg_catalog.upper'::REGPROCEDURE, 'upper'::REGPROC::OID +SELECT 'upper'::REGPROC, 'upper(string)'::REGPROCEDURE, 'pg_catalog.upper(string)'::REGPROCEDURE, 'upper'::REGPROC::OID ---- -upper upper upper 3615042040 +upper upper upper 829 -query error invalid function name +query error type "regprocedure" does not exist SELECT 'invalid.more.pg_catalog.upper'::REGPROCEDURE +# Not supported by Materialize. +onlyif cockroach query OOO -SELECT 'upper(int)'::REGPROC, 'upper(int)'::REGPROCEDURE, 'upper(int)'::REGPROC::OID +SELECT 'upper'::REGPROC, 'upper(string)'::REGPROCEDURE, 'upper'::REGPROC::OID ---- -upper upper 3615042040 +upper upper 829 + +query error string is not a valid identifier: "blah\(ignored\)" +SELECT 'blah(ignored)'::REGPROC -query error unknown function: blah\(\) -SELECT 'blah(ignored, ignored)'::REGPROC, 'blah(ignored, ignored)'::REGPROCEDURE +query error type "regprocedure" does not exist +SELECT 'blah(int, int)'::REGPROCEDURE -query error unknown function: blah\(\) +query error string is not a valid identifier: " blah \( ignored , ignored \) " SELECT ' blah ( ignored , ignored ) '::REGPROC -query error unknown function: blah\(\) +query error string is not a valid identifier: "blah \(\)" SELECT 'blah ()'::REGPROC -query error unknown function: blah\(\) +query error string is not a valid identifier: "blah\( \)" SELECT 'blah( )'::REGPROC -query error unknown function: blah\(, \)\(\) +query error string is not a valid identifier: "blah\(, \)" SELECT 'blah(, )'::REGPROC -query error more than one function named 'sqrt' +query error more than one function named "sqrt" SELECT 'sqrt'::REGPROC -query OOOO -SELECT 'array_in'::REGPROC, 'array_in(a,b,c)'::REGPROC, 'pg_catalog.array_in'::REGPROC, 'pg_catalog.array_in( a ,b, c )'::REGPROC +query OO +SELECT 'array_in'::REGPROC, 'pg_catalog.array_in'::REGPROC ---- -array_in array_in array_in array_in +750 750 -query OOOO -SELECT 'array_in'::REGPROCEDURE, 'array_in(a,b,c)'::REGPROCEDURE, 'pg_catalog.array_in'::REGPROCEDURE, 'pg_catalog.array_in( a ,b, c )'::REGPROCEDURE +# Not supported by Materialize. +onlyif cockroach +query OO +SELECT 'array_in(int)'::REGPROCEDURE, 'pg_catalog.array_in(int)'::REGPROCEDURE ---- -array_in array_in array_in array_in +array_in array_in +# Not supported by Materialize. +onlyif cockroach query OO SELECT 'public'::REGNAMESPACE, 'public'::REGNAMESPACE::OID ---- -public 3426283741 +public 105 + +# Not supported by Materialize. +onlyif cockroach +query OO +SELECT 'root'::REGROLE, 'root'::REGROLE::OID +---- +root 1546506610 query OO SELECT 'bool'::REGTYPE, 'bool'::REGTYPE::OID ---- -boolean 16 +16 16 +# Not supported by Materialize. +onlyif cockroach query OO SELECT 'numeric(10,3)'::REGTYPE, 'numeric( 10, 3 )'::REGTYPE ---- numeric numeric -query error type 'foo.' does not exist +query OO +SELECT '"char"'::REGTYPE, 'pg_catalog.int4'::REGTYPE +---- +18 23 + +query error string is not a valid identifier: "foo\." SELECT 'foo.'::REGTYPE query error pgcode 42P01 relation "blah" does not exist SELECT 'blah'::REGCLASS -query error unknown function: blah\(\) +query error pgcode 42883 function "blah" does not exist SELECT 'blah'::REGPROC -query error unknown function: blah\(\) -SELECT 'blah'::REGPROCEDURE +query error pgcode 42883 type "regprocedure" does not exist +SELECT 'blah()'::REGPROCEDURE -query error namespace 'blah' does not exist +query error pgcode 42704 type "regnamespace" does not exist SELECT 'blah'::REGNAMESPACE -query error type 'blah' does not exist +query error pgcode 42704 type "regrole" does not exist +SELECT 'blah'::REGROLE + +query error pgcode 42704 type "blah" does not exist SELECT 'blah'::REGTYPE +query error pgcode 42704 type "pg_catalog\.int" does not exist +SELECT 'pg_catalog.int'::REGTYPE + ## Test other cast syntaxes query O SELECT CAST ('pg_constraint' AS REGCLASS) ---- -pg_constraint +16846 # This forces the b_expr form of the cast syntax. query OO -SELECT ('pg_constraint')::REGCLASS, ('pg_constraint')::REGCLASS::OID +SELECT ('pg_constraint')::REGCLASS, (('pg_constraint')::REGCLASS::OID::INT-('pg_constraint')::REGCLASS::OID::INT)::OID ---- -pg_constraint 4294967232 +16846 0 ## Test visibility of pg_* via oid casts. +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE a (id INT PRIMARY KEY) +CREATE TABLE a (id INT PRIMARY KEY); +CREATE TYPE typ AS ENUM ('a') + +let $table_oid +SELECT c.oid FROM pg_class c WHERE c.relname = 'a'; + +# Not supported by Materialize. +onlyif cockroach +query O +SELECT $table_oid::oid::regclass +---- +a +let $type_oid +SELECT t.oid FROM pg_type t WHERE t.typname = 'typ'; + +# Not supported by Materialize. +onlyif cockroach +query O +SELECT $type_oid::oid::regtype +---- +typ + +# Not supported by Materialize. +onlyif cockroach query T SELECT relname from pg_class where oid='a'::regclass ---- a -## Regression for materialize#16767 - ensure regclass casts use normalized table names +# Not supported by Materialize. +onlyif cockroach +query T +SELECT typname from pg_type where oid='typ'::regtype +---- +typ + +## Regression for #16767 - ensure regclass casts use normalized table names +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE hasCase (id INT PRIMARY KEY) +CREATE TABLE hasCase (id INT PRIMARY KEY); +CREATE TYPE typHasCase AS ENUM ('a') +# Not supported by Materialize. +onlyif cockroach query T SELECT relname from pg_class where oid='hasCase'::regclass ---- hascase +# Not supported by Materialize. +onlyif cockroach +query T +SELECT typname from pg_type where oid='typHasCase'::regtype +---- +typhascase + statement ok CREATE TABLE "quotedCase" (id INT PRIMARY KEY) -query error pgcode 42P01 relation "quotedcase" does not exist +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE "typQuotedCase" AS ENUM ('a') + +query error pgcode 42P01 relation "quotedCase" does not exist SELECT relname from pg_class where oid='quotedCase'::regclass query T @@ -220,28 +327,51 @@ SELECT relname from pg_class where oid='"quotedCase"'::regclass ---- quotedCase -# a non-root user with sufficient permissions can get the OID of a table from -# the current database +query error pgcode 42704 type "typQuotedCase" does not exist +SELECT typname from pg_type where oid='typQuotedCase'::regtype + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT typname from pg_type where oid='"typQuotedCase"'::regtype +---- +typQuotedCase + +# a non-root user with sufficient permissions can get the OID of a table or +# type from the current database +# Not supported by Materialize. +onlyif cockroach statement ok GRANT ALL ON DATABASE test TO testuser +# Not supported by Materialize. +onlyif cockroach statement ok GRANT SELECT ON test.* TO testuser user testuser +# Not supported by Materialize. +onlyif cockroach query T SELECT relname from pg_class where oid='a'::regclass ---- a +# Not supported by Materialize. +onlyif cockroach +query T +SELECT typname from pg_type where oid='typ'::regtype +---- +typ + user root statement ok CREATE DATABASE otherdb -## a non-root user can't get the OID of a table from a different database +## a non-root user can't get the OID of a table or type from a different database user testuser @@ -251,34 +381,65 @@ SET DATABASE = otherdb query error pgcode 42P01 relation "a" does not exist SELECT 'a'::regclass +query error pgcode 42704 type "typ" does not exist +SELECT 'typ'::regtype + user root statement ok SET DATABASE = otherdb +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE a (id INT PRIMARY KEY, foo STRING) +CREATE TABLE a (id INT PRIMARY KEY, foo STRING); +CREATE TYPE typ AS ENUM ('a', 'b') ## There is now a table named 'a' in both the database 'otherdb' and the ## database 'test'. The following query shows that the root user can still ## determine the OID of the table 'a' by using a regclass cast, despite the ## fact that the root user has visibility into both of the tables. The 'a' that ## gets selected should be the 'a' that exists in the current database. +## The same exact reasoning applies to the type named 'typ'. ## See https://github.com/cockroachdb/cockroach/issues/13695 +# Not supported by Materialize. +onlyif cockroach query OI SELECT relname, relnatts FROM pg_class WHERE oid='a'::regclass ---- a 2 +# Not supported by Materialize. +onlyif cockroach +query OI +SELECT t.typname, count(*) FROM pg_type t +LEFT JOIN pg_enum e ON t.oid = e.enumtypid +WHERE t.oid = 'typ'::regtype +GROUP BY t.typname; +---- +typ 2 + statement ok SET DATABASE = test +# Not supported by Materialize. +onlyif cockroach query OI SELECT relname, relnatts FROM pg_class WHERE oid='a'::regclass ---- a 1 +# Not supported by Materialize. +onlyif cockroach +query OI +SELECT t.typname, count(*) FROM pg_type t +LEFT JOIN pg_enum e ON t.oid = e.enumtypid +WHERE t.oid = 'typ'::regtype +GROUP BY t.typname; +---- +typ 1 + statement ok CREATE DATABASE thirddb @@ -292,6 +453,12 @@ SET DATABASE = thirddb query error pgcode 42P01 relation "a" does not exist SELECT relname, relnatts FROM pg_class WHERE oid='a'::regclass +query error pgcode 42704 type "typ" does not exist +SELECT t.typname, count(*) FROM pg_type t +LEFT JOIN pg_enum e ON t.oid = e.enumtypid +WHERE t.oid = 'typ'::regtype +GROUP BY t.typname; + statement ok CREATE TABLE o (a OID PRIMARY KEY) @@ -309,27 +476,349 @@ SELECT * FROM o WHERE a <= 4 1 4 -# Regression test for materialize#23652. +# Regression test for #23652. +# Not supported by Materialize. +onlyif cockroach query B SELECT NOT (prorettype::regtype::text = 'foo') AND proretset FROM pg_proc WHERE proretset=false LIMIT 1 ---- false -query TTTTT -SELECT crdb_internal.create_regtype(10, 'foo'), crdb_internal.create_regclass(10, 'foo'), crdb_internal.create_regproc(10, 'foo'), crdb_internal.create_regprocedure(10, 'foo'), crdb_internal.create_regnamespace(10, 'foo') +# Not supported by Materialize. +onlyif cockroach +query TTTTTT +SELECT crdb_internal.create_regtype(10, 'foo'), + crdb_internal.create_regclass(10, 'foo'), + crdb_internal.create_regproc(10, 'foo'), + crdb_internal.create_regprocedure(10, 'foo'), + crdb_internal.create_regnamespace(10, 'foo'), + crdb_internal.create_regrole(10, 'foo') ---- -foo foo foo foo foo +foo foo foo foo foo foo -query OOOOO -SELECT crdb_internal.create_regtype(10, 'foo')::oid, crdb_internal.create_regclass(10, 'foo')::oid, crdb_internal.create_regproc(10, 'foo')::oid, crdb_internal.create_regprocedure(10, 'foo')::oid, crdb_internal.create_regnamespace(10, 'foo')::oid +# Not supported by Materialize. +onlyif cockroach +query OOOOOO +SELECT crdb_internal.create_regtype(10, 'foo')::oid, + crdb_internal.create_regclass(10, 'foo')::oid, + crdb_internal.create_regproc(10, 'foo')::oid, + crdb_internal.create_regprocedure(10, 'foo')::oid, + crdb_internal.create_regnamespace(10, 'foo')::oid, + crdb_internal.create_regrole(10, 'foo')::oid ---- -10 10 10 10 10 +10 10 10 10 10 10 -# Regression test for cockroach#32422: ensure that VALUES nodes properly retain special +# Regression test for #32422: ensure that VALUES nodes properly retain special # OID properties. query OO VALUES ('pg_constraint'::REGCLASS, 'pg_catalog.pg_constraint'::REGCLASS) ---- -pg_constraint pg_constraint +16846 16846 + +# Not supported by Materialize. +onlyif cockroach +# Ensure that arrays of reg* types work okay. +query T +SELECT proargtypes::REGTYPE[] FROM pg_proc WHERE proname = 'obj_description' +---- +{oid} +{oid,text} + +# Not supported by Materialize. +onlyif cockroach +# Ensure that you can get a regtype for the trigger type. +query I +SELECT 'trigger'::REGTYPE::INT +---- +0 + +# Regression test for #41708. + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT 1::OID::TEXT, quote_literal(1::OID) +---- +1 '1' + +# Allow INT-OID comparison. Regression test for #53143. +statement ok +SELECT + c.oid, + a.attnum, + a.attname, + c.relname, + n.nspname, + a.attnotnull + OR (t.typtype = 'd' AND t.typnotnull), + pg_catalog.pg_get_expr(d.adbin, d.adrelid) LIKE '%nextval(%' +FROM + pg_catalog.pg_class AS c + JOIN pg_catalog.pg_namespace AS n ON (c.relnamespace = n.oid) + JOIN pg_catalog.pg_attribute AS a ON (c.oid = a.attrelid) + JOIN pg_catalog.pg_type AS t ON (a.atttypid = t.oid) + LEFT JOIN pg_catalog.pg_attrdef AS d ON + (d.adrelid = a.attrelid AND d.adnum = a.attnum) + JOIN (SELECT 1 AS oid, 1 AS attnum) AS vals ON + (c.oid = vals.oid AND a.attnum = vals.attnum); + +statement error string is not a valid identifier: "\\\\"regression_53686\\\\"" +SELECT '\"regression_53686\"'::regclass + +statement ok +CREATE TABLE "regression_53686""" (a int) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT 'regression_53686"'::regclass +---- +"regression_53686""" + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT 'public.regression_53686"'::regclass +---- +"regression_53686""" + +query T +SELECT 'pg_catalog."radians"'::regproc +---- +1609 + +query T +SELECT 'pg_catalog."radians"'::regproc +---- +1609 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT 'pg_catalog."radians"("float4")'::regprocedure +---- +radians + +statement error string is not a valid identifier: "pg_catalog\.\\"radians\\"\\"\\"" +SELECT 'pg_catalog."radians"""'::regproc + +# Not supported by Materialize. +onlyif cockroach +query TTTTT +SELECT + '12345'::regclass::string, + '12345'::regtype::string, + '12345'::oid::string, + '12345'::regproc::string, + '12345'::regprocedure::string +---- +12345 12345 12345 12345 12345 + +# Not supported by Materialize. +onlyif cockroach +query T +PREPARE regression_56193 AS SELECT $1::regclass; +EXECUTE regression_56193('regression_53686"'::regclass) +---- +"regression_53686""" + +query O +SELECT (-1)::OID +---- +4294967295 + +query O +SELECT (-1)::REGPROC +---- +4294967295 + +query O +SELECT (-1)::REGCLASS +---- +4294967295 + +# Test that we can cast a constant directly to regclass. +statement ok +CREATE TABLE regression_62205(a INT PRIMARY KEY) + +let $regression_62205_oid +SELECT 'regression_62205'::regclass::oid + +# Not supported by Materialize. +onlyif cockroach +query O +SELECT $regression_62205_oid::regclass +---- +regression_62205 + +# Check we error as appropriate if the OID type is not legit. +statement error pgcode 22P02 invalid input syntax for type oid: invalid digit found in string: "regression_69907" +SELECT 'regression_69907'::oid + +# Not supported by Materialize. +onlyif cockroach +# 4294967295 is MaxUint32. +# -2147483648 is MinInt32. +query OIBB +SELECT o, i, o > i, i > o FROM (VALUES + (1::oid, 4294967295::int8), + (1::oid, -2147483648::int8), + ((-1)::oid, 4294967295::int8), + ((-1)::oid, -2147483648::int8), + ((-2147483648)::oid, 4294967295::int8), + ((-2147483648)::oid, -2147483648::int8), + (4294967295::oid, 4294967295::int8), + (4294967295::oid, -2147483648::int8) +) tbl(o, i) +---- +1 4294967295 false true +1 -2147483648 false true +4294967295 4294967295 false false +4294967295 -2147483648 true false +2147483648 4294967295 false true +2147483648 -2147483648 false false +4294967295 4294967295 false false +4294967295 -2147483648 true false + +# Not supported by Materialize. +onlyif cockroach +# 4294967296 is (MaxUint32 + 1). +query error OID out of range: 4294967296 +SELECT 1:::OID >= 4294967296:::INT8 + +# Not supported by Materialize. +onlyif cockroach +query error OID out of range: 4294967296 +SELECT 4294967296:::INT8 >= 1:::OID + +# Not supported by Materialize. +onlyif cockroach +# -2147483649 is (MinInt32 - 1). +query error OID out of range: -2147483649 +SELECT 1:::OID >= -2147483649:::INT8 + +# Not supported by Materialize. +onlyif cockroach +query error OID out of range: -2147483649 +SELECT -2147483649:::INT8 >= 1:::OID + +# Test that we can cast index names to a regclass, and vice-versa. + +statement ok +CREATE TABLE table_with_indexes (a INT PRIMARY key, b INT) + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT relname, oid::regclass::string from pg_class where oid='table_with_indexes_pkey'::regclass +---- +table_with_indexes_pkey table_with_indexes_pkey + +statement ok +CREATE INDEX my_b_index ON table_with_indexes(b) + +query TT +SELECT relname, oid::regclass::string from pg_class where oid='my_b_index'::regclass +---- +my_b_index my_b_index + +# Test that we can cast table and index names from different schemas. + +statement ok +CREATE SCHEMA other_schema + +statement ok +CREATE TABLE other_schema.table_with_indexes (a INT PRIMARY key, b INT) + +statement ok +CREATE INDEX my_b_index ON other_schema.table_with_indexes(b) + +query TTT +SELECT c.relname, c.oid::regclass::string, n.nspname from pg_class c +JOIN pg_namespace n ON c.relnamespace = n.oid +WHERE c.oid='other_schema.table_with_indexes'::regclass +---- +table_with_indexes other_schema.table_with_indexes other_schema + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT c.relname, c.oid::regclass::string, n.nspname from pg_class c +JOIN pg_namespace n ON c.relnamespace = n.oid +WHERE c.oid='other_schema.table_with_indexes_pkey'::regclass +---- +table_with_indexes_pkey table_with_indexes_pkey other_schema + +query TTT +SELECT c.relname, c.oid::regclass::string, n.nspname from pg_class c +JOIN pg_namespace n ON c.relnamespace = n.oid +WHERE c.oid='other_schema.my_b_index'::regclass +---- +my_b_index other_schema.my_b_index other_schema + +# Changing the search_path should influence what gets resolved while casting. + +statement ok +SET search_path = other_schema, public + +query TTT +SELECT c.relname, c.oid::regclass::string, n.nspname from pg_class c +JOIN pg_namespace n ON c.relnamespace = n.oid +WHERE c.oid='table_with_indexes'::regclass +---- +table_with_indexes table_with_indexes other_schema + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT c.relname, c.oid::regclass::string, n.nspname from pg_class c +JOIN pg_namespace n ON c.relnamespace = n.oid +WHERE c.oid='table_with_indexes_pkey'::regclass +---- +table_with_indexes_pkey table_with_indexes_pkey other_schema + +query TTT +SELECT c.relname, c.oid::regclass::string, n.nspname from pg_class c +JOIN pg_namespace n ON c.relnamespace = n.oid +WHERE c.oid='my_b_index'::regclass +---- +my_b_index my_b_index other_schema + +statement ok +SET search_path = public, other_schema + +query TTT +SELECT c.relname, c.oid::regclass::string, n.nspname from pg_class c +JOIN pg_namespace n ON c.relnamespace = n.oid +WHERE c.oid='table_with_indexes'::regclass +---- +table_with_indexes table_with_indexes public + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT c.relname, c.oid::regclass::string, n.nspname from pg_class c +JOIN pg_namespace n ON c.relnamespace = n.oid +WHERE c.oid='table_with_indexes_pkey'::regclass +---- +table_with_indexes_pkey table_with_indexes_pkey public + +query TTT +SELECT c.relname, c.oid::regclass::string, n.nspname from pg_class c +JOIN pg_namespace n ON c.relnamespace = n.oid +WHERE c.oid='my_b_index'::regclass +---- +my_b_index my_b_index public + +statement ok +RESET search_path + +# Check that we can cast table names from pg_catalog also. +query TTT +SELECT c.relname, c.oid::regclass::string, n.nspname from pg_class c +JOIN pg_namespace n ON c.relnamespace = n.oid +WHERE c.oid='pg_type'::regclass +---- +pg_type pg_type pg_catalog diff --git a/test/sqllogictest/cockroach/postgres_jsonb.slt b/test/sqllogictest/cockroach/postgres_jsonb.slt index 773f3588ecda6..90bf893b0cc4e 100644 --- a/test/sqllogictest/cockroach/postgres_jsonb.slt +++ b/test/sqllogictest/cockroach/postgres_jsonb.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,12 +9,15 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/postgres_jsonb +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/postgres_jsonb # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach @@ -65,16 +68,6 @@ SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'scalar' ---- NULL -query T -SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'array' ----- -NULL - -query T -SELECT test_json ->> 'field2' FROM test_jsonb WHERE json_type = 'object' ----- -val2 - query T SELECT test_json -> 2 FROM test_jsonb WHERE json_type = 'scalar' ---- diff --git a/test/sqllogictest/cockroach/postgresjoin.slt b/test/sqllogictest/cockroach/postgresjoin.slt index ee64e3c5d8eab..b259ee5d9dddd 100644 --- a/test/sqllogictest/cockroach/postgresjoin.slt +++ b/test/sqllogictest/cockroach/postgresjoin.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,12 +9,15 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/postgresjoin +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/postgresjoin # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach @@ -1872,11 +1875,15 @@ cc 22 2 23 3 dd NULL NULL 33 3 ee 42 2 NULL NULL +# Not supported by Materialize. +onlyif cockroach query TIIIIII rowsort SELECT * FROM (SELECT name, n as s1_n, 1 as s1_1 FROM t1) as s1 NATURAL INNER JOIN (SELECT name, n as s2_n, 2 as s2_2 FROM t2) as s2 NATURAL INNER JOIN (SELECT name, n as s3_n, 3 as s3_2 FROM t3) s3 ---- bb 11 1 12 2 13 3 +# Not supported by Materialize. +onlyif cockroach query TIIIIII rowsort SELECT * FROM (SELECT name, n as s1_n, 1 as s1_1 FROM t1) as s1 NATURAL FULL JOIN (SELECT name, n as s2_n, 2 as s2_2 FROM t2) as s2 NATURAL FULL JOIN (SELECT name, n as s3_n, 3 as s3_2 FROM t3) s3 ---- diff --git a/test/sqllogictest/cockroach/prepare.slt b/test/sqllogictest/cockroach/prepare.slt deleted file mode 100644 index d179b1a046514..0000000000000 --- a/test/sqllogictest/cockroach/prepare.slt +++ /dev/null @@ -1,1042 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/prepare -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -## Tests for ensuring that prepared statements can't get overwritten and for -## deallocate and deallocate all. -statement error prepared statement \"a\" does not exist -DEALLOCATE a - -statement -PREPARE a AS SELECT 1 - -query I -EXECUTE a ----- -1 - -query I -EXECUTE a ----- -1 - -statement error prepared statement \"a\" already exists -PREPARE a AS SELECT 1 - -statement -DEALLOCATE a - -statement error prepared statement \"a\" does not exist -DEALLOCATE a - -statement error prepared statement \"a\" does not exist -EXECUTE a - -statement -PREPARE a AS SELECT 1 - -statement -PREPARE b AS SELECT 1 - -query I -EXECUTE a ----- -1 - -query I -EXECUTE b ----- -1 - -statement ok -DEALLOCATE ALL - -statement error prepared statement \"a\" does not exist -DEALLOCATE a - -statement error prepared statement \"a\" does not exist -EXECUTE a - -statement error prepared statement \"b\" does not exist -DEALLOCATE b - -statement error prepared statement \"b\" does not exist -EXECUTE b - -## Typing tests - no type hints -# -query error syntax error at or near \"\)\" -PREPARE a as () - -statement error could not determine data type of placeholder \$1 -PREPARE a AS SELECT $1 - -statement error could not determine data type of placeholder \$1 -PREPARE a AS SELECT $2:::int - -statement error could not determine data type of placeholder \$2 -PREPARE a AS SELECT $1:::int, $3:::int - -statement ok -PREPARE a AS SELECT $1:::int + $2 - -query I -EXECUTE a(3, 1) ----- -4 - -query error could not parse "foo" as type int -EXECUTE a('foo', 1) - -query error expected EXECUTE parameter expression to have type int, but '3.5' has type decimal -EXECUTE a(3.5, 1) - -query error aggregate functions are not allowed in EXECUTE parameter -EXECUTE a(max(3), 1) - -query error window functions are not allowed in EXECUTE parameter -EXECUTE a(rank() over (partition by 3), 1) - -query error variable sub-expressions are not allowed in EXECUTE parameter -EXECUTE a((SELECT 3), 1) - -query error wrong number of parameters for prepared statement \"a\": expected 2, got 3 -EXECUTE a(1, 1, 1) - -query error wrong number of parameters for prepared statement \"a\": expected 2, got 0 -EXECUTE a - -# Regression test for cockroach#36153. -statement error unknown signature: array_length\(int, int\) -PREPARE fail AS SELECT array_length($1, 1) - -## Type hints - -statement -PREPARE b (int) AS SELECT $1 - -query I -EXECUTE b(3) ----- -3 - -query error could not parse "foo" as type int -EXECUTE b('foo') - -statement -PREPARE allTypes(int, float, string, bytea, date, timestamp, timestamptz, bool, decimal) AS -SELECT $1, $2, $3, $4, $5, $6, $7, $8, $9 - -query IRTTTTTBR -EXECUTE allTypes(0, 0.0, 'foo', 'bar', '2017-08-08', '2015-08-30 03:34:45.34567', '2015-08-30 03:34:45.34567', true, 3.4) ----- -0 0 foo bar 2017-08-08 00:00:00 +0000 +0000 2015-08-30 03:34:45.34567 +0000 +0000 2015-08-30 03:34:45.34567 +0000 UTC true 3.4 - -## Other - -statement -PREPARE c AS SELECT count(*) - -query I -EXECUTE c ----- -1 - -statement -CREATE TABLE t (a int) - -statement -PREPARE i AS INSERT INTO t(a) VALUES($1) RETURNING $1 + 1 - -statement -PREPARE s AS SELECT * FROM t - -query I -EXECUTE i(1) ----- -2 - -query I -EXECUTE i(2) ----- -3 - -query error could not parse "foo" as type int -EXECUTE i('foo') - -query error expected EXECUTE parameter expression to have type int, but '2.3' has type decimal -EXECUTE i(2.3) - -query I -EXECUTE i(3.3::int) ----- -4 - -query I colnames -EXECUTE s ----- -a -1 -2 -3 - -# DISCARD ROWS drops the results, but does not affect the schema or the -# internal plan. -query I colnames -EXECUTE s DISCARD ROWS ----- -a - -statement -DEALLOCATE ALL - -# Regression test for materialize#15970 - -statement -PREPARE x AS SELECT avg(column1) OVER (PARTITION BY column2) FROM (VALUES (1, 2), (3, 4)) - -query R rowsort -EXECUTE x ----- -1 -3 - -statement -PREPARE y AS SELECT avg(a.column1) OVER (PARTITION BY a.column2) FROM (VALUES (1, 2), (3, 4)) a - -query R rowsort -EXECUTE y ----- -1 -3 - -statement -DEALLOCATE ALL - -# Regression test for database-issues#4634 - -statement -CREATE TABLE IF NOT EXISTS f (v INT) - -statement -PREPARE x AS SELECT * FROM f - -statement -ALTER TABLE f ADD COLUMN u int - -statement -INSERT INTO f VALUES (1, 2) - -statement error cached plan must not change result type -EXECUTE x - -# Ensure that plan changes prevent INSERTs from succeeding. - -statement -PREPARE y AS INSERT INTO f VALUES ($1, $2) RETURNING * - -statement -EXECUTE y (2, 3) - -statement -ALTER TABLE f ADD COLUMN t int - -statement error cached plan must not change result type -EXECUTE y (3, 4) - -query III -SELECT * FROM f ----- -1 2 NULL -2 3 NULL - -# Ensure that we have a memory monitor for preparing statements - -statement -PREPARE z AS SELECT upper('a') - -# Ensure that GROUP BY HAVING doesn't mutate the parsed AST (materialize#16388) -statement -CREATE TABLE foo (a int) - -statement -PREPARE groupbyhaving AS SELECT min(1) FROM foo WHERE a = $1 GROUP BY a HAVING count(a) = 0 - -query I -EXECUTE groupbyhaving(1) ----- - -# Mismatch between expected and hinted types should prepare, but potentially -# fail to execute if the cast is not possible. -statement -PREPARE wrongTypePossibleCast(float) AS INSERT INTO foo VALUES ($1) - -statement -EXECUTE wrongTypePossibleCast(2.3) - -statement -PREPARE wrongTypeImpossibleCast(string) AS INSERT INTO foo VALUES ($1) - -statement -EXECUTE wrongTypeImpossibleCast('3') - -statement error could not parse "crabgas" as type int -EXECUTE wrongTypeImpossibleCast('crabgas') - -# Check statement compatibility - -statement ok -PREPARE s AS SELECT a FROM t; PREPARE p1 AS UPSERT INTO t(a) VALUES($1) RETURNING a - -query I -EXECUTE s ----- -1 -2 -3 - -query I -EXECUTE p1(123) ----- -123 - -statement ok -PREPARE p2 AS UPDATE t SET a = a + $1 RETURNING a - -query I -EXECUTE s ----- -1 -2 -3 -123 - -query I -EXECUTE p2(123) ----- -124 -125 -126 -246 - -statement ok -PREPARE p3 AS DELETE FROM t WHERE a = $1 RETURNING a - -query I -EXECUTE s ----- -124 -125 -126 -246 - -query I -EXECUTE p3(124) ----- -124 - -statement ok -PREPARE p4 AS CANCEL JOB $1 - -query error pq: job with ID 123 does not exist -EXECUTE p4(123) - -statement ok -PREPARE p5 AS PAUSE JOB $1 - -query error pq: job with ID 123 does not exist -EXECUTE p5(123) - -statement ok -PREPARE p6 AS RESUME JOB $1 - -query error pq: job with ID 123 does not exist -EXECUTE p6(123) - -# Ensure that SET / SET CLUSTER SETTING know about placeholders -statement ok -PREPARE setp(string) AS SET application_name = $1 - -query T -SET application_name = 'foo'; SHOW application_name ----- -foo - -query T -EXECUTE setp('hello'); SHOW application_name ----- -hello - -# Note: we can't check the result of SET CLUSTER SETTING synchronously -# because it doesn't propagate immediately. - -statement ok -PREPARE sets(string) AS SET CLUSTER SETTING cluster.organization = $1 - -statement ok -EXECUTE sets('hello') - -# materialize#19597 - -statement error could not determine data type of placeholder -PREPARE x19597 AS SELECT $1 IN ($2, null); - -statement error multiple conflicting type annotations around \$1 -PREPARE invalid AS SELECT $1:::int + $1:::float - -statement error type annotation around \$1 conflicts with specified type int -PREPARE invalid (int) AS SELECT $1:::float - -statement ok -PREPARE innerStmt AS SELECT $1:::int i, 'foo' t - -statement error syntax error at or near "execute" -PREPARE outerStmt AS SELECT * FROM [EXECUTE innerStmt(3)] WHERE t = $1 - -query error syntax error at or near "execute" -SELECT * FROM [EXECUTE innerStmt(1)] CROSS JOIN [EXECUTE x] - -statement ok -PREPARE selectin AS SELECT 1 in ($1, $2) - -statement ok -PREPARE selectin2 AS SELECT $1::int in ($2, $3) - -query B -EXECUTE selectin(5, 1) ----- -true - -query B -EXECUTE selectin2(1, 5, 1) ----- -true - -# Regression tests for materialize#21701. -statement ok -CREATE TABLE kv (k INT PRIMARY KEY, v INT) - -statement ok -INSERT INTO kv VALUES (1, 1), (2, 2), (3, 3) - -statement ok -PREPARE x21701a AS SELECT * FROM kv WHERE k = $1 - -query II -EXECUTE x21701a(NULL) ----- - -statement ok -PREPARE x21701b AS SELECT * FROM kv WHERE k IS DISTINCT FROM $1 - -query II -EXECUTE x21701b(NULL) ----- -1 1 -2 2 -3 3 - -statement ok -PREPARE x21701c AS SELECT * FROM kv WHERE k IS NOT DISTINCT FROM $1 - -query II -EXECUTE x21701c(NULL) ----- - -statement ok -DROP TABLE kv - -# Test that a PREPARE statement after a CREATE TABLE in the same TRANSACTION -# doesn't hang. -subtest 24578 - -statement ok -BEGIN TRANSACTION - -statement ok -create table bar (id integer) - -statement ok -PREPARE forbar AS insert into bar (id) VALUES (1) - -statement ok -COMMIT TRANSACTION - -# Test placeholder in aggregate. -statement ok -CREATE TABLE aggtab (a INT PRIMARY KEY); -INSERT INTO aggtab (a) VALUES (1) - -statement ok -PREPARE aggprep AS SELECT max(a + $1:::int) FROM aggtab - -query I -EXECUTE aggprep(10) ----- -11 - -query I -EXECUTE aggprep(20) ----- -21 - -# Test placeholder in subquery, where the placeholder will be constant folded -# and then used to select an index. -statement ok -CREATE TABLE abc (a INT PRIMARY KEY, b INT, c INT); -CREATE TABLE xyz (x INT PRIMARY KEY, y INT, z INT, INDEX(y)); -INSERT INTO abc (a, b, c) VALUES (1, 10, 100); -INSERT INTO xyz (x, y, z) VALUES (1, 5, 50); -INSERT INTO xyz (x, y, z) VALUES (2, 6, 60); - -statement ok -PREPARE subqueryprep AS SELECT * FROM abc WHERE EXISTS(SELECT * FROM xyz WHERE y IN ($1 + 1)) - -query III -EXECUTE subqueryprep(4) ----- -1 10 100 - -query III -EXECUTE subqueryprep(5) ----- -1 10 100 - -query III -EXECUTE subqueryprep(6) ----- - -# -# Test prepared statements that rely on context, and ensure they are invalidated -# when that context changes. -# - -statement ok -CREATE DATABASE otherdb - -statement ok -USE otherdb - -statement ok -CREATE TABLE othertable (a INT PRIMARY KEY, b INT); INSERT INTO othertable (a, b) VALUES (1, 10) - -## Current database change: Use current_database function, and ensure its return -## value changes when current database changes. -statement ok -PREPARE change_db AS SELECT current_database() - -query T -EXECUTE change_db ----- -otherdb - -statement ok -USE test - -query T -EXECUTE change_db ----- -test - -statement ok -USE otherdb - -## Name resolution change: Query table in current database. Ensure that it is -## not visible in another database. -statement ok -PREPARE change_db_2 AS SELECT * FROM othertable - -query II -EXECUTE change_db_2 ----- -1 10 - -statement ok -USE test - -query error pq: relation "othertable" does not exist -EXECUTE change_db_2 - -statement ok -CREATE TABLE othertable (a INT PRIMARY KEY, b INT); INSERT INTO othertable (a, b) VALUES (2, 20) - -query II -EXECUTE change_db_2 ----- -2 20 - -# Same test with a query which refers to the same table twice initially, but -# later the two tables are different. -statement ok -PREPARE change_db_3 AS SELECT * from othertable AS t1, test.othertable AS t2 - -query IIII -EXECUTE change_db_3 ----- -2 20 2 20 - -statement ok -USE otherdb - -query IIII -EXECUTE change_db_3 ----- -1 10 2 20 - -statement ok -DROP TABLE test.othertable - -## Search path change: Change the search path and ensure that the prepared plan -## is invalidated. -statement ok -PREPARE change_search_path AS SELECT * FROM othertable - -query II -EXECUTE change_search_path ----- -1 10 - -statement ok -SET search_path = pg_catalog - -query error pq: relation "othertable" does not exist -EXECUTE change_search_path - -## New table in search path: check tricky case where originally resolved table -## still exists but re-resolving with new search path yields another table. -statement ok -SET search_path=public,pg_catalog - -# During prepare, pg_type resolves to pg_catalog.pg_type. -statement ok -PREPARE new_table_in_search_path AS SELECT typname FROM pg_type - -statement ok -CREATE TABLE pg_type(typname STRING); INSERT INTO pg_type VALUES('test') - -# Now, it should resolve to the table we just created. -query T -EXECUTE new_table_in_search_path ----- -test - -statement ok -DROP TABLE pg_type - -## Even more tricky case: the query has two table references that resolve to -## the same table now, but later resolve to separate tables. -statement ok -PREPARE new_table_in_search_path_2 AS - SELECT a.typname, b.typname FROM pg_type AS a, pg_catalog.pg_type AS b ORDER BY a.typname, b.typname LIMIT 1 - -query TT -EXECUTE new_table_in_search_path_2 ----- -_bit _bit - -statement ok -CREATE TABLE pg_type(typname STRING); INSERT INTO pg_type VALUES('test') - -query TT -EXECUTE new_table_in_search_path_2 ----- -test _bit - -statement ok -DROP TABLE pg_type - -statement ok -RESET search_path - -## Functions: Use function which depends on context, and which is constant- -## folded by the heuristic planner. Ensure that it's not constant folded when -## part of prepared plan. -query B -SELECT has_column_privilege('testuser', 'othertable', 1, 'SELECT') ----- -false - -statement ok -GRANT ALL ON othertable TO testuser - -query B -SELECT has_column_privilege('testuser', 'othertable', 1, 'SELECT') ----- -true - -statement ok -REVOKE ALL ON othertable FROM testuser - -## Location change: Change the current location (affects timezone) and make -## sure the query is invalidated. -statement ok -PREPARE change_loc AS SELECT '2000-01-01 18:05:10.123'::timestamptz - -query T -EXECUTE change_loc ----- -2000-01-01 18:05:10.123 +0000 UTC - -statement ok -SET TIME ZONE 'EST'; - -query T -EXECUTE change_loc ----- -2000-01-01 18:05:10.123 -0500 -0500 - -statement ok -SET TIME ZONE 'UTC'; - -## Permissions: Grant and then revoke permission to select from a table. The -## prepared plan should be invalidated. -statement ok -GRANT ALL ON othertable TO testuser - -user testuser - -statement ok -USE otherdb - -statement ok -PREPARE change_privileges AS SELECT * FROM othertable - -query II -EXECUTE change_privileges ----- -1 10 - -user root - -statement ok -REVOKE ALL ON othertable FROM testuser - -user testuser - -query error pq: user testuser does not have SELECT privilege on relation othertable -EXECUTE change_privileges - -user root - -## Permissions: Use UPDATE statement that requires both UPDATE and SELECT -## privileges. -statement ok -GRANT ALL ON othertable TO testuser - -user testuser - -statement ok -USE otherdb - -statement ok -PREPARE update_privileges AS UPDATE othertable SET b=$1 - -user root - -statement ok -REVOKE UPDATE ON othertable FROM testuser - -user testuser - -query error pq: user testuser does not have UPDATE privilege on relation othertable -EXECUTE update_privileges(5) - -user root - -statement ok -GRANT UPDATE ON othertable TO testuser - -statement ok -REVOKE SELECT ON othertable FROM testuser - -user testuser - -query error pq: user testuser does not have SELECT privilege on relation othertable -EXECUTE update_privileges(5) - -user root - -query II -SELECT * FROM othertable ----- -1 10 - -user root - -## Schema change (rename): Rename column in table and ensure that the prepared -## statement is updated to incorporate it. -statement ok -PREPARE change_rename AS SELECT * FROM othertable - -query II colnames -EXECUTE change_rename ----- -a b -1 10 - -statement ok -ALTER TABLE othertable RENAME COLUMN b TO c - -query II colnames -EXECUTE change_rename ----- -a c -1 10 - -statement ok -ALTER TABLE othertable RENAME COLUMN c TO b - -query II colnames -EXECUTE change_rename ----- -a b -1 10 - -## Schema change (placeholders): Similar to previous case, but with placeholder -## present. -statement ok -PREPARE change_placeholders AS SELECT * FROM othertable WHERE a=$1 - -query II colnames -EXECUTE change_placeholders(1) ----- -a b -1 10 - -statement ok -ALTER TABLE othertable RENAME COLUMN b TO c - -query II colnames -EXECUTE change_placeholders(1) ----- -a c -1 10 - -statement ok -ALTER TABLE othertable RENAME COLUMN c TO b - -query II colnames -EXECUTE change_placeholders(1) ----- -a b -1 10 - -## Schema change (view): Change view name and ensure that prepared query is -## invalidated. -statement ok -CREATE VIEW otherview AS SELECT a, b FROM othertable - -statement ok -PREPARE change_view AS SELECT * FROM otherview - -query II -EXECUTE change_view ----- -1 10 - -statement ok -ALTER VIEW otherview RENAME TO otherview2 - -# HP and CBO return slightly different errors, so accept both. -query error pq: relation "(otherdb.public.)?otherview" does not exist -EXECUTE change_view - -statement ok -DROP VIEW otherview2 - -## Schema change: Drop column and ensure that correct error is reported. -statement ok -PREPARE change_drop AS SELECT * FROM othertable WHERE b=10 - -query II -EXECUTE change_drop ----- -1 10 - -statement ok -ALTER TABLE othertable DROP COLUMN b - -query error pq: column "b" does not exist -EXECUTE change_drop - -statement ok -ALTER TABLE othertable ADD COLUMN b INT; UPDATE othertable SET b=10 - -query II -EXECUTE change_drop ----- -1 10 - -## Uncommitted schema change: Rename column in table in same transaction as -## execution of prepared statement and make prepared statement incorporates it. -statement ok -PREPARE change_schema_uncommitted AS SELECT * FROM othertable - -statement ok -BEGIN TRANSACTION - -query II colnames -EXECUTE change_schema_uncommitted ----- -a b -1 10 - -statement ok -ALTER TABLE othertable RENAME COLUMN b TO c - -query II colnames -EXECUTE change_schema_uncommitted ----- -a c -1 10 - -# Change the schema again and verify that the previously prepared plan is not -# reused. Testing this is important because the second schema change won't -# bump the table descriptor version again. -statement ok -ALTER TABLE othertable RENAME COLUMN c TO d - -query II colnames -EXECUTE change_schema_uncommitted ----- -a d -1 10 - -statement ok -ROLLBACK TRANSACTION - -# Same virtual table in different catalogs (these virtual table instances have -# the same table ID). -statement ok -CREATE SEQUENCE seq - -statement ok -PREPARE pg_catalog_query AS SELECT * FROM pg_catalog.pg_sequence - -query OOIIIIIB colnames -EXECUTE pg_catalog_query ----- -seqrelid seqtypid seqstart seqincrement seqmax seqmin seqcache seqcycle -67 20 1 1 9223372036854775807 1 1 false - -statement ok -USE test - -query OOIIIIIB colnames -EXECUTE pg_catalog_query ----- -seqrelid seqtypid seqstart seqincrement seqmax seqmin seqcache seqcycle - -# Verify error when placeholders are used without prepare. -statement error no value provided for placeholder: \$1 -SELECT $1:::int - -# Verify sequences get re-resolved. -statement ok -CREATE SEQUENCE seq - -statement ok -PREPARE seqsel AS SELECT * FROM seq - -query I -SELECT nextval('seq') ----- -1 - -query IIB -EXECUTE seqsel ----- -1 0 true - -statement ok -DROP SEQUENCE seq - -statement ok -CREATE SEQUENCE seq - -query IIB -EXECUTE seqsel ----- -0 0 true - -# Null placeholder values need to be assigned static types. Otherwise, we won't -# be able to disambiguate the concat function overloads. -statement ok -PREPARE foobar AS VALUES ($1:::string || $2:::string) - -query T -EXECUTE foobar(NULL, NULL) ----- -NULL - -subtest regression_35145 - -# Verify db-independent query behaves properly even when db does not exist - -statement ok -SET application_name = ap35145 - -# Prepare in custom db - -statement ok -CREATE DATABASE d35145; SET database = d35145; - -statement ok -PREPARE display_appname AS SELECT setting FROM pg_settings WHERE name = 'application_name' - -query T -EXECUTE display_appname ----- -ap35145 - -# Check what happens when the db where the stmt was prepared disappears "underneath". - -statement ok -DROP DATABASE d35145 - -query error database "d35145" does not exist -EXECUTE display_appname - -statement ok -CREATE DATABASE d35145 - -query T -EXECUTE display_appname ----- -ap35145 - -# Check what happens when the stmt is executed over a non-existent, unrelated db. - -statement ok -CREATE DATABASE d35145_2; SET database = d35145_2; DROP DATABASE d35145_2 - -query error database "d35145_2" does not exist -EXECUTE display_appname - -# Check what happens when the stmt is executed over no db whatsoever. - -statement ok -SET database = '' - -query error cannot access virtual schema in anonymous database -EXECUTE display_appname diff --git a/test/sqllogictest/cockroach/privilege_builtins.slt b/test/sqllogictest/cockroach/privilege_builtins.slt new file mode 100644 index 0000000000000..b6f52e509174b --- /dev/null +++ b/test/sqllogictest/cockroach/privilege_builtins.slt @@ -0,0 +1,1703 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/privilege_builtins +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER bar; CREATE USER all_user_db; CREATE USER all_user_schema + +statement ok +CREATE SCHEMA test_schema + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON DATABASE test TO bar + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CONNECT ON DATABASE test to testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON SCHEMA test_schema TO bar + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON SCHEMA test_schema TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT USAGE ON SCHEMA test_schema TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON DATABASE test to all_user_db; + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON SCHEMA test_schema to all_user_schema; + +statement ok +CREATE TABLE t (a INT, b INT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT DELETE ON t TO bar; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE seq; + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT SELECT ON seq TO bar; + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT SELECT ON seq TO testuser; + + +## has_any_column_privilege + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_any_column_privilege(12345, 'SELECT'), + has_any_column_privilege(12345, 'INSERT'), + has_any_column_privilege(12345, 'UPDATE'), + has_any_column_privilege(12345, 'REFERENCES') +---- +NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_any_column_privilege(12345::OID::REGCLASS, 'SELECT'), + has_any_column_privilege(12345::OID::REGCLASS, 'INSERT'), + has_any_column_privilege(12345::OID::REGCLASS, 'UPDATE'), + has_any_column_privilege(12345::OID::REGCLASS, 'REFERENCES') +---- +NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_any_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'SELECT'), + has_any_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'INSERT'), + has_any_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'UPDATE'), + has_any_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'REFERENCES') +---- +true false false true + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_any_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'SELECT'), + has_any_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'INSERT'), + has_any_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'UPDATE'), + has_any_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'REFERENCES') +---- +true true true true + +query error pgcode 42P01 function "has_any_column_privilege" does not exist +SELECT has_any_column_privilege('does_not_exist', 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT has_any_column_privilege('pg_type', 'SELECT'), + has_any_column_privilege('pg_type', 'INSERT'), + has_any_column_privilege('pg_type', 'UPDATE'), + has_any_column_privilege('pg_type', 'REFERENCES'), + has_any_column_privilege('pg_type', 'SELECT, INSERT, UPDATE'), + has_any_column_privilege('pg_type', 'INSERT, UPDATE') +---- +true false false true true false + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_any_column_privilege('t', 'SELECT'), + has_any_column_privilege('t', 'INSERT'), + has_any_column_privilege('t', 'UPDATE'), + has_any_column_privilege('t', 'REFERENCES'), + has_any_column_privilege('t', 'SELECT, INSERT, UPDATE') +---- +true true true true true + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_any_column_privilege('t', 'SELECT WITH GRANT OPTION'), + has_any_column_privilege('t', 'INSERT WITH GRANT OPTION'), + has_any_column_privilege('t', 'UPDATE WITH GRANT OPTION'), + has_any_column_privilege('t', 'REFERENCES WITH GRANT OPTION'), + has_any_column_privilege('t', 'SELECT WITH GRANT OPTION, INSERT WITH GRANT OPTION, UPDATE WITH GRANT OPTION') +---- +true true true true true + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_any_column_privilege('t'::Name, 'SELECT'), + has_any_column_privilege('t'::Name, 'INSERT'), + has_any_column_privilege('t'::Name, 'UPDATE'), + has_any_column_privilege('t'::Name, 'REFERENCES'), + has_any_column_privilege('t'::Name, 'SELECT, INSERT, UPDATE') +---- +true true true true true + +query error pgcode 22023 function "has_any_column_privilege" does not exist +SELECT has_any_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), '') + +query error pgcode 22023 function "has_any_column_privilege" does not exist +SELECT has_any_column_privilege('t', 'USAGE') + +query error pgcode 22023 function "has_any_column_privilege" does not exist +SELECT has_any_column_privilege('t', 'SELECT, USAGE') + +query error pgcode 42704 function "has_any_column_privilege" does not exist +SELECT has_any_column_privilege('no_user', 't', 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_any_column_privilege('bar', 't', 'SELECT'), + has_any_column_privilege('bar', 't', 'INSERT'), + has_any_column_privilege('bar', 't', 'UPDATE'), + has_any_column_privilege('bar', 't', 'REFERENCES'), + has_any_column_privilege('bar', 't', 'SELECT, INSERT, UPDATE') +---- +false false false false false + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_any_column_privilege('bar', 't', 'SELECT WITH GRANT OPTION'), + has_any_column_privilege('bar', 't', 'INSERT WITH GRANT OPTION'), + has_any_column_privilege('bar', 't', 'UPDATE WITH GRANT OPTION'), + has_any_column_privilege('bar', 't', 'REFERENCES WITH GRANT OPTION'), + has_any_column_privilege('bar', 't', 'SELECT WITH GRANT OPTION, INSERT WITH GRANT OPTION, UPDATE WITH GRANT OPTION') +---- +false false false false false + + +## has_column_privilege + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_column_privilege(12345, 1, 'SELECT'), + has_column_privilege(12345, 1, 'INSERT'), + has_column_privilege(12345, 1, 'UPDATE'), + has_column_privilege(12345, 1, 'REFERENCES') +---- +NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 1, 'SELECT'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 1, 'INSERT'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 1, 'UPDATE'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 1, 'REFERENCES') +---- +true false false true + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 1, 'SELECT'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 2, 'INSERT'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 1, 'UPDATE'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 2, 'REFERENCES') +---- +true true true true + +query error pgcode 42P01 function "has_column_privilege" does not exist +SELECT has_column_privilege('does_not_exist', 1, 'SELECT') + +query error pgcode 42703 function "has_column_privilege" does not exist +SELECT has_column_privilege('pg_type', 100, 'SELECT') + +query error pgcode 42703 function "has_column_privilege" does not exist +SELECT has_column_privilege('pg_type'::regclass, 100, 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT has_column_privilege('pg_type', 1, 'SELECT'), + has_column_privilege('pg_type', 1, 'INSERT'), + has_column_privilege('pg_type', 1, 'UPDATE'), + has_column_privilege('pg_type', 1, 'REFERENCES'), + has_column_privilege('pg_type', 1, 'SELECT, INSERT, UPDATE'), + has_column_privilege('pg_type', 1, 'INSERT, UPDATE') +---- +true false false true true false + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_column_privilege('t', 1, 'SELECT'), + has_column_privilege('t', 1, 'INSERT'), + has_column_privilege('t', 1, 'UPDATE'), + has_column_privilege('t', 1, 'REFERENCES'), + has_column_privilege('t', 1, 'SELECT, INSERT, UPDATE') +---- +true true true true true + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_column_privilege('t', 1, 'SELECT WITH GRANT OPTION'), + has_column_privilege('t', 1, 'INSERT WITH GRANT OPTION'), + has_column_privilege('t', 1, 'UPDATE WITH GRANT OPTION'), + has_column_privilege('t', 1, 'REFERENCES WITH GRANT OPTION'), + has_column_privilege('t', 1, 'SELECT WITH GRANT OPTION, INSERT WITH GRANT OPTION, UPDATE WITH GRANT OPTION') +---- +true true true true true + +query error pgcode 22023 function "has_column_privilege" does not exist +SELECT has_column_privilege('t', 1, 'USAGE') + +query error pgcode 42704 function "has_column_privilege" does not exist +SELECT has_column_privilege('no_user', 't', 1, 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_column_privilege('bar', 't', 1, 'SELECT'), + has_column_privilege('bar', 't', 1, 'INSERT'), + has_column_privilege('bar', 't', 1, 'UPDATE'), + has_column_privilege('bar', 't', 1, 'REFERENCES'), + has_column_privilege('bar', 't', 1, 'SELECT, INSERT, UPDATE') +---- +false false false false false + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_column_privilege('bar', 't', 1, 'SELECT WITH GRANT OPTION'), + has_column_privilege('bar', 't', 1, 'INSERT WITH GRANT OPTION'), + has_column_privilege('bar', 't', 1, 'UPDATE WITH GRANT OPTION'), + has_column_privilege('bar', 't', 1, 'REFERENCES WITH GRANT OPTION'), + has_column_privilege('bar', 't', 1, 'SELECT WITH GRANT OPTION, INSERT WITH GRANT OPTION, UPDATE WITH GRANT OPTION') +---- +false false false false false + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_column_privilege(12345, 'col', 'SELECT'), + has_column_privilege(12345, 'col', 'INSERT'), + has_column_privilege(12345, 'col', 'UPDATE'), + has_column_privilege(12345, 'col', 'REFERENCES') +---- +NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'typname', 'SELECT'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'typname', 'INSERT'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'typname', 'UPDATE'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'typname', 'REFERENCES') +---- +true false false true + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'a', 'SELECT'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'b', 'INSERT'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'a', 'UPDATE'), + has_column_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'b', 'REFERENCES') +---- +true true true true + +query error pgcode 42P01 function "has_column_privilege" does not exist +SELECT has_column_privilege('does_not_exist', 'col', 'SELECT') + +query error pgcode 42703 function "has_column_privilege" does not exist +SELECT has_column_privilege('pg_type', 'does not exist', 'SELECT') + +query error pgcode 42703 function "has_column_privilege" does not exist +SELECT has_column_privilege('pg_type'::regclass, 'does not exist', 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT has_column_privilege('pg_type', 'typname', 'SELECT'), + has_column_privilege('pg_type', 'typname', 'INSERT'), + has_column_privilege('pg_type', 'typname', 'UPDATE'), + has_column_privilege('pg_type', 'typname', 'REFERENCES'), + has_column_privilege('pg_type', 'typname', 'SELECT, INSERT, UPDATE'), + has_column_privilege('pg_type', 'typname', 'INSERT, UPDATE') +---- +true false false true true false + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_column_privilege('t', 'a', 'SELECT'), + has_column_privilege('t', 'a', 'INSERT'), + has_column_privilege('t', 'a', 'UPDATE'), + has_column_privilege('t', 'a', 'REFERENCES'), + has_column_privilege('t', 'a', 'SELECT, INSERT, UPDATE') +---- +true true true true true + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_column_privilege('t', 'a', 'SELECT WITH GRANT OPTION'), + has_column_privilege('t', 'a', 'INSERT WITH GRANT OPTION'), + has_column_privilege('t', 'a', 'UPDATE WITH GRANT OPTION'), + has_column_privilege('t', 'a', 'REFERENCES WITH GRANT OPTION'), + has_column_privilege('t', 'a', 'SELECT WITH GRANT OPTION, INSERT WITH GRANT OPTION, UPDATE WITH GRANT OPTION') +---- +true true true true true + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_column_privilege('t'::Name, 'a'::Name, 'SELECT WITH GRANT OPTION'), + has_column_privilege('t'::Name, 'a'::Name, 'INSERT WITH GRANT OPTION'), + has_column_privilege('t'::Name, 'a'::Name, 'UPDATE WITH GRANT OPTION'), + has_column_privilege('t'::Name, 'a'::Name, 'REFERENCES WITH GRANT OPTION'), + has_column_privilege('t'::Name, 'a'::Name, 'SELECT WITH GRANT OPTION, INSERT WITH GRANT OPTION, UPDATE WITH GRANT OPTION') +---- +true true true true true + +query error pgcode 22023 function "has_column_privilege" does not exist +SELECT has_column_privilege('t', 'a', 'USAGE') + +query error pgcode 42704 function "has_column_privilege" does not exist +SELECT has_column_privilege('no_user', 't', 'a', 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_column_privilege('bar', 't', 'a', 'SELECT'), + has_column_privilege('bar', 't', 'a', 'INSERT'), + has_column_privilege('bar', 't', 'a', 'UPDATE'), + has_column_privilege('bar', 't', 'a', 'REFERENCES'), + has_column_privilege('bar', 't', 'a', 'SELECT, INSERT, UPDATE') +---- +false false false false false + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_column_privilege('bar', 't', 'a', 'SELECT WITH GRANT OPTION'), + has_column_privilege('bar', 't', 'a', 'INSERT WITH GRANT OPTION'), + has_column_privilege('bar', 't', 'a', 'UPDATE WITH GRANT OPTION'), + has_column_privilege('bar', 't', 'a', 'REFERENCES WITH GRANT OPTION'), + has_column_privilege('bar', 't', 'a', 'SELECT WITH GRANT OPTION, INSERT WITH GRANT OPTION, UPDATE WITH GRANT OPTION') +---- +false false false false false + + +## has_database_privilege + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_database_privilege(12345, 'CREATE'), + has_database_privilege(12345, 'CONNECT'), + has_database_privilege(12345, 'TEMPORARY'), + has_database_privilege(12345, 'TEMP') +---- +NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_database_privilege((SELECT oid FROM pg_database WHERE datname = 'system'), 'CREATE'), + has_database_privilege((SELECT oid FROM pg_database WHERE datname = 'system'), 'CONNECT'), + has_database_privilege((SELECT oid FROM pg_database WHERE datname = 'system'), 'TEMPORARY'), + has_database_privilege((SELECT oid FROM pg_database WHERE datname = 'system'), 'TEMP') +---- +false true false false + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_database_privilege((SELECT oid FROM pg_database WHERE datname = 'test'), 'CREATE'), + has_database_privilege((SELECT oid FROM pg_database WHERE datname = 'test'), 'CONNECT'), + has_database_privilege((SELECT oid FROM pg_database WHERE datname = 'test'), 'TEMPORARY'), + has_database_privilege((SELECT oid FROM pg_database WHERE datname = 'test'), 'TEMP') +---- +true true true true + +query error pgcode 3D000 database "does_not_exist" does not exist +SELECT has_database_privilege('does_not_exist', 'CREATE') + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_database_privilege('system', ' CrEaTe '), + has_database_privilege('system', ' CONNECT'), + has_database_privilege('system', 'TEMPORARY'), + has_database_privilege('system', 'TEMP'), + has_database_privilege('system', ' CrEaTe ,CONNECT') +---- +false true false false true + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_database_privilege('test', ' CrEaTe '), + has_database_privilege('test', ' CONNECT'), + has_database_privilege('test', 'TEMPORARY'), + has_database_privilege('test', 'TEMP'), + has_database_privilege('test', ' CrEaTe ,CONNECT') +---- +true true true true true + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_database_privilege('test', 'CREATE WITH GRANT OPTION'), + has_database_privilege('test', 'CONNECT WITH GRANT OPTION'), + has_database_privilege('test', 'TEMPORARY WITH GRANT OPTION'), + has_database_privilege('test', 'TEMP WITH GRANT OPTION'), + has_database_privilege('test', 'CREATE WITH GRANT OPTION, CONNECT WITH GRANT OPTION') +---- +true true true true true + +# Not supported by Materialize. +onlyif cockroach +query BBBBB +SELECT has_database_privilege('test'::Name, 'CREATE'), + has_database_privilege('test'::Name, 'CONNECT'), + has_database_privilege('test'::Name, 'TEMPORARY'), + has_database_privilege('test'::Name, 'TEMP'), + has_database_privilege('test'::Name, 'CREATE, CONNECT') +---- +true true true true true + +query T +SELECT datname FROM pg_database WHERE has_database_privilege(datname, 'CREATE') ORDER BY datname +---- +materialize + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT datname FROM pg_database WHERE has_database_privilege(datname, 'CONNECT') ORDER BY datname +---- +defaultdb +postgres +system +test + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT datname FROM pg_database WHERE has_database_privilege(datname, 'TEMP') ORDER BY datname +---- +defaultdb +postgres +test + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT datname FROM pg_database WHERE has_database_privilege(datname, 'TEMPORARY') ORDER BY datname +---- +defaultdb +postgres +test + +query error pgcode 22023 database "test" does not exist +SELECT has_database_privilege('test', 'UPDATE') + +query error pgcode 22023 database "test" does not exist +SELECT has_database_privilege('test', 'CREATE, UPDATE') + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42704 role "no_user" does not exist +SELECT has_database_privilege('no_user', 'test', 'CREATE') + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT has_database_privilege('bar', 'test', 'CREATE'), + has_database_privilege('bar', 'test', 'CONNECT'), + has_database_privilege('bar', 'test', 'TEMPORARY'), + has_database_privilege('bar', 'test', 'TEMP'), + has_database_privilege('bar', 'test', 'CREATE, CONNECT'), + has_database_privilege('bar', 'test', 'CREATE, TEMP') +---- +true true true true true true + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CONNECT ON DATABASE test TO bar + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_database_privilege('bar', 'test', 'CONNECT') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT has_database_privilege('bar', 'test', 'CREATE WITH GRANT OPTION'), + has_database_privilege('bar', 'test', 'CONNECT WITH GRANT OPTION'), + has_database_privilege('bar', 'test', 'TEMPORARY WITH GRANT OPTION'), + has_database_privilege('bar', 'test', 'TEMP WITH GRANT OPTION'), + has_database_privilege('bar', 'test', 'CREATE WITH GRANT OPTION, CONNECT WITH GRANT OPTION'), + has_database_privilege('bar', 'test', 'CREATE WITH GRANT OPTION, TEMP WITH GRANT OPTION') +---- +false false false false false false + + +## has_foreign_data_wrapper_privilege + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_foreign_data_wrapper_privilege(12345, 'USAGE') +---- +NULL + +query error pgcode 42704 function "has_foreign_data_wrapper_privilege" does not exist +SELECT has_foreign_data_wrapper_privilege('does_not_exist', 'USAGE') + +query error pgcode 42704 function "has_foreign_data_wrapper_privilege" does not exist +SELECT has_foreign_data_wrapper_privilege('does_not_exist'::Name, 'USAGE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_foreign_data_wrapper_privilege(12345, 'USAGE WITH GRANT OPTION') +---- +NULL + +query error pgcode 22023 function "has_foreign_data_wrapper_privilege" does not exist +SELECT has_foreign_data_wrapper_privilege(12345, 'UPDATE') + +query error pgcode 22023 function "has_foreign_data_wrapper_privilege" does not exist +SELECT has_foreign_data_wrapper_privilege(12345, 'USAGE, UPDATE') + +query error pgcode 42704 function "has_foreign_data_wrapper_privilege" does not exist +SELECT has_foreign_data_wrapper_privilege('no_user', 12345, 'USAGE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_foreign_data_wrapper_privilege('bar', 12345, 'USAGE') +---- +NULL + + +## has_function_privilege + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_function_privilege(12345, 'EXECUTE') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_function_privilege((SELECT oid FROM pg_proc LIMIT 1), 'EXECUTE') +---- +true + +query error function "has_function_privilege" does not exist +SELECT has_function_privilege('does_not_exist', 'EXECUTE') + +query error pgcode 42883 function "has_function_privilege" does not exist +SELECT has_function_privilege('does_not_exist()', 'EXECUTE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_function_privilege('version()', ' EXECUTE ') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_function_privilege('version()', 'EXECUTE') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_function_privilege('cos(float)', 'EXECUTE WITH GRANT OPTION') +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_function_privilege('cos(float)', 'EXECUTE, EXECUTE WITH GRANT OPTION') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_function_privilege('version()'::Name, 'EXECUTE') +---- +true + +query error pgcode 22023 function "has_function_privilege" does not exist +SELECT has_function_privilege('acos(float)', 'UPDATE') + +query error pgcode 22023 function "has_function_privilege" does not exist +SELECT has_function_privilege('acos(float)', 'EXECUTE, UPDATE') + +query error pgcode 42704 function "has_function_privilege" does not exist +SELECT has_function_privilege('no_user', 'acos(float)', 'EXECUTE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_function_privilege('bar', 'current_date'::REGPROC, 'EXECUTE') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_function_privilege('bar', 'current_date'::REGPROC::OID, 'EXECUTE') +---- +true + + +## has_language_privilege + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_language_privilege(12345, 'USAGE') +---- +NULL + +query error pgcode 42704 function "has_language_privilege" does not exist +SELECT has_language_privilege('does_not_exist', 'USAGE') + +query error pgcode 42704 function "has_language_privilege" does not exist +SELECT has_language_privilege('does_not_exist'::Name, 'USAGE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_language_privilege(12345, 'USAGE WITH GRANT OPTION') +---- +NULL + +query error pgcode 22023 function "has_language_privilege" does not exist +SELECT has_language_privilege(12345, 'UPDATE') + +query error pgcode 22023 function "has_language_privilege" does not exist +SELECT has_language_privilege(12345, 'USAGE, UPDATE') + +query error pgcode 42704 function "has_language_privilege" does not exist +SELECT has_language_privilege('no_user', 12345, 'USAGE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_language_privilege('bar', 12345, 'USAGE') +---- +NULL + + +## has_schema_privilege + +query BB +SELECT has_schema_privilege(12345, 'CREATE'), + has_schema_privilege(12345, 'USAGE') +---- +NULL NULL + +query BB +SELECT has_schema_privilege((SELECT oid FROM pg_namespace WHERE nspname = 'crdb_internal'), 'CREATE'), + has_schema_privilege((SELECT oid FROM pg_namespace WHERE nspname = 'crdb_internal'), 'USAGE') +---- +NULL NULL + +query BB +SELECT has_schema_privilege((SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'), 'CREATE'), + has_schema_privilege((SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'), 'USAGE') +---- +false true + +query BB +SELECT has_schema_privilege((SELECT oid FROM pg_namespace WHERE nspname = 'public'), 'CREATE'), + has_schema_privilege((SELECT oid FROM pg_namespace WHERE nspname = 'public'), 'USAGE') +---- +true true + +query error pgcode 3F000 schema "does_not_exist" does not exist +SELECT has_schema_privilege('does_not_exist', 'CREATE') + +query BBB +SELECT has_schema_privilege('public', 'CREATE'), + has_schema_privilege('public', 'USAGE'), + has_schema_privilege('public', 'CREATE, USAGE') +---- +true true true + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_schema_privilege('public', 'CREATE WITH GRANT OPTION'), + has_schema_privilege('public', 'USAGE WITH GRANT OPTION'), + has_schema_privilege('public', 'CREATE WITH GRANT OPTION, USAGE WITH GRANT OPTION') +---- +true true true + +query BBB +SELECT has_schema_privilege('public'::Name, 'CREATE'), + has_schema_privilege('public'::Name, 'USAGE'), + has_schema_privilege('public'::Name, 'CREATE, USAGE') +---- +true true true + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 22023 unrecognized privilege type: "UPDATE" +SELECT has_schema_privilege('public', 'UPDATE') + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 22023 unrecognized privilege type: "UPDATE" +SELECT has_schema_privilege('public', 'CREATE, UPDATE') + +query error pgcode 42704 role "no_user" does not exist +SELECT has_schema_privilege('no_user', 'public', 'CREATE') + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_schema_privilege('bar', 'public', 'CREATE'), + has_schema_privilege('bar', 'public', 'USAGE'), + has_schema_privilege('bar', 'public', 'CREATE, USAGE') +---- +true true true + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_schema_privilege('bar', 'public', 'CREATE WITH GRANT OPTION'), + has_schema_privilege('bar', 'public', 'USAGE WITH GRANT OPTION'), + has_schema_privilege('bar', 'public', 'CREATE WITH GRANT OPTION, USAGE WITH GRANT OPTION') +---- +false false false + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_schema_privilege('testuser', 'public', 'CREATE'), + has_schema_privilege('testuser', 'public', 'USAGE'), + has_schema_privilege('testuser', 'public', 'CREATE, USAGE') +---- +true true true + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_schema_privilege('bar', 'test_schema', 'CREATE'), + has_schema_privilege('bar', 'test_schema', 'USAGE'), + has_schema_privilege('bar', 'test_schema', 'CREATE, USAGE') +---- +true false true + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_schema_privilege('testuser', 'test_schema', 'CREATE'), + has_schema_privilege('testuser', 'test_schema', 'USAGE'), + has_schema_privilege('testuser', 'test_schema', 'CREATE, USAGE') +---- +true true true + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_schema_privilege('all_user_db', 'public', 'CREATE'), + has_schema_privilege('all_user_db', 'public', 'USAGE'), + has_schema_privilege('all_user_db', 'public', 'CREATE, USAGE') +---- +true true true + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_schema_privilege('all_user_db', 'test_schema', 'CREATE'), + has_schema_privilege('all_user_db', 'test_schema', 'USAGE'), + has_schema_privilege('all_user_db', 'test_schema', 'CREATE, USAGE') +---- +false false false + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_schema_privilege('all_user_schema', 'public', 'CREATE'), + has_schema_privilege('all_user_schema', 'public', 'USAGE'), + has_schema_privilege('all_user_schema', 'public', 'CREATE, USAGE') +---- +true true true + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_schema_privilege('all_user_schema', 'test_schema', 'CREATE'), + has_schema_privilege('all_user_schema', 'test_schema', 'USAGE'), + has_schema_privilege('all_user_schema', 'test_schema', 'CREATE, USAGE') +---- +true true true + + +## has_sequence_privilege + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_sequence_privilege(12345, 'USAGE'), + has_sequence_privilege(12345, 'SELECT'), + has_sequence_privilege(12345, 'UPDATE') +---- +NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_sequence_privilege((SELECT oid FROM pg_class WHERE relname = 'seq'), 'USAGE'), + has_sequence_privilege((SELECT oid FROM pg_class WHERE relname = 'seq'), 'SELECT'), + has_sequence_privilege((SELECT oid FROM pg_class WHERE relname = 'seq'), 'UPDATE') +---- +true true true + +query error pgcode 42P01 function "has_sequence_privilege" does not exist +SELECT has_sequence_privilege('does_not_exist', 'SELECT') + +query error pgcode 42809 function "has_sequence_privilege" does not exist +SELECT has_sequence_privilege('t', 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_sequence_privilege('seq', 'USAGE'), + has_sequence_privilege('seq', 'SELECT'), + has_sequence_privilege('seq', 'UPDATE') +---- +true true true + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_sequence_privilege('seq', 'USAGE WITH GRANT OPTION'), + has_sequence_privilege('seq', 'SELECT WITH GRANT OPTION'), + has_sequence_privilege('seq', 'UPDATE WITH GRANT OPTION') +---- +true true true + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_sequence_privilege('seq'::Name, 'USAGE'), + has_sequence_privilege('seq'::Name, 'SELECT'), + has_sequence_privilege('seq'::Name, 'UPDATE') +---- +true true true + +query error pgcode 22023 function "has_sequence_privilege" does not exist +SELECT has_sequence_privilege('seq', 'DELETE') + +query error pgcode 22023 function "has_sequence_privilege" does not exist +SELECT has_sequence_privilege('seq', 'SELECT, DELETE') + +user testuser + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_sequence_privilege('seq', 'USAGE'), + has_sequence_privilege('seq', 'SELECT'), + has_sequence_privilege('seq', 'UPDATE') +---- +false true false + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_sequence_privilege('seq', 'USAGE WITH GRANT OPTION'), + has_sequence_privilege('seq', 'SELECT WITH GRANT OPTION'), + has_sequence_privilege('seq', 'UPDATE WITH GRANT OPTION') +---- +false false false + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT USAGE, SELECT, UPDATE ON seq TO testuser WITH GRANT OPTION + +# Not supported by Materialize. +onlyif cockroach +# should be "true true true" +query BBB +SELECT has_sequence_privilege('testuser', 'seq', 'USAGE WITH GRANT OPTION'), + has_sequence_privilege('testuser', 'seq', 'SELECT WITH GRANT OPTION'), + has_sequence_privilege('testuser', 'seq', 'UPDATE WITH GRANT OPTION') +---- +true true true + +# Not supported by Materialize. +onlyif cockroach +# incorrectly grants USAGE (should only have SELECT AND UPDATE) +# see https://github.com/cockroachdb/cockroach/issues/82414 +statement ok +GRANT SELECT, UPDATE ON seq TO testuser WITH GRANT OPTION + +# Not supported by Materialize. +onlyif cockroach +# should be "false true true" +query BBB +SELECT has_sequence_privilege('testuser', 'seq', 'USAGE WITH GRANT OPTION'), + has_sequence_privilege('testuser', 'seq', 'SELECT WITH GRANT OPTION'), + has_sequence_privilege('testuser', 'seq', 'UPDATE WITH GRANT OPTION') +---- +true true true + +query error pgcode 42704 function "has_sequence_privilege" does not exist +SELECT has_sequence_privilege('no_user', 'seq', 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_sequence_privilege('bar', 'seq', 'USAGE'), + has_sequence_privilege('bar', 'seq', 'SELECT'), + has_sequence_privilege('bar', 'seq', 'UPDATE') +---- +false true false + +# Not supported by Materialize. +onlyif cockroach +query BBB +SELECT has_sequence_privilege('bar', 'seq', 'USAGE WITH GRANT OPTION'), + has_sequence_privilege('bar', 'seq', 'SELECT WITH GRANT OPTION'), + has_sequence_privilege('bar', 'seq', 'UPDATE WITH GRANT OPTION') +---- +false false false + + +## has_server_privilege + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_server_privilege(12345, 'USAGE') +---- +NULL + +query error pgcode 42704 function "has_server_privilege" does not exist +SELECT has_server_privilege('does_not_exist', 'USAGE') + +query error pgcode 42704 function "has_server_privilege" does not exist +SELECT has_server_privilege('does_not_exist'::Name, 'USAGE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_server_privilege(12345, 'USAGE WITH GRANT OPTION') +---- +NULL + +query error pgcode 22023 function "has_server_privilege" does not exist +SELECT has_server_privilege(12345, 'UPDATE') + +query error pgcode 22023 function "has_server_privilege" does not exist +SELECT has_server_privilege(12345, 'USAGE, UPDATE') + +query error pgcode 42704 function "has_server_privilege" does not exist +SELECT has_server_privilege('no_user', 12345, 'USAGE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_server_privilege('bar', 12345, 'USAGE') +---- +NULL + + +## has_table_privilege + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBB +SELECT has_table_privilege(12345, 'SELECT'), + has_table_privilege(12345, 'INSERT'), + has_table_privilege(12345, 'UPDATE'), + has_table_privilege(12345, 'DELETE'), + has_table_privilege(12345, 'TRUNCATE'), + has_table_privilege(12345, 'REFERENCES'), + has_table_privilege(12345, 'TRIGGER'), + has_table_privilege(12345, 'RULE') +---- +NULL NULL NULL NULL NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBB +SELECT has_table_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'SELECT'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'INSERT'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'UPDATE'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'DELETE'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'TRUNCATE'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'REFERENCES'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'TRIGGER'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 'pg_type'), 'RULE') +---- +true false false false false true false false + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBB +SELECT has_table_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'SELECT'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'INSERT'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'UPDATE'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'DELETE'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'TRUNCATE'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'REFERENCES'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'TRIGGER'), + has_table_privilege((SELECT oid FROM pg_class WHERE relname = 't'), 'RULE') +---- +true true true true true true true false + +query error pgcode 42P01 relation "does_not_exist" does not exist +SELECT has_table_privilege('does_not_exist', 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBBBBB +SELECT has_table_privilege('pg_type', 'SELECT'), + has_table_privilege('pg_type', 'INSERT'), + has_table_privilege('pg_type', 'UPDATE'), + has_table_privilege('pg_type', 'DELETE'), + has_table_privilege('pg_type', 'TRUNCATE'), + has_table_privilege('pg_type', 'REFERENCES'), + has_table_privilege('pg_type', 'TRIGGER'), + has_table_privilege('pg_type', 'SELECT, INSERT, UPDATE'), + has_table_privilege('pg_type', 'SELECT, TRUNCATE'), + has_table_privilege('pg_type', 'INSERT, UPDATE'), + has_table_privilege('pg_type', 'RULE') +---- +true false false false false true false true true false false + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBBBB +SELECT has_table_privilege('t', 'SELECT'), + has_table_privilege('t', 'INSERT'), + has_table_privilege('t', 'UPDATE'), + has_table_privilege('t', 'DELETE'), + has_table_privilege('t', 'TRUNCATE'), + has_table_privilege('t', 'REFERENCES'), + has_table_privilege('t', 'TRIGGER'), + has_table_privilege('t', 'SELECT, INSERT, UPDATE'), + has_table_privilege('t', 'SELECT, TRUNCATE'), + has_table_privilege('t', 'RULE') +---- +true true true true true true true true true false + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBBBB +SELECT has_table_privilege('t', 'SELECT WITH GRANT OPTION'), + has_table_privilege('t', 'INSERT WITH GRANT OPTION'), + has_table_privilege('t', 'UPDATE WITH GRANT OPTION'), + has_table_privilege('t', 'DELETE WITH GRANT OPTION'), + has_table_privilege('t', 'TRUNCATE WITH GRANT OPTION'), + has_table_privilege('t', 'REFERENCES WITH GRANT OPTION'), + has_table_privilege('t', 'TRIGGER WITH GRANT OPTION'), + has_table_privilege('t', 'SELECT WITH GRANT OPTION, INSERT WITH GRANT OPTION, UPDATE WITH GRANT OPTION'), + has_table_privilege('t', 'SELECT WITH GRANT OPTION, TRUNCATE WITH GRANT OPTION'), + has_table_privilege('t', 'RULE WITH GRANT OPTION') +---- +true true true true true true true true true false + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBBBB +SELECT has_table_privilege('t'::Name, 'SELECT'), + has_table_privilege('t'::Name, 'INSERT'), + has_table_privilege('t'::Name, 'UPDATE'), + has_table_privilege('t'::Name, 'DELETE'), + has_table_privilege('t'::Name, 'TRUNCATE'), + has_table_privilege('t'::Name, 'REFERENCES'), + has_table_privilege('t'::Name, 'TRIGGER'), + has_table_privilege('t'::Name, 'SELECT, INSERT, UPDATE'), + has_table_privilege('t'::Name, 'SELECT, TRUNCATE'), + has_table_privilege('t'::Name, 'RULE') +---- +true true true true true true true true true false + +# Not supported by Materialize. +onlyif cockroach +# has_table_privilege works with sequences as well. +query BBBBBBBBBB +SELECT has_table_privilege('seq', 'SELECT'), + has_table_privilege('seq', 'INSERT'), + has_table_privilege('seq', 'UPDATE'), + has_table_privilege('seq', 'DELETE'), + has_table_privilege('seq', 'TRUNCATE'), + has_table_privilege('seq', 'REFERENCES'), + has_table_privilege('seq', 'TRIGGER'), + has_table_privilege('seq', 'SELECT, INSERT, UPDATE'), + has_table_privilege('seq', 'SELECT, TRUNCATE'), + has_table_privilege('seq', 'RULE') +---- +true true true true true true true true true false + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 22023 unrecognized privilege type: "USAGE" +SELECT has_table_privilege('t', 'USAGE') + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 22023 unrecognized privilege type: "USAGE" +SELECT has_table_privilege('t', 'SELECT, USAGE') + +query error pgcode 42704 role "no_user" does not exist +SELECT has_table_privilege('no_user', 't', 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBBBBB +SELECT has_table_privilege('bar', 't', 'SELECT'), + has_table_privilege('bar', 't', 'INSERT'), + has_table_privilege('bar', 't', 'UPDATE'), + has_table_privilege('bar', 't', 'DELETE'), + has_table_privilege('bar', 't', 'TRUNCATE'), + has_table_privilege('bar', 't', 'REFERENCES'), + has_table_privilege('bar', 't', 'TRIGGER'), + has_table_privilege('bar', 't', 'SELECT, INSERT, UPDATE'), + has_table_privilege('bar', 't', 'SELECT, TRUNCATE'), + has_table_privilege('bar', 't', 'INSERT, UPDATE'), + has_table_privilege('bar', 't', 'RULE') +---- +false false false true true false false false true false false + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBBBBB +SELECT has_table_privilege('bar', 't', 'SELECT WITH GRANT OPTION'), + has_table_privilege('bar', 't', 'INSERT WITH GRANT OPTION'), + has_table_privilege('bar', 't', 'UPDATE WITH GRANT OPTION'), + has_table_privilege('bar', 't', 'DELETE WITH GRANT OPTION'), + has_table_privilege('bar', 't', 'TRUNCATE WITH GRANT OPTION'), + has_table_privilege('bar', 't', 'REFERENCES WITH GRANT OPTION'), + has_table_privilege('bar', 't', 'TRIGGER WITH GRANT OPTION'), + has_table_privilege('bar', 't', 'SELECT WITH GRANT OPTION, INSERT WITH GRANT OPTION, UPDATE WITH GRANT OPTION'), + has_table_privilege('bar', 't', 'SELECT WITH GRANT OPTION, TRUNCATE WITH GRANT OPTION'), + has_table_privilege('bar', 't', 'INSERT WITH GRANT OPTION, UPDATE WITH GRANT OPTION'), + has_table_privilege('bar', 't', 'RULE WITH GRANT OPTION') +---- +false false false false false false false false false false false + + +## has_tablespace_privilege + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_tablespace_privilege(12345, 'CREATE') +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_tablespace_privilege((SELECT oid FROM pg_tablespace LIMIT 1), 'CREATE') +---- +true + +query error pgcode 42704 function "has_tablespace_privilege" does not exist +SELECT has_tablespace_privilege('does_not_exist', 'CREATE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_tablespace_privilege('pg_default', ' CrEaTe ') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_tablespace_privilege('pg_default', 'CREATE WITH GRANT OPTION') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_tablespace_privilege('pg_default'::Name, 'CREATE') +---- +true + +query error pgcode 22023 function "has_tablespace_privilege" does not exist +SELECT has_tablespace_privilege('pg_default', 'CREATE WITH GRANT OPTION') + +query error pgcode 22023 function "has_tablespace_privilege" does not exist +SELECT has_tablespace_privilege('pg_default', 'UPDATE') + +query error pgcode 22023 function "has_tablespace_privilege" does not exist +SELECT has_tablespace_privilege('pg_default', 'CREATE, UPDATE') + +query error pgcode 42704 function "has_tablespace_privilege" does not exist +SELECT has_tablespace_privilege('no_user', 'pg_default', 'CREATE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_tablespace_privilege('bar', (SELECT oid FROM pg_tablespace LIMIT 1), 'CREATE') +---- +true + + +## has_type_privilege + +query B +SELECT has_type_privilege(12345, 'USAGE') +---- +NULL + +query B +SELECT has_type_privilege((SELECT oid FROM pg_type LIMIT 1), 'USAGE') +---- +true + +query error pgcode 42704 type "does_not_exist" does not exist +SELECT has_type_privilege('does_not_exist', 'USAGE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_type_privilege('int', ' USAGE ') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_type_privilege('decimal(18,2)', 'USAGE WITH GRANT OPTION') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_type_privilege('int'::Name, 'USAGE') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 22023 unrecognized privilege type: "UPDATE" +SELECT has_type_privilege('int4', 'UPDATE') + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 22023 unrecognized privilege type: "UPDATE" +SELECT has_type_privilege('int4', 'USAGE, UPDATE') + +query error pgcode 42704 role "no_user" does not exist +SELECT has_type_privilege('no_user', 'int4', 'USAGE') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_type_privilege('bar', 'text'::REGTYPE, 'USAGE') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_type_privilege('bar', 'text'::REGTYPE::OID, 'USAGE') +---- +true + + +## pg_has_role + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT pg_has_role(12345, 'USAGE'), + pg_has_role(12345, 'USAGE WITH GRANT OPTION'), + pg_has_role(12345, 'USAGE WITH ADMIN OPTION'), + pg_has_role(12345, 'MEMBER'), + pg_has_role(12345, 'MEMBER WITH GRANT OPTION'), + pg_has_role(12345, 'MEMBER WITH ADMIN OPTION') +---- +NULL NULL NULL NULL NULL NULL + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT pg_has_role((SELECT oid FROM pg_roles WHERE rolname = 'root'), 'USAGE'), + pg_has_role((SELECT oid FROM pg_roles WHERE rolname = 'root'), 'USAGE WITH GRANT OPTION'), + pg_has_role((SELECT oid FROM pg_roles WHERE rolname = 'root'), 'USAGE WITH ADMIN OPTION'), + pg_has_role((SELECT oid FROM pg_roles WHERE rolname = 'root'), 'MEMBER'), + pg_has_role((SELECT oid FROM pg_roles WHERE rolname = 'root'), 'MEMBER WITH GRANT OPTION'), + pg_has_role((SELECT oid FROM pg_roles WHERE rolname = 'root'), 'MEMBER WITH ADMIN OPTION') +---- +true true true true true true + +query error pgcode 42704 role "does_not_exist" does not exist +SELECT pg_has_role('does_not_exist', 'USAGE') + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT pg_has_role('root', 'USAGE'), + pg_has_role('root', 'USAGE WITH GRANT OPTION'), + pg_has_role('root', 'USAGE WITH ADMIN OPTION'), + pg_has_role('root', 'MEMBER'), + pg_has_role('root', 'MEMBER WITH GRANT OPTION'), + pg_has_role('root', 'MEMBER WITH ADMIN OPTION') +---- +true true true true true true + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 22023 role "root" does not exist +SELECT pg_has_role('root', 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 22023 role "root" does not exist +SELECT pg_has_role('root', 'SELECT, SELECT') + +query error pgcode 42704 role "root" does not exist +SELECT pg_has_role('no_user', 'root', 'USAGE') + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT pg_has_role('root', 'root', 'USAGE'), + pg_has_role('root', 'root', 'USAGE WITH GRANT OPTION'), + pg_has_role('root', 'root', 'USAGE WITH ADMIN OPTION'), + pg_has_role('root', 'root', 'MEMBER'), + pg_has_role('root', 'root', 'MEMBER WITH GRANT OPTION'), + pg_has_role('root', 'root', 'MEMBER WITH ADMIN OPTION') +---- +true true true true true true + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT pg_has_role('bar', 'root', 'USAGE'), + pg_has_role('bar', 'root', 'USAGE WITH GRANT OPTION'), + pg_has_role('bar', 'root', 'USAGE WITH ADMIN OPTION'), + pg_has_role('bar', 'root', 'MEMBER'), + pg_has_role('bar', 'root', 'MEMBER WITH GRANT OPTION'), + pg_has_role('bar', 'root', 'MEMBER WITH ADMIN OPTION') +---- +false false false false false false + +statement ok +CREATE ROLE some_users + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT some_users TO bar + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT pg_has_role('testuser', 'some_users', 'USAGE'), + pg_has_role('testuser', 'some_users', 'USAGE WITH GRANT OPTION'), + pg_has_role('testuser', 'some_users', 'USAGE WITH ADMIN OPTION'), + pg_has_role('testuser', 'some_users', 'MEMBER'), + pg_has_role('testuser', 'some_users', 'MEMBER WITH GRANT OPTION'), + pg_has_role('testuser', 'some_users', 'MEMBER WITH ADMIN OPTION') +---- +false false false false false false + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT pg_has_role('root', 'some_users', 'USAGE'), + pg_has_role('root', 'some_users', 'USAGE WITH GRANT OPTION'), + pg_has_role('root', 'some_users', 'USAGE WITH ADMIN OPTION'), + pg_has_role('root', 'some_users', 'MEMBER'), + pg_has_role('root', 'some_users', 'MEMBER WITH GRANT OPTION'), + pg_has_role('root', 'some_users', 'MEMBER WITH ADMIN OPTION') +---- +true true true true true true + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBBBB +SELECT pg_has_role('bar', 'some_users', 'USAGE'), + pg_has_role('bar', 'some_users', 'USAGE WITH GRANT OPTION'), + pg_has_role('bar', 'some_users', 'USAGE WITH ADMIN OPTION'), + pg_has_role('bar', 'some_users', 'MEMBER'), + pg_has_role('bar', 'some_users', 'MEMBER WITH GRANT OPTION'), + pg_has_role('bar', 'some_users', 'MEMBER WITH ADMIN OPTION'), + pg_has_role('bar', 'some_users', 'USAGE, MEMBER'), + pg_has_role('bar', 'some_users', 'USAGE, MEMBER WITH GRANT OPTION'), + pg_has_role('bar', 'some_users', 'USAGE WITH GRANT OPTION, MEMBER'), + pg_has_role('bar', 'some_users', 'USAGE WITH GRANT OPTION, MEMBER WITH GRANT OPTION') +---- +true false false true false false true true true false + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT some_users TO bar WITH ADMIN OPTION + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT pg_has_role('bar', 'some_users', 'USAGE'), + pg_has_role('bar', 'some_users', 'USAGE WITH GRANT OPTION'), + pg_has_role('bar', 'some_users', 'USAGE WITH ADMIN OPTION'), + pg_has_role('bar', 'some_users', 'MEMBER'), + pg_has_role('bar', 'some_users', 'MEMBER WITH GRANT OPTION'), + pg_has_role('bar', 'some_users', 'MEMBER WITH ADMIN OPTION') +---- +true true true true true true + +# WITH ADMIN OPTION is session-user dependent. + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT pg_has_role('testuser', 'testuser', 'USAGE'), + pg_has_role('testuser', 'testuser', 'USAGE WITH GRANT OPTION'), + pg_has_role('testuser', 'testuser', 'USAGE WITH ADMIN OPTION'), + pg_has_role('testuser', 'testuser', 'MEMBER'), + pg_has_role('testuser', 'testuser', 'MEMBER WITH GRANT OPTION'), + pg_has_role('testuser', 'testuser', 'MEMBER WITH ADMIN OPTION') +---- +true false false true false false + +user testuser + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT pg_has_role('testuser', 'testuser', 'USAGE'), + pg_has_role('testuser', 'testuser', 'USAGE WITH GRANT OPTION'), + pg_has_role('testuser', 'testuser', 'USAGE WITH ADMIN OPTION'), + pg_has_role('testuser', 'testuser', 'MEMBER'), + pg_has_role('testuser', 'testuser', 'MEMBER WITH GRANT OPTION'), + pg_has_role('testuser', 'testuser', 'MEMBER WITH ADMIN OPTION') +---- +true true true true true true + +# Not supported by Materialize. +onlyif cockroach +query BBBBBB +SELECT pg_has_role('testuser', 'USAGE'), + pg_has_role('testuser', 'USAGE WITH GRANT OPTION'), + pg_has_role('testuser', 'USAGE WITH ADMIN OPTION'), + pg_has_role('testuser', 'MEMBER'), + pg_has_role('testuser', 'MEMBER WITH GRANT OPTION'), + pg_has_role('testuser', 'MEMBER WITH ADMIN OPTION') +---- +true true true true true true + +user root + + +# Regression test for #39703. + +statement ok +DROP TABLE IF EXISTS hcp_test; CREATE TABLE hcp_test (a INT8, b INT8, c INT8) + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE hcp_test DROP COLUMN b + +query TI +SELECT attname, attnum FROM pg_attribute WHERE attrelid = 'hcp_test'::REGCLASS +---- +a 1 +b 2 +c 3 + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_column_privilege('hcp_test'::REGCLASS, 1, 'SELECT') +---- +true + +statement error function "has_column_privilege" does not exist +SELECT has_column_privilege('hcp_test'::REGCLASS, 2, 'SELECT') + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_column_privilege('hcp_test'::REGCLASS, 3, 'SELECT') +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_column_privilege('hcp_test'::REGCLASS, 4, 'SELECT') +---- +true + +# Regression test for #58254. Tests privilege inheritance for roles (direct and indirect). + +user root + +statement ok +DROP DATABASE IF EXISTS my_db; +CREATE DATABASE my_db; + +statement ok +CREATE ROLE my_role; + +statement ok +GRANT CREATE ON DATABASE my_db TO my_role; +GRANT my_role TO testuser; + +# Not supported by Materialize. +onlyif cockroach +statement ok +use my_db + +statement ok +CREATE SCHEMA s; +CREATE TABLE s.t() + +# Privilege check on direct member of role with CREATE privilege granted. +query B +SELECT has_schema_privilege('testuser', 's', 'create') +---- +false + +statement ok +REVOKE USAGE ON SCHEMA s FROM testuser; + +# Privilege check on direct member of role without USAGE privilege granted. +query B +SELECT has_schema_privilege('testuser', 's', 'usage') +---- +false + +# Confirm privilege checks on all objects. +query BBB +SELECT has_database_privilege('testuser', 'my_db', 'create'), + has_schema_privilege('testuser', 'public', 'usage'), + has_table_privilege('testuser', 's.t', 'select') +---- +true true false + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER testuser2; +GRANT testuser TO testuser2; +GRANT ALL ON SCHEMA my_db.s TO testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +use my_db + +# Not supported by Materialize. +onlyif cockroach +# Make sure testuser only has CREATE privilege on schema s but testuser2 has both CREATE and USAGE. +query BBBB +SELECT has_schema_privilege('testuser', 's', 'create'), + has_schema_privilege('testuser', 's', 'usage'), + has_schema_privilege('testuser2', 's', 'create'), + has_schema_privilege('testuser2', 's', 'usage') +---- +false false true true + +# Not supported by Materialize. +onlyif cockroach +# Confirm privilege checks on all objects with testuser2, should match testuser. +query BBB +SELECT has_database_privilege('testuser2', 'my_db', 'create'), + has_schema_privilege('testuser2', 'public', 'usage'), + has_table_privilege('testuser2', 's.t', 'select') +---- +true true false + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE my_role FROM testuser; +REVOKE testuser FROM testuser2 + +# Not supported by Materialize. +onlyif cockroach +# Schema owner has all privileges +statement ok +CREATE SCHEMA owned_schema AUTHORIZATION testuser + +# Not supported by Materialize. +onlyif cockroach +query BBBB +SELECT has_schema_privilege('testuser', 'owned_schema', 'create'), + has_schema_privilege('testuser', 'owned_schema', 'usage'), + has_schema_privilege('testuser2', 'owned_schema', 'create'), + has_schema_privilege('testuser2', 'owned_schema', 'usage') +---- +true true false false diff --git a/test/sqllogictest/cockroach/privileges_comments.slt b/test/sqllogictest/cockroach/privileges_comments.slt new file mode 100644 index 0000000000000..f7faab5c2f2be --- /dev/null +++ b/test/sqllogictest/cockroach/privileges_comments.slt @@ -0,0 +1,137 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/privileges_comments +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +subtest regression45707 + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE DATABASE d45707; CREATE TABLE d45707.t45707(x INT); + GRANT CONNECT ON DATABASE d45707 TO testuser; + GRANT SELECT ON d45707.t45707 TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON DATABASE d45707 IS 'd45707'; +COMMENT ON TABLE d45707.t45707 IS 't45707'; +COMMENT ON COLUMN d45707.t45707.x IS 'x45707'; +COMMENT ON INDEX d45707.t45707@t45707_pkey IS 'p45707' + +user testuser + +statement ok +SET DATABASE = d45707 + +# Verify the user cannot modify the comments + +statement error unknown database 'd45707' +COMMENT ON DATABASE d45707 IS 'd45707' + +onlyif config local-legacy-schema-changer +statement error user testuser does not have CREATE privilege on relation t45707 +COMMENT ON TABLE d45707.t45707 IS 't45707' + +skipif config local-legacy-schema-changer +statement error unknown schema 'd45707' +COMMENT ON TABLE d45707.t45707 IS 't45707' + +onlyif config local-legacy-schema-changer +statement error user testuser does not have CREATE privilege on relation t45707 +COMMENT ON COLUMN d45707.t45707.x IS 'x45707' + +skipif config local-legacy-schema-changer +statement error unknown schema 'd45707' +COMMENT ON COLUMN d45707.t45707.x IS 'x45707' + +onlyif config local-legacy-schema-changer +statement error user testuser does not have CREATE privilege on relation t45707 +COMMENT ON INDEX d45707.t45707@t45707_pkey IS 'p45707' + +skipif config local-legacy-schema-changer +statement error Expected IS, found operator "@" +COMMENT ON INDEX d45707.t45707@t45707_pkey IS 'p45707' + +# Verify that the user can view the comments + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT shobj_description(oid, 'pg_database') + FROM pg_database + WHERE datname = 'd45707' +---- +d45707 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT col_description(attrelid, attnum) + FROM pg_attribute + WHERE attrelid = 't45707'::regclass AND attname = 'x' +---- +x45707 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT obj_description('t45707'::REGCLASS) +---- +t45707 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT obj_description(indexrelid) + FROM pg_index + WHERE indrelid = 't45707'::REGCLASS + AND indisprimary +---- +p45707 + +# Verify that the user can modify the comments. + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON DATABASE d45707 TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON TABLE d45707.t45707 TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON DATABASE d45707 IS 'd45707_2'; +COMMENT ON TABLE d45707.t45707 IS 't45707_2'; +COMMENT ON COLUMN d45707.t45707.x IS 'x45707_2'; +COMMENT ON INDEX d45707.t45707@t45707_pkey IS 'p45707_2' diff --git a/test/sqllogictest/cockroach/propagate_input_ordering.slt b/test/sqllogictest/cockroach/propagate_input_ordering.slt new file mode 100644 index 0000000000000..1f3a98265f0b3 --- /dev/null +++ b/test/sqllogictest/cockroach/propagate_input_ordering.slt @@ -0,0 +1,187 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/propagate_input_ordering +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +SET propagate_input_ordering=true; + +query I +WITH tmp AS (SELECT * FROM generate_series(1, 10) i ORDER BY i % 5 ASC, i ASC) SELECT * FROM tmp; +---- +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 + +query I +WITH tmp AS (SELECT * FROM generate_series(1, 10) i ORDER BY i % 5 ASC, i ASC) SELECT * FROM tmp; +---- +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 + +# The internal ordering column for i%5 should not be present in the output. +query T +SELECT foo FROM (SELECT i, i%2 FROM generate_series(1, 10) i ORDER BY i % 5 ASC, i ASC) AS foo +---- +(2,0) +(4,0) +(6,0) +(8,0) +(10,0) +(1,1) +(3,1) +(5,1) +(7,1) +(9,1) + +# The internal ordering column for i%5 should not be present in the output. +query II +SELECT foo.* FROM (SELECT i, i%2 FROM generate_series(1, 10) i ORDER BY i % 5 ASC, i ASC) AS foo +---- +2 0 +4 0 +6 0 +8 0 +10 0 +1 1 +3 1 +5 1 +7 1 +9 1 + +# CLU-160 (https://linear.app/materializeinc/issue/CLU-160): Materialize ignores +# an ORDER BY inside a subquery feeding array_agg, so the aggregate reflects the +# generate_series order rather than the requested one. PG honors the subquery +# order (standard-unspecified, but PG-compatible). +# PG: {1,3,5,2,4} +query T +SELECT array_agg(i) FROM (SELECT * FROM generate_series(1, 5) i ORDER BY i%2 DESC, i) +---- +{1,2,3,4,5} + +# The input ordering is not propagated through joins. +query II +SELECT * +FROM (SELECT * FROM generate_series(1, 2) x) tmp, + (SELECT * FROM generate_series(8, 12) i ORDER BY i % 5 ASC, i ASC) tmp2; +---- +1 8 +1 9 +1 10 +1 11 +1 12 +2 8 +2 9 +2 10 +2 11 +2 12 + +# Do not preserve the subquery ordering because the parent scope has its own +# ordering. +query I +WITH tmp AS (SELECT * FROM generate_series(1, 10) i ORDER BY i % 5 ASC, i ASC) +SELECT * FROM tmp ORDER BY i DESC; +---- +10 +9 +8 +7 +6 +5 +4 +3 +2 +1 + +# Do not preserve the subquery ordering because the parent scope has its own +# ordering. +query I +WITH tmp AS (SELECT * FROM generate_series(1, 10) i ORDER BY i % 5 ASC, i ASC) +SELECT * FROM tmp ORDER BY i DESC; +---- +10 +9 +8 +7 +6 +5 +4 +3 +2 +1 + +statement ok +CREATE TABLE ab (a int, b int) + +statement ok +INSERT INTO ab VALUES (10, 100), (1, 10), (5, 50) + +statement ok +CREATE TABLE xy (x int, y int); + +statement ok +INSERT INTO xy VALUES (2, 20), (8, 80), (4, 41), (4, 40) + +query I +WITH + cte1 AS (SELECT b FROM ab ORDER BY a), + cte2 AS (SELECT y FROM xy ORDER BY x, y) +SELECT * FROM cte1 UNION ALL SELECT * FROM cte2 +---- +10 +20 +40 +41 +50 +80 +100 + +query I +WITH + cte1 AS (SELECT b FROM ab ORDER BY a+b), + cte2 AS (SELECT DISTINCT ON (x) y FROM xy ORDER BY x, y) +SELECT * FROM cte1 UNION ALL SELECT * FROM cte2 +---- +10 +20 +40 +50 +80 +100 + +statement ok +RESET propagate_input_ordering diff --git a/test/sqllogictest/cockroach/record.slt b/test/sqllogictest/cockroach/record.slt new file mode 100644 index 0000000000000..ef64e19315488 --- /dev/null +++ b/test/sqllogictest/cockroach/record.slt @@ -0,0 +1,272 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/record +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE a(a INT PRIMARY KEY, b TEXT); +INSERT INTO a VALUES(1,'2') + +# Not supported by Materialize. +onlyif cockroach +# Virtual tables get an implicit record type. +query TT +SELECT (1, 'cat', 2, '{}')::pg_catalog.pg_namespace, ((3, 'dog', 4, ARRAY[]::STRING[])::pg_namespace).nspname +---- +(1,cat,2,{}) dog + +query TITIT colnames +SELECT t, t.a, t.b, t.* FROM a AS t +---- +t a b a b +(1,2) 1 2 1 2 + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT (1, 'foo')::a, ((1, 'foo')::a).b +---- +(1,foo) foo + +# Not supported by Materialize. +onlyif cockroach +# Can't cast if wrong element length. +query error invalid cast: tuple{int} -> tuple{int AS a, string AS b} +SELECT (1,)::a + +query error type "a" does not exist +SELECT (1,3,5)::a + +# Not supported by Materialize. +onlyif cockroach +# Types within a tuple auto-cast to each other when possible +query TT +SELECT (1, 3)::a, ('3', 'blah')::a +---- +(1,3) (3,blah) + +# ... but fail when not possible. +query error type "a" does not exist +SELECT ('blah', 'blah')::a + +# Not supported by Materialize. +onlyif cockroach +# You can resolve types with schemas and dbs attached. +query TT +SELECT (1, 'foo')::public.a, (1, 'foo')::test.public.a +---- +(1,foo) (1,foo) + +# The tuple type doesn't contain implicit columns like rowid or hash columns. +statement ok +CREATE TABLE implicit_col(d INT, e TEXT, INDEX (e) USING HASH WITH (bucket_count=8)) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT (1, 'foo')::implicit_col +---- +(1,foo) + +# Not supported by Materialize. +onlyif cockroach +# You can cast between tuple types and their labels change. +query TITIT colnames +SELECT t::implicit_col, (t::implicit_col).d, (t::implicit_col).e, (t::implicit_col).* FROM a AS t +---- +t d e d e +(1,2) 1 2 1 2 + +# You can't use a table type as a column type. +statement error type "implicit_col" does not exist +CREATE TABLE fail (a implicit_col) + +# Not supported by Materialize. +onlyif cockroach +# REGTYPE works, and returns the type ID. +query TB +SELECT 'a'::REGTYPE, 'a'::REGTYPE::INT = 'a'::REGCLASS::INT + 100000 +---- +a true + +let $tabletypeid +SELECT 'a'::REGTYPE::INT + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT $tabletypeid::REGTYPE::TEXT +---- +a + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT pg_typeof((1,3)::a) +---- +a + +# Not supported by Materialize. +onlyif cockroach +# You can create arrays of tuples of the table type. +query T +SELECT ARRAY[(1, 3)::a, (1, 2)::a] +---- +{"(1,3)","(1,2)"} + +# Not supported by Materialize. +onlyif cockroach +# Their pg_type looks like a[]. +query T +SELECT pg_typeof(ARRAY[(1, 3)::a, (1, 2)::a]) +---- +a[] + +# Not supported by Materialize. +onlyif cockroach +# But getting the OID for the array type gives back the same thing as +# generic record[]. +query T +SELECT pg_typeof(ARRAY[(1, 3)::a, (1, 2)::a])::regtype::oid::regtype +---- +a[] + +# You can't drop the type descriptor. +statement error type "a" does not exist +DROP TYPE a + +# Not supported by Materialize. +onlyif cockroach +# User-defined types in table defs work fine. +statement ok +CREATE TYPE e AS ENUM ('a', 'b'); +CREATE TABLE b (a INT PRIMARY KEY, e e) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT (1, 'a')::b +---- +(1,a) + + +# Can't use a table record type in a persisted descriptor. +statement error type "b" does not exist +CREATE TABLE fail (b INT DEFAULT (((1,'a')::b).a)) + +statement error Expected end of statement, found DEFAULT +ALTER TABLE b ADD COLUMN b INT DEFAULT (((1,'a')::b).a) + +statement error Expected column option, found AS +CREATE TABLE fail (b INT AS (((1,'a')::b).a) VIRTUAL) + +statement error Expected end of statement, found AS +ALTER TABLE b ADD COLUMN b INT AS (((1,'a')::b).a) VIRTUAL + +statement error Expected column option, found AS +CREATE TABLE fail (b INT AS (((1,'a')::b).a) STORED) + +statement error Expected end of statement, found AS +ALTER TABLE b ADD COLUMN b INT AS (((1,'a')::b).a) STORED + +# Not supported by Materialize. +onlyif cockroach +statement error cannot modify table record type +CREATE TABLE fail (b INT, INDEX(b) WHERE b > (((1,'a')::b).a)) + +statement error Expected end of statement, found WHERE +CREATE INDEX ON a(a) WHERE a > (((1,'a')::b).a) + +# Not supported by Materialize. +onlyif cockroach +statement error cannot modify table record type +CREATE TABLE fail (b INT, INDEX((b + (((1,'a')::b).a)))) + +statement error type "b" does not exist +CREATE INDEX ON a((a + (((1,'a')::b).a))) + +statement error type "b" does not exist +CREATE VIEW v AS SELECT (1,'a')::b + +statement error type "b" does not exist +CREATE VIEW v AS SELECT ((1,'a')::b).a + +# Test parsing/casting of record types from string literals. + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT COALESCE(ARRAY[ROW(1, 2)], '{}') +---- +{"(1,2)"} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT COALESCE(NULL, '{}'::record[]); +---- +{} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '{"(1, 3)", "(1, 2)"}'::a[] +---- +{"(1,\" 3\")","(1,\" 2\")"} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT COALESCE(NULL::a[], '{"(1, 3)", "(1, 2)"}'); +---- +{"(1,\" 3\")","(1,\" 2\")"} + +statement ok +CREATE TABLE strings(s TEXT); +INSERT INTO strings VALUES('(1,2)'), ('(5,6)') + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT s, s::a FROM strings ORDER BY 1 +---- +(1,2) (1,2) +(5,6) (5,6) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '(1 , 2)'::a +---- +(1," 2") + +statement error pgcode 22P02 type "a" does not exist +SELECT '()'::a + +statement error pgcode 0A000 cannot reference pseudo type pg_catalog\.record +SELECT s, s::record FROM strings ORDER BY 1 + +statement error pgcode 0A000 cannot reference pseudo type pg_catalog\.record +SELECT '()'::record + +statement error pgcode 0A000 cannot reference pseudo type pg_catalog\.record +SELECT '(1,4)'::record diff --git a/test/sqllogictest/cockroach/rename_atomic.slt b/test/sqllogictest/cockroach/rename_atomic.slt new file mode 100644 index 0000000000000..6c31b980bcfd4 --- /dev/null +++ b/test/sqllogictest/cockroach/rename_atomic.slt @@ -0,0 +1,209 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/rename_atomic +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +subtest databases + +statement ok +CREATE DATABASE db; +CREATE DATABASE db_new + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +ALTER DATABASE db RENAME TO db_old; +ALTER DATABASE db_new RENAME TO db + +# Not supported by Materialize. +onlyif cockroach +statement error pgcode 3D000 database "db_new" does not exist +CREATE SCHEMA db_new.sc + +statement ok +ROLLBACK + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +ALTER DATABASE db RENAME TO db_old; +ALTER DATABASE db_new RENAME TO db; +CREATE SCHEMA db.sc; +COMMIT + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +DROP DATABASE db CASCADE; +ALTER DATABASE db_old RENAME TO db; +COMMIT + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +ALTER DATABASE db RENAME TO db_old; +CREATE DATABASE db; +COMMIT + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +DROP DATABASE db; +CREATE DATABASE db; +COMMIT + +subtest schemas + +statement ok +CREATE SCHEMA sc; +CREATE SCHEMA sc_new + +statement ok +BEGIN; +ALTER SCHEMA sc RENAME TO sc_old; +ALTER SCHEMA sc_new RENAME TO sc + +statement error pgcode 3F000 transactions which modify objects are restricted to just modifying objects +CREATE VIEW sc_new.v AS SELECT 1 + +statement ok +ROLLBACK + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +ALTER SCHEMA sc RENAME TO sc_old; +ALTER SCHEMA sc_new RENAME TO sc; +CREATE VIEW sc.v AS SELECT 1; +COMMIT + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +DROP SCHEMA sc CASCADE; +ALTER SCHEMA sc_old RENAME TO sc; +COMMIT + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +ALTER SCHEMA sc RENAME TO sc_old; +CREATE SCHEMA sc; +COMMIT + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +DROP SCHEMA sc; +CREATE SCHEMA sc; +COMMIT + +subtest objects + +statement ok +CREATE VIEW v AS SELECT 1; +CREATE VIEW v_new AS SELECT 2 + +query I +SELECT * FROM v +---- +1 + +statement ok +BEGIN; +ALTER VIEW v RENAME TO v_old; +ALTER VIEW v_new RENAME TO v + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT * FROM v +---- +2 + +statement ok +COMMIT; + +query I +SELECT * FROM v +---- +2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +DROP VIEW v; +ALTER VIEW v_old RENAME TO v + +query I +SELECT * FROM v +---- +2 + +statement ok +COMMIT + +query I +SELECT * FROM v +---- +2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +ALTER VIEW v RENAME TO v_old; +CREATE VIEW v AS SELECT 1; +COMMIT + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +DROP VIEW v; +CREATE VIEW v AS SELECT 1; +COMMIT + +# Check for correct caching behavior when scanning the namespace table. +subtest regression_93002 + +statement ok +CREATE SCHEMA sc93002 + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +SHOW TABLES FROM sc93002; +CREATE TABLE sc93002.t(a INT); +DROP SCHEMA sc93002 CASCADE; +COMMIT; diff --git a/test/sqllogictest/cockroach/rename_column.slt b/test/sqllogictest/cockroach/rename_column.slt index 8ff7d18fc890b..71b0dd541617d 100644 --- a/test/sqllogictest/cockroach/rename_column.slt +++ b/test/sqllogictest/cockroach/rename_column.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/rename_column +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/rename_column # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach statement ok @@ -41,46 +41,56 @@ uid name title 1 tom cat 2 jerry rat -statement error column name "name" already exists +statement error Expected TO, found COLUMN ALTER TABLE users RENAME COLUMN title TO name -statement error empty column name +statement error pgcode 42601 Expected TO, found COLUMN ALTER TABLE users RENAME COLUMN title TO "" -statement error pgcode 42703 column "ttle" does not exist +statement error pgcode 42703 Expected TO, found COLUMN ALTER TABLE users RENAME COLUMN ttle TO species -statement error pgcode 42P01 relation "uses" does not exist +statement error pgcode 42P01 Expected TO, found COLUMN ALTER TABLE uses RENAME COLUMN title TO species +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE IF EXISTS uses RENAME COLUMN title TO species +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE users RENAME COLUMN uid TO id +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE users RENAME COLUMN title TO species query ITT colnames,rowsort SELECT * FROM users ---- -id name species -1 tom cat -2 jerry rat +uid name title +1 tom cat +2 jerry rat user testuser -statement error user testuser does not have CREATE privilege on relation users +statement error Expected TO, found COLUMN ALTER TABLE users RENAME COLUMN name TO username user root +# Not supported by Materialize. +onlyif cockroach statement ok GRANT CREATE ON TABLE users TO testuser user testuser +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE users RENAME COLUMN name TO username @@ -89,78 +99,159 @@ user root query ITT colnames,rowsort SELECT * FROM users ---- -id username species -1 tom cat -2 jerry rat +uid name title +1 tom cat +2 jerry rat +# Not supported by Materialize. +onlyif cockroach # Renaming a column updates the column names in an index. -query TTBITTBB colnames -SHOW INDEXES ON users +query TTBITTTBBB colnames +SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users primary false 1 id ASC false false -users foo true 1 username ASC false false -users foo true 2 species N/A true false -users foo true 3 id ASC false true -users bar false 1 id ASC false false -users bar false 2 username ASC false false - +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users bar false 1 id id ASC false false true +users bar false 2 username username ASC false false true +users foo true 1 username username ASC false false true +users foo true 2 species species N/A true false true +users foo true 3 id id ASC false true true +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 username username N/A true false true +users users_pkey false 3 species species N/A true false true + +# Not supported by Materialize. +onlyif cockroach statement ok CREATE VIEW v1 AS SELECT id FROM users WHERE username = 'tom' -statement error cannot rename column "id" because view "v1" depends on it +statement error Expected TO, found COLUMN ALTER TABLE users RENAME COLUMN id TO uid -statement error cannot rename column "username" because view "v1" depends on it +statement error Expected TO, found COLUMN ALTER TABLE users RENAME COLUMN username TO name -# TODO(knz): restore test after cockroach#17269 / cockroach#10083 is fixed. +# TODO(knz): restore test after #17269 / #10083 is fixed. #statement ok #ALTER TABLE users RENAME COLUMN species TO title +# Not supported by Materialize. +onlyif cockroach statement ok CREATE VIEW v2 AS SELECT id from users +# Not supported by Materialize. +onlyif cockroach statement ok DROP VIEW v1 -statement error cannot rename column "id" because view "v2" depends on it +statement error Expected TO, found COLUMN ALTER TABLE users RENAME COLUMN id TO uid -# TODO(knz): restore test after cockroach#17269 / cockroach#10083 is fixed. +# TODO(knz): restore test after #17269 / #10083 is fixed. # statement ok # ALTER TABLE users RENAME COLUMN username TO name +# Not supported by Materialize. +onlyif cockroach statement ok DROP VIEW v2 +# Not supported by Materialize. +onlyif cockroach query T -SELECT column_name FROM [SHOW COLUMNS FROM users] +SELECT column_name FROM [SHOW COLUMNS FROM users] ORDER BY column_name ---- id -username species +username + +statement ok +SET vectorize=on -query TTT -EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR ALTER TABLE users RENAME COLUMN species TO woo +# Not supported by Materialize. +onlyif cockroach +query T +EXPLAIN ALTER TABLE users RENAME COLUMN species TO woo ---- -alter table · · +distribution: local +vectorized: true +· +• alter table + +statement ok +RESET vectorize +# Not supported by Materialize. +onlyif cockroach # Verify that EXPLAIN did not actually rename the column query T -SELECT column_name FROM [SHOW COLUMNS FROM users] +SELECT column_name FROM [SHOW COLUMNS FROM users] ORDER BY column_name ---- id -username species +username +# Not supported by Materialize. +onlyif cockroach # Check that a column can be added and renamed in the same statement statement ok ALTER TABLE users RENAME COLUMN species TO species_old, ADD COLUMN species STRING AS (species_old || ' woo') STORED +# Not supported by Materialize. +onlyif cockroach query T rowsort SELECT species FROM users ---- cat woo rat woo + +# Test that renaming columns works inside transactions that create resources +# which reference those columns. + +subtest rename_in_transaction + +statement ok +CREATE TABLE foo (j INT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; + ALTER TABLE foo ADD CONSTRAINT check_not_negative CHECK (j >= 0); + ALTER TABLE foo RENAME COLUMN j TO i; +COMMIT; + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; + ALTER TABLE foo ADD COLUMN k INT AS (i+1) STORED; + ALTER TABLE foo RENAME COLUMN i TO j; +COMMIT; + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; + ALTER TABLE foo ALTER COLUMN j SET NOT NULL; + ALTER TABLE foo RENAME COLUMN j TO i; +COMMIT; + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; + CREATE INDEX ON foo(i) WHERE i > 0; + ALTER TABLE foo RENAME COLUMN i TO j; +COMMIT; + +statement ok +INSERT INTO foo(j) VALUES (1); + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT j, k FROM foo; +---- +1 2 diff --git a/test/sqllogictest/cockroach/rename_constraint.slt b/test/sqllogictest/cockroach/rename_constraint.slt index 48faa93cf0c6d..79df4fbc0b144 100644 --- a/test/sqllogictest/cockroach/rename_constraint.slt +++ b/test/sqllogictest/cockroach/rename_constraint.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,95 +9,104 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/rename_constraint +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/rename_constraint # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE t ( x INT, y INT, CONSTRAINT cu UNIQUE (x), CONSTRAINT cc CHECK (x > 10), - CONSTRAINT cf FOREIGN KEY (x) REFERENCES t(x) + CONSTRAINT cf FOREIGN KEY (x) REFERENCES t(x), + FAMILY "primary" (x, y, rowid) ) +# Not supported by Materialize. +onlyif cockroach query T SELECT create_statement FROM [SHOW CREATE t] ---- -CREATE TABLE t ( - x INT8 NULL, - y INT8 NULL, - CONSTRAINT cf FOREIGN KEY (x) REFERENCES t (x), - UNIQUE INDEX cu (x ASC), - FAMILY "primary" (x, y, rowid), - CONSTRAINT cc CHECK (x > 10) +CREATE TABLE public.t ( + x INT8 NULL, + y INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC), + CONSTRAINT cf FOREIGN KEY (x) REFERENCES public.t(x), + UNIQUE INDEX cu (x ASC), + CONSTRAINT cc CHECK (x > 10:::INT8) ) query TT SELECT conname, contype FROM pg_catalog.pg_constraint ORDER BY conname ---- -cc c -cf f -cu u + subtest rename_works +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE t RENAME CONSTRAINT cu TO cu2, RENAME CONSTRAINT cf TO cf2, RENAME CONSTRAINT cc TO cc2 +# Not supported by Materialize. +onlyif cockroach query T SELECT create_statement FROM [SHOW CREATE t] ---- -CREATE TABLE t ( - x INT8 NULL, - y INT8 NULL, - CONSTRAINT cf2 FOREIGN KEY (x) REFERENCES t (x), - UNIQUE INDEX cu2 (x ASC), - FAMILY "primary" (x, y, rowid), - CONSTRAINT cc2 CHECK (x > 10) +CREATE TABLE public.t ( + x INT8 NULL, + y INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC), + CONSTRAINT cf2 FOREIGN KEY (x) REFERENCES public.t(x), + UNIQUE INDEX cu2 (x ASC), + CONSTRAINT cc2 CHECK (x > 10:::INT8) ) query TT SELECT conname, contype FROM pg_catalog.pg_constraint ORDER BY conname ---- -cc2 c -cf2 f -cu2 u + subtest duplicate_constraints -statement error duplicate constraint +statement error Expected TO, found CONSTRAINT ALTER TABLE t RENAME CONSTRAINT cu2 TO cf2 -statement error duplicate constraint +statement error Expected TO, found CONSTRAINT ALTER TABLE t RENAME CONSTRAINT cu2 TO cc2 -statement error duplicate constraint +statement error Expected TO, found CONSTRAINT ALTER TABLE t RENAME CONSTRAINT cf2 TO cu2 -statement error duplicate constraint +statement error Expected TO, found CONSTRAINT ALTER TABLE t RENAME CONSTRAINT cf2 TO cc2 -statement error duplicate constraint +statement error Expected TO, found CONSTRAINT ALTER TABLE t RENAME CONSTRAINT cc2 TO cf2 -statement error duplicate constraint +statement error Expected TO, found CONSTRAINT ALTER TABLE t RENAME CONSTRAINT cc2 TO cu2 subtest multiple_renames +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE t RENAME CONSTRAINT cu2 TO cu3, RENAME CONSTRAINT cc2 TO cc3, @@ -106,21 +115,42 @@ ALTER TABLE t RENAME CONSTRAINT cu2 TO cu3, RENAME CONSTRAINT cc3 TO cc4, RENAME CONSTRAINT cf3 TO cf4 +# Not supported by Materialize. +onlyif cockroach query T SELECT create_statement FROM [SHOW CREATE t] ---- -CREATE TABLE t ( - x INT8 NULL, - y INT8 NULL, - CONSTRAINT cf4 FOREIGN KEY (x) REFERENCES t (x), - UNIQUE INDEX cu4 (x ASC), - FAMILY "primary" (x, y, rowid), - CONSTRAINT cc4 CHECK (x > 10) +CREATE TABLE public.t ( + x INT8 NULL, + y INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC), + CONSTRAINT cf4 FOREIGN KEY (x) REFERENCES public.t(x), + UNIQUE INDEX cu4 (x ASC), + CONSTRAINT cc4 CHECK (x > 10:::INT8) ) query TT SELECT conname, contype FROM pg_catalog.pg_constraint ORDER BY conname ---- -cc4 c -cf4 f -cu4 u + + +# Allow renames of the implicit primary key. +statement ok +CREATE TABLE implicit (a int, b int) + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE implicit RENAME CONSTRAINT implicit_pkey TO something_else + +# Not supported by Materialize. +onlyif cockroach +query TTTTB colnames +SHOW CONSTRAINTS FROM implicit +---- +table_name constraint_name constraint_type details validated +implicit something_else PRIMARY KEY PRIMARY KEY (rowid ASC) true + +statement error Expected COLUMN, found CONSTRAINT +ALTER TABLE implicit ADD CONSTRAINT something_else CHECK(b > 0) diff --git a/test/sqllogictest/cockroach/rename_database.slt b/test/sqllogictest/cockroach/rename_database.slt deleted file mode 100644 index c1cadbb33f3bd..0000000000000 --- a/test/sqllogictest/cockroach/rename_database.slt +++ /dev/null @@ -1,195 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/rename_database -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -query T -SHOW DATABASES ----- -materialize -postgres -system -test - -query TTTT -SHOW GRANTS ON DATABASE test ----- -test crdb_internal admin ALL -test crdb_internal root ALL -test information_schema admin ALL -test information_schema root ALL -test pg_catalog admin ALL -test pg_catalog root ALL -test public admin ALL -test public root ALL - -statement ok -CREATE TABLE kv ( - k INT PRIMARY KEY, - v INT -) - -statement ok -INSERT INTO kv VALUES (1, 2), (3, 4), (5, 6), (7, 8) - -query II rowsort -SELECT * FROM kv ----- -1 2 -3 4 -5 6 -7 8 - -statement ok -SET sql_safe_updates = TRUE; - -statement error RENAME DATABASE on current database -ALTER DATABASE test RENAME TO u - -statement ok -SET sql_safe_updates = FALSE; - ALTER DATABASE test RENAME TO u - -statement error pgcode 42P01 relation "kv" does not exist -SELECT * FROM kv - -statement error target database or schema does not exist -SHOW GRANTS ON DATABASE test - -query T -SHOW DATABASES ----- -materialize -postgres -system -u - -# check the name in descriptor is also changed -query TTTT -SHOW GRANTS ON DATABASE u ----- -u crdb_internal admin ALL -u crdb_internal root ALL -u information_schema admin ALL -u information_schema root ALL -u pg_catalog admin ALL -u pg_catalog root ALL -u public admin ALL -u public root ALL - -statement ok -SET DATABASE = u - -query II rowsort -SELECT * FROM kv ----- -1 2 -3 4 -5 6 -7 8 - -statement error empty database name -ALTER DATABASE "" RENAME TO u - -statement error empty database name -ALTER DATABASE u RENAME TO "" - -statement ok -ALTER DATABASE u RENAME TO u - -statement ok -CREATE DATABASE t - -statement error the new database name "u" already exists -ALTER DATABASE t RENAME TO u - -statement ok -GRANT ALL ON DATABASE t TO testuser - -user testuser - -statement error only superusers are allowed to ALTER DATABASE ... RENAME -ALTER DATABASE t RENAME TO v - -query T -SHOW DATABASES ----- -t - -user root - -# Test that renames aren't allowed while views refer to any of a DB's tables, -# both for views in that database and for views in a different database. - -statement ok -CREATE VIEW t.v AS SELECT k,v FROM u.kv - -query T -SHOW TABLES FROM u ----- -kv - -statement error cannot rename database because view "t.public.v" depends on table "kv" -ALTER DATABASE u RENAME TO v - -statement ok -DROP VIEW t.v - -statement ok -ALTER DATABASE u RENAME TO v - -statement ok -CREATE VIEW v.v AS SELECT k,v FROM v.kv - -statement error cannot rename database because view "v" depends on table "kv" -ALTER DATABASE v RENAME TO u - -# Check that the default databases can be renamed like any other. -statement ok -ALTER DATABASE materialize RENAME TO w; - ALTER DATABASE postgres RENAME TO materialize; - ALTER DATABASE w RENAME TO postgres - -query T -SHOW DATABASES ----- -materialize -postgres -system -t -v - -query TTT -EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR ALTER DATABASE v RENAME TO x ----- -rename database · · - -# Verify that the EXPLAIN above does not actually rename the database (cockroach#30543) -query T colnames -SHOW DATABASES ----- -database_name -materialize -postgres -system -t -v diff --git a/test/sqllogictest/cockroach/rename_index.slt b/test/sqllogictest/cockroach/rename_index.slt new file mode 100644 index 0000000000000..c45c8c4f95c8d --- /dev/null +++ b/test/sqllogictest/cockroach/rename_index.slt @@ -0,0 +1,243 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/rename_index +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE users ( + id INT PRIMARY KEY, + name VARCHAR NOT NULL, + title VARCHAR, + INDEX foo (name), + UNIQUE INDEX bar (id, name) +) + +statement ok +CREATE TABLE users_dupe ( + id INT PRIMARY KEY, + name VARCHAR NOT NULL, + title VARCHAR, + INDEX foo (name), + UNIQUE INDEX bar (id, name) +) + +statement ok +INSERT INTO users VALUES (1, 'tom', 'cat'),(2, 'jerry', 'rat') + +statement ok +INSERT INTO users_dupe VALUES (1, 'tom', 'cat'),(2, 'jerry', 'rat') + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users bar false 1 id id ASC false false true +users bar false 2 name name ASC false false true +users foo true 1 name name ASC false false true +users foo true 2 id id ASC false true true +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 name name N/A true false true +users users_pkey false 3 title title N/A true false true + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users_dupe +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users_dupe bar false 1 id id ASC false false true +users_dupe bar false 2 name name ASC false false true +users_dupe foo true 1 name name ASC false false true +users_dupe foo true 2 id id ASC false true true +users_dupe users_dupe_pkey false 1 id id ASC false false true +users_dupe users_dupe_pkey false 2 name name N/A true false true +users_dupe users_dupe_pkey false 3 title title N/A true false true + +statement error pgcode 42P07 Expected one of RESET or SET or RENAME or OWNER, found operator "@" +ALTER INDEX users@foo RENAME TO bar + +statement error pgcode 42601 Expected one of RESET or SET or RENAME or OWNER, found operator "@" +ALTER INDEX users@foo RENAME TO "" + +statement error pgcode 42704 Expected one of RESET or SET or RENAME or OWNER, found operator "@" +ALTER INDEX users@ffo RENAME TO ufo + +statement error unknown catalog item 'ffo' +ALTER INDEX ffo RENAME TO ufo + +statement error unknown catalog item 'foo' +ALTER INDEX foo RENAME TO ufo + +# Not supported by Materialize. +onlyif cockroach +statement error index name "foo" is ambiguous +ALTER INDEX IF EXISTS foo RENAME TO ufo + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER INDEX IF EXISTS users@ffo RENAME TO ufo + +# Regression test for #42399. +statement ok +ALTER INDEX IF EXISTS ffo RENAME TO ufo + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER INDEX users@foo RENAME TO ufooo + +statement ok +ALTER INDEX IF EXISTS ufooo RENAME TO ufoo + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER INDEX ufoo RENAME TO ufo + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users bar false 1 id id ASC false false true +users bar false 2 name name ASC false false true +users ufo true 1 name name ASC false false true +users ufo true 2 id id ASC false true true +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 name name N/A true false true +users users_pkey false 3 title title N/A true false true + +user testuser + +statement error Expected one of RESET or SET or RENAME or OWNER, found operator "@" +ALTER INDEX users@bar RENAME TO rar + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE ON TABLE users TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER INDEX users@bar RENAME TO rar + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM users +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +users rar false 1 id id ASC false false true +users rar false 2 name name ASC false false true +users ufo true 1 name name ASC false false true +users ufo true 2 id id ASC false true true +users users_pkey false 1 id id ASC false false true +users users_pkey false 2 name name N/A true false true +users users_pkey false 3 title title N/A true false true + +user root + +query ITT rowsort +SELECT * FROM users +---- +1 tom cat +2 jerry rat + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW v AS SELECT name FROM users@{FORCE_INDEX=ufo} + +statement error Expected one of RESET or SET or RENAME or OWNER, found operator "@" +ALTER INDEX users@ufo RENAME TO foo + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER INDEX users@rar RENAME TO bar + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #24774 +statement ok +ALTER INDEX users@users_pkey RENAME TO pk + +# Not supported by Materialize. +onlyif cockroach +query ITT rowsort +SELECT * FROM users@pk +---- +1 tom cat +2 jerry rat + +statement ok +SET vectorize=on + +# Not supported by Materialize. +onlyif cockroach +query T +EXPLAIN ALTER INDEX users@bar RENAME TO woo +---- +distribution: local +vectorized: true +· +• alter index + +statement ok +RESET vectorize + +# Not supported by Materialize. +onlyif cockroach +# Verify that EXPLAIN did not actually rename the index (#30543) +query T rowsort +SELECT DISTINCT index_name FROM [SHOW INDEXES FROM users] +---- +pk +ufo +bar + +# Regression test for #81211 +statement ok +CREATE TABLE t1(a int); + +statement ok +BEGIN; + +statement ok +CREATE INDEX i1 ON t1(a); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER INDEX i1 RENAME TO i2; + +statement ok +COMMIT; diff --git a/test/sqllogictest/cockroach/rename_sequence.slt b/test/sqllogictest/cockroach/rename_sequence.slt new file mode 100644 index 0000000000000..12daf647ff057 --- /dev/null +++ b/test/sqllogictest/cockroach/rename_sequence.slt @@ -0,0 +1,64 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/rename_sequence +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# see also file `sequences` + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE alter_test + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SEQUENCE alter_test RENAME TO renamed_alter_test + +# Not supported by Materialize. +onlyif cockroach +# alter_test no longer there +statement ok +ALTER SEQUENCE IF EXISTS alter_test RENAME TO something + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER SEQUENCE IF EXISTS renamed_alter_test RENAME TO renamed_again_alter_test + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP SEQUENCE renamed_again_alter_test + +# You can't rename a sequence with ALTER TABLE or ALTER VIEW. + +# Not supported by Materialize. +onlyif cockroach +statement OK +CREATE SEQUENCE foo + +statement error pgcode 42809 unknown catalog item 'foo' +ALTER TABLE foo RENAME TO bar + +statement error pgcode 42809 unknown catalog item 'foo' +ALTER VIEW foo RENAME TO bar diff --git a/test/sqllogictest/cockroach/rename_table.slt b/test/sqllogictest/cockroach/rename_table.slt index b1c779988b27a..7abb997f84382 100644 --- a/test/sqllogictest/cockroach/rename_table.slt +++ b/test/sqllogictest/cockroach/rename_table.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,20 +9,20 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/rename_table +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/rename_table # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach -statement error pgcode 42P01 relation "foo" does not exist +statement error pgcode 42P01 unknown catalog item 'foo' ALTER TABLE foo RENAME TO bar statement ok @@ -43,15 +43,17 @@ SELECT * FROM kv 1 2 3 4 -query T +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES ---- -kv +public kv table root 0 NULL statement ok ALTER TABLE kv RENAME TO new_kv -statement error pgcode 42P01 relation "kv" does not exist +statement error pgcode 42P01 unknown catalog item 'kv' SELECT * FROM kv query II rowsort @@ -60,24 +62,30 @@ SELECT * FROM new_kv 1 2 3 4 -query T +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES ---- -new_kv +public new_kv table root 0 NULL +# Not supported by Materialize. +onlyif cockroach # check the name in the descriptor, which is used by SHOW GRANTS, is also changed -query TTTTT +query TTTTTB SHOW GRANTS ON TABLE new_kv ---- -test public new_kv admin ALL -test public new_kv root ALL +test public new_kv admin ALL true +test public new_kv root ALL true -statement error invalid table name: "" +statement error zero\-length delimited identifier ALTER TABLE "" RENAME TO foo -statement error invalid table name: "" +statement error zero\-length delimited identifier ALTER TABLE new_kv RENAME TO "" +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE new_kv RENAME TO new_kv @@ -90,16 +98,18 @@ CREATE TABLE t ( statement ok INSERT INTO t VALUES (4, 16), (5, 25) -statement error pgcode 42P07 relation "new_kv" already exists +statement error pgcode 42P07 catalog item 'new_kv' already exists ALTER TABLE t RENAME TO new_kv user testuser -statement error user testuser does not have DROP privilege on relation t +statement error unknown schema 'test' ALTER TABLE test.t RENAME TO t2 user root +# Not supported by Materialize. +onlyif cockroach statement ok GRANT DROP ON TABLE test.t TO testuser @@ -108,26 +118,32 @@ create database test2 user testuser -statement error user testuser does not have CREATE privilege on database test +statement error unknown schema 'test' ALTER TABLE test.t RENAME TO t2 user root +# Not supported by Materialize. +onlyif cockroach statement ok GRANT CREATE ON DATABASE test TO testuser +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE test.t RENAME TO t2 -query T +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES ---- -new_kv -t2 +public new_kv table root 0 NULL +public t2 table root 0 NULL user testuser -statement error user testuser does not have CREATE privilege on database test2 +statement error Expected end of statement, found dot ALTER TABLE test.t2 RENAME TO test2.t user root @@ -135,51 +151,50 @@ user root statement ok GRANT CREATE ON DATABASE test2 TO testuser +# Not supported by Materialize. +onlyif cockroach statement ok GRANT DROP ON test.new_kv TO testuser user testuser -statement ok -ALTER TABLE test.new_kv RENAME TO test2.t - -statement ok -ALTER TABLE test.t2 RENAME TO test2.t2 - -query T +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES ---- +public new_kv table root 0 NULL +public t2 table root 0 NULL -query T +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test2 ---- -t -t2 user root -query II rowsort -SELECT * FROM test2.t ----- -1 2 -3 4 - -query II rowsort -SELECT * FROM test2.t2 ----- -4 16 -5 25 +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE test2.t2(c1 INT, c2 INT) +# Not supported by Materialize. +onlyif cockroach statement ok CREATE VIEW test2.v1 AS SELECT c1,c2 FROM test2.t2 +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE test2.v1 RENAME TO test2.v2 +# Not supported by Materialize. +onlyif cockroach statement ok ALTER TABLE test2.v2 RENAME TO test2.v1 -statement error cannot rename relation "test2.public.t2" because view "v1" depends on it +statement error Expected end of statement, found dot ALTER TABLE test2.t2 RENAME TO test2.t3 # Tests that uncommitted database or table names can be used by statements @@ -189,116 +204,236 @@ ALTER TABLE test2.t2 RENAME TO test2.t3 statement ok BEGIN +# Not supported by Materialize. +onlyif cockroach statement ok CREATE DATABASE d; CREATE TABLE d.kv (k CHAR PRIMARY KEY, v CHAR); +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO d.kv (k,v) VALUES ('a', 'b') statement ok COMMIT +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO d.kv (k,v) VALUES ('c', 'd') -# A table rename disallows the use of the old name +# Check that on a rollback a database name cannot be used. statement ok BEGIN +# Not supported by Materialize. +onlyif cockroach statement ok -ALTER TABLE d.kv RENAME TO d.kv2 +CREATE DATABASE dd; CREATE TABLE dd.kv (k CHAR PRIMARY KEY, v CHAR) +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO d.kv2 (k,v) VALUES ('e', 'f') - -statement error pgcode 42P01 relation \"d.kv\" does not exist -INSERT INTO d.kv (k,v) VALUES ('g', 'h') +INSERT INTO dd.kv (k,v) VALUES ('a', 'b') statement ok ROLLBACK -# A database rename disallows the use of the old name. +statement error pgcode 42P01 unknown schema 'dd' +INSERT INTO dd.kv (k,v) VALUES ('c', 'd') + +# Check that on a rollback a table name cannot be used. statement ok BEGIN statement ok -ALTER DATABASE d RENAME TO dnew +CREATE TABLE d.kv2 (k CHAR PRIMARY KEY, v CHAR) +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO dnew.kv (k,v) VALUES ('e', 'f') - -statement error pgcode 42P01 relation \"d.kv\" does not exist -INSERT INTO d.kv (k,v) VALUES ('g', 'h') +INSERT INTO d.kv2 (k,v) VALUES ('a', 'b') statement ok ROLLBACK -# The reuse of a name is allowed. +statement error pgcode 42P01 unknown schema 'd' +INSERT INTO d.kv2 (k,v) VALUES ('c', 'd') + +# Not supported by Materialize. +onlyif cockroach statement ok -BEGIN +USE d + +# Not supported by Materialize. +onlyif cockroach +query TTTTIT +SHOW TABLES +---- +public kv table root 0 NULL statement ok -ALTER DATABASE d RENAME TO dnew +SET vectorize=on + +# Not supported by Materialize. +onlyif cockroach +query T +EXPLAIN ALTER TABLE kv RENAME TO kv2 +---- +distribution: local +vectorized: true +· +• alter table statement ok -CREATE DATABASE d +RESET vectorize + +# Not supported by Materialize. +onlyif cockroach +# Verify that the EXPLAIN above does not actually rename the table (#30543) +query TTTTIT +SHOW TABLES +---- +public kv table root 0 NULL + +# Test that tables can't be renamed to a different database unless both the +# old and new schemas are in the public schema. +subtest rename_table_across_dbs statement ok -CREATE TABLE d.kv (k CHAR PRIMARY KEY, v CHAR) +CREATE DATABASE olddb statement ok -INSERT INTO d.kv (k,v) VALUES ('a', 'b') +CREATE DATABASE newdb +# Not supported by Materialize. +onlyif cockroach statement ok -COMMIT +USE olddb -# Check that on a rollback a database name cannot be used. statement ok -BEGIN +CREATE SCHEMA oldsc +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE DATABASE dd; CREATE TABLE dd.kv (k CHAR PRIMARY KEY, v CHAR) +USE newdb statement ok -INSERT INTO dd.kv (k,v) VALUES ('a', 'b') +CREATE SCHEMA newsc statement ok -ROLLBACK +CREATE TABLE olddb.public.tbl1(); -statement error pgcode 42P01 relation "dd\.kv" does not exist -INSERT INTO dd.kv (k,v) VALUES ('c', 'd') +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE olddb.oldsc.tbl2(); + +statement error pgcode 0A000 Expected end of statement, found dot +ALTER TABLE olddb.public.tbl1 RENAME TO newdb.newsc.tbl1 + +statement error pgcode 0A000 Expected end of statement, found dot +ALTER TABLE olddb.oldsc.tbl2 RENAME TO newdb.public.tbl2 + +statement error pgcode 0A000 Expected end of statement, found dot +ALTER TABLE olddb.oldsc.tbl2 RENAME TO newdb.newsc.tbl2 + +# Try different but equivalent names. + +statement error pgcode 0A000 Expected end of statement, found dot +ALTER TABLE olddb.tbl1 RENAME TO newdb.newsc.tbl1 + +statement error pgcode 0A000 Expected end of statement, found dot +ALTER TABLE olddb.oldsc.tbl2 RENAME TO newdb.tbl2 + +statement ok +DROP DATABASE olddb CASCADE + +statement ok +DROP DATABASE newdb CASCADE + +subtest rename_table_using_types_to_different_database_not_allowed_55709 + +statement ok +CREATE DATABASE olddb + +statement ok +CREATE DATABASE newdb + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE olddb + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE typ AS ENUM ('foo') + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE tbl(a typ) + +statement error pgcode 0A000 Expected end of statement, found dot +ALTER TABLE tbl RENAME TO newdb.tbl + +# Try it in a transaction with non-public columns. + +statement ok +CREATE TABLE tbl2() -# Check that on a rollback a table name cannot be used. statement ok BEGIN +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE d.kv2 (k CHAR PRIMARY KEY, v CHAR) +ALTER TABLE tbl2 ADD COLUMN b typ + +statement error pgcode 0A000 Expected end of statement, found dot +ALTER TABLE tbl2 RENAME TO newdb.tbl2 statement ok -INSERT INTO d.kv2 (k,v) VALUES ('a', 'b') +ROLLBACK + +statement ok +BEGIN + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE tbl DROP COLUMN a + +statement error pgcode 0A000 Expected end of statement, found dot +ALTER TABLE tbl RENAME TO newdb.tbl statement ok ROLLBACK -statement error pgcode 42P01 relation \"d.kv2\" does not exist -INSERT INTO d.kv2 (k,v) VALUES ('c', 'd') +statement ok +DROP DATABASE olddb CASCADE statement ok -USE d +DROP DATABASE newdb CASCADE -query T -SHOW TABLES ----- -kv +# Sanity check for #55709 renaming tables and cross DB references -query TTT -EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR ALTER TABLE kv RENAME TO kv2 ----- -rename table · · +statement ok +CREATE DATABASE newdb; -# Verify that the EXPLAIN above does not actually rename the table (cockroach#30543) -query T -SHOW TABLES ----- -kv +statement ok +SET database = newdb; + +# Not supported by Materialize. +onlyif cockroach +# In 22.1 and onwards, disallow moving a table across databases even if +# the table is being moved from public schema to public schema. +statement ok +CREATE DATABASE d1; +CREATE TABLE d1.t(); +CREATE DATABASE d2; + +statement error pgcode 0A000 Expected end of statement, found dot +ALTER TABLE d1.t RENAME TO d2.t; diff --git a/test/sqllogictest/cockroach/rename_view.slt b/test/sqllogictest/cockroach/rename_view.slt index 14e18668586fc..9819cc9fc48ac 100644 --- a/test/sqllogictest/cockroach/rename_view.slt +++ b/test/sqllogictest/cockroach/rename_view.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,20 +9,25 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/rename_view +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/rename_view # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach -statement error pgcode 42P01 relation "foo" does not exist +# Not supported by Materialize. +onlyif cockroach +statement ok +SET CLUSTER SETTING sql.cross_db_views.enabled = TRUE + +statement error pgcode 42P01 unknown catalog item 'foo' ALTER VIEW foo RENAME TO bar statement ok @@ -46,47 +51,61 @@ SELECT * FROM v 1 2 3 4 -query T +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES ---- -kv -v +public kv table root 0 NULL +public v view root 0 NULL -statement error pgcode 42809 "kv" is not a view +statement error pgcode 42809 kv is a table not a view ALTER VIEW kv RENAME TO new_kv +# Not supported by Materialize. +onlyif cockroach # We allow ALTER TABLE for renaming views. statement ok ALTER TABLE v RENAME TO new_v +# Not supported by Materialize. +onlyif cockroach statement error pgcode 42P01 relation "v" does not exist SELECT * FROM v +# Not supported by Materialize. +onlyif cockroach query II rowsort SELECT * FROM new_v ---- 1 2 3 4 -query T +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES ---- -kv -new_v +public kv table root 0 NULL +public new_v view root 0 NULL +# Not supported by Materialize. +onlyif cockroach # check the name in the descriptor, which is used by SHOW GRANTS, is also changed -query TTTTT +query TTTTTB SHOW GRANTS ON new_v ---- -test public new_v admin ALL -test public new_v root ALL +test public new_v admin ALL true +test public new_v root ALL true -statement error invalid table name: "" +statement error zero\-length delimited identifier ALTER VIEW "" RENAME TO foo -statement error invalid table name: "" +statement error zero\-length delimited identifier ALTER VIEW new_v RENAME TO "" +# Not supported by Materialize. +onlyif cockroach statement ok ALTER VIEW new_v RENAME TO new_v @@ -99,19 +118,23 @@ CREATE TABLE t ( statement ok INSERT INTO t VALUES (4, 16), (5, 25) +# Not supported by Materialize. +onlyif cockroach statement ok CREATE VIEW v as SELECT c1,c2 from t -statement error pgcode 42P07 relation "new_v" already exists +statement error pgcode 42P07 renaming conflict: in materialize\.public\.v, "v" potentially used ambiguously as item and column ALTER VIEW v RENAME TO new_v user testuser -statement error user testuser does not have DROP privilege on relation v +statement error unknown schema 'test' ALTER VIEW test.v RENAME TO v2 user root +# Not supported by Materialize. +onlyif cockroach statement ok GRANT DROP ON test.v TO testuser @@ -120,28 +143,34 @@ create database test2 user testuser -statement error user testuser does not have CREATE privilege on database test +statement error unknown schema 'test' ALTER VIEW test.v RENAME TO v2 user root +# Not supported by Materialize. +onlyif cockroach statement ok GRANT CREATE ON DATABASE test TO testuser +# Not supported by Materialize. +onlyif cockroach statement ok ALTER VIEW test.v RENAME TO v2 -query T +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test ---- -kv -new_v -t -v2 +public kv table root 0 NULL +public new_v view root 0 NULL +public t table root 0 NULL +public v2 view root 0 NULL user testuser -statement error user testuser does not have CREATE privilege on database test2 +statement error Expected end of statement, found dot ALTER VIEW test.v2 RENAME TO test2.v user root @@ -149,52 +178,67 @@ user root statement ok GRANT CREATE ON DATABASE test2 TO testuser +# Not supported by Materialize. +onlyif cockroach statement ok GRANT DROP ON test.new_v TO testuser user testuser +# Not supported by Materialize. +onlyif cockroach statement ok -ALTER VIEW test.new_v RENAME TO test2.v +ALTER VIEW test.new_v RENAME TO test.v -statement ok -ALTER VIEW test.v2 RENAME TO test2.v2 - -query T +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test ---- - -query T +public kv table root 0 NULL +public t table root 0 NULL +public v view root 0 NULL +public v2 view root 0 NULL + +# Not supported by Materialize. +onlyif cockroach +query TTTTIT SHOW TABLES FROM test2 ---- -v -v2 user root +# Not supported by Materialize. +onlyif cockroach query II rowsort -SELECT * FROM test2.v +SELECT * FROM test.v ---- 1 2 3 4 +# Not supported by Materialize. +onlyif cockroach query II rowsort -SELECT * FROM test2.v2 +SELECT * FROM test.v2 ---- 4 16 5 25 +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE VIEW v3 AS SELECT count(*) FROM test2.v AS v JOIN test2.v2 AS v2 ON v.k > v2.c1 +CREATE VIEW v3 AS SELECT count(*) FROM test.v AS v JOIN test.v2 AS v2 ON v.k > v2.c1 -statement error cannot rename relation "test2.public.v" because view "test.public.v3" depends on it -ALTER VIEW test2.v RENAME TO test2.v3 +statement error Expected end of statement, found dot +ALTER VIEW test.v RENAME TO test.v3 -statement error cannot rename relation "test2.public.v2" because view "test.public.v3" depends on it -ALTER VIEW test2.v2 RENAME TO v4 +statement error unknown schema 'test' +ALTER VIEW test.v2 RENAME TO v4 +# Not supported by Materialize. +onlyif cockroach statement ok ALTER VIEW v3 RENAME TO v4 -statement error cannot rename relation "test2.public.v2" because view "test.public.v4" depends on it -ALTER VIEW test2.v2 RENAME TO v5 +statement error unknown schema 'test' +ALTER VIEW test.v2 RENAME TO v5 diff --git a/test/sqllogictest/cockroach/reset.slt b/test/sqllogictest/cockroach/reset.slt new file mode 100644 index 0000000000000..95af6362e7063 --- /dev/null +++ b/test/sqllogictest/cockroach/reset.slt @@ -0,0 +1,101 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/reset +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement error unrecognized configuration parameter "foo" +RESET FOO + +statement ok +SET SEARCH_PATH = foo + +query T +SHOW SEARCH_PATH +---- +foo + +statement ok +RESET SEARCH_PATH + +query T +SHOW SEARCH_PATH +---- +public + +# Not supported by Materialize. +onlyif cockroach +statement error parameter "server_version" cannot be changed +RESET SERVER_VERSION + +# Not supported by Materialize. +onlyif cockroach +statement error parameter "server_version_num" cannot be changed +RESET SERVER_VERSION_NUM + +# Lower case + +statement ok +SET search_path = foo + +query T +SHOW search_path +---- +foo + +statement ok +RESET search_path + +query T +SHOW search_path +---- +public + +statement ok +RESET client_encoding; RESET NAMES + +# Not supported by Materialize. +onlyif cockroach +query T +SET timezone = 'Europe/Amsterdam'; SHOW TIMEZONE +---- +Europe/Amsterdam + +# Not supported by Materialize. +onlyif cockroach +query T +RESET timezone; SHOW TIMEZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SET time zone 'Europe/Amsterdam'; SHOW TIME ZONE +---- +Europe/Amsterdam + +# Not supported by Materialize. +onlyif cockroach +query T +RESET time zone; SHOW TIME ZONE +---- +UTC diff --git a/test/sqllogictest/cockroach/returning.slt b/test/sqllogictest/cockroach/returning.slt index 55c457f1d14b0..7d1736ee77b2e 100644 --- a/test/sqllogictest/cockroach/returning.slt +++ b/test/sqllogictest/cockroach/returning.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,38 +9,46 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/returning +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/returning # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach statement ok CREATE TABLE a (a int, b int) -# Issue materialize#6092 - table aliases in returning clauses. +# Issue #6092 - table aliases in returning clauses. +# Not supported by Materialize. +onlyif cockroach query II INSERT INTO a AS alias VALUES(1, 2) RETURNING alias.a, alias.b ---- 1 2 +# Not supported by Materialize. +onlyif cockroach query II UPDATE a AS alias SET b = 1 RETURNING alias.a, alias.b ---- 1 1 +# Not supported by Materialize. +onlyif cockroach # Can't mix aliases and non-aliases. query error no data source matches prefix: a UPDATE a AS alias SET b = 1 RETURNING alias.a, a.b +# Not supported by Materialize. +onlyif cockroach query II DELETE FROM a AS alias RETURNING alias.a, alias.b ---- diff --git a/test/sqllogictest/cockroach/rows_from.slt b/test/sqllogictest/cockroach/rows_from.slt index eda1f22bbf656..f3c7cfb3754f7 100644 --- a/test/sqllogictest/cockroach/rows_from.slt +++ b/test/sqllogictest/cockroach/rows_from.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/rows_from +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/rows_from # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET enable_with_ordinality_legacy_fallback = true ----- -COMPLETE 0 - query II colnames SELECT * FROM ROWS FROM (generate_series(1,2), generate_series(4,8)) ---- @@ -54,46 +52,55 @@ SELECT * FROM ROWS FROM (generate_series(1,0), generate_series(1,1)) generate_series generate_series NULL 1 -## TODO: In Materialize, `TabletizedScalar` somehow doesn't work with `greatest`. This works in both Postgres and -## Cockroach. -#query II colnames -#SELECT * FROM ROWS FROM (generate_series(1,2), greatest(1,2,3,4)) -#---- -#generate_series greatest -#1 4 -#2 NULL +# Not supported by Materialize. +onlyif cockroach +query II colnames +SELECT * FROM ROWS FROM (generate_series(1,2), greatest(1,2,3,4)) +---- +generate_series greatest +1 4 +2 NULL +# Not supported by Materialize. +onlyif cockroach query IT colnames -SELECT * FROM ROWS FROM (generate_series(1,2), current_user()) +SELECT * FROM ROWS FROM (generate_series(1,2), current_user) ---- -generate_series current_user -2 NULL -1 materialize +generate_series current_user +1 root +2 NULL +# Not supported by Materialize. +onlyif cockroach query TI colnames -SELECT * FROM ROWS FROM (current_user(), generate_series(1,2)) +SELECT * FROM ROWS FROM (current_user, generate_series(1,2)) ---- current_user generate_series -NULL 2 -materialize 1 +root 1 +NULL 2 +# Not supported by Materialize. +onlyif cockroach query TT colnames -SELECT * FROM ROWS FROM (current_user(), current_user()) +SELECT * FROM ROWS FROM (current_user, current_user) ---- current_user current_user -materialize materialize +root root +# Not supported by Materialize. +onlyif cockroach query III colnames SELECT * FROM ROWS FROM (information_schema._pg_expandarray(array[4,5,6]), generate_series(10,15)); ---- -x n generate_series +x n generate_series +4 1 10 +5 2 11 +6 3 12 NULL NULL 13 NULL NULL 14 NULL NULL 15 -4 1 10 -5 2 11 -6 3 12 -## No `pg_get_keywords` in Materialize -#statement error pg_get_keywords\(\): set-returning functions must appear at the top level of FROM -#SELECT * FROM ROWS FROM(generate_series(length((pg_get_keywords()).word),10)); +# Regression test for #27389. + +statement error function "pg_get_keywords" does not exist +SELECT * FROM ROWS FROM(generate_series(length((pg_get_keywords()).word),10)); diff --git a/test/sqllogictest/cockroach/savepoints.slt b/test/sqllogictest/cockroach/savepoints.slt new file mode 100644 index 0000000000000..8c6982ee8abe6 --- /dev/null +++ b/test/sqllogictest/cockroach/savepoints.slt @@ -0,0 +1,69 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/savepoints +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Regression test for https://github.com/cockroachdb/cockroach/issues/94337. +# The linked issue only manifests itself if the read request is able to drop +# latches early. Before this bug was fixed, one of the conditions required for +# a read request to drop its latches early was that it needed to have a higher +# read timestamp compared to the timestamp at which it had written all intents +# the read overlapped with. Adding the sleeps here bumps the transaction's read +# timestamp, by virtue of the closed timestamp interval. + +statement ok +CREATE TABLE a (id INT); + +statement ok +BEGIN + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT pg_sleep(1.5) + +# Not supported by Materialize. +onlyif cockroach +statement ok +SAVEPOINT s + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT pg_sleep(1.5) + +statement ok +INSERT INTO a(id) VALUES (0); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ROLLBACK TO SAVEPOINT s + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT * FROM a +---- + +statement ok +COMMIT diff --git a/test/sqllogictest/cockroach/scale.slt b/test/sqllogictest/cockroach/scale.slt index 83b801e76cba1..4f0a6846a4dd4 100644 --- a/test/sqllogictest/cockroach/scale.slt +++ b/test/sqllogictest/cockroach/scale.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/scale +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/scale # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach statement ok @@ -37,7 +37,7 @@ INSERT INTO test VALUES ('ab') statement ok INSERT INTO test VALUES ('abcd') -statement error value too long for type CHAR\(4\) \(column "t"\) +statement error value too long for type character\(4\) INSERT INTO test VALUES ('abcdef') statement ok @@ -52,28 +52,38 @@ UPDATE test SET t = 'b' WHERE t = 'abcde' statement error value too long UPDATE test SET t = 'cdefg' WHERE t = 'ab' +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE tb ( b BIT(3), UNIQUE INDEX a (b) ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO tb VALUES (B'001') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO tb VALUES (B'011') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO tb VALUES (B'111') -statement error bit string length 4 does not match type BIT\(3\) +statement error unknown catalog item 'tb' INSERT INTO tb VALUES (B'1111') +# Not supported by Materialize. +onlyif cockroach statement ok UPDATE tb SET b = B'010' WHERE b = B'111' -statement error bit string length 5 does not match type BIT\(3\) +statement error unknown catalog item 'tb' UPDATE tb SET b = B'10000' WHERE b = B'010' statement ok @@ -96,16 +106,16 @@ INSERT INTO tc VALUES (32767) statement ok INSERT INTO tc VALUES (60000-59999) -statement error integer out of range for type int2 \(column "b"\) +statement error "\-32769" smallint out of range INSERT INTO tc VALUES (-32769) -statement error integer out of range for type int2 \(column "b"\) +statement error "32768" smallint out of range INSERT INTO tc VALUES (32768) statement ok UPDATE tc SET b = 80 WHERE b = 50 -statement error integer out of range for type int2 \(column "b"\) +statement error "32768" smallint out of range UPDATE tc SET b = 32768 WHERE b = 32767 statement ok @@ -123,16 +133,16 @@ INSERT INTO tc1 VALUES (-2147483648) statement ok INSERT INTO tc1 VALUES (2147483647) -statement error integer out of range for type int4 \(column "b"\) +statement error "\-2147483649" integer out of range INSERT INTO tc1 VALUES (-2147483649) -statement error integer out of range for type int4 \(column "b"\) +statement error "2147483648" integer out of range INSERT INTO tc1 VALUES (2147483648) statement ok UPDATE tc1 SET b = 80 WHERE b = 50 -statement error integer out of range for type int4 \(column "b"\) +statement error "2147483648" integer out of range UPDATE tc1 SET b = 2147483648 WHERE b = 2147483647 statement ok @@ -147,32 +157,40 @@ INSERT INTO td VALUES (DECIMAL '3.1') statement ok INSERT INTO td VALUES (DECIMAL '3.14') +# Not supported by Materialize. +onlyif cockroach statement error duplicate INSERT INTO td VALUES (DECIMAL '3.1415') -statement error type DECIMAL\(3,2\) \(column "d"\): value with precision 3, scale 2 must round to an absolute value less than 10\^1 +# Not supported by Materialize. +onlyif cockroach +statement error type DECIMAL\(3,2\): value with precision 3, scale 2 must round to an absolute value less than 10\^1 INSERT INTO td VALUES (DECIMAL '13.1415') query R rowsort SELECT d FROM td ---- -3.10 +3.1 3.14 +# Not supported by Materialize. +onlyif cockroach statement error must round UPDATE td SET d = DECIMAL '101.414' WHERE d = DECIMAL '3.14' statement ok UPDATE td SET d = DECIMAL '1.414' WHERE d = DECIMAL '3.14' +# Not supported by Materialize. +onlyif cockroach statement error duplicate UPDATE td SET d = DECIMAL '1.41' WHERE d = DECIMAL '3.1' query R rowsort SELECT d FROM td ---- -3.10 1.41 +3.1 statement ok CREATE TABLE td2 (x DECIMAL(3), y DECIMAL) @@ -183,7 +201,7 @@ INSERT INTO td2 VALUES (DECIMAL '123.1415', DECIMAL '123.1415') query RR select x, y FROM td2 ---- -123 123.1415 +123.1415 123.1415 # Ensure decimal columns greater than 16 precision are supported. @@ -197,7 +215,9 @@ INSERT INTO td3 VALUES (123456789012.123456789012, 12.3, 1234567890.1234567890) query RRR select * from td3 ---- -123456789012.123456789012 12.3 1234567890.1234567890 +123456789012.123456789012 12.3 1234567890.123456789 +# Not supported by Materialize. +onlyif cockroach statement error must round INSERT INTO td3 (c) VALUES (12345678901) diff --git a/test/sqllogictest/cockroach/secondary_index_column_families.slt b/test/sqllogictest/cockroach/secondary_index_column_families.slt new file mode 100644 index 0000000000000..9b16da78e7248 --- /dev/null +++ b/test/sqllogictest/cockroach/secondary_index_column_families.slt @@ -0,0 +1,183 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/secondary_index_column_families +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +# Ensure updates that remove a k/v pair succeed. +statement ok +CREATE TABLE t ( + x INT PRIMARY KEY, + y INT, + z INT, + w INT, + INDEX i (y) STORING (z, w), + FAMILY (x), FAMILY (y), FAMILY (z), FAMILY (w) +); +INSERT INTO t VALUES (1, 2, 3, 4); +UPDATE t SET z = NULL, w = NULL WHERE y = 2 + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT y, z, w FROM t@i WHERE y = 2 +---- +2 NULL NULL + +# Test some cases around insert on conflict. +statement ok +DROP TABLE IF EXISTS t; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t ( + x INT PRIMARY KEY, + y INT, + z STRING, + v INT, + UNIQUE INDEX i (y) STORING (z, v) +); +INSERT INTO t VALUES (1, 2, '3', 4), (5, 6, '7', 8); +INSERT INTO t VALUES (10, 2, '10', 10) ON CONFLICT (y) DO NOTHING + +# Not supported by Materialize. +onlyif cockroach +query ITI rowsort +SELECT y, z, v FROM t@i +---- +2 3 4 +6 7 8 + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t VALUES (10, 2, '10', 10) ON CONFLICT (y) DO UPDATE set x = 20, z = '20', v = 20 WHERE t.y = 2 + +# Not supported by Materialize. +onlyif cockroach +query ITI rowsort +SELECT y, z, v FROM t@i +---- +2 20 20 +6 7 8 + +# Test some cases around upsert. +statement ok +DROP TABLE IF EXISTS t; + +statement ok +CREATE TABLE t ( + x INT PRIMARY KEY, + y STRING, + z DECIMAL, + w INT, + FAMILY (y), FAMILY (z), FAMILY (x, w), + INDEX i (y) STORING (z, w) +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t VALUES (1, '2', 3.0, 4), (5, '6', 7.00, 8); +UPSERT INTO t VALUES (9, '10', 11.000, 12), (1, '3', 5.0, 16) + +# Not supported by Materialize. +onlyif cockroach +query TTI rowsort +SELECT y, z, w FROM t@i +---- +3 5.0 16 +6 7.00 8 +10 11.000 12 + +# Test some cases around schema changes. +statement ok +DROP TABLE IF EXISTS t; + +statement ok +CREATE TABLE t ( + x INT PRIMARY KEY, + y DECIMAL, + z INT, + w INT, + v INT +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t VALUES (1, 2, 3, 4, 5), (6, 7, 8, 9, 10), (11, 12, 13, 14, 15); +CREATE INDEX i ON t (y) STORING (z, w, v) + +# Not supported by Materialize. +onlyif cockroach +query TIII rowsort +SELECT y, z, w, v FROM t@i +---- +2 3 4 5 +7 8 9 10 +12 13 14 15 + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX t@i + +query ITIII rowsort +SELECT * FROM t +---- + + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t ADD COLUMN u INT DEFAULT (20) CREATE FAMILY new_fam; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX i ON t (y) STORING (z, w, v, u) + +# Not supported by Materialize. +onlyif cockroach +query TIIII rowsort +SELECT y, z, w, v, u FROM t@i +---- +2 3 4 5 20 +7 8 9 10 20 +12 13 14 15 20 + +# Regression for #42992. +statement ok +CREATE TABLE t42992 (x TIMESTAMP PRIMARY KEY, y INT, z INT, UNIQUE INDEX i (y) STORING (z), FAMILY (x), FAMILY (y), FAMILY (z)) + +statement ok +INSERT INTO t42992 VALUES (now(), NULL, 2) + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT y, z FROM t42992@i +---- +NULL 2 diff --git a/test/sqllogictest/cockroach/select.slt b/test/sqllogictest/cockroach/select.slt index 85e8fdbda6d90..cb1b73397a837 100644 --- a/test/sqllogictest/cockroach/select.slt +++ b/test/sqllogictest/cockroach/select.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/select +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/select # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - # SELECT with no table. query I @@ -47,9 +45,13 @@ two four statement ok CREATE TABLE abc (a INT PRIMARY KEY, b INT, c INT) -query error syntax error at or near "from" +# Not supported by Materialize. +onlyif cockroach +query error at or near "from": syntax error SELECT FROM abc +# Not supported by Materialize. +onlyif cockroach query error could not parse "hello" as type bool SELECT * FROM abc WHERE 'hello' @@ -74,7 +76,7 @@ TABLE abc ---- 1 2 3 -query error syntax error at or near "*" +query error Expected identifier, found star TABLE abc.* query III colnames @@ -160,7 +162,7 @@ NULL query T SELECT k FROM kv ---- -1 value hashing to 60b725f10c9c85c70d97880dfe8191b3 +a query TT SELECT kv.K,KV.v FROM kv @@ -172,41 +174,51 @@ SELECT kv.* FROM kv ---- a NULL -# Regression tests for database-issues#7241 +# Not supported by Materialize. +onlyif cockroach +# Regression tests for #24169 query TT SELECT test.kv.* FROM kv ---- a NULL +# Not supported by Materialize. +onlyif cockroach query TT SELECT test.public.kv.* FROM kv ---- a NULL +# Not supported by Materialize. +onlyif cockroach query TT SELECT test.public.kv.* FROM test.kv ---- a NULL +# Not supported by Materialize. +onlyif cockroach query TT SELECT test.kv.* FROM test.public.kv ---- a NULL -query error no data source matches pattern: foo.\* +query error no table named 'foo' in scope SELECT foo.* FROM kv -query error cannot use "\*" without a FROM clause +query error SELECT \* with no tables specified is not valid SELECT * +# Not supported by Materialize. +onlyif cockroach query error "kv.*" cannot be aliased SELECT kv.* AS foo FROM kv -query error no data source matches pattern: bar.kv.\* +query error no table named 'bar\.kv' in scope SELECT bar.kv.* FROM kv -# Don't panic with invalid names (materialize#8024) -query error cannot subscript type tuple\{char AS k, char AS v\} because it is not an array +# Don't panic with invalid names (#8024) +query error cannot subscript type record\(k: char\(1\),v: char\(1\)\?\) SELECT kv.*[1] FROM kv query T colnames @@ -246,12 +258,14 @@ CREATE TABLE xyzw ( statement ok INSERT INTO xyzw VALUES (4, 5, 6, 7), (1, 2, 3, 4) -query error pq: column "x" does not exist +query error column "x" does not exist SELECT * FROM xyzw LIMIT x -query error pq: column "y" does not exist +query error column "y" does not exist SELECT * FROM xyzw OFFSET 1 + y +# Not supported by Materialize. +onlyif cockroach query error argument of LIMIT must be type int, not type decimal SELECT * FROM xyzw LIMIT 3.3 @@ -260,19 +274,21 @@ SELECT * FROM xyzw ORDER BY 1 LIMIT '1' ---- 1 2 3 4 +# Not supported by Materialize. +onlyif cockroach query error argument of OFFSET must be type int, not type decimal SELECT * FROM xyzw OFFSET 1.5 -query error negative value for LIMIT +query error LIMIT must not be negative SELECT * FROM xyzw LIMIT -100 -query error negative value for OFFSET +query error Invalid OFFSET clause: must not be negative, got \-100 SELECT * FROM xyzw OFFSET -100 -query error numeric constant out of int64 range +query error "9223372036854775808" bigint out of range SELECT * FROM xyzw LIMIT 9223372036854775808 -query error numeric constant out of int64 range +query error Invalid OFFSET clause: "9223372036854775808" bigint out of range SELECT * FROM xyzw OFFSET 9223372036854775808 query IIII @@ -310,40 +326,53 @@ SELECT * FROM xyzw ORDER BY y OFFSET 1 LIMIT 1 ---- 4 5 6 7 +# Not supported by Materialize. +onlyif cockroach # Multiplying by zero so the result is deterministic. query IIII SELECT * FROM xyzw LIMIT (random() * 0.0)::int OFFSET (random() * 0.0)::int ---- -query error pgcode 42601 multiple LIMIT clauses not allowed +query error pgcode 42601 multiple LIMIT/FETCH clauses not allowed ((SELECT a FROM t LIMIT 1)) LIMIT 1 query IIII SELECT * FROM (SELECT * FROM xyzw LIMIT 5) OFFSET 5 ---- +# Not supported by Materialize. +onlyif cockroach query II rowsort SELECT z, y FROM xyzw@foo ---- 3 2 6 5 +# Not supported by Materialize. +onlyif cockroach query I SELECT z FROM test.xyzw@foo WHERE y = 5 ---- 6 +# Not supported by Materialize. +onlyif cockroach query I SELECT xyzw.y FROM test.xyzw@foo WHERE z = 3 ---- 2 -query error pgcode 42P01 relation "test.unknown" does not exist +query error pgcode 42P01 Expected end of statement, found operator "@" SELECT z FROM test.unknown@foo WHERE y = 5 -query error index "unknown" not found +query error pgcode 42704 Expected end of statement, found operator "@" SELECT z FROM test.xyzw@unknown WHERE y = 5 +query error pgcode 42704 Expected end of statement, found operator "@" +SELECT z FROM test.xyzw@[42] WHERE y = 5 + +# Not supported by Materialize. +onlyif cockroach query I SELECT w FROM test.xyzw@foo WHERE y = 5 ---- @@ -383,18 +412,20 @@ NULL NULL NULL statement ok CREATE TABLE MaxIntTest (a INT PRIMARY KEY) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO MaxIntTest VALUES (9223372036854775807) query I SELECT a FROM MaxIntTest WHERE a = 9223372036854775807 ---- -9223372036854775807 -query error no value provided for placeholder + +query error expected 1 parameters but got 0 SELECT $1::int -# Regression tests for materialize#22670. +# Regression tests for #22670. query B SELECT 1 IN (1, 2) ---- @@ -415,6 +446,13 @@ SELECT 1 IN (NULL, 2) ---- NULL +# Note: The desired behavior here differs from the desired behavior of +# NULL IN as tested below. +query B +SELECT NULL IN ((1, 1)) +---- +NULL + query B SELECT (1, NULL) IN ((1, 1)) ---- @@ -425,6 +463,25 @@ SELECT (2, NULL) IN ((1, 1)) ---- false +query error Expected an expression, found right parenthesis +SELECT () IN (1,2) + +query error Expected an expression, found right parenthesis +SELECT () IN ((1,2)) + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT () IN (()); +---- +true + +query error invalid input syntax for type integer: invalid digit found in string: "string" +SELECT ('string', NULL) IN ((1, 1)) + +query error unequal number of entries in row expressions +SELECT (2, 'string', NULL) IN ((1, 1)) + query B SELECT (1, 1) IN ((1, NULL)) ---- @@ -437,103 +494,133 @@ false # Tests with a tuple coming from a subquery. query B -SELECT NULL::int IN (SELECT * FROM (VALUES (1)) AS t(a)) +SELECT NULL IN (SELECT * FROM (VALUES (1)) AS t(a)) ---- NULL query B -SELECT (1, NULL::int) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) +SELECT (1, NULL) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) ---- NULL +query error subquery1 has 2 columns available but 1 columns specified +SELECT NULL IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)); + +query error Expected an expression, found right parenthesis +SELECT () IN (SELECT * FROM (VALUES (1)) AS t(a)) + +query error Expected an expression, found right parenthesis +SELECT () IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) + +query error invalid input syntax for type integer: invalid digit found in string: "string" +SELECT ('string', NULL) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) + +query error subquery3 has 2 columns available but 3 columns specified +SELECT (2, 'string', NULL) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) + query B -SELECT (2, NULL::int) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) +SELECT (2, NULL) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) ---- false query B -SELECT (NULL::int, 1) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) +SELECT (NULL, 1) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) ---- NULL query B -SELECT (NULL::int, 2) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) +SELECT (NULL, 2) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) ---- false query B -SELECT (NULL::int, NULL::int) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) +SELECT (NULL, NULL) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) ---- NULL query B -SELECT NULL::int NOT IN (SELECT * FROM (VALUES (1)) AS t(a)) +SELECT NULL NOT IN (SELECT * FROM (VALUES (1)) AS t(a)) ---- NULL +query error subquery1 has 2 columns available but 1 columns specified +SELECT NULL NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) + +query error Expected an expression, found right parenthesis +SELECT () NOT IN (SELECT * FROM (VALUES (1)) AS t(a)) + +query error Expected an expression, found right parenthesis +SELECT () NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) + +query error invalid input syntax for type integer: invalid digit found in string: "string" +SELECT ('string', NULL) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) + +query error subquery3 has 2 columns available but 3 columns specified +SELECT (2, 'string', NULL) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) + query B -SELECT (1, NULL::int) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) +SELECT (1, NULL) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) ---- NULL query B -SELECT (2, NULL::int) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) +SELECT (2, NULL) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) ---- true query B -SELECT (NULL::int, 1) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) +SELECT (NULL, 1) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) ---- NULL query B -SELECT (NULL::int, 2) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) +SELECT (NULL, 2) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) ---- true query B -SELECT (NULL::int, NULL::int) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) +SELECT (NULL, NULL) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b)) ---- NULL # Tests with an empty IN tuple. query B -SELECT NULL::int IN (SELECT * FROM (VALUES (1)) AS t(a) WHERE a > 1) +SELECT NULL IN (SELECT * FROM (VALUES (1)) AS t(a) WHERE a > 1) ---- false query B -SELECT (1, NULL::int) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) +SELECT (1, NULL) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) ---- false query B -SELECT (NULL::int, 1) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) +SELECT (NULL, 1) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) ---- false query B -SELECT (NULL::int, NULL::int) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) +SELECT (NULL, NULL) IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) ---- false query B -SELECT NULL::int NOT IN (SELECT * FROM (VALUES (1)) AS t(a) WHERE a > 1) +SELECT NULL NOT IN (SELECT * FROM (VALUES (1)) AS t(a) WHERE a > 1) ---- true query B -SELECT (1, NULL::int) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) +SELECT (1, NULL) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) ---- true query B -SELECT (NULL::int, 1) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) +SELECT (NULL, 1) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) ---- true query B -SELECT (NULL::int, NULL::int) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) +SELECT (NULL, NULL) NOT IN (SELECT * FROM (VALUES (1, 1)) AS t(a, b) WHERE a > 1) ---- true @@ -614,6 +701,8 @@ SELECT * FROM b 2 20 3 30 +# Not supported by Materialize. +onlyif cockroach query I rowsort SELECT x FROM b WHERE rowid > 0 ---- @@ -621,6 +710,17 @@ SELECT x FROM b WHERE rowid > 0 2 3 +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT x FROM b WHERE b.rowid > 0 +---- +1 +2 +3 + +# Not supported by Materialize. +onlyif cockroach # ------------------------------------------------------------------------------ # String inequality filter. # ------------------------------------------------------------------------------ @@ -628,6 +728,8 @@ statement ok CREATE TABLE c (n INT PRIMARY KEY, str STRING, INDEX str(str DESC)); INSERT INTO c SELECT i, to_english(i) FROM generate_series(1, 10) AS g(i) +# Not supported by Materialize. +onlyif cockroach query IT rowsort SELECT * FROM c WHERE str >= 'moo' ---- @@ -639,12 +741,203 @@ SELECT * FROM c WHERE str >= 'moo' 9 nine 10 one-zero +# Not supported by Materialize. +onlyif cockroach # ------------------------------------------------------------------------------ # "*" must expand to zero columns if there are zero columns to select. # ------------------------------------------------------------------------------ statement ok CREATE TABLE nocols(x INT); ALTER TABLE nocols DROP COLUMN x +# Not supported by Materialize. +onlyif cockroach query I SELECT 1, * FROM nocols ---- + +# ------------------------------------------------------------------------------ +# Wide tables can tickle edge cases. +# ------------------------------------------------------------------------------ + +statement ok +CREATE TABLE wide (id INT4 NOT NULL, a INT4, b VARCHAR(255), c INT4, d VARCHAR(255), e VARCHAR(255), f INT4, g VARCHAR(255), h VARCHAR(255), i VARCHAR(255), j VARCHAR(255), k INT4, + l FLOAT4, m FLOAT8, n INT2, PRIMARY KEY (id)) + +statement ok +INSERT INTO wide(id, n) VALUES(0, 10) + +query IITITTITTTTIRRI +SELECT * FROM wide +---- +0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 10 + +# Regression test for #44203 (filter that is not folded inside the optimizer, +# but is statically evaluated to true when building the filterNode). +statement ok +CREATE TABLE t44203(c0 BOOL) + +statement ok +INSERT INTO t44203(c0) VALUES (false) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW v44203(c0) AS SELECT c0 FROM t44203 WHERE t44203.c0 OFFSET NULL + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT * FROM v44203 WHERE current_user() != '' +---- + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #44132 - generated column causes incorrect scan. +statement ok +CREATE TABLE t44132(c0 BOOL UNIQUE, c1 INT AS (NULL) STORED) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t44132 (c0) VALUES (true) + +# Not supported by Materialize. +onlyif cockroach +query BI +SELECT * FROM t44132 WHERE c0 +---- +true NULL + +# Tests for `disallow_full_table_scans` +statement ok +CREATE TABLE t_disallow_scans(a INT, b INT, INDEX b_idx(b), INDEX b_partial(b) WHERE a > 0); + +statement ok +SELECT * FROM t_disallow_scans + +# First disable full scans with a hint. +statement error unexpected character in input: \{ +SELECT * FROM t_disallow_scans@{NO_FULL_SCAN} + +statement error unexpected character in input: \{ +SELECT * FROM t_disallow_scans@{FORCE_INDEX=b_idx,NO_FULL_SCAN} + +statement error unexpected character in input: \{ +SELECT * FROM t_disallow_scans@{FORCE_INDEX=b_partial,NO_FULL_SCAN} WHERE a > 0 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t_disallow_scans@{NO_FULL_SCAN} WHERE a > 0 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t_disallow_scans@{FORCE_INDEX=b_idx,NO_FULL_SCAN} WHERE b > 0 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t_disallow_scans@{FORCE_INDEX=b_partial,NO_FULL_SCAN} WHERE a > 0 AND b = 1 + +# Now disable full scans with the session variable. +statement ok +SET disallow_full_table_scans = true; + +# Not supported by Materialize. +onlyif cockroach +# Full scans are prohibited because we don't have stats on the table. +statement error pq: query `SELECT \* FROM t_disallow_scans` contains a full table/index scan which is explicitly disallowed +SELECT * FROM t_disallow_scans + +statement error Expected end of statement, found operator "@" +SELECT * FROM t_disallow_scans@b_idx + +# Not supported by Materialize. +onlyif cockroach +# Full scans of partial indexes are allowed. +statement ok +SELECT * FROM t_disallow_scans@b_partial WHERE a > 0 + +# Disable 'large_full_scan_rows' heuristic and inject the stats in order to +# test 'disallow_full_table_scans' in isolation. +statement ok +SET large_full_scan_rows = 0; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t_disallow_scans INJECT STATISTICS '[ + { + "columns": ["rowid"], + "created_at": "2021-09-15 19:38:46.017315", + "distinct_count": 3, + "null_count": 0, + "row_count": 3 + }, + { + "columns": ["b"], + "created_at": "2021-09-15 19:38:46.017315", + "distinct_count": 1, + "null_count": 0, + "row_count": 3 + }, + { + "columns": ["a"], + "created_at": "2021-09-15 19:38:46.017315", + "distinct_count": 3, + "null_count": 0, + "row_count": 3 + } +]' + +# Not supported by Materialize. +onlyif cockroach +statement error pq: query `SELECT \* FROM t_disallow_scans` contains a full table/index scan which is explicitly disallowed +SELECT * FROM t_disallow_scans + +statement error Expected end of statement, found operator "@" +SELECT * FROM t_disallow_scans@b_idx + +# Internal statements should still be allowed with this setting. +statement ok +SELECT * FROM pg_class + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM crdb_internal.jobs + +# Tests for 'large_full_scan_rows'. +statement ok +SET large_full_scan_rows = 1000 + +# These queries succeed because the full table/index scans aren't considered +# "large". +statement ok +SELECT * FROM t_disallow_scans + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t_disallow_scans@b_idx + +statement ok +SET large_full_scan_rows = 2 + +# Not supported by Materialize. +onlyif cockroach +statement error pq: query `SELECT \* FROM t_disallow_scans` contains a full table/index scan which is explicitly disallowed +SELECT * FROM t_disallow_scans + +statement error Expected end of statement, found operator "@" +SELECT * FROM t_disallow_scans@b_idx + +# Cleanup +statement ok +SET disallow_full_table_scans = false; +RESET large_full_scan_rows; + +# Regression test for #58104. +statement ok +SELECT * FROM pg_catalog.pg_attrdef WHERE (adnum = 1 AND adrelid = 1) OR (adbin = 'foo' AND adrelid = 2) diff --git a/test/sqllogictest/cockroach/select_for_update.slt b/test/sqllogictest/cockroach/select_for_update.slt new file mode 100644 index 0000000000000..102edfe125171 --- /dev/null +++ b/test/sqllogictest/cockroach/select_for_update.slt @@ -0,0 +1,627 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/select_for_update +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR UPDATE +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR NO KEY UPDATE +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR SHARE +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR KEY SHARE +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR UPDATE FOR SHARE FOR NO KEY UPDATE FOR KEY SHARE +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42P01 relation "a" in FOR UPDATE clause not found in FROM clause +SELECT 1 FOR UPDATE OF a + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42P01 relation "a" in FOR SHARE clause not found in FROM clause +SELECT 1 FOR SHARE OF a, b + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42P01 relation "a" in FOR UPDATE clause not found in FROM clause +SELECT 1 FOR UPDATE OF a FOR SHARE OF b, c FOR NO KEY UPDATE OF d FOR KEY SHARE OF e, f + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FROM + (SELECT 1) a, + (SELECT 1) b, + (SELECT 1) c, + (SELECT 1) d, + (SELECT 1) e, + (SELECT 1) f +FOR UPDATE OF a FOR SHARE OF b, c FOR NO KEY UPDATE OF d FOR KEY SHARE OF e, f +---- +1 + +# However, we do mirror Postgres in that we require FOR UPDATE targets to be +# unqualified names and reject anything else. + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42601 FOR UPDATE must specify unqualified relation names +SELECT 1 FOR UPDATE OF public.a + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42601 FOR UPDATE must specify unqualified relation names +SELECT 1 FOR UPDATE OF db.public.a + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR UPDATE SKIP LOCKED +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR NO KEY UPDATE SKIP LOCKED +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR SHARE SKIP LOCKED +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR KEY SHARE SKIP LOCKED +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42P01 relation "a" in FOR UPDATE clause not found in FROM clause +SELECT 1 FOR UPDATE OF a SKIP LOCKED + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42P01 relation "a" in FOR UPDATE clause not found in FROM clause +SELECT 1 FOR UPDATE OF a SKIP LOCKED FOR NO KEY UPDATE OF b SKIP LOCKED + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42P01 relation "a" in FOR UPDATE clause not found in FROM clause +SELECT 1 FOR UPDATE OF a SKIP LOCKED FOR NO KEY UPDATE OF b NOWAIT + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42P01 relation "a" in FOR UPDATE clause not found in FROM clause +SELECT 1 FOR UPDATE OF a SKIP LOCKED FOR SHARE OF b, c SKIP LOCKED FOR NO KEY UPDATE OF d SKIP LOCKED FOR KEY SHARE OF e, f SKIP LOCKED + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR UPDATE NOWAIT +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR NO KEY UPDATE NOWAIT +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR SHARE NOWAIT +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT 1 FOR KEY SHARE NOWAIT +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42P01 relation "a" in FOR UPDATE clause not found in FROM clause +SELECT 1 FOR UPDATE OF a NOWAIT + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42P01 relation "a" in FOR UPDATE clause not found in FROM clause +SELECT 1 FOR UPDATE OF a NOWAIT FOR NO KEY UPDATE OF b NOWAIT + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 42P01 relation "a" in FOR UPDATE clause not found in FROM clause +SELECT 1 FOR UPDATE OF a NOWAIT FOR SHARE OF b, c NOWAIT FOR NO KEY UPDATE OF d NOWAIT FOR KEY SHARE OF e, f NOWAIT + +# Locking clauses both inside and outside of parenthesis are handled correctly. + +# Not supported by Materialize. +onlyif cockroach +query I +((SELECT 1)) FOR UPDATE SKIP LOCKED +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +((SELECT 1) FOR UPDATE SKIP LOCKED) +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +((SELECT 1 FOR UPDATE SKIP LOCKED)) +---- +1 + +# Not supported by Materialize. +onlyif cockroach +# FOR READ ONLY is ignored, like in Postgres. +query I +SELECT 1 FOR READ ONLY +---- +1 + +# Various operations are not supported when locking clauses are provided. +# FeatureNotSupported errors are thrown for each of them. + +statement error pgcode 0A000 Expected end of statement, found UPDATE +SELECT 1 UNION SELECT 1 FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found FOR +SELECT * FROM (SELECT 1 UNION SELECT 1) a FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found FOR +VALUES (1) FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found FOR +SELECT * FROM (VALUES (1)) a FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found UPDATE +SELECT DISTINCT 1 FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found FOR +SELECT * FROM (SELECT DISTINCT 1) a FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found FOR +SELECT 1 GROUP BY 1 FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found FOR +SELECT * FROM (SELECT 1 GROUP BY 1) a FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found FOR +SELECT 1 HAVING TRUE FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found FOR +SELECT * FROM (SELECT 1 HAVING TRUE) a FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found UPDATE +SELECT count(1) FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found FOR +SELECT * FROM (SELECT count(1)) a FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found UPDATE +SELECT count(1) OVER () FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found FOR +SELECT * FROM (SELECT count(1) OVER ()) a FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found UPDATE +SELECT generate_series(1, 2) FOR UPDATE + +statement error pgcode 0A000 Expected end of statement, found FOR +SELECT * FROM (SELECT generate_series(1, 2)) a FOR UPDATE + +# Not supported by Materialize. +onlyif cockroach +# Set-returning functions in the from list are allowed. +query I +SELECT * FROM generate_series(1, 2) FOR UPDATE +---- +1 +2 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT * FROM (SELECT * FROM generate_series(1, 2)) a FOR UPDATE +---- +1 +2 + +# Use of SELECT FOR UPDATE/SHARE requires SELECT and UPDATE privileges. + +statement ok +CREATE TABLE t (k INT PRIMARY KEY, v int, FAMILY (k, v)) + +user testuser + +statement error pgcode 42501 permission denied for TABLE "materialize\.public\.t" +SELECT * FROM t + +statement error pgcode 42501 Expected end of statement, found UPDATE +SELECT * FROM t FOR UPDATE + +statement error pgcode 42501 Expected end of statement, found identifier "share" +SELECT * FROM t FOR SHARE + +user root + +statement ok +GRANT SELECT ON t TO testuser + +user testuser + +statement ok +SELECT * FROM t + +statement error pgcode 42501 Expected end of statement, found UPDATE +SELECT * FROM t FOR UPDATE + +statement error pgcode 42501 Expected end of statement, found identifier "share" +SELECT * FROM t FOR SHARE + +user root + +statement ok +REVOKE SELECT ON t FROM testuser + +statement ok +GRANT UPDATE ON t TO testuser + +user testuser + +statement error pgcode 42501 permission denied for TABLE "materialize\.public\.t" +SELECT * FROM t + +statement error pgcode 42501 Expected end of statement, found UPDATE +SELECT * FROM t FOR UPDATE + +statement error pgcode 42501 Expected end of statement, found identifier "share" +SELECT * FROM t FOR SHARE + +user root + +statement ok +GRANT SELECT ON t TO testuser + +user testuser + +statement ok +SELECT * FROM t + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t FOR UPDATE + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t FOR SHARE + +user root + +# Use of SELECT FOR UPDATE/SHARE in ReadOnly Transaction + +statement ok +BEGIN READ ONLY + +statement error Expected end of statement, found UPDATE +SELECT * FROM t FOR UPDATE + +statement ok +ROLLBACK + +statement ok +BEGIN READ ONLY + +statement error Expected end of statement, found NO +SELECT * FROM t FOR NO KEY UPDATE + +statement ok +ROLLBACK + +statement ok +BEGIN READ ONLY + +statement error Expected end of statement, found identifier "share" +SELECT * FROM t FOR SHARE + +statement ok +ROLLBACK + +statement ok +BEGIN READ ONLY + +statement error Expected end of statement, found KEY +SELECT * FROM t FOR KEY SHARE + +statement ok +ROLLBACK + +# The NOWAIT wait policy returns error when a conflicting lock is encountered. + +statement ok +INSERT INTO t VALUES (1, 1) + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; UPDATE t SET v = 2 WHERE k = 1 + +user testuser + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 55P03 could not obtain lock on row \(k\)=\(1\) in t@t_pkey +SELECT * FROM t FOR UPDATE NOWAIT + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 55P03 could not obtain lock on row \(k\)=\(1\) in t@t_pkey +SELECT * FROM t FOR SHARE FOR UPDATE OF t NOWAIT + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 55P03 could not obtain lock on row \(k\)=\(1\) in t@t_pkey +SELECT * FROM t FOR SHARE NOWAIT FOR UPDATE OF t + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 55P03 could not obtain lock on row \(k\)=\(1\) in t@t_pkey +BEGIN; SELECT * FROM t FOR UPDATE NOWAIT + +statement ok +ROLLBACK + +user root + +statement ok +ROLLBACK + +# The NOWAIT wait policy can be applied to a subset of the tables being locked. + +statement ok +CREATE TABLE t2 (k INT PRIMARY KEY, v2 int) + +statement ok +GRANT SELECT ON t2 TO testuser + +statement ok +GRANT UPDATE ON t2 TO testuser + +statement ok +INSERT INTO t2 VALUES (1, 11) + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; UPDATE t SET v = 2 WHERE k = 1 + +user testuser + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 55P03 could not obtain lock on row \(k\)=\(1\) in t@t_pkey +SELECT v, v2 FROM t JOIN t2 USING (k) FOR SHARE FOR SHARE OF t NOWAIT + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 55P03 could not obtain lock on row \(k\)=\(1\) in t@t_pkey +SELECT v, v2 FROM t JOIN t2 USING (k) FOR SHARE OF t2 FOR SHARE OF t NOWAIT + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 55P03 could not obtain lock on row \(k\)=\(1\) in t@t_pkey +SELECT v, v2 FROM t JOIN t2 USING (k) FOR SHARE NOWAIT FOR SHARE OF t + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 55P03 could not obtain lock on row \(k\)=\(1\) in t@t_pkey +SELECT v, v2 FROM t JOIN t2 USING (k) FOR SHARE NOWAIT FOR SHARE OF t2 + +statement ok +SET statement_timeout = '10ms' + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 57014 query execution canceled due to statement timeout +SELECT v, v2 FROM t JOIN t2 USING (k) FOR SHARE FOR SHARE OF t2 NOWAIT + +# Not supported by Materialize. +onlyif cockroach +query error pgcode 57014 query execution canceled due to statement timeout +SELECT v, v2 FROM t JOIN t2 USING (k) FOR SHARE OF t FOR SHARE OF t2 NOWAIT + +statement ok +SET statement_timeout = 0 + +user root + +statement ok +ROLLBACK + +# The SKIP LOCKED wait policy skip rows when a conflicting lock is encountered. + +statement ok +INSERT INTO t VALUES (2, 2), (3, 3), (4, 4) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t3 ( + k INT PRIMARY KEY, + v INT, + u INT, + INDEX (u), + FAMILY (k, v, u) +); +INSERT INTO t3 VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 2); +GRANT SELECT ON t3 TO testuser; +GRANT UPDATE ON t3 TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; UPDATE t SET v = 3 WHERE k = 2; UPDATE t3 SET v = 3 WHERE k = 2 + +user testuser + +statement ok +BEGIN + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT * FROM t FOR UPDATE SKIP LOCKED +---- +1 1 +3 3 +4 4 + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE t SET v = 4 WHERE k = 3 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT * FROM t FOR UPDATE SKIP LOCKED +---- +1 1 +3 4 +4 4 + +# Not supported by Materialize. +onlyif cockroach +# All columns are available from the secondary index on u, so no index join is +# needed. The secondary index can produce the row where k=2 since the row is +# only locked in the primary index. +query II +SELECT k, u FROM t3 WHERE u = 2 FOR UPDATE SKIP LOCKED +---- +2 2 +4 2 + +# Not supported by Materialize. +onlyif cockroach +# An index join is needed to fetch column v. The index join filters out the +# first row, which is locked. +query III +SELECT * FROM t3 WHERE u = 2 FOR UPDATE SKIP LOCKED +---- +4 4 2 + +# Not supported by Materialize. +onlyif cockroach +# Since the limit is not pushed below the index join, we still see the second row. +query III +SELECT * FROM t3 WHERE u = 2 LIMIT 1 FOR UPDATE SKIP LOCKED +---- +4 4 2 + +user root + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT * FROM t FOR UPDATE SKIP LOCKED +---- +2 3 + +statement ok +ROLLBACK + +user testuser + +statement ok +ROLLBACK + +user root + +# Not supported by Materialize. +onlyif cockroach +# Regression test for not propagating lock spans with leaf txns (#94290). +statement ok +CREATE TABLE t94290 (a INT, b INT, c INT, PRIMARY KEY(a), UNIQUE INDEX(b)); +INSERT INTO t94290 VALUES (1,2,3); + +# If the lock spans are not propagated, then the second query would take almost +# 5 seconds. +statement ok +SET statement_timeout = '2s'; + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t94290 WHERE b = 2 FOR UPDATE; + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM t94290 WHERE b = 2 FOR UPDATE; + +statement ok +RESET statement_timeout; diff --git a/test/sqllogictest/cockroach/select_index.slt b/test/sqllogictest/cockroach/select_index.slt index d13352f29ca91..7073e0bfd0312 100644 --- a/test/sqllogictest/cockroach/select_index.slt +++ b/test/sqllogictest/cockroach/select_index.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,26 +9,26 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/select_index +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/select_index # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - statement ok CREATE TABLE t ( a INT PRIMARY KEY, b INT, - c INT + c INT, + INDEX b_desc (b DESC), + INDEX bc (b, c) ) statement ok @@ -49,10 +49,7 @@ statement ok CREATE TABLE ab ( s STRING, i INT -) - -statement ok -INSERT INTO ab VALUES ('a', 1), ('b', 1), ('c', 1) +); INSERT INTO ab VALUES ('a', 1), ('b', 1), ('c', 1) query IT rowsort SELECT i, s FROM ab WHERE (i, s) < (1, 'c') @@ -63,13 +60,15 @@ SELECT i, s FROM ab WHERE (i, s) < (1, 'c') statement ok CREATE INDEX baz ON ab (i, s) +# Not supported by Materialize. +onlyif cockroach query IT rowsort SELECT i, s FROM ab@baz WHERE (i, s) < (1, 'c') ---- 1 a 1 b -# Issue materialize#14426: verify we don't have an internal filter that contains "a IN ()" +# Issue #14426: verify we don't have an internal filter that contains "a IN ()" # (which causes an error in DistSQL due to expression serialization). statement ok CREATE TABLE tab0( @@ -82,12 +81,13 @@ query I SELECT k FROM tab0 WHERE (a IN (6) AND a > 6) OR b >= 4 ---- -# Regression tests for materialize#12022 +# Regression tests for #12022 statement ok CREATE TABLE t12022 ( c1 INT, c2 BOOL, + UNIQUE INDEX i (c1, c2) ); statement ok @@ -95,6 +95,8 @@ INSERT INTO t12022 VALUES (1, NULL), (1, false), (1, true), (2, NULL), (2, false), (2, true); +# Not supported by Materialize. +onlyif cockroach query IB SELECT * FROM t12022@i WHERE (c1, c2) > (1, NULL) ORDER BY (c1, c2); ---- @@ -102,6 +104,8 @@ SELECT * FROM t12022@i WHERE (c1, c2) > (1, NULL) ORDER BY (c1, c2); 2 false 2 true +# Not supported by Materialize. +onlyif cockroach query IB SELECT * FROM t12022@i WHERE (c1, c2) > (1, false) ORDER BY (c1, c2); ---- @@ -110,6 +114,8 @@ SELECT * FROM t12022@i WHERE (c1, c2) > (1, false) ORDER BY (c1, c2); 2 false 2 true +# Not supported by Materialize. +onlyif cockroach query IB SELECT * FROM t12022@i WHERE (c1, c2) > (1, true) ORDER BY (c1, c2); ---- @@ -117,6 +123,8 @@ SELECT * FROM t12022@i WHERE (c1, c2) > (1, true) ORDER BY (c1, c2); 2 false 2 true +# Not supported by Materialize. +onlyif cockroach query IB SELECT * FROM t12022@i WHERE (c1, c2) < (2, NULL) ORDER BY (c1, c2); ---- @@ -124,6 +132,8 @@ SELECT * FROM t12022@i WHERE (c1, c2) < (2, NULL) ORDER BY (c1, c2); 1 false 1 true +# Not supported by Materialize. +onlyif cockroach query IB SELECT * FROM t12022@i WHERE (c1, c2) < (2, false) ORDER BY (c1, c2); ---- @@ -131,6 +141,8 @@ SELECT * FROM t12022@i WHERE (c1, c2) < (2, false) ORDER BY (c1, c2); 1 false 1 true +# Not supported by Materialize. +onlyif cockroach query IB SELECT * FROM t12022@i WHERE (c1, c2) < (2, true) ORDER BY (c1, c2); ---- @@ -140,7 +152,9 @@ SELECT * FROM t12022@i WHERE (c1, c2) < (2, true) ORDER BY (c1, c2); 2 false -# Regression test for materialize#20035. +# Not supported by Materialize. +onlyif cockroach +# Regression test for #20035. statement ok CREATE TABLE favorites ( id INT NOT NULL DEFAULT unique_rowid(), @@ -153,8 +167,15 @@ CREATE TABLE favorites ( created_ts TIMESTAMP NULL, guid_id STRING(100) NOT NULL, locale STRING(10) NOT NULL DEFAULT NULL, + CONSTRAINT "primary" PRIMARY KEY (id ASC), + UNIQUE INDEX favorites_idx (resource_type ASC, device_group ASC, resource_key ASC, customerid ASC), + INDEX favorites_guid_idx (guid_id ASC), + INDEX favorites_glob_fav_idx (resource_type ASC, device_group ASC, jurisdiction ASC, brand ASC, locale ASC, resource_key ASC), + FAMILY "primary" (id, resource_type, resource_key, device_group, customerid, jurisdiction, brand, created_ts, guid_id, locale) ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO favorites (customerid, guid_id, resource_type, device_group, jurisdiction, brand, locale, resource_key) VALUES (1, '1', 'GAME', 'web', 'MT', 'xxx', 'en_GB', 'tp'), @@ -164,6 +185,8 @@ INSERT INTO favorites (customerid, guid_id, resource_type, device_group, jurisdi (5, '5', 'GAME', 'web', 'MT', 'xxx', 'en_GB', 'ts3'), (6, '6', 'GAME', 'web', 'MT', 'xxx', 'en_GB', 'ts4') +# Not supported by Materialize. +onlyif cockroach query TI rowsort SELECT resource_key, @@ -188,9 +211,11 @@ CREATE TABLE abcd ( b INT, c INT, d INT, + INDEX adb (a, d, b), + INDEX abcd (a, b, c, d) ) -# Regression tests for materialize#20362 (IS NULL handling). +# Regression tests for #20362 (IS NULL handling). statement ok INSERT INTO abcd VALUES (NULL, NULL, NULL), @@ -226,6 +251,8 @@ INSERT INTO abcd VALUES (1, 10, 5), (1, 10, 10) +# Not supported by Materialize. +onlyif cockroach query IIII rowsort SELECT * FROM abcd@abcd WHERE a IS NULL AND b > 5 ---- @@ -234,6 +261,8 @@ NULL 10 1 NULL NULL 10 5 NULL NULL 10 10 NULL +# Not supported by Materialize. +onlyif cockroach query IIII rowsort SELECT * FROM abcd@abcd WHERE a IS NULL AND b < 5 ---- @@ -242,6 +271,8 @@ NULL 1 1 NULL NULL 1 5 NULL NULL 1 10 NULL +# Not supported by Materialize. +onlyif cockroach query IIII partialsort(1,2) SELECT * FROM abcd@abcd WHERE a IS NULL ORDER BY b ---- @@ -262,18 +293,20 @@ NULL 10 1 NULL NULL 10 5 NULL NULL 10 10 NULL +# Not supported by Materialize. +onlyif cockroach query IIII SELECT * FROM abcd@abcd WHERE a = 1 AND b IS NULL AND c > 0 AND c < 10 ORDER BY c ---- 1 NULL 1 NULL 1 NULL 5 NULL -# Regression test for materialize#21831. +# Regression test for #21831. statement ok -CREATE TABLE str (k INT PRIMARY KEY, v STRING) +CREATE TABLE str (k INT PRIMARY KEY, v STRING, INDEX(v)) statement ok -INSERT INTO str VALUES (1, 'A'), (4, 'AB'), (2, 'ABC'), (5, 'ABCD'), (3, 'ABCDEZ'), (9, 'ABD') +INSERT INTO str VALUES (1, 'A'), (4, 'AB'), (2, 'ABC'), (5, 'ABCD'), (3, 'ABCDEZ'), (9, 'ABD'), (10, '\CBA'), (11, 'A%'), (12, 'CAB.*'), (13, 'CABD') query IT rowsort SELECT k, v FROM str WHERE v LIKE 'ABC%' @@ -282,11 +315,43 @@ SELECT k, v FROM str WHERE v LIKE 'ABC%' 5 ABCD 3 ABCDEZ +query IT rowsort +SELECT k, v FROM str WHERE v LIKE '\ABC%' +---- +2 ABC +5 ABCD +3 ABCDEZ + +statement error Evaluation error: unterminated escape sequence in LIKE +SELECT k, v FROM str WHERE v LIKE 'ABC\' + +query IT rowsort +SELECT k, v FROM str WHERE v LIKE '\\CBA%' +---- +10 \CBA + +query IT rowsort +SELECT k, v FROM str WHERE v LIKE 'A\%' +---- +11 A% + +query IT rowsort +SELECT k, v FROM str WHERE v LIKE 'CAB.*' +---- +12 CAB.* + query IT rowsort SELECT k, v FROM str WHERE v LIKE 'ABC%Z' ---- 3 ABCDEZ +query IT rowsort +SELECT k, v FROM str WHERE v LIKE '\ABCDE_' +---- +3 ABCDEZ + +# Not supported by Materialize. +onlyif cockroach query IT rowsort SELECT k, v FROM str WHERE v SIMILAR TO 'ABC_*' ---- @@ -294,9 +359,9 @@ SELECT k, v FROM str WHERE v SIMILAR TO 'ABC_*' 5 ABCD 3 ABCDEZ -# Regression tests for materialize#22670. +# Regression tests for #22670. statement ok -CREATE TABLE xy (x INT, y INT) +CREATE TABLE xy (x INT, y INT, INDEX (y)) statement ok CREATE INDEX xy_idx ON xy (x, y) @@ -311,7 +376,7 @@ SELECT * FROM xy WHERE x IN (NULL, 1, 2) 1 1 statement ok -CREATE TABLE ef (e INT, f INT) +CREATE TABLE ef (e INT, f INT, INDEX(f)) statement ok INSERT INTO ef VALUES (NULL, 1), (1, 1) @@ -327,94 +392,131 @@ SELECT * FROM xy WHERE (x, y) IN ((NULL, NULL), (1, NULL), (NULL, 1), (1, 1), (1 ---- 1 1 +# Not supported by Materialize. +onlyif cockroach # Test index constraints for IS (NOT) TRUE/FALSE. statement ok CREATE TABLE bool1 ( a BOOL, + INDEX (a) ); INSERT INTO bool1 VALUES (NULL), (TRUE), (FALSE) +# Not supported by Materialize. +onlyif cockroach query B SELECT * FROM bool1 WHERE a IS NULL ---- NULL +# Not supported by Materialize. +onlyif cockroach query B rowsort SELECT * FROM bool1 WHERE a IS NOT NULL ---- false true +# Not supported by Materialize. +onlyif cockroach query B SELECT * FROM bool1 WHERE a IS TRUE ---- true +# Not supported by Materialize. +onlyif cockroach query B rowsort SELECT * FROM bool1 WHERE a IS NOT TRUE ---- NULL false +# Not supported by Materialize. +onlyif cockroach query B SELECT * FROM bool1 WHERE a IS FALSE ---- false +# Not supported by Materialize. +onlyif cockroach query B rowsort SELECT * FROM bool1 WHERE a IS NOT FALSE ---- NULL true +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE bool2 ( a BOOL NOT NULL, + INDEX (a) ); INSERT INTO bool2 VALUES (TRUE), (FALSE) +# Not supported by Materialize. +onlyif cockroach query B SELECT * FROM bool2 WHERE a IS NULL ---- +# Not supported by Materialize. +onlyif cockroach query B rowsort SELECT * FROM bool2 WHERE a IS NOT NULL ---- false true +# Not supported by Materialize. +onlyif cockroach query B SELECT * FROM bool2 WHERE a IS TRUE ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT * FROM bool2 WHERE a IS NOT TRUE ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT * FROM bool2 WHERE a IS FALSE ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT * FROM bool2 WHERE a IS NOT FALSE ---- true +# Not supported by Materialize. +onlyif cockroach # Test index constraints for IS (NOT) DISTINCT FROM on an integer column. statement ok CREATE TABLE int ( a INT, + INDEX (a) ); INSERT INTO int VALUES (NULL), (0), (1), (2) +# Not supported by Materialize. +onlyif cockroach query I SELECT * FROM int WHERE a IS NOT DISTINCT FROM 2 ---- 2 +# Not supported by Materialize. +onlyif cockroach query I rowsort SELECT * FROM int WHERE a IS DISTINCT FROM 2 ---- @@ -431,6 +533,12 @@ CREATE TABLE noncover ( b INT, c INT, d INT, + INDEX b (b), + UNIQUE INDEX c (c), + FAMILY (a), + FAMILY (b), + FAMILY (c), + FAMILY (d) ) statement ok @@ -441,21 +549,13 @@ SELECT * FROM noncover WHERE b = 2 ---- 1 2 3 4 +# Not supported by Materialize. +onlyif cockroach query IIII SET tracing=on, kv; SELECT * FROM noncover WHERE b = 2; SET tracing=off ---- 1 2 3 4 -# Verify that the index join span created doesn't include any potential child -# interleaved tables. We look only for spans with the primary prefix to avoid -# inconsistency between the fakedist and local test configurations. - -query T rowsort -SELECT message FROM [SHOW KV TRACE FOR SESSION] -WHERE message LIKE 'Scan /Table/65/1%' ----- -Scan /Table/65/1/1{-/#} - # Subset of output columns, not including tested column. query II SELECT a, d FROM noncover WHERE b=2 @@ -565,6 +665,8 @@ SELECT w FROM t3 WHERE v > 0 AND v < 100 ORDER BY v 2 1 +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE tab1 ( pk INTEGER NOT NULL, @@ -582,6 +684,8 @@ CREATE TABLE tab1 ( FAMILY "primary" (pk, col0, col1, col2, col3, col4, col5) ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO tab1(pk, col0, col3) VALUES (1, 65, 65), @@ -592,6 +696,8 @@ INSERT INTO tab1(pk, col0, col3) VALUES (6, 72, 72), (7, 82, 82) +# Not supported by Materialize. +onlyif cockroach query II SELECT pk, col0 FROM tab1 WHERE (col3 BETWEEN 66 AND 87) ORDER BY 1 DESC ---- @@ -621,3 +727,104 @@ SELECT * FROM abc WHERE (c IS NULL OR c=2) AND a>0 1 1 NULL 1 2 NULL 2 2 2 + +# Regression test for #38878 (incorrect span generation with OR and exclusive +# string boundaries). +statement ok +CREATE TABLE t38878 (k1 STRING, k2 STRING, v INT, PRIMARY KEY (k1, k2)) + +statement ok +INSERT INTO t38878 VALUES ('a', 'u', 1), ('b', 'v', 2), ('c', 'w', 3), ('d', 'x', 4), ('d', 'x2', 5) + +query TTI rowsort +SELECT * FROM t38878 WHERE k1 = 'b' OR (k1 > 'b' AND k1 < 'd') +---- +b v 2 +c w 3 + +query TTI rowsort +SELECT * FROM t38878 WHERE (k1 = 'd' AND k2 = 'x') OR k1 = 'b' OR (k1 > 'b' AND k1 < 'd') +---- +b v 2 +c w 3 +d x 4 + +# Regression test for #47976 (optimizer OOM and timeouts with many ORs). +statement ok +CREATE TABLE t47976 ( + k INT PRIMARY KEY, + a INT, + b FLOAT, + c INT, + INDEX (a), + INDEX (b), + INDEX (c) +) + +statement ok +SELECT k FROM t47976 WHERE + (a >= 6 OR b < 8 OR c IN (23, 27, 53)) AND + (a = 1 OR b >= 12 OR c IS NULL) AND + (a < 1 OR b = 6.8 OR c = 12) AND + (a > 4 OR b <= 5.23 OR c IN (1, 2, 3)) AND + (a = 12 OR b = 15.23 OR c = 14) AND + (a > 58 OR b < 0 OR c >= 13) + +# Not supported by Materialize. +onlyif cockroach +# Regression test for incorrectly splitting a lookup row (with NULL values not +# in the lookup key) into family spans (#76289). +statement ok +CREATE TABLE t76289_1 ( + pk1 DECIMAL NOT NULL, pk2 INT8 NOT NULL, c1 INT8, c2 INT8, + PRIMARY KEY (pk1, pk2), + UNIQUE (pk2), + FAMILY fam_c1 (c1), FAMILY fam_c2 (pk1, pk2, c2) +); +INSERT INTO t76289_1 (pk1, pk2, c1) VALUES (1:::DECIMAL, 0:::INT8, 0:::INT8); + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT c2 FROM t76289_1 WHERE pk2 = 0; +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t76289_2 ( + pk1 DECIMAL NOT NULL, pk2 INT8 NOT NULL, c1 INT8, c2 INT8, + PRIMARY KEY (pk1, pk2), + INDEX (pk2), + FAMILY fam_c1 (c1), FAMILY fam_c2 (pk1, pk2, c2) +); +INSERT INTO t76289_2 (pk1, pk2, c1) VALUES (1:::DECIMAL, 0:::INT8, 0:::INT8); + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT c2 FROM t76289_2@t76289_2_pk2_idx WHERE pk2 = 0; +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +# Regression test for incorrectly splitting a row to scan (with NULL values in +# the row) into family spans when reading from the secondary index if the KV +# is omitted for some column families (#88110). +statement ok +CREATE TABLE t88110 ( + _i INT8 NOT NULL, _bool BOOL, _int INT8, + UNIQUE (_bool) STORING(_int), + FAMILY (_bool), + FAMILY (_i, _int) +); +INSERT INTO t88110 (_i, _bool, _int) VALUES (0, false, NULL); + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT DISTINCT _int FROM t88110 WHERE NOT _bool; +---- +NULL diff --git a/test/sqllogictest/cockroach/select_index_flags.slt b/test/sqllogictest/cockroach/select_index_flags.slt index adbcc680e3594..072f7ec0e175c 100644 --- a/test/sqllogictest/cockroach/select_index_flags.slt +++ b/test/sqllogictest/cockroach/select_index_flags.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/select_index_flags +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/select_index_flags # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach statement ok @@ -43,20 +43,26 @@ SELECT * FROM abcd WHERE a >= 20 AND a <= 30 20 21 22 23 30 31 32 33 +# Not supported by Materialize. +onlyif cockroach # Force primary query IIII rowsort -SELECT * FROM abcd@primary WHERE a >= 20 AND a <= 30 +SELECT * FROM abcd@abcd_pkey WHERE a >= 20 AND a <= 30 ---- 20 21 22 23 30 31 32 33 +# Not supported by Materialize. +onlyif cockroach # Force primary, reverse scan. query IIII rowsort -SELECT * FROM abcd@{FORCE_INDEX=primary,DESC} WHERE a >= 20 AND a <= 30 +SELECT * FROM abcd@{FORCE_INDEX=abcd_pkey,DESC} WHERE a >= 20 AND a <= 30 ---- 20 21 22 23 30 31 32 33 +# Not supported by Materialize. +onlyif cockroach # Force index b query IIII rowsort SELECT * FROM abcd@b WHERE a >= 20 AND a <= 30 @@ -64,6 +70,8 @@ SELECT * FROM abcd@b WHERE a >= 20 AND a <= 30 20 21 22 23 30 31 32 33 +# Not supported by Materialize. +onlyif cockroach # Force index b, reverse scan. query IIII rowsort SELECT * FROM abcd@{FORCE_INDEX=b,DESC} WHERE a >= 20 AND a <= 30 @@ -71,6 +79,8 @@ SELECT * FROM abcd@{FORCE_INDEX=b,DESC} WHERE a >= 20 AND a <= 30 20 21 22 23 30 31 32 33 +# Not supported by Materialize. +onlyif cockroach # Force index cd query IIII rowsort SELECT * FROM abcd@cd WHERE a >= 20 AND a <= 30 @@ -78,6 +88,8 @@ SELECT * FROM abcd@cd WHERE a >= 20 AND a <= 30 20 21 22 23 30 31 32 33 +# Not supported by Materialize. +onlyif cockroach # Force index bcd query IIII rowsort SELECT * FROM abcd@bcd WHERE a >= 20 AND a <= 30 @@ -85,6 +97,8 @@ SELECT * FROM abcd@bcd WHERE a >= 20 AND a <= 30 20 21 22 23 30 31 32 33 +# Not supported by Materialize. +onlyif cockroach # Force index b (covering) query I rowsort SELECT b FROM abcd@b WHERE a >= 20 AND a <= 30 @@ -92,6 +106,8 @@ SELECT b FROM abcd@b WHERE a >= 20 AND a <= 30 21 31 +# Not supported by Materialize. +onlyif cockroach # Force index b (non-covering due to WHERE clause) query I rowsort SELECT b FROM abcd@b WHERE c >= 20 AND c <= 30 @@ -105,13 +121,17 @@ SELECT c, d FROM abcd WHERE c >= 20 AND c < 40 22 23 32 33 +# Not supported by Materialize. +onlyif cockroach # Force primary index query II rowsort -SELECT c, d FROM abcd@primary WHERE c >= 20 AND c < 40 +SELECT c, d FROM abcd@abcd_pkey WHERE c >= 20 AND c < 40 ---- 22 23 32 33 +# Not supported by Materialize. +onlyif cockroach # Force index b query II rowsort SELECT c, d FROM abcd@b WHERE c >= 20 AND c < 40 @@ -119,8 +139,12 @@ SELECT c, d FROM abcd@b WHERE c >= 20 AND c < 40 22 23 32 33 +# Not supported by Materialize. +onlyif cockroach query error index \"badidx\" not found SELECT * FROM abcd@badidx +# Not supported by Materialize. +onlyif cockroach query error index \"badidx\" not found SELECT * FROM abcd@{FORCE_INDEX=badidx} diff --git a/test/sqllogictest/cockroach/select_search_path.slt b/test/sqllogictest/cockroach/select_search_path.slt index 7de26b585e198..f6568f5a32f9d 100644 --- a/test/sqllogictest/cockroach/select_search_path.slt +++ b/test/sqllogictest/cockroach/select_search_path.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,23 +9,23 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/select_search_path +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/select_search_path # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach # Test that pg_catalog tables are accessible without qualifying table/view # names. -query T +query TTTTIT SHOW TABLES ---- @@ -33,7 +33,7 @@ SHOW TABLES query I SELECT count(DISTINCT(1)) FROM pg_attrdef ---- -0 +1 query I SELECT count(DISTINCT(1)) FROM pg_attribute @@ -59,12 +59,16 @@ SELECT count(DISTINCT(1)) FROM pg_tables statement ok CREATE DATABASE t1 +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE t1.numbers (n INTEGER) statement ok CREATE DATABASE t2 +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE t2.words (w TEXT) @@ -74,12 +78,14 @@ CREATE TABLE t2.words (w TEXT) statement ok SET DATABASE = t1 +# Not supported by Materialize. +onlyif cockroach query I SELECT count(*) FROM numbers ---- 0 -query error pq: relation "words" does not exist +query error unknown catalog item 'words' SELECT count(*) FROM words # There's no table with default values in t1. @@ -114,9 +120,11 @@ SELECT count(DISTINCT(1)) FROM pg_tables statement ok SET DATABASE = t2 -query error pq: relation "numbers" does not exist +query error unknown catalog item 'numbers' SELECT count(*) FROM numbers +# Not supported by Materialize. +onlyif cockroach query I SELECT count(*) FROM words ---- diff --git a/test/sqllogictest/cockroach/select_table_alias.slt b/test/sqllogictest/cockroach/select_table_alias.slt index 1815023e4e530..db5d0a6ace10a 100644 --- a/test/sqllogictest/cockroach/select_table_alias.slt +++ b/test/sqllogictest/cockroach/select_table_alias.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/select_table_alias +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/select_table_alias # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - # Tests for SELECT with table aliasing. statement ok @@ -101,10 +99,10 @@ foo1 foo2 c # Verify we can't resolve columns using overridden table or colum names. -query error column "abc.foo1" does not exist +query error column "abc\.foo1" does not exist SELECT abc.foo1 FROM abc AS foo (foo1) -query error column "abc.b" does not exist +query error column "abc\.b" does not exist SELECT abc.b FROM abc AS foo (foo1) query error column "foo.a" does not exist @@ -133,27 +131,29 @@ foo1 foo2 1 3 2 5 -# NOTE(benesch): rowid is a CockroachDB-ism that we are unlikely to support. -# -# statement ok -# SELECT rowid, foo.rowid FROM ab AS foo (foo1, foo2) -# -# query error no data source matches prefix: ab -# SELECT ab.rowid FROM ab AS foo (foo1) +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT rowid, foo.rowid FROM ab AS foo (foo1, foo2) + +query error column "ab\.rowid" does not exist +SELECT ab.rowid FROM ab AS foo (foo1) query error foo has 2 columns available but 3 columns specified SELECT * FROM ab AS foo (foo1, foo2, foo3) -# TODO(benesch): support scalar functions in table position. -# -# query T colnames -# SELECT * FROM length('abc') AS x -# ---- -# x -# 3 -# -# query T colnames -# TABLE ROWS FROM length('abc') AS x -# ---- -# x -# 3 +# Not supported by Materialize. +onlyif cockroach +query T colnames +SELECT * FROM to_english(3) AS x +---- +x +three + +# Not supported by Materialize. +onlyif cockroach +query T colnames +TABLE ROWS FROM (to_english(3)) AS x; +---- +x +three diff --git a/test/sqllogictest/cockroach/set.slt b/test/sqllogictest/cockroach/set.slt new file mode 100644 index 0000000000000..7f8bd35747f04 --- /dev/null +++ b/test/sqllogictest/cockroach/set.slt @@ -0,0 +1,1040 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/set +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: local + +statement error unrecognized configuration parameter "foo" +SET foo = bar + +statement error unrecognized configuration parameter "foo" +SHOW foo + +# Not supported by Materialize. +onlyif cockroach +statement error database "foo" does not exist +SET database = foo + +# Not supported by Materialize. +onlyif cockroach +# Ensure that the failing SET DATABASE call did not alter the session. +# The default session.database value is "test". +statement ok +SHOW TABLES + +statement ok +CREATE DATABASE foo + +statement ok +SET database = foo + +# Create a table in the session database. +statement ok +CREATE TABLE bar (k INT PRIMARY KEY) + +# Not supported by Materialize. +onlyif cockroach +# Verify that the table is indeed in "foo". +query TTTTIT +SHOW TABLES FROM foo +---- +public bar table root 0 NULL + +# Not supported by Materialize. +onlyif cockroach +# Verify set to empty string. +statement ok +SET database = "" + +query T colnames +SHOW database +---- +database +foo + +# Not supported by Materialize. +onlyif cockroach +statement error no database or schema specified +SHOW TABLES + +# Not supported by Materialize. +onlyif cockroach +# Verify SHOW TABLES FROM works when there is no current database. +query TTTTIT +SHOW TABLES FROM foo +---- +public bar table root 0 NULL + +# SET statement succeeds, CREATE TABLE fails. +statement error pgcode 42P07 table "foo\.public\.bar" already exists +SET database = foo; CREATE TABLE bar (k INT PRIMARY KEY) + +query T colnames +SHOW database +---- +database +foo + +# Not supported by Materialize. +onlyif cockroach +# SET succeeds +query TTTTIT +SHOW TABLES from foo +---- +public bar table root 0 NULL + +statement error Expected equals sign or TO, found left parenthesis +SET ROW (1, TRUE, NULL) + +statement ok +SET application_name = helloworld + +query T colnames +SHOW application_name +---- +application_name +helloworld + +# Not supported by Materialize. +onlyif cockroach +# SESSION_USER is a special keyword, check that SHOW knows about it. +query T +SHOW session_user +---- +root + +## Test SET ... TO DEFAULT works + +statement ok +SET distsql TO ON + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW distsql +---- +distsql +on + +statement ok +SET distsql TO DEFAULT + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW distsql +---- +distsql +off + +## Test that our no-op compatibility vars work + +statement ok +SET application_name = 'hello' + +statement ok +SET extra_float_digits = 0 + +# SQL-481 (https://linear.app/materializeinc/issue/SQL-481): Materialize accepts +# extra_float_digits without range-checking it. PG and CockroachDB reject values +# outside -15..3. +# PG/CRDB: statement error 123 is outside the valid range for parameter "extra_float_digits" +statement ok +SET extra_float_digits = 123 + +statement ok +SET client_min_messages = 'debug1' + +statement ok +SET standard_conforming_strings = 'on' + +statement error parameter "standard_conforming_strings" can only be set to "on" +SET standard_conforming_strings = 'off' + +statement ok +SET client_encoding = 'UTF8' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET client_encoding = 'UT! '' @#!$%%F------!@!!!8 '' ' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET client_encoding = 'unicode' + +statement error invalid value for parameter "client_encoding": "other" +SET client_encoding = 'other' + +statement error unrecognized configuration parameter "server_encoding" +SET server_encoding = 'UTF8' + +statement error unrecognized configuration parameter "server_encoding" +SET server_encoding = 'other' + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW ssl +---- +on + +statement error unrecognized configuration parameter "ssl" +SET ssl = 'off' + +statement ok +SET escape_string_warning = 'ON' + +statement ok +SET escape_string_warning = 'off' + +statement ok +SET datestyle = 'ISO' + +query T +SHOW datestyle +---- +ISO, MDY + +statement ok +SET datestyle = 'ISO, MDY' + +query T +SHOW datestyle +---- +ISO, MDY + +statement ok +SET datestyle = 'mdy, iso' + +query T +SHOW datestyle +---- +ISO, MDY + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET datestyle = 'ymd' + +query T +SHOW datestyle +---- +ISO, MDY + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET datestyle = 'DMY, ISo' + +query T +SHOW datestyle +---- +ISO, MDY + +statement error parameter "DateStyle" can only be set to "ISO, MDY" +SET datestyle = 'postgres' + +statement error parameter "DateStyle" can only be set to "ISO, MDY" +SET datestyle = 'german' + +statement error parameter "DateStyle" can only be set to "ISO, MDY" +SET datestyle = 'sql' + +statement error parameter "DateStyle" can only be set to "ISO, MDY" +SET datestyle = 'other' + +statement ok +SET intervalstyle = 'postgres' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET intervalstyle = 'iso_8601' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET intervalstyle = 'sql_standard' + +statement error invalid value for parameter "IntervalStyle": "other" +SET intervalstyle = 'other' + +statement ok +SET search_path = 'blah' + +statement ok +SET distsql = always + +statement ok +SET distsql = on + +statement ok +SET distsql = off + +statement error unrecognized configuration parameter "distsql" +SET distsql = bogus + +statement ok +SET vectorize = on + +statement ok +SET vectorize = experimental_always + +statement ok +SET vectorize = off + +statement error unrecognized configuration parameter "vectorize" +SET vectorize = bogus + +statement ok +SET optimizer = on + +statement error unrecognized configuration parameter "optimizer" +SET optimizer = local + +statement error unrecognized configuration parameter "optimizer" +SET optimizer = off + +statement error unrecognized configuration parameter "optimizer" +SET optimizer = bogus + +statement ok +SET bytea_output = escape + +statement ok +SET bytea_output = hex + +statement error unrecognized configuration parameter "bytea_output" +SET bytea_output = bogus + +statement ok +SET default_tablespace = '' + +statement error unrecognized configuration parameter "default_tablespace" +SET default_tablespace = 'bleepis' + +query T colnames +SHOW server_version +---- +server_version +9.5.0 + +query T colnames +SHOW server_version_num +---- +server_version_num +90500 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW log_timezone +---- +UTC + +# Test read-only variables +statement error unrecognized configuration parameter "max_index_keys" +SET max_index_keys = 32 + +statement error unrecognized configuration parameter "node_id" +SET node_id = 123 + +statement error unrecognized configuration parameter "log_timezone" +SET log_timezone = 'Australia/South' + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT name, value FROM system.settings WHERE name = 'testing.str' +---- + +# quoted identifiers +statement ok +SET "timezone" = 'UTC' + +# even quoted in postgres the session variable names are +# case-insensitive for SET and SHOW. +statement ok +SET "TIMEZONE" = 'UTC' + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW "TIMEZONE" +---- +UTC + +# without quoted identifiers +statement ok +SET timezone = 'UTC' + +query T +SHOW timezone +---- +UTC + +# TIMEZONE alias - TIME ZONE two words/tokens +statement ok +SET TIME ZONE 'UTC' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #19727 - invalid EvalContext used to evaluate arguments to set. +statement ok +SET application_name = current_timestamp()::string + +# Test statement_timeout on a long-running query. +statement ok +SET statement_timeout = 1 + +statement error canceling statement due to statement timeout +SELECT * FROM generate_series(1,1000000) + +# Test that statement_timeout can be set with an interval string. +statement ok +SET statement_timeout = '0ms' + +# Test that statement_timeout can be set with an interval string, defaulting to +# milliseconds as a unit. +statement ok +SET statement_timeout = '10000' + +query T +SHOW statement_timeout +---- +10 s + +# Set the statement timeout to something absurdly small, so that no query would +# presumably be able to go through. It should still be possible to get out of +# this "bad state" by resetting the statement timeout. +subtest impossible_statement_timeout_recovery + +statement ok +SET statement_timeout = '1us' + +# Not supported by Materialize. +onlyif cockroach +statement error query execution canceled due to statement timeout +SHOW statement_timeout + +statement ok +SET statement_timeout = 0 + +query T +SHOW statement_timeout +---- +0 s + +statement ok +SET lock_timeout = '1ms' + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW lock_timeout +---- +1 + +statement ok +SET lock_timeout = 0 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW lock_timeout +---- +0 + +statement ok +SET idle_in_session_timeout = 10000 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW idle_in_session_timeout +---- +10000 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW idle_session_timeout +---- +10000 + +statement ok +SET idle_session_timeout = 100000 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW idle_in_session_timeout +---- +100000 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW idle_session_timeout +---- +100000 + +statement ok +SET idle_in_session_timeout = 0; +SET idle_in_transaction_session_timeout = 123456 + +query T +SHOW idle_in_transaction_session_timeout +---- +2 min + +statement ok +SET idle_in_transaction_session_timeout = 0 + +statement error unrecognized configuration parameter "ssl_renegotiation_limit" +SET ssl_renegotiation_limit = 123 + +statement ok +SET SESSION tracing=false + +statement error pgcode 42601 unrecognized configuration parameter "tracing" +SET SESSION tracing=1 + +subtest regression_35109_flowable + +statement ok +SET DATESTYLE = ISO; + SET INTERVALSTYLE = POSTGRES; + SET extra_float_digits TO 3; + SET synchronize_seqscans TO off; + SET statement_timeout = 0; + SET lock_timeout = 0; + SET idle_in_transaction_session_timeout = 0; + SET row_security = off; + +subtest regression_41567_subqueries + +statement error Expected end of statement, found left parenthesis +SET SESSION SCHEMA EXISTS ( TABLE ( ( ( ( ( ( ( ( TABLE error ) ) ) ) ) ) ) ) ORDER BY INDEX FAMILY . IS . MAXVALUE @ OF DESC , INDEX FAMILY . FOR . ident @ ident ASC ) + +statement error Expected a keyword at the beginning of a statement, found identifier "use" +USE EXISTS ( TABLE error ) IS NULL + +statement error Expected a keyword at the beginning of a statement, found identifier "use" +PREPARE a AS USE EXISTS ( TABLE error ) IS NULL + +subtest bools +# Ensure that we can set variables to on/off and yes/no. +statement ok +SET enable_zigzag_join = 'on'; +SET enable_zigzag_join = 'off'; +SET enable_zigzag_join = 'true'; +SET enable_zigzag_join = 'false'; +SET enable_zigzag_join = 'yes'; +SET enable_zigzag_join = 'no'; +SET enable_zigzag_join = on; +SET enable_zigzag_join = off; +SET enable_zigzag_join = true; +SET enable_zigzag_join = false; +SET enable_zigzag_join = yes; +SET enable_zigzag_join = no + +# Check error code. +statement error pgcode 22023 unrecognized configuration parameter "enable_zigzag_join" +SET enable_zigzag_join = nonsense + +statement ok +SET experimental_distsql_planning = always; +SET experimental_distsql_planning = on; +SET experimental_distsql_planning = off + +subtest dummy_session_vars + +query T noticetrace +SET synchronous_commit = off; SET enable_seqscan = false +---- +WARNING: setting session var "synchronous_commit" is a no-op +WARNING: setting session var "enable_seqscan" is a no-op + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW synchronous_commit +---- +synchronous_commit +off + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW enable_seqscan +---- +enable_seqscan +off + +query T noticetrace +SET synchronous_commit = on; SET enable_seqscan = true +---- +WARNING: setting session var "synchronous_commit" is a no-op +WARNING: setting session var "enable_seqscan" is a no-op + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW synchronous_commit +---- +synchronous_commit +on + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW enable_seqscan +---- +enable_seqscan +on + +statement ok +BEGIN + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TRANSACTION NOT DEFERRABLE + +statement error Expected transaction mode, found identifier "deferrable" +SET TRANSACTION DEFERRABLE + +statement ok +rollback + +statement ok +SET standard_conforming_strings=true + +statement ok +SET standard_conforming_strings='true' + +statement ok +SET standard_conforming_strings='on' + +subtest default_table_access_method_test + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW default_table_access_method +---- +heap + +statement ok +SET default_table_access_method = 'heap' + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW default_table_access_method +---- +heap + +statement error unrecognized configuration parameter "default_table_access_method" +SET default_table_access_method = 'not-heap' + +subtest default_with_oids_test + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW default_with_oids +---- +off + +statement ok +SET default_with_oids = 'false' + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW default_with_oids +---- +off + +statement error unrecognized configuration parameter "default_with_oids" +SET default_with_oids = 'true' + +subtest xmloption_test + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW xmloption +---- +content + +statement ok +SET xmloption = 'content' + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW xmloption +---- +content + +statement error unrecognized configuration parameter "xmloption" +SET xmloption = 'document' + +subtest backslash_quote_test + +statement ok +SET backslash_quote = 'safe_encoding'; + +statement error unrecognized configuration parameter "backslash_quote" +SET backslash_quote = 'on'; + +statement error unrecognized configuration parameter "backslash_quote" +SET backslash_quote = 'off'; + +statement error unrecognized configuration parameter "backslash_quote" +SET backslash_quote = '123'; + +# Not supported by Materialize. +onlyif cockroach +# Regression test for not being able to set sql.trace.txn.enable_threshold +# cluster setting to non-zero value (#68005). +statement ok +SET cluster setting sql.trace.txn.enable_threshold='1s' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET cluster setting sql.trace.txn.enable_threshold='0s' + +statement ok +SET disable_plan_gists = 'true' + +statement ok +SET disable_plan_gists = 'false' + +statement ok +SET index_recommendations_enabled = 'true' + +statement ok +SET index_recommendations_enabled = 'false' + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW LC_COLLATE +---- +C.UTF-8 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW LC_CTYPE +---- +C.UTF-8 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW LC_MESSAGES +---- +C.UTF-8 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW LC_MONETARY +---- +C.UTF-8 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW LC_NUMERIC +---- +C.UTF-8 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW LC_TIME +---- +C.UTF-8 + +statement error unrecognized configuration parameter "lc_collate" +SET LC_COLLATE = 'C.UTF-8' + +statement error unrecognized configuration parameter "lc_ctype" +SET LC_CTYPE = 'C.UTF-8' + +statement ok +SET LC_MESSAGES = 'C.UTF-8' + +statement ok +SET LC_MONETARY = 'C.UTF-8' + +statement ok +SET LC_NUMERIC = 'C.UTF-8' + +statement ok +SET LC_TIME = 'C.UTF-8' + +statement error unrecognized configuration parameter "lc_messages" +SET LC_MESSAGES = 'en_US.UTF-8' + +statement error unrecognized configuration parameter "lc_monetary" +SET LC_MONETARY = 'en_US.UTF-8' + +statement error unrecognized configuration parameter "lc_numeric" +SET LC_NUMERIC = 'en_US.UTF-8' + +statement error unrecognized configuration parameter "lc_time" +SET LC_TIME = 'en_US.UTF-8' + +subtest check_function_bodies_test + +statement ok +SET check_function_bodies = true + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW check_function_bodies +---- +on + +statement ok +SET check_function_bodies = false + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW check_function_bodies +---- +off + +# Test custom session variables + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET custom_option.set_SQL = 'abc'; +SELECT set_config('custom_option.set_config', 'def', false); +RESET custom_option.use_default; +SET tracing.custom = 'ijk' + +# Not supported by Materialize. +onlyif cockroach +# Custom options are case insensitive. +query T colnames +SHOW Custom_option.set_sql +---- +custom_option.set_sql +abc + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW custom_option.set_config +---- +def + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT current_setting('custom_option.use_default') +---- +· + +# Not supported by Materialize. +onlyif cockroach +statement ok +RESET custom_option.set_config + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW custom_option.set_config +---- +· + +# Not supported by Materialize. +onlyif cockroach +# Ensure it does not show up on SHOW ALL or pg_settings. +query T +SELECT variable FROM [SHOW ALL] WHERE variable LIKE 'custom_option.%' +---- + +query T +SELECT name FROM pg_catalog.pg_settings WHERE name LIKE 'custom_option.%' +---- + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW tracing +---- +off + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW tracing.custom +---- +ijk + +# Show a notice if a custom session variable has the same name as a cluster setting. +query T noticetrace +SET server.shutdown.drain_wait = '10s' +---- +NOTICE: setting custom variable "server.shutdown.drain_wait" +HINT: did you mean SET CLUSTER SETTING? + +# Test that RESET ALL changes custom options to empty strings. +statement ok +RESET ALL + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW tracing.custom +---- +· + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW custom_option.set_sql +---- +· + +statement error Expected end of statement, found dot +SHOW custom_option.does_not_yet_exist + +statement error unrecognized configuration parameter "join_reader_ordering_strategy_batch_size" +SET join_reader_ordering_strategy_batch_size = '-1B' + +statement ok +SET join_reader_ordering_strategy_batch_size = '1B' + +statement ok +SET parallelize_multi_key_lookup_joins_enabled = true + +statement ok +SET parallelize_multi_key_lookup_joins_enabled = false + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW opt_split_scan_limit +---- +2048 + +statement error unrecognized configuration parameter "opt_split_scan_limit" +SET opt_split_scan_limit = -1 + +statement error unrecognized configuration parameter "opt_split_scan_limit" +SET opt_split_scan_limit = 2147483648 + +statement ok +SET opt_split_scan_limit = 100000 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW opt_split_scan_limit +---- +100000 + +statement ok +RESET opt_split_scan_limit + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW opt_split_scan_limit +---- +2048 + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW enable_auto_rehoming +---- +off + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW experimental_enable_auto_rehoming +---- +off + +statement ok +SET enable_auto_rehoming = on + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW enable_auto_rehoming +---- +on + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW experimental_enable_auto_rehoming +---- +on + +statement ok +SET experimental_enable_auto_rehoming = off + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW experimental_enable_auto_rehoming +---- +off + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW enable_auto_rehoming +---- +off + +statement error unrecognized configuration parameter "enable_auto_rehoming" +SET enable_auto_rehoming = bogus + +statement error unrecognized configuration parameter "experimental_enable_auto_rehoming" +SET experimental_enable_auto_rehoming = bogus diff --git a/test/sqllogictest/cockroach/set_role.slt b/test/sqllogictest/cockroach/set_role.slt new file mode 100644 index 0000000000000..411957d5aa571 --- /dev/null +++ b/test/sqllogictest/cockroach/set_role.slt @@ -0,0 +1,472 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/set_role +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE priv_t (pk INT PRIMARY KEY); +CREATE TABLE no_priv_t (pk INT PRIMARY KEY); +GRANT SELECT ON priv_t TO testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SCHEMA root; +CREATE TABLE root.root_table (); +CREATE SCHEMA testuser; +GRANT ALL ON SCHEMA testuser TO testuser; +CREATE TABLE testuser.testuser_table (); +GRANT ALL ON TABLE testuser.testuser_table TO testuser + +# Cannot become node or public. +statement error role name "public" is reserved +CREATE ROLE public + +statement error pgcode 42704 Expected equals sign or TO, found PUBLIC +SET ROLE public + +# Not supported by Materialize. +onlyif cockroach +statement error role name "node" is reserved +CREATE ROLE node + +statement error pgcode 42704 Expected equals sign or TO, found NODE +SET ROLE node + +# Check root can reset and become itself. +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +materialize materialize materialize materialize + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW ROLE +---- +none + +statement ok +RESET ROLE + +statement error pgcode 42704 Expected equals sign or TO, found identifier "non_existent_user" +SET ROLE non_existent_user + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +materialize materialize materialize materialize + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW ROLE +---- +root + +statement ok +SET ROLE = root + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +materialize materialize materialize materialize + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW ROLE +---- +root + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM root_table + +statement error unknown catalog item 'testuser_table' +SELECT * FROM testuser_table + +statement ok +SET ROLE = 'testuser' + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +materialize materialize materialize materialize + +query T +SHOW is_superuser +---- +off + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM priv_t + +statement error unknown catalog item 'no_priv_t' +SELECT * FROM no_priv_t + +statement error unknown catalog item 'root_table' +SELECT * FROM root_table + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM testuser_table + +statement ok +RESET ROLE + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM root_table + +statement error unknown catalog item 'testuser_table' +SELECT * FROM testuser_table + +# Not supported by Materialize. +onlyif cockroach +# Check root can transition between testuser and testuser2. +statement ok +CREATE USER testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE testuser2 + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +materialize materialize materialize materialize + +query T +SHOW is_superuser +---- +off + +statement ok +SET ROLE = 'NoNe' + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +materialize materialize materialize materialize + +query T +SHOW is_superuser +---- +off + +# Check testuser cannot transition to other users as it has no privileges. +user testuser + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +testuser testuser testuser testuser + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW ROLE +---- +none + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE testuser + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +testuser testuser testuser testuser + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW ROLE +---- +testuser + +statement error pgcode 42501 Expected equals sign or TO, found identifier "root" +SET ROLE root + +statement error pgcode 42501 Expected equals sign or TO, found identifier "testuser2" +SET ROLE testuser2 + +# Grant admin to testuser. + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT admin TO testuser + +# testuser can now transition to testuser2, but not root. + +user testuser + +statement error pgcode 42501 Expected equals sign or TO, found identifier "root" +SET ROLE root + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE testuser2 + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +testuser testuser testuser testuser + +query T +SHOW is_superuser +---- +off + +statement error pgcode 42501 unknown catalog item 'priv_t' +SELECT * FROM priv_t + +statement error pgcode 42501 unknown catalog item 'no_priv_t' +SELECT * FROM no_priv_t + +statement ok +RESET ROLE + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +testuser testuser testuser testuser + +query T +SHOW is_superuser +---- +off + +# testuser2 cannot become anyone. + +user testuser2 + +statement error pgcode 42501 Expected equals sign or TO, found identifier "root" +SET ROLE root + +statement error pgcode 42501 Expected equals sign or TO, found identifier "testuser" +SET ROLE testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE testuser2 + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +testuser2 testuser2 testuser2 testuser2 + +statement ok +RESET ROLE + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +testuser2 testuser2 testuser2 testuser2 + +# Set testuser2 as admin, check testuser2 can become testuser +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT admin TO testuser2 + +user testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE testuser + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +testuser2 testuser2 testuser2 testuser2 + +statement ok +RESET ROLE + +# Revoke admin but give testuser privileges for testuser2. +# Make a testrole role. +# Check testuser2 can become testuser and testrole as they are still +# "admin" when impersonating testuser. +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE ROLE testrole; +REVOKE admin FROM testuser2; +GRANT testuser TO testuser2 + +statement ok +RESET ROLE + +user testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE testuser + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +testuser2 testuser2 testuser2 testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE testrole + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +testuser2 testuser2 testuser2 testuser2 + +statement ok +RESET ROLE + +# SET ROLE testuser to testuser2, then revoke admin. +# Test permissions forbidden, but reset is allowed. + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE testuser2 + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE admin FROM testuser + +user testuser + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +testuser testuser testuser testuser + +statement error pgcode 42501 Expected equals sign or TO, found identifier "testuser2" +SET ROLE testuser2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE 'none' + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +testuser testuser testuser testuser + + +# SET ROLE is specially cased in SET LOCAL as it uses SetWithPlanner, +# so test it behaves as appropriate. Also ensure that the node_sessions +# is correctly attributed to root instead of testuser. + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ADMIN TO testuser; + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +SET LOCAL ROLE testuser + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +materialize materialize materialize materialize + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT user_name FROM crdb_internal.node_sessions +WHERE active_queries LIKE 'SELECT user_name%' +---- +root + +statement ok +ROLLBACK + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +materialize materialize materialize materialize + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET ROLE testuser + +# Verify that RESET ALL does *not* affect role. +statement ok +RESET ALL + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +materialize materialize materialize materialize + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT user_name FROM crdb_internal.node_sessions +WHERE active_queries LIKE 'SELECT user_name%' +---- +root + +# Not supported by Materialize. +onlyif cockroach +# Verify that SET SESSION AUTHORIZATION *does* reset the role. +statement ok +SET SESSION AUTHORIZATION DEFAULT + +query TTTT +SELECT current_user(), current_user, session_user(), session_user +---- +materialize materialize materialize materialize diff --git a/test/sqllogictest/cockroach/set_time_zone.slt b/test/sqllogictest/cockroach/set_time_zone.slt new file mode 100644 index 0000000000000..d89a365e4f7ad --- /dev/null +++ b/test/sqllogictest/cockroach/set_time_zone.slt @@ -0,0 +1,315 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/set_time_zone +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# SQL-501 (https://linear.app/materializeinc/issue/SQL-501) and database-issues#1599 +# (https://github.com/MaterializeInc/database-issues/issues/1599): Materialize's +# TimeZone session variable only accepts "UTC". It rejects the numeric offsets, +# POSIX forms, and IANA names below, all of which PG and CockroachDB accept as +# "statement ok" (their SHOW TIME ZONE would then reflect the zone instead of +# staying UTC). AT TIME ZONE '' still works; only the session variable is +# restricted. +statement error invalid value for parameter "TimeZone" +SET TIME ZONE 0 + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 +0000 UTC + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE 10 + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 +1000 +1000 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE -10 + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 -1000 -1000 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE '10' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 +1000 +1000 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE '+10' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 +1000 +1000 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE '-10' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 -1000 -1000 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE '+10.5' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 +1030 +1030 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE '-10.5' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 -1030 -1030 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE '+10.555' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 +1033 +1033 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE '-10.555' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 -1033 -1033 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE ' +10' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 +1000 +1000 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE ' -10' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 -1000 -1000 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE 'GMT+3' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 -0300 -0300 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE 'GMT-3' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 +0300 +0300 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE 'UTC+3' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 -0300 -0300 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE 'UTC-3' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 +0300 +0300 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE 'Asia/Tokyo' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 +0900 +0900 + +statement error invalid value for parameter "TimeZone" +SET TIME ZONE 'zulu' + +query T +SHOW TIME ZONE +---- +UTC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT TIME '05:40:00'::TIMETZ +---- +0000-01-01 05:40:00 +0000 UTC + +statement error invalid value for parameter "TimeZone": "168" +SET TIME ZONE '168' + +statement error invalid value for parameter "TimeZone": "\-168" +SET TIME ZONE '-168' + +statement error invalid value for parameter "TimeZone": "\-0500" +SET TIME ZONE '-0500' + +statement error invalid value for parameter "TimeZone": "0500" +SET TIME ZONE '0500' + +statement error invalid value for parameter "TimeZone": "\-0500" +SET TIME ZONE '-0500' diff --git a/test/sqllogictest/cockroach/shift.slt b/test/sqllogictest/cockroach/shift.slt index bf41fedae4686..4537d44f08691 100644 --- a/test/sqllogictest/cockroach/shift.slt +++ b/test/sqllogictest/cockroach/shift.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,36 +9,40 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/shift +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/shift # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach # Check non-constant eval +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE t AS SELECT 1 AS i -statement error shift argument out of range +statement error unknown catalog item 't' SELECT i << 64 FROM t -statement error shift argument out of range +statement error unknown catalog item 't' SELECT i >> 64 FROM t -statement error shift argument out of range +statement error unknown catalog item 't' SELECT i << -1 FROM t -statement error shift argument out of range +statement error unknown catalog item 't' SELECT i >> -1 FROM t +# Not supported by Materialize. +onlyif cockroach query II SELECT i << 63 >> 63, i << 62 >> 62 FROM t ---- @@ -46,15 +50,23 @@ SELECT i << 63 >> 63, i << 62 >> 62 FROM t # Check constant folding +# Not supported by Materialize. +onlyif cockroach statement error shift argument out of range SELECT 1 << 64 +# Not supported by Materialize. +onlyif cockroach statement error shift argument out of range SELECT 1 >> 64 +# Not supported by Materialize. +onlyif cockroach statement error shift argument out of range SELECT 1 << -1 +# Not supported by Materialize. +onlyif cockroach statement error shift argument out of range SELECT 1 >> -1 diff --git a/test/sqllogictest/cockroach/show_create.slt b/test/sqllogictest/cockroach/show_create.slt new file mode 100644 index 0000000000000..0567cc8724c0b --- /dev/null +++ b/test/sqllogictest/cockroach/show_create.slt @@ -0,0 +1,256 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/show_create +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +SET experimental_enable_unique_without_index_constraints = true + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE c ( + a INT NOT NULL, + b INT NULL, + INDEX c_a_b_idx (a ASC, b ASC), + UNIQUE WITHOUT INDEX (a, b), + CONSTRAINT unique_a_partial UNIQUE WITHOUT INDEX (a) WHERE b > 0, + FAMILY fam_0_a_rowid (a, rowid), + FAMILY fam_1_b (b) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON TABLE c IS 'table' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON COLUMN c.a IS 'column' + +# Not supported by Materialize. +onlyif cockroach +statement ok +COMMENT ON INDEX c_a_b_idx IS 'index' + +statement ok +CREATE TABLE d (d INT PRIMARY KEY) + +# Not supported by Materialize. +onlyif cockroach +query TT colnames +SHOW CREATE c +---- +table_name create_statement +c CREATE TABLE public.c ( + a INT8 NOT NULL, + b INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT c_pkey PRIMARY KEY (rowid ASC), + INDEX c_a_b_idx (a ASC, b ASC), + FAMILY fam_0_a_rowid (a, rowid), + FAMILY fam_1_b (b), + CONSTRAINT unique_a_b UNIQUE WITHOUT INDEX (a, b), + CONSTRAINT unique_a_partial UNIQUE WITHOUT INDEX (a) WHERE b > 0:::INT8 + ); + COMMENT ON TABLE public.c IS 'table'; + COMMENT ON COLUMN public.c.a IS 'column'; + COMMENT ON INDEX public.c@c_a_b_idx IS 'index' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE c ADD CONSTRAINT check_b CHECK (b IN (1, 2, 3)) NOT VALID; +ALTER TABLE c ADD CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES d (d) NOT VALID; +ALTER TABLE c ADD CONSTRAINT unique_a UNIQUE (a); +ALTER TABLE c ADD CONSTRAINT unique_b UNIQUE WITHOUT INDEX (b) NOT VALID; +ALTER TABLE c ADD CONSTRAINT unique_b_partial UNIQUE WITHOUT INDEX (b) WHERE a > 0 NOT VALID; + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE c +---- +c CREATE TABLE public.c ( + a INT8 NOT NULL, + b INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT c_pkey PRIMARY KEY (rowid ASC), + CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES public.d(d) NOT VALID, + INDEX c_a_b_idx (a ASC, b ASC), + UNIQUE INDEX unique_a (a ASC), + FAMILY fam_0_a_rowid (a, rowid), + FAMILY fam_1_b (b), + CONSTRAINT check_b CHECK (b IN (1:::INT8, 2:::INT8, 3:::INT8)) NOT VALID, + CONSTRAINT unique_a_b UNIQUE WITHOUT INDEX (a, b), + CONSTRAINT unique_a_partial UNIQUE WITHOUT INDEX (a) WHERE b > 0:::INT8, + CONSTRAINT unique_b UNIQUE WITHOUT INDEX (b) NOT VALID, + CONSTRAINT unique_b_partial UNIQUE WITHOUT INDEX (b) WHERE a > 0:::INT8 NOT VALID + ); + COMMENT ON TABLE public.c IS 'table'; + COMMENT ON COLUMN public.c.a IS 'column'; + COMMENT ON INDEX public.c@c_a_b_idx IS 'index' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE c VALIDATE CONSTRAINT check_b; +ALTER TABLE c VALIDATE CONSTRAINT fk_a; +ALTER TABLE c VALIDATE CONSTRAINT unique_a; +ALTER TABLE c VALIDATE CONSTRAINT unique_b; +ALTER TABLE c VALIDATE CONSTRAINT unique_a_b; +ALTER TABLE c VALIDATE CONSTRAINT unique_b_partial; + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE c +---- +c CREATE TABLE public.c ( + a INT8 NOT NULL, + b INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT c_pkey PRIMARY KEY (rowid ASC), + CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES public.d(d), + INDEX c_a_b_idx (a ASC, b ASC), + UNIQUE INDEX unique_a (a ASC), + FAMILY fam_0_a_rowid (a, rowid), + FAMILY fam_1_b (b), + CONSTRAINT check_b CHECK (b IN (1:::INT8, 2:::INT8, 3:::INT8)), + CONSTRAINT unique_a_b UNIQUE WITHOUT INDEX (a, b), + CONSTRAINT unique_a_partial UNIQUE WITHOUT INDEX (a) WHERE b > 0:::INT8, + CONSTRAINT unique_b UNIQUE WITHOUT INDEX (b), + CONSTRAINT unique_b_partial UNIQUE WITHOUT INDEX (b) WHERE a > 0:::INT8 + ); + COMMENT ON TABLE public.c IS 'table'; + COMMENT ON COLUMN public.c.a IS 'column'; + COMMENT ON INDEX public.c@c_a_b_idx IS 'index' + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE c WITH REDACT +---- +c CREATE TABLE public.c ( + a INT8 NOT NULL, + b INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT c_pkey PRIMARY KEY (rowid ASC), + CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES public.d(d), + INDEX c_a_b_idx (a ASC, b ASC), + UNIQUE INDEX unique_a (a ASC), + FAMILY fam_0_a_rowid (a, rowid), + FAMILY fam_1_b (b), + CONSTRAINT check_b CHECK (b IN (‹×›:::INT8, ‹×›:::INT8, ‹×›:::INT8)), + CONSTRAINT unique_a_b UNIQUE WITHOUT INDEX (a, b), + CONSTRAINT unique_a_partial UNIQUE WITHOUT INDEX (a) WHERE b > ‹×›:::INT8, + CONSTRAINT unique_b UNIQUE WITHOUT INDEX (b), + CONSTRAINT unique_b_partial UNIQUE WITHOUT INDEX (b) WHERE a > ‹×›:::INT8 + ); + COMMENT ON TABLE public.c IS 'table'; + COMMENT ON COLUMN public.c.a IS 'column'; + COMMENT ON INDEX public.c@c_a_b_idx IS 'index' + +subtest alter_column_type_not_break_show_create + +statement ok +SET enable_experimental_alter_column_type_general = true; + +statement ok +CREATE TABLE t (c INT); + +statement ok +COMMENT ON COLUMN t.c IS 'first comment'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + c INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); +COMMENT ON COLUMN public.t.c IS 'first comment' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t ALTER COLUMN c TYPE character varying; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + c VARCHAR NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); +COMMENT ON COLUMN public.t.c IS 'first comment' + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t WITH REDACT]; +---- +CREATE TABLE public.t ( + c VARCHAR NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); +COMMENT ON COLUMN public.t.c IS 'first comment' + + +statement ok +CREATE TABLE t1 ( + k INT PRIMARY KEY, + a INT UNIQUE, + b STRING, + INDEX (a, b) +) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE INDEXES FROM t1 +---- +t1_pkey CREATE UNIQUE INDEX t1_pkey ON public.t1 (k ASC) +t1_a_key CREATE UNIQUE INDEX t1_a_key ON public.t1 (a ASC) +t1_a_b_idx CREATE INDEX t1_a_b_idx ON public.t1 (a ASC, b ASC) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE SECONDARY INDEXES FROM t1 +---- +t1_a_key CREATE UNIQUE INDEX t1_a_key ON public.t1 (a ASC) +t1_a_b_idx CREATE INDEX t1_a_b_idx ON public.t1 (a ASC, b ASC) + +statement error Expected end of statement, found INDEXES +SHOW CREATE INDEXES FROM nonexistent + +statement error Expected end of statement, found identifier "secondary" +SHOW CREATE SECONDARY INDEXES FROM nonexistent diff --git a/test/sqllogictest/cockroach/show_create_all_schemas.slt b/test/sqllogictest/cockroach/show_create_all_schemas.slt new file mode 100644 index 0000000000000..128ee69077e45 --- /dev/null +++ b/test/sqllogictest/cockroach/show_create_all_schemas.slt @@ -0,0 +1,92 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/show_create_all_schemas +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE DATABASE d + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE d + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL SCHEMAS +---- +create_statement +CREATE SCHEMA public; + +statement ok +CREATE SCHEMA test + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL SCHEMAS +---- +create_statement +CREATE SCHEMA public; +CREATE SCHEMA test; + +statement ok +CREATE SCHEMA test2 + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL SCHEMAS +---- +create_statement +CREATE SCHEMA public; +CREATE SCHEMA test; +CREATE SCHEMA test2; + +statement ok +DROP SCHEMA test + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL SCHEMAS +---- +create_statement +CREATE SCHEMA public; +CREATE SCHEMA test2; + +# Not supported by Materialize. +onlyif cockroach +# Make sure database names with hyphens work well. +statement ok +CREATE DATABASE "d-d"; +USE "d-d"; +SHOW CREATE ALL SCHEMAS; + +# Not supported by Materialize. +onlyif cockroach +# Make sure database names with quotes work well. +statement ok +CREATE DATABASE "a""bc"; +USE "a""bc"; +SHOW CREATE ALL SCHEMAS; diff --git a/test/sqllogictest/cockroach/show_create_all_tables.slt b/test/sqllogictest/cockroach/show_create_all_tables.slt new file mode 100644 index 0000000000000..970101c0a17dd --- /dev/null +++ b/test/sqllogictest/cockroach/show_create_all_tables.slt @@ -0,0 +1,548 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/show_create_all_tables +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE DATABASE d + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE d + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE d.parent ( + x INT, + y INT, + z INT, + UNIQUE (x, y, z), + FAMILY f1 (x, y, z), + UNIQUE (x) +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE d.full_test ( + x INT, + y INT, + z INT, + FOREIGN KEY (x, y, z) REFERENCES d.parent (x, y, z) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE, + FAMILY f1 (x, y, z), + UNIQUE (x) + ); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE d.full_test ADD CONSTRAINT test_fk FOREIGN KEY (x) REFERENCES d.parent (x) ON DELETE CASCADE + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW d.vx AS SELECT 1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE d.s + +# Not supported by Materialize. +onlyif cockroach +# parent should come before full_test due to dependency ordering. +# if dependency's aren't considered, full_test will appear first due to +# lexicographical ordering. +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE TABLE public.parent ( + x INT8 NULL, + y INT8 NULL, + z INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT parent_pkey PRIMARY KEY (rowid ASC), + UNIQUE INDEX parent_x_y_z_key (x ASC, y ASC, z ASC), + UNIQUE INDEX parent_x_key (x ASC), + FAMILY f1 (x, y, z, rowid) +); +CREATE TABLE public.full_test ( + x INT8 NULL, + y INT8 NULL, + z INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT full_test_pkey PRIMARY KEY (rowid ASC), + UNIQUE INDEX full_test_x_key (x ASC), + FAMILY f1 (x, y, z, rowid) +); +CREATE VIEW public.vx ( + "?column?" +) AS SELECT 1; +CREATE SEQUENCE public.s MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1; +ALTER TABLE public.full_test ADD CONSTRAINT full_test_x_y_z_fkey FOREIGN KEY (x, y, z) REFERENCES public.parent(x, y, z) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE public.full_test ADD CONSTRAINT test_fk FOREIGN KEY (x) REFERENCES public.parent(x) ON DELETE CASCADE; +-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES +ALTER TABLE public.full_test VALIDATE CONSTRAINT full_test_x_y_z_fkey; +ALTER TABLE public.full_test VALIDATE CONSTRAINT test_fk; + +# testuser does not have CONNECT on database d and cannot see any tables. +user testuser + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement + +user root + +statement ok +GRANT CREATE on DATABASE d TO testuser + +# Not supported by Materialize. +onlyif cockroach +# testuser should be able to see the descriptors with +# CREATE privilege on the database. +# TODO(richardjcai): Replace this with CONNECT and +# add CONNECT privilege required on the builtin description once #59676 is in. +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE TABLE public.parent ( + x INT8 NULL, + y INT8 NULL, + z INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT parent_pkey PRIMARY KEY (rowid ASC), + UNIQUE INDEX parent_x_y_z_key (x ASC, y ASC, z ASC), + UNIQUE INDEX parent_x_key (x ASC), + FAMILY f1 (x, y, z, rowid) +); +CREATE TABLE public.full_test ( + x INT8 NULL, + y INT8 NULL, + z INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT full_test_pkey PRIMARY KEY (rowid ASC), + UNIQUE INDEX full_test_x_key (x ASC), + FAMILY f1 (x, y, z, rowid) +); +CREATE VIEW public.vx ( + "?column?" +) AS SELECT 1; +CREATE SEQUENCE public.s MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1; +ALTER TABLE public.full_test ADD CONSTRAINT full_test_x_y_z_fkey FOREIGN KEY (x, y, z) REFERENCES public.parent(x, y, z) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE public.full_test ADD CONSTRAINT test_fk FOREIGN KEY (x) REFERENCES public.parent(x) ON DELETE CASCADE; +-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES +ALTER TABLE public.full_test VALIDATE CONSTRAINT full_test_x_y_z_fkey; +ALTER TABLE public.full_test VALIDATE CONSTRAINT test_fk; + +user root + +# Make sure temp tables don't show up in crdb_internal.show_create_all_tables. +statement ok +CREATE DATABASE temp_test + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE temp_test + +statement ok +SET experimental_enable_temp_tables = 'on' + +statement ok +CREATE TEMPORARY TABLE t() + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement + +# Not supported by Materialize. +onlyif cockroach +# Test that a database with foreign keys has the right order. +statement ok +CREATE DATABASE test_fk_order; +USE test_fk_order; +-- B -> A +CREATE TABLE b (i int PRIMARY KEY); +CREATE TABLE a (i int REFERENCES b); +INSERT INTO b VALUES (1); +INSERT INTO a VALUES (1); +-- Test multiple tables to make sure transitive deps are sorted correctly. +-- E -> D -> C +-- G -> F -> D -> C +CREATE TABLE g (i int PRIMARY KEY); +CREATE TABLE f (i int PRIMARY KEY, g int REFERENCES g, FAMILY f1 (i, g)); +CREATE TABLE e (i int PRIMARY KEY); +CREATE TABLE d (i int PRIMARY KEY, e int REFERENCES e, f int REFERENCES f, FAMILY f1 (i, e, f)); +CREATE TABLE c (i int REFERENCES d); +-- Test a table that uses a sequence to make sure the sequence is dumped first. +CREATE SEQUENCE s; +CREATE TABLE s_tbl (id INT PRIMARY KEY DEFAULT nextval('s'), v INT, FAMILY f1 (id, v)); + +# Not supported by Materialize. +onlyif cockroach +# Table order should be B, A, G, F, E, D, C, sequence s, s_tbl. +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE TABLE public.b ( + i INT8 NOT NULL, + CONSTRAINT b_pkey PRIMARY KEY (i ASC) +); +CREATE TABLE public.a ( + i INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT a_pkey PRIMARY KEY (rowid ASC) +); +CREATE TABLE public.g ( + i INT8 NOT NULL, + CONSTRAINT g_pkey PRIMARY KEY (i ASC) +); +CREATE TABLE public.f ( + i INT8 NOT NULL, + g INT8 NULL, + CONSTRAINT f_pkey PRIMARY KEY (i ASC), + FAMILY f1 (i, g) +); +CREATE TABLE public.e ( + i INT8 NOT NULL, + CONSTRAINT e_pkey PRIMARY KEY (i ASC) +); +CREATE TABLE public.d ( + i INT8 NOT NULL, + e INT8 NULL, + f INT8 NULL, + CONSTRAINT d_pkey PRIMARY KEY (i ASC), + FAMILY f1 (i, e, f) +); +CREATE TABLE public.c ( + i INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT c_pkey PRIMARY KEY (rowid ASC) +); +CREATE SEQUENCE public.s MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1; +CREATE TABLE public.s_tbl ( + id INT8 NOT NULL DEFAULT nextval('public.s'::REGCLASS), + v INT8 NULL, + CONSTRAINT s_tbl_pkey PRIMARY KEY (id ASC), + FAMILY f1 (id, v) +); +ALTER TABLE public.a ADD CONSTRAINT a_i_fkey FOREIGN KEY (i) REFERENCES public.b(i); +ALTER TABLE public.f ADD CONSTRAINT f_g_fkey FOREIGN KEY (g) REFERENCES public.g(i); +ALTER TABLE public.d ADD CONSTRAINT d_e_fkey FOREIGN KEY (e) REFERENCES public.e(i); +ALTER TABLE public.d ADD CONSTRAINT d_f_fkey FOREIGN KEY (f) REFERENCES public.f(i); +ALTER TABLE public.c ADD CONSTRAINT c_i_fkey FOREIGN KEY (i) REFERENCES public.d(i); +-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES +ALTER TABLE public.a VALIDATE CONSTRAINT a_i_fkey; +ALTER TABLE public.f VALIDATE CONSTRAINT f_g_fkey; +ALTER TABLE public.d VALIDATE CONSTRAINT d_e_fkey; +ALTER TABLE public.d VALIDATE CONSTRAINT d_f_fkey; +ALTER TABLE public.c VALIDATE CONSTRAINT c_i_fkey; + +# Test that a cycle between two tables is handled correctly. +statement ok +CREATE DATABASE test_cycle; + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE test_cycle; + +statement ok +CREATE TABLE loop_a ( + id INT PRIMARY KEY, + b_id INT, + INDEX(b_id), + FAMILY f1 (id, b_id) +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE loop_b ( + id INT PRIMARY KEY, + a_id INT REFERENCES loop_a ON DELETE CASCADE, + FAMILY f1 (id, a_id) +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE loop_a ADD CONSTRAINT b_id_delete_constraint +FOREIGN KEY (b_id) REFERENCES loop_b (id) ON DELETE CASCADE; + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE TABLE public.loop_b ( + id INT8 NOT NULL, + a_id INT8 NULL, + CONSTRAINT loop_b_pkey PRIMARY KEY (id ASC), + FAMILY f1 (id, a_id) +); +CREATE TABLE public.loop_a ( + id INT8 NOT NULL, + b_id INT8 NULL, + CONSTRAINT loop_a_pkey PRIMARY KEY (id ASC), + INDEX loop_a_b_id_idx (b_id ASC), + FAMILY f1 (id, b_id) +); +ALTER TABLE public.loop_b ADD CONSTRAINT loop_b_a_id_fkey FOREIGN KEY (a_id) REFERENCES public.loop_a(id) ON DELETE CASCADE; +ALTER TABLE public.loop_a ADD CONSTRAINT b_id_delete_constraint FOREIGN KEY (b_id) REFERENCES public.loop_b(id) ON DELETE CASCADE; +-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES +ALTER TABLE public.loop_b VALIDATE CONSTRAINT loop_b_a_id_fkey; +ALTER TABLE public.loop_a VALIDATE CONSTRAINT b_id_delete_constraint; + +# Test that a primary key with a non-default name works. +statement ok +CREATE DATABASE test_primary_key; + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE test_primary_key; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE test_primary_key.t ( + i int, + CONSTRAINT pk_name PRIMARY KEY (i) +); + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE TABLE public.t ( + i INT8 NOT NULL, + CONSTRAINT pk_name PRIMARY KEY (i ASC) +); + +# Not supported by Materialize. +onlyif cockroach +# Test that computed columns are shown correctly. +statement ok +CREATE DATABASE test_computed_column; +USE test_computed_column; +CREATE TABLE test_computed_column.t ( + a INT PRIMARY KEY, + b INT AS (a + 1) STORED, + FAMILY f1 (a, b) +); + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NULL AS (a + 1:::INT8) STORED, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + FAMILY f1 (a, b) +); + +# Not supported by Materialize. +onlyif cockroach +# Test showing a table with a semicolon in the table, index, and +# column names properly escapes. +statement ok +CREATE DATABASE test_escaping; +USE test_escaping; +CREATE TABLE test_escaping.";" (";" int, index (";")); +INSERT INTO test_escaping.";" VALUES (1); + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE TABLE public.";" ( + ";" INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT ";_pkey" PRIMARY KEY (rowid ASC), + INDEX ";_;_idx" (";" ASC) +); + +# Not supported by Materialize. +onlyif cockroach +# Ensure quotes in comments are properly escaped, also that the object names +# are properly escaped in the output of the COMMENT statements. +statement ok +CREATE DATABASE test_comment; +USE test_comment; +CREATE TABLE test_comment."t t" ("x'" INT PRIMARY KEY); +COMMENT ON TABLE test_comment."t t" IS 'has '' quotes'; +COMMENT ON INDEX test_comment."t t"@"t t_pkey" IS 'has '' more '' quotes'; +COMMENT ON COLUMN test_comment."t t"."x'" IS 'i '' just '' love '' quotes'; +COMMENT ON CONSTRAINT "t t_pkey" ON test_comment."t t" IS 'new constraint comment'; + + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE TABLE public."t t" ( + "x'" INT8 NOT NULL, + CONSTRAINT "t t_pkey" PRIMARY KEY ("x'" ASC) +); +COMMENT ON TABLE public."t t" IS e'has \' quotes'; +COMMENT ON COLUMN public."t t"."x'" IS e'i \' just \' love \' quotes'; +COMMENT ON INDEX public."t t"@"t t_pkey" IS e'has \' more \' quotes'; +COMMENT ON CONSTRAINT "t t_pkey" ON public."t t" IS 'new constraint comment'; + +# Not supported by Materialize. +onlyif cockroach +# Ensure schemas are shown correctly. +statement ok +CREATE DATABASE test_schema; +USE test_schema; +CREATE SCHEMA sc1; +CREATE SCHEMA sc2; +CREATE TABLE sc1.t (x int); +CREATE TABLE sc2.t (x int); + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE TABLE sc1.t ( + x INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); +CREATE TABLE sc2.t ( + x INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); + +# Not supported by Materialize. +onlyif cockroach +# Ensure sequences are shown correctly. +statement ok +CREATE DATABASE test_sequence; +USE test_sequence; +CREATE SEQUENCE s1 INCREMENT 123; + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE SEQUENCE public.s1 MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 123 START 1; + +# Not supported by Materialize. +onlyif cockroach +# Test with UDTs. +statement ok +CREATE DATABASE type_test; +USE type_test; +CREATE TYPE test AS enum(); +CREATE TABLE t(x test); + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE TABLE public.t ( + x type_test.public.test NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); + +# Not supported by Materialize. +onlyif cockroach +# Test with column families. +statement ok +CREATE DATABASE column_family_test; +USE column_family_test; +CREATE TABLE t(x INT, y INT, z INT, h STRING, FAMILY f1 (x, y), FAMILY f2 (z), FAMILY f3(h)); + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TABLES +---- +create_statement +CREATE TABLE public.t ( + x INT8 NULL, + y INT8 NULL, + z INT8 NULL, + h STRING NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC), + FAMILY f1 (x, y, rowid), + FAMILY f2 (z), + FAMILY f3 (h) +); + +# Not supported by Materialize. +onlyif cockroach +# Make sure database names with hyphens work well. +statement ok +CREATE DATABASE "d-d"; +USE "d-d"; +CREATE TABLE t(); +SHOW CREATE ALL TABLES; + +# Not supported by Materialize. +onlyif cockroach +# Make sure database names with quotes work well. +statement ok +CREATE DATABASE "a""bc"; +USE "a""bc"; +CREATE TABLE t(); +SHOW CREATE ALL SCHEMAS; diff --git a/test/sqllogictest/cockroach/show_create_all_tables_builtin.slt b/test/sqllogictest/cockroach/show_create_all_tables_builtin.slt new file mode 100644 index 0000000000000..8e9aac9795e78 --- /dev/null +++ b/test/sqllogictest/cockroach/show_create_all_tables_builtin.slt @@ -0,0 +1,541 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/show_create_all_tables_builtin +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement error unknown schema 'crdb_internal' +SELECT crdb_internal.show_create_all_tables('d') + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE DATABASE d; +REVOKE CONNECT ON DATABASE d FROM public + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.show_create_all_tables('d') +---- + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE d.parent ( + x INT, + y INT, + z INT, + UNIQUE (x, y, z), + FAMILY f1 (x, y, z), + UNIQUE (x) +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE d.full_test ( + x INT, + y INT, + z INT, + FOREIGN KEY (x, y, z) REFERENCES d.parent (x, y, z) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE, + FAMILY f1 (x, y, z), + UNIQUE (x) + ); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE d.full_test ADD CONSTRAINT test_fk FOREIGN KEY (x) REFERENCES d.parent (x) ON DELETE CASCADE + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW d.vx AS SELECT 1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE SEQUENCE d.s + +# Not supported by Materialize. +onlyif cockroach +# parent should come before full_test due to dependency ordering. +# if dependency's aren't considered, full_test will appear first due to +# lexicographical ordering. +query T +SELECT crdb_internal.show_create_all_tables('d') +---- +CREATE TABLE public.parent ( + x INT8 NULL, + y INT8 NULL, + z INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT parent_pkey PRIMARY KEY (rowid ASC), + UNIQUE INDEX parent_x_y_z_key (x ASC, y ASC, z ASC), + UNIQUE INDEX parent_x_key (x ASC), + FAMILY f1 (x, y, z, rowid) +); +CREATE TABLE public.full_test ( + x INT8 NULL, + y INT8 NULL, + z INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT full_test_pkey PRIMARY KEY (rowid ASC), + UNIQUE INDEX full_test_x_key (x ASC), + FAMILY f1 (x, y, z, rowid) +); +CREATE VIEW public.vx ( + "?column?" +) AS SELECT 1; +CREATE SEQUENCE public.s MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1; +ALTER TABLE public.full_test ADD CONSTRAINT full_test_x_y_z_fkey FOREIGN KEY (x, y, z) REFERENCES public.parent(x, y, z) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE public.full_test ADD CONSTRAINT test_fk FOREIGN KEY (x) REFERENCES public.parent(x) ON DELETE CASCADE; +-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES +ALTER TABLE public.full_test VALIDATE CONSTRAINT full_test_x_y_z_fkey; +ALTER TABLE public.full_test VALIDATE CONSTRAINT test_fk; + +# testuser does not have CONNECT on database d and cannot see any tables. +user testuser + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.show_create_all_tables('d') +---- + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE on DATABASE d TO testuser + +# Not supported by Materialize. +onlyif cockroach +# testuser should be able to see the descriptors with +# CREATE privilege on the database. +# TODO(richardjcai): Replace this with CONNECT and +# add CONNECT privilege required on the builtin description once #59676 is in. +query T +SELECT crdb_internal.show_create_all_tables('d') +---- +CREATE TABLE public.parent ( + x INT8 NULL, + y INT8 NULL, + z INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT parent_pkey PRIMARY KEY (rowid ASC), + UNIQUE INDEX parent_x_y_z_key (x ASC, y ASC, z ASC), + UNIQUE INDEX parent_x_key (x ASC), + FAMILY f1 (x, y, z, rowid) +); +CREATE TABLE public.full_test ( + x INT8 NULL, + y INT8 NULL, + z INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT full_test_pkey PRIMARY KEY (rowid ASC), + UNIQUE INDEX full_test_x_key (x ASC), + FAMILY f1 (x, y, z, rowid) +); +CREATE VIEW public.vx ( + "?column?" +) AS SELECT 1; +CREATE SEQUENCE public.s MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1; +ALTER TABLE public.full_test ADD CONSTRAINT full_test_x_y_z_fkey FOREIGN KEY (x, y, z) REFERENCES public.parent(x, y, z) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE public.full_test ADD CONSTRAINT test_fk FOREIGN KEY (x) REFERENCES public.parent(x) ON DELETE CASCADE; +-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES +ALTER TABLE public.full_test VALIDATE CONSTRAINT full_test_x_y_z_fkey; +ALTER TABLE public.full_test VALIDATE CONSTRAINT test_fk; + +user root + +# Make sure temp tables don't show up in crdb_internal.show_create_all_tables. +statement ok +CREATE DATABASE temp_test + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE temp_test + +statement ok +SET experimental_enable_temp_tables = 'on' + +statement ok +CREATE TEMPORARY TABLE t() + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.show_create_all_tables('temp_test') +---- + +# Not supported by Materialize. +onlyif cockroach +# Test that a database with foreign keys has the right order. +statement ok +CREATE DATABASE test_fk_order; +USE test_fk_order; +-- B -> A +CREATE TABLE b (i int PRIMARY KEY); +CREATE TABLE a (i int REFERENCES b); +INSERT INTO b VALUES (1); +INSERT INTO a VALUES (1); +-- Test multiple tables to make sure transitive deps are sorted correctly. +-- E -> D -> C +-- G -> F -> D -> C +CREATE TABLE g (i int PRIMARY KEY); +CREATE TABLE f (i int PRIMARY KEY, g int REFERENCES g, FAMILY f1 (i, g)); +CREATE TABLE e (i int PRIMARY KEY); +CREATE TABLE d (i int PRIMARY KEY, e int REFERENCES e, f int REFERENCES f, FAMILY f1 (i, e, f)); +CREATE TABLE c (i int REFERENCES d); +-- Test a table that uses a sequence to make sure the sequence is dumped first. +CREATE SEQUENCE s; +CREATE TABLE s_tbl (id INT PRIMARY KEY DEFAULT nextval('s'), v INT, FAMILY f1 (id, v)); + +# Not supported by Materialize. +onlyif cockroach +# Table order should be B, A, E, G, F, D, C, sequence s, s_tbl. +query T +SELECT crdb_internal.show_create_all_tables('test_fk_order') +---- +CREATE TABLE public.b ( + i INT8 NOT NULL, + CONSTRAINT b_pkey PRIMARY KEY (i ASC) +); +CREATE TABLE public.a ( + i INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT a_pkey PRIMARY KEY (rowid ASC) +); +CREATE TABLE public.g ( + i INT8 NOT NULL, + CONSTRAINT g_pkey PRIMARY KEY (i ASC) +); +CREATE TABLE public.f ( + i INT8 NOT NULL, + g INT8 NULL, + CONSTRAINT f_pkey PRIMARY KEY (i ASC), + FAMILY f1 (i, g) +); +CREATE TABLE public.e ( + i INT8 NOT NULL, + CONSTRAINT e_pkey PRIMARY KEY (i ASC) +); +CREATE TABLE public.d ( + i INT8 NOT NULL, + e INT8 NULL, + f INT8 NULL, + CONSTRAINT d_pkey PRIMARY KEY (i ASC), + FAMILY f1 (i, e, f) +); +CREATE TABLE public.c ( + i INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT c_pkey PRIMARY KEY (rowid ASC) +); +CREATE SEQUENCE public.s MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1; +CREATE TABLE public.s_tbl ( + id INT8 NOT NULL DEFAULT nextval('public.s'::REGCLASS), + v INT8 NULL, + CONSTRAINT s_tbl_pkey PRIMARY KEY (id ASC), + FAMILY f1 (id, v) +); +ALTER TABLE public.a ADD CONSTRAINT a_i_fkey FOREIGN KEY (i) REFERENCES public.b(i); +ALTER TABLE public.f ADD CONSTRAINT f_g_fkey FOREIGN KEY (g) REFERENCES public.g(i); +ALTER TABLE public.d ADD CONSTRAINT d_e_fkey FOREIGN KEY (e) REFERENCES public.e(i); +ALTER TABLE public.d ADD CONSTRAINT d_f_fkey FOREIGN KEY (f) REFERENCES public.f(i); +ALTER TABLE public.c ADD CONSTRAINT c_i_fkey FOREIGN KEY (i) REFERENCES public.d(i); +-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES +ALTER TABLE public.a VALIDATE CONSTRAINT a_i_fkey; +ALTER TABLE public.f VALIDATE CONSTRAINT f_g_fkey; +ALTER TABLE public.d VALIDATE CONSTRAINT d_e_fkey; +ALTER TABLE public.d VALIDATE CONSTRAINT d_f_fkey; +ALTER TABLE public.c VALIDATE CONSTRAINT c_i_fkey; + +# Test that a cycle between two tables is handled correctly. +statement ok +CREATE DATABASE test_cycle; + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE test_cycle; + +statement ok +CREATE TABLE loop_a ( + id INT PRIMARY KEY, + b_id INT, + INDEX(b_id), + FAMILY f1 (id, b_id) +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE loop_b ( + id INT PRIMARY KEY, + a_id INT REFERENCES loop_a ON DELETE CASCADE, + FAMILY f1 (id, a_id) +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE loop_a ADD CONSTRAINT b_id_delete_constraint +FOREIGN KEY (b_id) REFERENCES loop_b (id) ON DELETE CASCADE; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.show_create_all_tables('test_cycle') +---- +CREATE TABLE public.loop_b ( + id INT8 NOT NULL, + a_id INT8 NULL, + CONSTRAINT loop_b_pkey PRIMARY KEY (id ASC), + FAMILY f1 (id, a_id) +); +CREATE TABLE public.loop_a ( + id INT8 NOT NULL, + b_id INT8 NULL, + CONSTRAINT loop_a_pkey PRIMARY KEY (id ASC), + INDEX loop_a_b_id_idx (b_id ASC), + FAMILY f1 (id, b_id) +); +ALTER TABLE public.loop_b ADD CONSTRAINT loop_b_a_id_fkey FOREIGN KEY (a_id) REFERENCES public.loop_a(id) ON DELETE CASCADE; +ALTER TABLE public.loop_a ADD CONSTRAINT b_id_delete_constraint FOREIGN KEY (b_id) REFERENCES public.loop_b(id) ON DELETE CASCADE; +-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES +ALTER TABLE public.loop_b VALIDATE CONSTRAINT loop_b_a_id_fkey; +ALTER TABLE public.loop_a VALIDATE CONSTRAINT b_id_delete_constraint; + +# Test that a primary key with a non-default name works. +statement ok +CREATE DATABASE test_primary_key; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE test_primary_key.t ( + i int, + CONSTRAINT pk_name PRIMARY KEY (i) +); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.show_create_all_tables('test_primary_key') +---- +CREATE TABLE public.t ( + i INT8 NOT NULL, + CONSTRAINT pk_name PRIMARY KEY (i ASC) +); + +# Not supported by Materialize. +onlyif cockroach +# Test that computed columns are shown correctly. +statement ok +CREATE DATABASE test_computed_column; +CREATE TABLE test_computed_column.t ( + a INT PRIMARY KEY, + b INT AS (a + 1) STORED, + FAMILY f1 (a, b) +); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.show_create_all_tables('test_computed_column') +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NULL AS (a + 1:::INT8) STORED, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + FAMILY f1 (a, b) +); + +# Not supported by Materialize. +onlyif cockroach +# Test showing a table with a semicolon in the table, index, and +# column names properly escapes. +statement ok +CREATE DATABASE test_escaping; +CREATE TABLE test_escaping.";" (";" int, index (";")); +INSERT INTO test_escaping.";" VALUES (1); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.show_create_all_tables('test_escaping') +---- +CREATE TABLE public.";" ( + ";" INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT ";_pkey" PRIMARY KEY (rowid ASC), + INDEX ";_;_idx" (";" ASC) +); + +# Not supported by Materialize. +onlyif cockroach +# Ensure quotes in comments are properly escaped, also that the object names +# are properly escaped in the output of the COMMENT statements. +statement ok +CREATE DATABASE test_comment; +CREATE TABLE test_comment."t t" ("x'" INT PRIMARY KEY); +COMMENT ON TABLE test_comment."t t" IS 'has '' quotes'; +COMMENT ON INDEX test_comment."t t"@"t t_pkey" IS 'has '' more '' quotes'; +COMMENT ON COLUMN test_comment."t t"."x'" IS 'i '' just '' love '' quotes'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.show_create_all_tables('test_comment') +---- +CREATE TABLE public."t t" ( + "x'" INT8 NOT NULL, + CONSTRAINT "t t_pkey" PRIMARY KEY ("x'" ASC) +); +COMMENT ON TABLE public."t t" IS e'has \' quotes'; +COMMENT ON COLUMN public."t t"."x'" IS e'i \' just \' love \' quotes'; +COMMENT ON INDEX public."t t"@"t t_pkey" IS e'has \' more \' quotes'; + +# Not supported by Materialize. +onlyif cockroach +# Ensure schemas are shown correctly. +statement ok +CREATE DATABASE test_schema; +USE test_schema; +CREATE SCHEMA sc1; +CREATE SCHEMA sc2; +CREATE TABLE sc1.t (x int); +CREATE TABLE sc2.t (x int); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.show_create_all_tables('test_schema') +---- +CREATE TABLE sc1.t ( + x INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); +CREATE TABLE sc2.t ( + x INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); + +# Not supported by Materialize. +onlyif cockroach +# Ensure sequences are shown correctly. +statement ok +CREATE DATABASE test_sequence; +USE test_sequence; +CREATE SEQUENCE s1 INCREMENT 123; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.show_create_all_tables('test_sequence') +---- +CREATE SEQUENCE public.s1 MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 123 START 1; + +# Ensure that the builtin can be run in unused and used transactions. + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE test_schema; + +# Not supported by Materialize. +onlyif cockroach +query T +BEGIN; +SELECT crdb_internal.show_create_all_tables('test_schema'); +COMMIT; +---- +CREATE TABLE sc1.t ( + x INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); +CREATE TABLE sc2.t ( + x INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); + +# Not supported by Materialize. +onlyif cockroach +query T +BEGIN; +SELECT * FROM sc1.t; +SELECT crdb_internal.show_create_all_tables('test_schema'); +COMMIT; +---- +CREATE TABLE sc1.t ( + x INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); +CREATE TABLE sc2.t ( + x INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); + +# Not supported by Materialize. +onlyif cockroach +# Regression test for not closing the ValueGenerators when they are recreated +# multiple times (#85418). +statement ok +CREATE DATABASE db_85418_1; +USE db_85418_1; +CREATE TABLE t_85418_1(); +CREATE TABLE t_85418_2(); +CREATE DATABASE db_85418_2; +USE db_85418_2; +CREATE TABLE t_85418_1(); +CREATE TABLE t_85418_2(); +CREATE TABLE dbs_85418(db STRING); +INSERT INTO dbs_85418 VALUES ('db_85418_1'), ('db_85418_2'); +SELECT crdb_internal.show_create_all_tables(db) FROM dbs_85418; + +# Not supported by Materialize. +onlyif cockroach +# Make sure database names with hyphens work well. +statement ok +CREATE DATABASE "d-d"; +USE "d-d"; +CREATE TABLE t(); +SELECT crdb_internal.show_create_all_tables('d-d'); + +# Not supported by Materialize. +onlyif cockroach +# Make sure database names with quotes work well. +statement ok +CREATE DATABASE "a""bc"; +USE "a""bc"; +CREATE TABLE t(); +SELECT crdb_internal.show_create_all_tables('a"bc'); diff --git a/test/sqllogictest/cockroach/show_create_all_types.slt b/test/sqllogictest/cockroach/show_create_all_types.slt new file mode 100644 index 0000000000000..c328b6cd64304 --- /dev/null +++ b/test/sqllogictest/cockroach/show_create_all_types.slt @@ -0,0 +1,112 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/show_create_all_types +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE DATABASE d + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE d + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TYPES +---- +create_statement + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE status AS ENUM ('open', 'closed', 'inactive'); + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TYPES +---- +create_statement +CREATE TYPE public.status AS ENUM ('open', 'closed', 'inactive'); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE tableObj AS ENUM('row', 'col'); + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TYPES +---- +create_statement +CREATE TYPE public.status AS ENUM ('open', 'closed', 'inactive'); +CREATE TYPE public.tableobj AS ENUM ('row', 'col'); + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TYPE status + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TYPES +---- +create_statement +CREATE TYPE public.tableobj AS ENUM ('row', 'col'); + +# type in user-defined schema +statement ok +CREATE SCHEMA s + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE s.status AS ENUM ('a', 'b', 'c'); + +# Not supported by Materialize. +onlyif cockroach +query T colnames +SHOW CREATE ALL TYPES +---- +create_statement +CREATE TYPE public.tableobj AS ENUM ('row', 'col'); +CREATE TYPE s.status AS ENUM ('a', 'b', 'c'); + +# Not supported by Materialize. +onlyif cockroach +# Make sure database names with hyphens work well. +statement ok +CREATE DATABASE "d-d"; +USE "d-d"; +SHOW CREATE ALL TYPES; + +# Not supported by Materialize. +onlyif cockroach +# Make sure database names with quotes work well. +statement ok +CREATE DATABASE "a""bc"; +USE "a""bc"; +SHOW CREATE ALL TYPES; diff --git a/test/sqllogictest/cockroach/show_create_redact.slt b/test/sqllogictest/cockroach/show_create_redact.slt new file mode 100644 index 0000000000000..a8690b69f4688 --- /dev/null +++ b/test/sqllogictest/cockroach/show_create_redact.slt @@ -0,0 +1,349 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/show_create_redact +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Test that column defaults are redacted. + +statement ok +CREATE TABLE a (a STRING DEFAULT 'a') + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE a WITH REDACT +---- +a CREATE TABLE public.a ( + a STRING NULL DEFAULT ‹×›:::STRING, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT a_pkey PRIMARY KEY (rowid ASC) + ) + +statement ok +CREATE TABLE b (b BOOLEAN DEFAULT false) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE b WITH REDACT +---- +b CREATE TABLE public.b ( + b BOOL NULL DEFAULT ‹×›, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT b_pkey PRIMARY KEY (rowid ASC) + ) + +statement ok +CREATE TABLE c (c CHAR DEFAULT 'c') + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE c WITH REDACT +---- +c CREATE TABLE public.c ( + c CHAR NULL DEFAULT ‹×›:::STRING, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT c_pkey PRIMARY KEY (rowid ASC) + ) + +statement ok +CREATE TABLE d (d DATE DEFAULT '1999-12-31') + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE d WITH REDACT +---- +d CREATE TABLE public.d ( + d DATE NULL DEFAULT ‹×›:::DATE, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT d_pkey PRIMARY KEY (rowid ASC) + ) + +statement ok +CREATE TABLE i (i INT DEFAULT 0) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE i WITH REDACT +---- +i CREATE TABLE public.i ( + i INT8 NULL DEFAULT ‹×›:::INT8, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT i_pkey PRIMARY KEY (rowid ASC) + ) + +statement ok +CREATE TABLE j (j JSON DEFAULT '{}') + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE j WITH REDACT +---- +j CREATE TABLE public.j ( + j JSONB NULL DEFAULT ‹×›:::JSONB, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT j_pkey PRIMARY KEY (rowid ASC) + ) + +statement ok +CREATE TABLE n (n INT DEFAULT NULL) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE n WITH REDACT +---- +n CREATE TABLE public.n ( + n INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT n_pkey PRIMARY KEY (rowid ASC) + ) + +# Test that constants in computed columns are redacted. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE ef (e INT, f INT AS (e + 1) VIRTUAL) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE ef WITH REDACT +---- +ef CREATE TABLE public.ef ( + e INT8 NULL, + f INT8 NULL AS (e + ‹×›:::INT8) VIRTUAL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT ef_pkey PRIMARY KEY (rowid ASC) + ) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE g (g GEOMETRY AS ('POINT (0 0)') VIRTUAL) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE g WITH REDACT +---- +g CREATE TABLE public.g ( + g GEOMETRY NULL AS (‹×›:::GEOMETRY) VIRTUAL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT g_pkey PRIMARY KEY (rowid ASC) + ) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE hi (h INTERVAL PRIMARY KEY, i INTERVAL AS (h - '12:00:00') STORED, FAMILY (h, i)) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE hi WITH REDACT +---- +hi CREATE TABLE public.hi ( + h INTERVAL NOT NULL, + i INTERVAL NULL AS (h - ‹×›:::INTERVAL) STORED, + CONSTRAINT hi_pkey PRIMARY KEY (h ASC), + FAMILY fam_0_h_i (h, i) + ) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE jk (j JSONB, k STRING PRIMARY KEY, jk JSONB AS (j->k->'foo') STORED, INVERTED INDEX (jk), FAMILY (k, j, jk)) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE jk WITH REDACT +---- +jk CREATE TABLE public.jk ( + j JSONB NULL, + k STRING NOT NULL, + jk JSONB NULL AS ((j->k)->‹×›:::STRING) STORED, + CONSTRAINT jk_pkey PRIMARY KEY (k ASC), + INVERTED INDEX jk_jk_idx (jk), + FAMILY fam_0_k_j_jk (k, j, jk) + ) + +# Test that constants in constraints are redacted. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE k (k INT PRIMARY KEY, CHECK (k > 0), CHECK (true)) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE k WITH REDACT +---- +k CREATE TABLE public.k ( + k INT8 NOT NULL, + CONSTRAINT k_pkey PRIMARY KEY (k ASC), + CONSTRAINT check_k CHECK (k > ‹×›:::INT8), + CONSTRAINT "check" CHECK (‹×›) + ) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE dl (d DECIMAL PRIMARY KEY, l DECIMAL, CHECK (d != l + 2.0), FAMILY (d, l)) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE dl WITH REDACT +---- +dl CREATE TABLE public.dl ( + d DECIMAL NOT NULL, + l DECIMAL NULL, + CONSTRAINT dl_pkey PRIMARY KEY (d ASC), + FAMILY fam_0_d_l (d, l), + CONSTRAINT check_d_l CHECK (d != (l + ‹×›:::DECIMAL)) + ) + +# Test that constants in expression indexes are redacted. + +statement ok +CREATE TABLE m (m STRING[], INDEX (array_cat(m, ARRAY['', NULL, 'm']))) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE m WITH REDACT +---- +m CREATE TABLE public.m ( + m STRING[] NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT m_pkey PRIMARY KEY (rowid ASC), + INDEX m_expr_idx (array_cat(m, ARRAY[‹×›:::STRING, ‹×›, ‹×›:::STRING]:::STRING[]) ASC) + ) + +statement ok +CREATE TABLE no (n NUMERIC PRIMARY KEY, o FLOAT, UNIQUE INDEX ((o / 1.1e7)), FAMILY (n, o)) + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE no WITH REDACT +---- +no CREATE TABLE public.no ( + n DECIMAL NOT NULL, + o FLOAT8 NULL, + CONSTRAINT no_pkey PRIMARY KEY (n ASC), + UNIQUE INDEX no_expr_key ((o / ‹×›:::FLOAT8) ASC), + FAMILY fam_0_n_o (n, o) + ) + +# Test that constants in partial indexes are redacted. + +statement ok +CREATE TABLE p (p UUID PRIMARY KEY, INDEX (p) WHERE p != 'acde070d-8c4c-4f0d-9d8a-162843c10333') + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE TABLE p WITH REDACT +---- +p CREATE TABLE public.p ( + p UUID NOT NULL, + CONSTRAINT p_pkey PRIMARY KEY (p ASC), + INDEX p_p_idx (p ASC) WHERE p != ‹×›:::UUID + ) + +# Test that constants in views are redacted. + +statement ok +CREATE VIEW q (q) AS SELECT 0 + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE VIEW q WITH REDACT +---- +q CREATE VIEW public.q ( + q + ) AS SELECT ‹×› + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW r (r) AS SELECT TIMESTAMP '1999-12-31 23:59:59' + i FROM hi WHERE h != '00:00:01' + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE VIEW r WITH REDACT +---- +r CREATE VIEW public.r ( + r + ) AS SELECT TIMESTAMP ‹×› + i FROM test.public.hi WHERE h != ‹×› + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW s (s) AS SELECT IF(b, 'abc', 'def') FROM b ORDER BY b AND NOT false LIMIT 10 + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE VIEW s WITH REDACT +---- +s CREATE VIEW public.s ( + s + ) AS SELECT + IF(b, ‹×›, ‹×›) + FROM + test.public.b + ORDER BY + b AND (NOT ‹×›) + LIMIT + ‹×› + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW t (t, u) AS SELECT jk || '[null]', j->a FROM a JOIN jk ON a = k || 'u' ORDER BY concat(a, 'ut') + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE VIEW t WITH REDACT +---- +t CREATE VIEW public.t ( + t, + u + ) AS SELECT + jk || ‹×›, j->a + FROM + test.public.a JOIN test.public.jk ON a = (k || ‹×›) + ORDER BY + concat(a, ‹×›) diff --git a/test/sqllogictest/cockroach/show_default_privileges.slt b/test/sqllogictest/cockroach/show_default_privileges.slt new file mode 100644 index 0000000000000..8b0707b093195 --- /dev/null +++ b/test/sqllogictest/cockroach/show_default_privileges.slt @@ -0,0 +1,261 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/show_default_privileges +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Default privileges start with an implicit set, the creator role has ALL +# and Public has usage. +query TBTTTB +SHOW DEFAULT PRIVILEGES +---- +PUBLIC NULL NULL type PUBLIC USAGE + +# Not supported by Materialize. +onlyif cockroach +# Ensure revoking "default" default privileges reflects in show default +# privileges. +statement ok +ALTER DEFAULT PRIVILEGES REVOKE ALL ON TABLES FROM root; +ALTER DEFAULT PRIVILEGES REVOKE USAGE ON TYPES FROM public; + +query TBTTTB +SHOW DEFAULT PRIVILEGES +---- +PUBLIC NULL NULL type PUBLIC USAGE + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES GRANT SELECT ON TABLES TO PUBLIC; +ALTER DEFAULT PRIVILEGES GRANT USAGE ON TYPES TO PUBLIC; +ALTER DEFAULT PRIVILEGES GRANT USAGE ON SCHEMAS TO PUBLIC; +ALTER DEFAULT PRIVILEGES GRANT SELECT ON SEQUENCES TO PUBLIC; + +query TBTTTB +SHOW DEFAULT PRIVILEGES +---- +PUBLIC NULL NULL type PUBLIC USAGE + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER foo + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER bar + +query TBTTTB +SHOW DEFAULT PRIVILEGES +---- +PUBLIC NULL NULL type PUBLIC USAGE + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES GRANT ALL ON TABLES TO foo, bar; +ALTER DEFAULT PRIVILEGES GRANT ALL ON TYPES TO foo, bar; +ALTER DEFAULT PRIVILEGES GRANT ALL ON SCHEMAS TO foo, bar; +ALTER DEFAULT PRIVILEGES GRANT ALL ON SEQUENCES TO foo, bar; + +# Not supported by Materialize. +onlyif cockroach +query TBTTTB +SHOW DEFAULT PRIVILEGES FOR ROLE foo, bar, root +---- +bar false functions bar ALL true +bar false schemas bar ALL true +bar false sequences bar ALL true +bar false tables bar ALL true +bar false types bar ALL true +bar false types public USAGE false +foo false functions foo ALL true +foo false schemas foo ALL true +foo false sequences foo ALL true +foo false tables foo ALL true +foo false types foo ALL true +foo false types public USAGE false +root false functions root ALL true +root false schemas bar ALL false +root false schemas foo ALL false +root false schemas public USAGE false +root false schemas root ALL true +root false sequences bar ALL false +root false sequences foo ALL false +root false sequences public SELECT false +root false sequences root ALL true +root false tables bar ALL false +root false tables foo ALL false +root false tables public SELECT false +root false types bar ALL false +root false types foo ALL false +root false types public USAGE false +root false types root ALL true + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT foo, bar TO root; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar GRANT ALL ON TABLES TO foo, bar; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar GRANT ALL ON TYPES TO foo, bar; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar GRANT ALL ON SCHEMAS TO foo, bar; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar GRANT ALL ON SEQUENCES TO foo, bar; + +query TBTTTB +SHOW DEFAULT PRIVILEGES +---- +PUBLIC NULL NULL type PUBLIC USAGE + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar REVOKE ALL ON TABLES FROM foo, bar; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar REVOKE ALL ON TYPES FROM foo, bar; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar REVOKE ALL ON SCHEMAS FROM foo, bar; +ALTER DEFAULT PRIVILEGES FOR ROLE foo, bar REVOKE ALL ON SEQUENCES FROM foo, bar; + +query TBTTTB +SHOW DEFAULT PRIVILEGES +---- +PUBLIC NULL NULL type PUBLIC USAGE + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES REVOKE SELECT ON TABLES FROM foo, bar, public; +ALTER DEFAULT PRIVILEGES REVOKE ALL ON TYPES FROM foo, bar, public; +ALTER DEFAULT PRIVILEGES REVOKE ALL ON SCHEMAS FROM foo, bar, public; +ALTER DEFAULT PRIVILEGES REVOKE ALL ON SEQUENCES FROM foo, bar, public; + +query TBTTTB +SHOW DEFAULT PRIVILEGES +---- +PUBLIC NULL NULL type PUBLIC USAGE + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES REVOKE ALL ON TABLES FROM foo, bar, public; +ALTER DEFAULT PRIVILEGES GRANT DROP, ZONECONFIG ON TABLES TO foo WITH GRANT OPTION; + +query TBTTTB +SHOW DEFAULT PRIVILEGES +---- +PUBLIC NULL NULL type PUBLIC USAGE + +# Not supported by Materialize. +onlyif cockroach +# Create a second database. +statement ok +CREATE DATABASE test2; +use test2; +CREATE USER testuser2; + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT testuser TO root; +ALTER DEFAULT PRIVILEGES FOR ROLE testuser GRANT DROP, ZONECONFIG ON TABLES TO foo WITH GRANT OPTION; + +# Not supported by Materialize. +onlyif cockroach +query TBTTTB +SHOW DEFAULT PRIVILEGES FOR ROLE testuser +---- +testuser false functions testuser ALL true +testuser false schemas testuser ALL true +testuser false sequences testuser ALL true +testuser false tables foo DROP true +testuser false tables foo ZONECONFIG true +testuser false tables testuser ALL true +testuser false types public USAGE false +testuser false types testuser ALL true + +# SHOW DEFAULT PRIVILEGES should show default privileges for the current role. +user testuser +query TBTTTB +SHOW DEFAULT PRIVILEGES +---- +PUBLIC NULL NULL type PUBLIC USAGE + +user root + +# Not supported by Materialize. +onlyif cockroach +query TBTTTB +SHOW DEFAULT PRIVILEGES FOR ROLE testuser +---- +testuser false functions testuser ALL true +testuser false schemas testuser ALL true +testuser false sequences testuser ALL true +testuser false tables foo DROP true +testuser false tables foo ZONECONFIG true +testuser false tables testuser ALL true +testuser false types public USAGE false +testuser false types testuser ALL true + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ROLE root GRANT DROP, ZONECONFIG ON TABLES TO foo WITH GRANT OPTION; + +# Not supported by Materialize. +onlyif cockroach +query TBTTTB +SHOW DEFAULT PRIVILEGES FOR ROLE root, testuser +---- +root false functions root ALL true +root false schemas root ALL true +root false sequences root ALL true +root false tables foo DROP true +root false tables foo ZONECONFIG true +root false tables root ALL true +root false types public USAGE false +root false types root ALL true +testuser false functions testuser ALL true +testuser false schemas testuser ALL true +testuser false sequences testuser ALL true +testuser false tables foo DROP true +testuser false tables foo ZONECONFIG true +testuser false tables testuser ALL true +testuser false types public USAGE false +testuser false types testuser ALL true + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER DEFAULT PRIVILEGES FOR ALL ROLES GRANT DROP, ZONECONFIG ON TABLES TO foo WITH GRANT OPTION; + +# Not supported by Materialize. +onlyif cockroach +# ForAllRoles is not a real role and thus is not the grantee for any privileges. +query TBTTTB +SHOW DEFAULT PRIVILEGES FOR ALL ROLES +---- +NULL true tables foo DROP true +NULL true tables foo ZONECONFIG true +NULL true types public USAGE false diff --git a/test/sqllogictest/cockroach/show_indexes.slt b/test/sqllogictest/cockroach/show_indexes.slt new file mode 100644 index 0000000000000..99e249c60a43c --- /dev/null +++ b/test/sqllogictest/cockroach/show_indexes.slt @@ -0,0 +1,99 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/show_indexes +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE t1 ( + a INT, + b INT, + c INT, + d INT, + PRIMARY KEY (a, b), + INDEX c_idx (c ASC), + UNIQUE INDEX d_b_idx (d ASC, b ASC), + INDEX expr_idx ((a+b), c) +) + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES from t1 +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +t1 c_idx true 1 c c ASC false false true +t1 c_idx true 2 a a ASC false true true +t1 c_idx true 3 b b ASC false true true +t1 d_b_idx false 1 d d ASC false false true +t1 d_b_idx false 2 b b ASC false false true +t1 d_b_idx false 3 a a ASC true true true +t1 expr_idx true 1 crdb_internal_idx_expr (a + b) ASC false false true +t1 expr_idx true 2 c c ASC false false true +t1 expr_idx true 3 a a ASC false true true +t1 expr_idx true 4 b b ASC false true true +t1 t1_pkey false 1 a a ASC false false true +t1 t1_pkey false 2 b b ASC false false true +t1 t1_pkey false 3 c c N/A true false true +t1 t1_pkey false 4 d d N/A true false true + +statement ok +CREATE TABLE t2 ( + a INT, + b INT, + c INT, + d INT, + e INT, + PRIMARY KEY (c, b, a), + INDEX a_e_c_idx (a ASC, e ASC, c ASC), + UNIQUE INDEX b_d_idx (b ASC, d ASC), + UNIQUE INDEX c_e_d_a_idx (c ASC, e ASC, d ASC, a ASC), + INDEX d_idx (d ASC) +) + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES from t2 +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +t2 a_e_c_idx true 1 a a ASC false false true +t2 a_e_c_idx true 2 e e ASC false false true +t2 a_e_c_idx true 3 c c ASC false false true +t2 a_e_c_idx true 4 b b ASC false true true +t2 b_d_idx false 1 b b ASC false false true +t2 b_d_idx false 2 d d ASC false false true +t2 b_d_idx false 3 c c ASC true true true +t2 b_d_idx false 4 a a ASC true true true +t2 c_e_d_a_idx false 1 c c ASC false false true +t2 c_e_d_a_idx false 2 e e ASC false false true +t2 c_e_d_a_idx false 3 d d ASC false false true +t2 c_e_d_a_idx false 4 a a ASC false false true +t2 c_e_d_a_idx false 5 b b ASC true true true +t2 d_idx true 1 d d ASC false false true +t2 d_idx true 2 c c ASC false true true +t2 d_idx true 3 b b ASC false true true +t2 d_idx true 4 a a ASC false true true +t2 t2_pkey false 1 c c ASC false false true +t2 t2_pkey false 2 b b ASC false false true +t2 t2_pkey false 3 a a ASC false false true +t2 t2_pkey false 4 d d N/A true false true +t2 t2_pkey false 5 e e N/A true false true diff --git a/test/sqllogictest/cockroach/show_tables.slt b/test/sqllogictest/cockroach/show_tables.slt new file mode 100644 index 0000000000000..ae13bad1ad52f --- /dev/null +++ b/test/sqllogictest/cockroach/show_tables.slt @@ -0,0 +1,101 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/show_tables +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: local + +statement ok +CREATE TABLE show_this_table() + +# Not supported by Materialize. +onlyif cockroach +query TTTTIT +SHOW TABLES +---- +public show_this_table table root 0 NULL + +statement ok +CREATE DATABASE other; +SET DATABASE = 'other' + +# Not supported by Materialize. +onlyif cockroach +query TTTTIT +SHOW TABLES FROM test +---- +public show_this_table table root 0 NULL + +statement ok +SET DATABASE = 'test' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET CLUSTER SETTING sql.show_tables.estimated_row_count.enabled = false + +# Not supported by Materialize. +onlyif cockroach +query TTTTT +SHOW TABLES +---- +public show_this_table table root NULL + +# Not supported by Materialize. +onlyif cockroach +query TTTTTT +SHOW TABLES WITH COMMENT +---- +public show_this_table table root NULL · + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET CLUSTER SETTING sql.show_tables.estimated_row_count.enabled = default + +statement ok +CREATE DATABASE "Do you like this for a database name?"; +SET database = "Do you like this for a database name?"; +CREATE SCHEMA sc; +CREATE TABLE sc.foo (i INT8); +CREATE TABLE foo (i INT8); + +# Not supported by Materialize. +onlyif cockroach +query TTTTIT +SHOW TABLES +---- +public foo table root 0 NULL +sc foo table root 0 NULL + + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE other + +# Not supported by Materialize. +onlyif cockroach +query TTTTIT +SHOW TABLES FROM "Do you like this for a database name?".sc +---- +sc foo table root 0 NULL diff --git a/test/sqllogictest/cockroach/show_var.slt b/test/sqllogictest/cockroach/show_var.slt new file mode 100644 index 0000000000000..4a210afafc524 --- /dev/null +++ b/test/sqllogictest/cockroach/show_var.slt @@ -0,0 +1,32 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/show_var +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Make sure that user get duplicate search paths as they set. +statement ok +SET search_path = public, public, a, b, c + +query T +SHOW search_path; +---- +public, public, a, b, c diff --git a/test/sqllogictest/cockroach/sqlsmith.slt b/test/sqllogictest/cockroach/sqlsmith.slt index 809518d7bd0f1..dc5aa043d25da 100644 --- a/test/sqllogictest/cockroach/sqlsmith.slt +++ b/test/sqllogictest/cockroach/sqlsmith.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,28 +9,27 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/sqlsmith +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/sqlsmith # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - # This file contains regression tests discovered by sqlsmith. -# Regression: materialize#28836 (nulls in string_agg) - -statement ok -SELECT subq_0.c3 AS c0, subq_0.c6 AS c1, subq_0.c4 AS c2, CASE WHEN (SELECT start_key FROM crdb_internal.ranges LIMIT 1 OFFSET 6) < CAST(NULLIF(pg_catalog.string_agg(CAST((SELECT start_key FROM crdb_internal.ranges LIMIT 1 OFFSET 7) AS BYTEA), CAST((SELECT pg_catalog.xor_agg(tgargs) FROM pg_catalog.pg_trigger) AS BYTEA)) OVER (PARTITION BY subq_0.c0 ORDER BY subq_0.c0, subq_0.c5, subq_0.c2), CAST(NULL AS BYTEA)) AS BYTEA) THEN subq_0.c6 ELSE subq_0.c6 END AS c3, subq_0.c2 AS c4, subq_0.c7 AS c5, CAST(COALESCE(subq_0.c7, subq_0.c7) AS INT8) AS c6 FROM (SELECT ref_0.table_name AS c0, ref_0.table_catalog AS c1, ref_0.table_type AS c2, (SELECT rolcreatedb FROM pg_catalog.pg_roles LIMIT 1 OFFSET 79) AS c3, ref_0.table_name AS c4, ref_0.version AS c5, ref_0.version AS c6, ref_0.version AS c7 FROM information_schema.tables AS ref_0 WHERE (ref_0.version IS NOT NULL) OR (pg_catalog.set_masklen(CAST(CAST(NULL AS INET) AS INET), CAST(ref_0.version AS INT8)) != (SELECT pg_catalog.max(client_addr) FROM pg_catalog.pg_stat_activity)) LIMIT 101) AS subq_0 WHERE subq_0.c7 IS NOT NULL +# Record disabled, not supported by Materialize: +# # Regression: #28836 (nulls in string_agg) +# skipif config 3node-tenant-default-configs #72565 +# statement ok +# SELECT subq_0.c3 AS c0, subq_0.c6 AS c1, subq_0.c4 AS c2, CASE WHEN (SELECT start_key FROM crdb_internal.ranges LIMIT 1 OFFSET 6) < CAST(NULLIF(pg_catalog.string_agg(CAST((SELECT start_key FROM crdb_internal.ranges LIMIT 1 OFFSET 7) AS BYTES), CAST((SELECT pg_catalog.xor_agg(tgargs) FROM pg_catalog.pg_trigger) AS BYTES)) OVER (PARTITION BY subq_0.c0 ORDER BY subq_0.c0, subq_0.c5, subq_0.c2), CAST(NULL AS BYTES)) AS BYTES) THEN subq_0.c6 ELSE subq_0.c6 END AS c3, subq_0.c2 AS c4, subq_0.c7 AS c5, CAST(COALESCE(subq_0.c7, subq_0.c7) AS INT8) AS c6 FROM (SELECT ref_0.table_name AS c0, ref_0.table_catalog AS c1, ref_0.table_type AS c2, (SELECT rolcreatedb FROM pg_catalog.pg_roles LIMIT 1 OFFSET 79) AS c3, ref_0.table_name AS c4, ref_0.version AS c5, ref_0.version AS c6, ref_0.version AS c7 FROM information_schema.tables AS ref_0 WHERE (ref_0.version IS NOT NULL) OR (pg_catalog.set_masklen(CAST(CAST(NULL AS INET) AS INET), CAST(ref_0.version AS INT8)) != (SELECT pg_catalog.max(client_addr) FROM pg_catalog.pg_stat_activity)) LIMIT 101) AS subq_0 WHERE subq_0.c7 IS NOT NULL # Regression: make sure lookup join planNode propagates its close signal. This # query could panic otherwise with a failure to empty all memory accounts. @@ -38,23 +37,31 @@ SELECT subq_0.c3 AS c0, subq_0.c6 AS c1, subq_0.c4 AS c2, CASE WHEN (SELECT star statement ok CREATE TABLE a (a INT PRIMARY KEY); +# Not supported by Materialize. +onlyif cockroach statement ok SELECT true FROM (SELECT ref_1.a AS c0 FROM crdb_internal.cluster_queries AS ref_0 JOIN a AS ref_1 ON (ref_0.node_id = ref_1.a) WHERE (SELECT a from a limit 1 offset 1) is null); -# Regression: cockroach#34437 (union all could produce panic in distsql planning) +# Regression: #34437 (union all could produce panic in distsql planning) statement ok -CREATE TABLE table8 (col1 TIME, col2 BYTEA, col4 OID, col6 NAME, col9 TIMESTAMP, PRIMARY KEY (col1)); +CREATE TABLE table8 (col1 TIME, col2 BYTES, col4 OID, col6 NAME, col9 TIMESTAMP, PRIMARY KEY (col1)); +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE table5 (col0 TIME NULL, col1 OID, col3 INET, PRIMARY KEY (col1 ASC)); +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO table8 (col1, col2, col4, col6) VALUES ('19:06:18.321589', NULL, NULL, NULL) UNION ALL (SELECT NULL, NULL, NULL, NULL FROM table5 AS tab_8); -# Regression: cockroach#36441 (raw indexed var can't be type checked) +# Not supported by Materialize. +onlyif cockroach +# Regression: #36441 (raw indexed var can't be type checked) query TO WITH with_20394 (col_162526) @@ -94,14 +101,16 @@ ORDER BY 1d6eaf81-8a2c-43c5-a495-a3b102917ab1 3697877132 d2d225e2-e9be-4420-a645-d1b8f577511c 3697877132 -# Regression: cockroach#36830 (can't run wrapped window node) +# Regression: #36830 (can't run wrapped window node) statement ok CREATE TABLE table9 (a INT8); statement ok INSERT INTO table9 SELECT lag(a) OVER (PARTITION BY a) FROM table9; -# Regression: cockroach#36607 (can't serialize or type-check arrays of NULL properly) +# Not supported by Materialize. +onlyif cockroach +# Regression: #36607 (can't serialize or type-check arrays of NULL properly) query TTTT WITH with_194015 (col_1548014) @@ -167,3 +176,55 @@ NULL 1984-01-07 00:00:00 +0000 +0000 NULL f96fd19a-d2a9-4d98-81dd-97e3fc2a45d NULL 1984-01-07 00:00:00 +0000 +0000 NULL f96fd19a-d2a9-4d98-81dd-97e3fc2a45d2 NULL 1984-01-07 00:00:00 +0000 +0000 NULL f96fd19a-d2a9-4d98-81dd-97e3fc2a45d2 NULL 1984-01-07 00:00:00 +0000 +0000 NULL f96fd19a-d2a9-4d98-81dd-97e3fc2a45d2 + +# Not supported by Materialize. +onlyif cockroach +# Regression: #48267 (invalid opt transformation of OR with NULL) +statement ok +CREATE TABLE t (d) AS VALUES ('2001-01-01'::DATE) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM t WHERE (d = d) OR (d = d) +---- +2001-01-01 00:00:00 +0000 +0000 + +# Regression: #48826 (array indirection with NULL argument) +query T +SELECT ARRAY[1][NULL] +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +# Regression: #64399 (panic due to optimizer ordering bug) +statement ok +CREATE TABLE ab ( + a INT, + b INT AS (a % 2) STORED, + INDEX (b) +); +CREATE TABLE cd ( + c INT, + d INT AS (c % 2) VIRTUAL +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT NULL +FROM ab AS ab1 + JOIN cd AS cd1 + JOIN cd AS cd2 ON cd1.c = cd2.c + JOIN ab AS ab2 ON + cd2.c = ab2.a + AND cd2.c = ab2.crdb_internal_mvcc_timestamp + AND cd1.c = ab2.a + AND cd1.c = ab2.b + AND cd1.d = ab2.b + ON ab1.b = cd1.d + JOIN cd AS cd3 ON + ab1.b = cd3.c + AND cd2.c = cd3.d + AND cd1.d = cd3.c diff --git a/test/sqllogictest/cockroach/srfs.slt b/test/sqllogictest/cockroach/srfs.slt index 1ca1627f4aacb..5b876712b6fd6 100644 --- a/test/sqllogictest/cockroach/srfs.slt +++ b/test/sqllogictest/cockroach/srfs.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/srfs +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/srfs # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach subtest generate_series @@ -40,44 +40,44 @@ query T colnames SELECT * FROM generate_series('2017-11-11 00:00:00'::TIMESTAMP, '2017-11-11 03:00:00'::TIMESTAMP, '1 hour') ---- generate_series -2017-11-11 00:00:00 +0000 +0000 -2017-11-11 01:00:00 +0000 +0000 -2017-11-11 02:00:00 +0000 +0000 -2017-11-11 03:00:00 +0000 +0000 +2017-11-11 00:00:00 +2017-11-11 02:00:00 +2017-11-11 01:00:00 +2017-11-11 03:00:00 query T colnames SELECT * FROM generate_series('2017-11-11 03:00:00'::TIMESTAMP, '2017-11-11 00:00:00'::TIMESTAMP, '-1 hour') ---- generate_series -2017-11-11 03:00:00 +0000 +0000 -2017-11-11 02:00:00 +0000 +0000 -2017-11-11 01:00:00 +0000 +0000 -2017-11-11 00:00:00 +0000 +0000 +2017-11-11 00:00:00 +2017-11-11 02:00:00 +2017-11-11 01:00:00 +2017-11-11 03:00:00 query T colnames SELECT * FROM generate_series('2017-11-11 03:00:00'::TIMESTAMP, '2017-11-15 00:00:00'::TIMESTAMP, '1 day') ---- generate_series -2017-11-11 03:00:00 +0000 +0000 -2017-11-12 03:00:00 +0000 +0000 -2017-11-13 03:00:00 +0000 +0000 -2017-11-14 03:00:00 +0000 +0000 +2017-11-13 03:00:00 +2017-11-14 03:00:00 +2017-11-11 03:00:00 +2017-11-12 03:00:00 query T colnames SELECT * FROM generate_series('2017-01-15 03:00:00'::TIMESTAMP, '2017-12-15 00:00:00'::TIMESTAMP, '1 month') ---- generate_series -2017-01-15 03:00:00 +0000 +0000 -2017-02-15 03:00:00 +0000 +0000 -2017-03-15 03:00:00 +0000 +0000 -2017-04-15 03:00:00 +0000 +0000 -2017-05-15 03:00:00 +0000 +0000 -2017-06-15 03:00:00 +0000 +0000 -2017-07-15 03:00:00 +0000 +0000 -2017-08-15 03:00:00 +0000 +0000 -2017-09-15 03:00:00 +0000 +0000 -2017-10-15 03:00:00 +0000 +0000 -2017-11-15 03:00:00 +0000 +0000 +2017-09-15 03:00:00 +2017-01-15 03:00:00 +2017-05-15 03:00:00 +2017-03-15 03:00:00 +2017-10-15 03:00:00 +2017-08-15 03:00:00 +2017-02-15 03:00:00 +2017-06-15 03:00:00 +2017-04-15 03:00:00 +2017-11-15 03:00:00 +2017-07-15 03:00:00 # Check what happens when we step through February in a leap year, starting on Jan 31. # This output is consistent with PostgreSQL 10. @@ -85,61 +85,63 @@ query T colnames SELECT * FROM generate_series('2016-01-31 03:00:00'::TIMESTAMP, '2016-12-31 00:00:00'::TIMESTAMP, '1 month') ---- generate_series -2016-01-31 03:00:00 +0000 +0000 -2016-02-29 03:00:00 +0000 +0000 -2016-03-29 03:00:00 +0000 +0000 -2016-04-29 03:00:00 +0000 +0000 -2016-05-29 03:00:00 +0000 +0000 -2016-06-29 03:00:00 +0000 +0000 -2016-07-29 03:00:00 +0000 +0000 -2016-08-29 03:00:00 +0000 +0000 -2016-09-29 03:00:00 +0000 +0000 -2016-10-29 03:00:00 +0000 +0000 -2016-11-29 03:00:00 +0000 +0000 -2016-12-29 03:00:00 +0000 +0000 +2016-03-29 03:00:00 +2016-10-29 03:00:00 +2016-02-29 03:00:00 +2016-01-31 03:00:00 +2016-08-29 03:00:00 +2016-06-29 03:00:00 +2016-04-29 03:00:00 +2016-11-29 03:00:00 +2016-07-29 03:00:00 +2016-09-29 03:00:00 +2016-05-29 03:00:00 +2016-12-29 03:00:00 # Similar to the previous, but we don't hit a 30-day month until July. query T colnames SELECT * FROM generate_series('2016-01-31 03:00:00'::TIMESTAMP, '2016-12-31 00:00:00'::TIMESTAMP, '2 month') ---- generate_series -2016-01-31 03:00:00 +0000 +0000 -2016-03-31 03:00:00 +0000 +0000 -2016-05-31 03:00:00 +0000 +0000 -2016-07-31 03:00:00 +0000 +0000 -2016-09-30 03:00:00 +0000 +0000 -2016-11-30 03:00:00 +0000 +0000 +2016-09-30 03:00:00 +2016-01-31 03:00:00 +2016-07-31 03:00:00 +2016-05-31 03:00:00 +2016-03-31 03:00:00 +2016-11-30 03:00:00 # Verify rollover when we're adding by months, days, and hours query T colnames SELECT * FROM generate_series('2016-01-30 22:00:00'::TIMESTAMP, '2016-12-31 00:00:00'::TIMESTAMP, '1 month 1 day 1 hour') ---- generate_series -2016-01-30 22:00:00 +0000 +0000 -2016-03-01 23:00:00 +0000 +0000 -2016-04-03 00:00:00 +0000 +0000 -2016-05-04 01:00:00 +0000 +0000 -2016-06-05 02:00:00 +0000 +0000 -2016-07-06 03:00:00 +0000 +0000 -2016-08-07 04:00:00 +0000 +0000 -2016-09-08 05:00:00 +0000 +0000 -2016-10-09 06:00:00 +0000 +0000 -2016-11-10 07:00:00 +0000 +0000 -2016-12-11 08:00:00 +0000 +0000 +2016-04-03 00:00:00 +2016-12-11 08:00:00 +2016-09-08 05:00:00 +2016-06-05 02:00:00 +2016-11-10 07:00:00 +2016-03-01 23:00:00 +2016-08-07 04:00:00 +2016-05-04 01:00:00 +2016-10-09 06:00:00 +2016-01-30 22:00:00 +2016-07-06 03:00:00 query T colnames SELECT * FROM generate_series('1996-02-29 22:00:00'::TIMESTAMP, '2004-03-01 00:00:00'::TIMESTAMP, '4 year') ---- generate_series -1996-02-29 22:00:00 +0000 +0000 -2000-02-29 22:00:00 +0000 +0000 -2004-02-29 22:00:00 +0000 +0000 +2004-02-29 22:00:00 +2000-02-29 22:00:00 +1996-02-29 22:00:00 query T colnames SELECT * FROM generate_series('2017-11-11 00:00:00'::TIMESTAMP, '2017-11-11 03:00:00'::TIMESTAMP, '-1 hour') ---- generate_series +# Not supported by Materialize. +onlyif cockroach query II colnames,rowsort SELECT * FROM generate_series(1, 2), generate_series(1, 2) ---- @@ -153,16 +155,16 @@ query I colnames SELECT * FROM generate_series(3, 1, -1) ---- generate_series -3 -2 1 +2 +3 query I colnames SELECT * FROM generate_series(3, 1) ---- generate_series -query error step cannot be 0 +query error step size cannot equal zero SELECT * FROM generate_series(1, 3, 0) query I colnames @@ -191,7 +193,7 @@ SELECT * FROM generate_series(1, 1) WITH ORDINALITY AS c(x, y) x y 1 1 -query error generator functions are not allowed in LIMIT +query error table functions are not allowed in LIMIT \(function pg_catalog\.generate_series\) SELECT * FROM (VALUES (1)) LIMIT generate_series(1, 3) query I colnames @@ -228,7 +230,7 @@ INSERT INTO t VALUES ('cat') statement ok INSERT INTO u VALUES ('bird') -query TTII colnames +query TTII colnames,rowsort SELECT t.*, u.*, generate_series(1,2), generate_series(3, 4) FROM t, u ---- a b generate_series generate_series @@ -286,10 +288,10 @@ x generate_series subtest unnest -statement error could not determine polymorphic type +statement error function unnest\(unknown\) is not unique SELECT * FROM unnest(NULL) -statement error could not determine polymorphic type +statement error function unnest\(unknown\) is not unique SELECT unnest(NULL) query I colnames @@ -334,9 +336,9 @@ ascii 99 subtest nested_SRF -# See materialize#20511 +# See #20511 -query error unimplemented: nested set-returning functions +query error table functions are not allowed in other table functions \(function pg_catalog\.generate_series\) SELECT generate_series(generate_series(1, 3), 3) query I @@ -346,10 +348,10 @@ SELECT generate_series(1, 3) + generate_series(1, 3) 4 6 -query error pq: column "generate_series" does not exist +query error WHERE clause error: column "generate_series" does not exist SELECT generate_series(1, 3) FROM t WHERE generate_series > 3 -# Regressions for materialize#15900: ensure that null parameters to generate_series don't +# Regressions for #15900: ensure that null parameters to generate_series don't # cause issues. query T colnames @@ -357,6 +359,8 @@ SELECT * from generate_series(1, (select * from generate_series(1, 0))) ---- generate_series +# Not supported by Materialize. +onlyif cockroach # The following query is designed to produce a null array argument to unnest # in a way that the type system can't detect before evaluation. query T colnames @@ -364,12 +368,16 @@ SELECT unnest((SELECT current_schemas((SELECT isnan((SELECT round(3.4, (SELECT g ---- unnest +# Not supported by Materialize. +onlyif cockroach query T colnames SELECT information_schema._pg_expandarray((SELECT current_schemas((SELECT isnan((SELECT round(3.4, (SELECT generate_series(1, 0))))))))); ---- information_schema._pg_expandarray -# Regression for materialize#18021. +# Not supported by Materialize. +onlyif cockroach +# Regression for #18021. query I colnames SELECT generate_series(9223372036854775807::int, -9223372036854775807::int, -9223372036854775807::int) ---- @@ -380,7 +388,9 @@ generate_series subtest pg_get_keywords -# pg_get_keywords for compatibility (materialize#10291) +# Not supported by Materialize. +onlyif cockroach +# pg_get_keywords for compatibility (#10291) query TTT colnames SELECT * FROM pg_get_keywords() WHERE word IN ('alter', 'and', 'between', 'cross') ORDER BY word ---- @@ -390,6 +400,8 @@ and R reserved between C unreserved (cannot be function or type name) cross T reserved (can be function or type name) +# Not supported by Materialize. +onlyif cockroach # Postgres enables renaming both the source and the column name for # single-column generators, but not for multi-column generators. query IITTT colnames @@ -397,7 +409,7 @@ SELECT a.*, b.*, c.* FROM generate_series(1,1) a, unnest(ARRAY[1]) b, pg_get_key ---- a b word catcode catdesc -# Regression for cockroach#36501: the column from a single-column SRF should not be +# Regression for #36501: the column from a single-column SRF should not be # renamed because of a higher-level table alias. query I colnames SELECT * FROM (SELECT * FROM generate_series(1, 2)) AS a @@ -427,13 +439,17 @@ ON uq.filter_id2 = ab.filter_id ---- 1 1 -# Beware of multi-valued SRFs in render position (database-issues#5675) +# Not supported by Materialize. +onlyif cockroach +# Beware of multi-valued SRFs in render position (#19149) query TTT colnames SELECT 'a' AS a, pg_get_keywords(), 'c' AS c LIMIT 1 ---- a pg_get_keywords c a (abort,U,unreserved) c +# Not supported by Materialize. +onlyif cockroach query TTT colnames SELECT 'a' AS a, pg_get_keywords() AS b, 'c' AS c LIMIT 1 ---- @@ -442,6 +458,8 @@ a (abort,U,unreserved) c subtest unary_table +# Not supported by Materialize. +onlyif cockroach query TTT colnames SELECT 'a' AS a, crdb_internal.unary_table() AS b, 'c' AS c LIMIT 1 ---- @@ -450,7 +468,7 @@ a () c subtest upper -# Regular scalar functions can be used as functions too. materialize#22312 +# Regular scalar functions can be used as functions too. #22312 query T colnames SELECT * FROM upper('abc') ---- @@ -467,16 +485,16 @@ public 1 subtest expandArray -query error pq: unknown signature: information_schema._pg_expandarray() +query error function information_schema\._pg_expandarray\(\) does not exist SELECT information_schema._pg_expandarray() -query error pq: unknown signature: information_schema._pg_expandarray() +query error function information_schema\._pg_expandarray\(\) does not exist SELECT * FROM information_schema._pg_expandarray() -query error pq: information_schema\._pg_expandarray\(\): cannot determine type of empty array\. Consider annotating with the desired type, for example ARRAY\[\]:::int\[\] +query error cannot determine type of empty array SELECT information_schema._pg_expandarray(ARRAY[]) -query error pq: information_schema\._pg_expandarray\(\): cannot determine type of empty array\. Consider annotating with the desired type, for example ARRAY\[\]:::int\[\] +query error cannot determine type of empty array SELECT * FROM information_schema._pg_expandarray(ARRAY[]) statement error could not determine polymorphic type @@ -485,11 +503,15 @@ SELECT * FROM information_schema._pg_expandarray(NULL) statement error could not determine polymorphic type SELECT information_schema._pg_expandarray(NULL) +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT information_schema._pg_expandarray(ARRAY[]:::int[]) ---- information_schema._pg_expandarray +# Not supported by Materialize. +onlyif cockroach query II colnames SELECT * FROM information_schema._pg_expandarray(ARRAY[]:::int[]) ---- @@ -498,7 +520,7 @@ x n query T colnames SELECT information_schema._pg_expandarray(ARRAY[100]) ---- -information_schema._pg_expandarray +_pg_expandarray (100,1) query II colnames @@ -510,37 +532,37 @@ x n query T colnames SELECT information_schema._pg_expandarray(ARRAY[2, 1]) ---- -information_schema._pg_expandarray -(2,1) +_pg_expandarray (1,2) +(2,1) query II colnames SELECT * FROM information_schema._pg_expandarray(ARRAY[2, 1]) ---- x n -2 1 -1 2 +1 2 +2 1 query T colnames SELECT information_schema._pg_expandarray(ARRAY[3, 2, 1]) ---- -information_schema._pg_expandarray -(3,1) -(2,2) +_pg_expandarray (1,3) +(2,2) +(3,1) query II colnames SELECT * FROM information_schema._pg_expandarray(ARRAY[3, 2, 1]) ---- x n -3 1 -2 2 -1 3 +1 3 +2 2 +3 1 query T colnames SELECT information_schema._pg_expandarray(ARRAY['a']) ---- -information_schema._pg_expandarray +_pg_expandarray (a,1) query TI colnames @@ -552,63 +574,63 @@ a 1 query T colnames SELECT information_schema._pg_expandarray(ARRAY['b', 'a']) ---- -information_schema._pg_expandarray -(b,1) +_pg_expandarray (a,2) +(b,1) query TI colnames SELECT * FROM information_schema._pg_expandarray(ARRAY['b', 'a']) ---- x n -b 1 -a 2 +a 2 +b 1 query T colnames SELECT information_schema._pg_expandarray(ARRAY['c', 'b', 'a']) ---- -information_schema._pg_expandarray -(c,1) -(b,2) +_pg_expandarray (a,3) +(b,2) +(c,1) query TI colnames SELECT * FROM information_schema._pg_expandarray(ARRAY['c', 'b', 'a']) ---- x n -c 1 -b 2 -a 3 +a 3 +b 2 +c 1 subtest srf_accessor -query error pq: type int is not composite +query error type integer is not composite SELECT (1).* -query error pq: type int is not composite +query error type integer is not composite SELECT ((1)).* -query error pq: type int is not composite +query error column notation applied to type integer, which is not a composite type SELECT (1).x -query error pq: type int is not composite +query error column notation applied to type integer, which is not a composite type SELECT ((1)).x -query error pq: type text is not composite +query error type text is not composite SELECT ('a').* -query error pq: type text is not composite +query error type text is not composite SELECT (('a')).* -query error pq: type text is not composite +query error column notation applied to type text, which is not a composite type SELECT ('a').x -query error pq: type text is not composite +query error column notation applied to type text, which is not a composite type SELECT (('a')).x -query error pq: unnest\(\): cannot determine type of empty array. Consider annotating with the desired type, for example ARRAY\[\]:::int\[\] +query error cannot determine type of empty array SELECT (unnest(ARRAY[])).* -query error type int is not composite +query error Expected a data type name, found colon SELECT (unnest(ARRAY[]:::INT[])).* subtest multi_column @@ -616,18 +638,18 @@ subtest multi_column query TI colnames SELECT (information_schema._pg_expandarray(ARRAY['c', 'b', 'a'])).* ---- -x n -c 1 -b 2 +x n a 3 +b 2 +c 1 query T colnames SELECT (information_schema._pg_expandarray(ARRAY['c', 'b', 'a'])).x ---- x -c -b a +b +c query I colnames SELECT (information_schema._pg_expandarray(ARRAY['c', 'b', 'a'])).n @@ -637,16 +659,16 @@ n 2 3 -query error pq: could not identify column "other" in tuple{string AS x, int AS n} +query error field other not found in data type record\(x: text\?,n: integer\?\) SELECT (information_schema._pg_expandarray(ARRAY['c', 'b', 'a'])).other query T colnames SELECT temp.x from information_schema._pg_expandarray(array['c','b','a']) AS temp; ---- x -c -b a +b +c query I colnames SELECT temp.n from information_schema._pg_expandarray(array['c','b','a']) AS temp; @@ -656,24 +678,24 @@ n 2 3 -query error pq: column "temp.other" does not exist +query error column "temp\.other" does not exist SELECT temp.other from information_schema._pg_expandarray(array['c','b','a']) AS temp; query TI colnames SELECT temp.* from information_schema._pg_expandarray(array['c','b','a']) AS temp; ---- x n -c 1 -b 2 -a 3 +a 3 +b 2 +c 1 query TI colnames SELECT * from information_schema._pg_expandarray(array['c','b','a']) AS temp; ---- x n -c 1 -b 2 -a 3 +a 3 +b 2 +c 1 query I colnames SELECT (i.keys).n FROM (SELECT information_schema._pg_expandarray(ARRAY[3,2,1]) AS keys) AS i @@ -686,22 +708,24 @@ n query II colnames SELECT (i.keys).* FROM (SELECT information_schema._pg_expandarray(ARRAY[3,2,1]) AS keys) AS i ---- -x n -3 1 -2 2 +x n 1 3 +2 2 +3 1 query T SELECT ((i.keys).*, 123) FROM (SELECT information_schema._pg_expandarray(ARRAY[3,2,1]) AS keys) AS i ---- -("(3,1)",123) -("(2,2)",123) ("(1,3)",123) +("(2,2)",123) +("(3,1)",123) subtest generate_subscripts # Basic use cases +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[3,2,1]) ---- @@ -718,6 +742,8 @@ generate_subscripts 2 3 +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[3,2,1], 1, false) ---- @@ -726,6 +752,8 @@ generate_subscripts 2 3 +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[3,2,1], 1, true) ---- @@ -743,6 +771,8 @@ s 3 4 +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT generate_subscripts('{NULL,1,NULL,2}'::int[], 1, true) AS s ---- @@ -759,11 +789,15 @@ SELECT * FROM generate_subscripts(ARRAY[3,2,1], 2) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[3,2,1], 2, false) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[3,2,1], 2, true) ---- @@ -774,11 +808,15 @@ SELECT * FROM generate_subscripts(ARRAY[3,2,1], 0) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[3,2,1], 0, false) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[3,2,1], 0, true) ---- @@ -789,52 +827,72 @@ SELECT * FROM generate_subscripts(ARRAY[3,2,1], -1) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[3,2,1], -1, false) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[3,2,1], -1, true) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach # With an empty array query I colnames SELECT * FROM generate_subscripts(ARRAY[]:::int[]) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[]:::int[], 1) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[]:::string[], 1, false) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[]:::bool[], 1, true) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[]:::int[], 0) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[]:::string[], -1, false) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[]:::bool[], 2, true) ---- generate_subscripts +# Not supported by Materialize. +onlyif cockroach # With an array with only one value query I colnames SELECT * FROM generate_subscripts(ARRAY[100]) @@ -848,12 +906,16 @@ SELECT * FROM generate_subscripts(ARRAY[100], 1) generate_subscripts 1 +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY['b'], 1, false) ---- generate_subscripts 1 +# Not supported by Materialize. +onlyif cockroach query I colnames SELECT * FROM generate_subscripts(ARRAY[true], 1, true) ---- @@ -862,39 +924,43 @@ generate_subscripts subtest srf_errors -query error generator functions are not allowed in ORDER BY +query error table functions are not allowed in ORDER BY clause \(function pg_catalog\.generate_series\) SELECT * FROM t ORDER BY generate_series(1, 3) -query error generator functions are not allowed in WHERE +query error WHERE clause error: table functions are not allowed in WHERE clause \(function pg_catalog\.generate_series\) SELECT * FROM t WHERE generate_series(1, 3) < 3 -query error generator functions are not allowed in HAVING +query error table functions are not allowed in HAVING clause \(function pg_catalog\.generate_series\) SELECT * FROM t HAVING generate_series(1, 3) < 3 -query error generator functions are not allowed in LIMIT +query error table functions are not allowed in LIMIT \(function pg_catalog\.generate_series\) SELECT * FROM t LIMIT generate_series(1, 3) -query error generator functions are not allowed in OFFSET +query error table functions are not allowed in OFFSET \(function pg_catalog\.generate_series\) SELECT * FROM t OFFSET generate_series(1, 3) -query error generator functions are not allowed in VALUES +query error table functions are not allowed in VALUES \(function pg_catalog\.generate_series\) VALUES (generate_series(1,3)) -statement error generator functions are not allowed in DEFAULT +statement error table functions are not allowed in DEFAULT expression \(function pg_catalog\.generate_series\) CREATE TABLE uu (x INT DEFAULT generate_series(1, 3)) -statement error generator functions are not allowed in CHECK +statement error CREATE TABLE with column constraint: CHECK \(pg_catalog\.generate_series\(1, 3\) < 3\) not yet supported CREATE TABLE uu (x INT CHECK (generate_series(1, 3) < 3)) -statement error generator functions are not allowed in computed column +statement error Expected column option, found AS CREATE TABLE uu (x INT AS (generate_series(1, 3)) STORED) subtest correlated_srf +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE vals (x INT, y INT, INDEX woo (x, y)); INSERT INTO vals VALUES (3, 4), (NULL, NULL), (5, 6); +# Not supported by Materialize. +onlyif cockroach query III colnames SELECT x, generate_series(1,x), generate_series(1,2) FROM vals ORDER BY 1,2,3 ---- @@ -910,6 +976,8 @@ NULL NULL 2 5 4 NULL 5 5 NULL +# Not supported by Materialize. +onlyif cockroach # Check that the expression is still valid if the dependent name # is not otherwise rendered (needed column elision). query I colnames,rowsort @@ -925,6 +993,8 @@ generate_series 4 5 +# Not supported by Materialize. +onlyif cockroach # Check that the number of rows is still correct # even if the SRF is not needed. query I @@ -935,14 +1005,594 @@ SELECT count(*) FROM (SELECT generate_series(1,x) FROM vals) query TI colnames SELECT relname, unnest(indkey) FROM pg_class, pg_index WHERE pg_class.oid = pg_index.indrelid ORDER BY relname, unnest ---- -relname unnest -ordered_t 1 -t 2 -u 2 -vals 1 -vals 2 -vals 3 - +relname unnest +mz_active_peeks_per_worker 1 +mz_active_peeks_per_worker 1 +mz_active_peeks_per_worker 1 +mz_active_peeks_per_worker 1 +mz_active_peeks_per_worker 1 +mz_active_peeks_per_worker 1 +mz_active_peeks_per_worker 2 +mz_active_peeks_per_worker 2 +mz_active_peeks_per_worker 2 +mz_active_peeks_per_worker 2 +mz_active_peeks_per_worker 2 +mz_active_peeks_per_worker 2 +mz_arrangement_batcher_allocations_raw 1 +mz_arrangement_batcher_allocations_raw 1 +mz_arrangement_batcher_allocations_raw 1 +mz_arrangement_batcher_allocations_raw 1 +mz_arrangement_batcher_allocations_raw 1 +mz_arrangement_batcher_allocations_raw 1 +mz_arrangement_batcher_allocations_raw 2 +mz_arrangement_batcher_allocations_raw 2 +mz_arrangement_batcher_allocations_raw 2 +mz_arrangement_batcher_allocations_raw 2 +mz_arrangement_batcher_allocations_raw 2 +mz_arrangement_batcher_allocations_raw 2 +mz_arrangement_batcher_capacity_raw 1 +mz_arrangement_batcher_capacity_raw 1 +mz_arrangement_batcher_capacity_raw 1 +mz_arrangement_batcher_capacity_raw 1 +mz_arrangement_batcher_capacity_raw 1 +mz_arrangement_batcher_capacity_raw 1 +mz_arrangement_batcher_capacity_raw 2 +mz_arrangement_batcher_capacity_raw 2 +mz_arrangement_batcher_capacity_raw 2 +mz_arrangement_batcher_capacity_raw 2 +mz_arrangement_batcher_capacity_raw 2 +mz_arrangement_batcher_capacity_raw 2 +mz_arrangement_batcher_records_raw 1 +mz_arrangement_batcher_records_raw 1 +mz_arrangement_batcher_records_raw 1 +mz_arrangement_batcher_records_raw 1 +mz_arrangement_batcher_records_raw 1 +mz_arrangement_batcher_records_raw 1 +mz_arrangement_batcher_records_raw 2 +mz_arrangement_batcher_records_raw 2 +mz_arrangement_batcher_records_raw 2 +mz_arrangement_batcher_records_raw 2 +mz_arrangement_batcher_records_raw 2 +mz_arrangement_batcher_records_raw 2 +mz_arrangement_batcher_size_raw 1 +mz_arrangement_batcher_size_raw 1 +mz_arrangement_batcher_size_raw 1 +mz_arrangement_batcher_size_raw 1 +mz_arrangement_batcher_size_raw 1 +mz_arrangement_batcher_size_raw 1 +mz_arrangement_batcher_size_raw 2 +mz_arrangement_batcher_size_raw 2 +mz_arrangement_batcher_size_raw 2 +mz_arrangement_batcher_size_raw 2 +mz_arrangement_batcher_size_raw 2 +mz_arrangement_batcher_size_raw 2 +mz_arrangement_batches_raw 1 +mz_arrangement_batches_raw 1 +mz_arrangement_batches_raw 1 +mz_arrangement_batches_raw 1 +mz_arrangement_batches_raw 1 +mz_arrangement_batches_raw 1 +mz_arrangement_batches_raw 2 +mz_arrangement_batches_raw 2 +mz_arrangement_batches_raw 2 +mz_arrangement_batches_raw 2 +mz_arrangement_batches_raw 2 +mz_arrangement_batches_raw 2 +mz_arrangement_heap_allocations_raw 1 +mz_arrangement_heap_allocations_raw 1 +mz_arrangement_heap_allocations_raw 1 +mz_arrangement_heap_allocations_raw 1 +mz_arrangement_heap_allocations_raw 1 +mz_arrangement_heap_allocations_raw 1 +mz_arrangement_heap_allocations_raw 2 +mz_arrangement_heap_allocations_raw 2 +mz_arrangement_heap_allocations_raw 2 +mz_arrangement_heap_allocations_raw 2 +mz_arrangement_heap_allocations_raw 2 +mz_arrangement_heap_allocations_raw 2 +mz_arrangement_heap_capacity_raw 1 +mz_arrangement_heap_capacity_raw 1 +mz_arrangement_heap_capacity_raw 1 +mz_arrangement_heap_capacity_raw 1 +mz_arrangement_heap_capacity_raw 1 +mz_arrangement_heap_capacity_raw 1 +mz_arrangement_heap_capacity_raw 2 +mz_arrangement_heap_capacity_raw 2 +mz_arrangement_heap_capacity_raw 2 +mz_arrangement_heap_capacity_raw 2 +mz_arrangement_heap_capacity_raw 2 +mz_arrangement_heap_capacity_raw 2 +mz_arrangement_heap_size_raw 1 +mz_arrangement_heap_size_raw 1 +mz_arrangement_heap_size_raw 1 +mz_arrangement_heap_size_raw 1 +mz_arrangement_heap_size_raw 1 +mz_arrangement_heap_size_raw 1 +mz_arrangement_heap_size_raw 2 +mz_arrangement_heap_size_raw 2 +mz_arrangement_heap_size_raw 2 +mz_arrangement_heap_size_raw 2 +mz_arrangement_heap_size_raw 2 +mz_arrangement_heap_size_raw 2 +mz_arrangement_records_raw 1 +mz_arrangement_records_raw 1 +mz_arrangement_records_raw 1 +mz_arrangement_records_raw 1 +mz_arrangement_records_raw 1 +mz_arrangement_records_raw 1 +mz_arrangement_records_raw 2 +mz_arrangement_records_raw 2 +mz_arrangement_records_raw 2 +mz_arrangement_records_raw 2 +mz_arrangement_records_raw 2 +mz_arrangement_records_raw 2 +mz_arrangement_sharing_raw 1 +mz_arrangement_sharing_raw 1 +mz_arrangement_sharing_raw 1 +mz_arrangement_sharing_raw 1 +mz_arrangement_sharing_raw 1 +mz_arrangement_sharing_raw 1 +mz_arrangement_sharing_raw 2 +mz_arrangement_sharing_raw 2 +mz_arrangement_sharing_raw 2 +mz_arrangement_sharing_raw 2 +mz_arrangement_sharing_raw 2 +mz_arrangement_sharing_raw 2 +mz_cluster_deployment_lineage 1 +mz_cluster_prometheus_metrics 1 +mz_cluster_prometheus_metrics 1 +mz_cluster_prometheus_metrics 1 +mz_cluster_prometheus_metrics 1 +mz_cluster_prometheus_metrics 1 +mz_cluster_prometheus_metrics 1 +mz_cluster_prometheus_metrics 2 +mz_cluster_prometheus_metrics 2 +mz_cluster_prometheus_metrics 2 +mz_cluster_prometheus_metrics 2 +mz_cluster_prometheus_metrics 2 +mz_cluster_prometheus_metrics 2 +mz_cluster_prometheus_metrics 4 +mz_cluster_prometheus_metrics 4 +mz_cluster_prometheus_metrics 4 +mz_cluster_prometheus_metrics 4 +mz_cluster_prometheus_metrics 4 +mz_cluster_prometheus_metrics 4 +mz_cluster_replica_frontiers 1 +mz_cluster_replica_history 7 +mz_cluster_replica_metrics 1 +mz_cluster_replica_metrics_history 1 +mz_cluster_replica_name_history 2 +mz_cluster_replica_size_internal 1 +mz_cluster_replica_sizes 1 +mz_cluster_replica_status_history 1 +mz_cluster_replica_statuses 1 +mz_cluster_replicas 1 +mz_clusters 1 +mz_columns 2 +mz_comments 1 +mz_compute_dataflow_global_ids_per_worker 1 +mz_compute_dataflow_global_ids_per_worker 1 +mz_compute_dataflow_global_ids_per_worker 1 +mz_compute_dataflow_global_ids_per_worker 1 +mz_compute_dataflow_global_ids_per_worker 1 +mz_compute_dataflow_global_ids_per_worker 1 +mz_compute_dataflow_global_ids_per_worker 2 +mz_compute_dataflow_global_ids_per_worker 2 +mz_compute_dataflow_global_ids_per_worker 2 +mz_compute_dataflow_global_ids_per_worker 2 +mz_compute_dataflow_global_ids_per_worker 2 +mz_compute_dataflow_global_ids_per_worker 2 +mz_compute_dataflow_global_ids_per_worker 3 +mz_compute_dataflow_global_ids_per_worker 3 +mz_compute_dataflow_global_ids_per_worker 3 +mz_compute_dataflow_global_ids_per_worker 3 +mz_compute_dataflow_global_ids_per_worker 3 +mz_compute_dataflow_global_ids_per_worker 3 +mz_compute_dependencies 2 +mz_compute_error_counts_raw 1 +mz_compute_error_counts_raw 1 +mz_compute_error_counts_raw 1 +mz_compute_error_counts_raw 1 +mz_compute_error_counts_raw 1 +mz_compute_error_counts_raw 1 +mz_compute_error_counts_raw 2 +mz_compute_error_counts_raw 2 +mz_compute_error_counts_raw 2 +mz_compute_error_counts_raw 2 +mz_compute_error_counts_raw 2 +mz_compute_error_counts_raw 2 +mz_compute_exports_per_worker 1 +mz_compute_exports_per_worker 1 +mz_compute_exports_per_worker 1 +mz_compute_exports_per_worker 1 +mz_compute_exports_per_worker 1 +mz_compute_exports_per_worker 1 +mz_compute_exports_per_worker 2 +mz_compute_exports_per_worker 2 +mz_compute_exports_per_worker 2 +mz_compute_exports_per_worker 2 +mz_compute_exports_per_worker 2 +mz_compute_exports_per_worker 2 +mz_compute_frontiers_per_worker 1 +mz_compute_frontiers_per_worker 1 +mz_compute_frontiers_per_worker 1 +mz_compute_frontiers_per_worker 1 +mz_compute_frontiers_per_worker 1 +mz_compute_frontiers_per_worker 1 +mz_compute_frontiers_per_worker 2 +mz_compute_frontiers_per_worker 2 +mz_compute_frontiers_per_worker 2 +mz_compute_frontiers_per_worker 2 +mz_compute_frontiers_per_worker 2 +mz_compute_frontiers_per_worker 2 +mz_compute_hydration_times 1 +mz_compute_hydration_times_per_worker 1 +mz_compute_hydration_times_per_worker 1 +mz_compute_hydration_times_per_worker 1 +mz_compute_hydration_times_per_worker 1 +mz_compute_hydration_times_per_worker 1 +mz_compute_hydration_times_per_worker 1 +mz_compute_hydration_times_per_worker 2 +mz_compute_hydration_times_per_worker 2 +mz_compute_hydration_times_per_worker 2 +mz_compute_hydration_times_per_worker 2 +mz_compute_hydration_times_per_worker 2 +mz_compute_hydration_times_per_worker 2 +mz_compute_import_frontiers_per_worker 1 +mz_compute_import_frontiers_per_worker 1 +mz_compute_import_frontiers_per_worker 1 +mz_compute_import_frontiers_per_worker 1 +mz_compute_import_frontiers_per_worker 1 +mz_compute_import_frontiers_per_worker 1 +mz_compute_import_frontiers_per_worker 2 +mz_compute_import_frontiers_per_worker 2 +mz_compute_import_frontiers_per_worker 2 +mz_compute_import_frontiers_per_worker 2 +mz_compute_import_frontiers_per_worker 2 +mz_compute_import_frontiers_per_worker 2 +mz_compute_import_frontiers_per_worker 3 +mz_compute_import_frontiers_per_worker 3 +mz_compute_import_frontiers_per_worker 3 +mz_compute_import_frontiers_per_worker 3 +mz_compute_import_frontiers_per_worker 3 +mz_compute_import_frontiers_per_worker 3 +mz_compute_lir_mapping_per_worker 1 +mz_compute_lir_mapping_per_worker 1 +mz_compute_lir_mapping_per_worker 1 +mz_compute_lir_mapping_per_worker 1 +mz_compute_lir_mapping_per_worker 1 +mz_compute_lir_mapping_per_worker 1 +mz_compute_lir_mapping_per_worker 2 +mz_compute_lir_mapping_per_worker 2 +mz_compute_lir_mapping_per_worker 2 +mz_compute_lir_mapping_per_worker 2 +mz_compute_lir_mapping_per_worker 2 +mz_compute_lir_mapping_per_worker 2 +mz_compute_lir_mapping_per_worker 3 +mz_compute_lir_mapping_per_worker 3 +mz_compute_lir_mapping_per_worker 3 +mz_compute_lir_mapping_per_worker 3 +mz_compute_lir_mapping_per_worker 3 +mz_compute_lir_mapping_per_worker 3 +mz_compute_operator_durations_histogram_raw 1 +mz_compute_operator_durations_histogram_raw 1 +mz_compute_operator_durations_histogram_raw 1 +mz_compute_operator_durations_histogram_raw 1 +mz_compute_operator_durations_histogram_raw 1 +mz_compute_operator_durations_histogram_raw 1 +mz_compute_operator_durations_histogram_raw 2 +mz_compute_operator_durations_histogram_raw 2 +mz_compute_operator_durations_histogram_raw 2 +mz_compute_operator_durations_histogram_raw 2 +mz_compute_operator_durations_histogram_raw 2 +mz_compute_operator_durations_histogram_raw 2 +mz_compute_operator_durations_histogram_raw 3 +mz_compute_operator_durations_histogram_raw 3 +mz_compute_operator_durations_histogram_raw 3 +mz_compute_operator_durations_histogram_raw 3 +mz_compute_operator_durations_histogram_raw 3 +mz_compute_operator_durations_histogram_raw 3 +mz_compute_operator_hydration_statuses_per_worker 1 +mz_compute_operator_hydration_statuses_per_worker 1 +mz_compute_operator_hydration_statuses_per_worker 1 +mz_compute_operator_hydration_statuses_per_worker 1 +mz_compute_operator_hydration_statuses_per_worker 1 +mz_compute_operator_hydration_statuses_per_worker 1 +mz_compute_operator_hydration_statuses_per_worker 2 +mz_compute_operator_hydration_statuses_per_worker 2 +mz_compute_operator_hydration_statuses_per_worker 2 +mz_compute_operator_hydration_statuses_per_worker 2 +mz_compute_operator_hydration_statuses_per_worker 2 +mz_compute_operator_hydration_statuses_per_worker 2 +mz_compute_operator_hydration_statuses_per_worker 3 +mz_compute_operator_hydration_statuses_per_worker 3 +mz_compute_operator_hydration_statuses_per_worker 3 +mz_compute_operator_hydration_statuses_per_worker 3 +mz_compute_operator_hydration_statuses_per_worker 3 +mz_compute_operator_hydration_statuses_per_worker 3 +mz_connections 3 +mz_console_cluster_utilization_overview 18 +mz_console_cluster_utilization_overview_24h 18 +mz_console_cluster_utilization_overview_3h 2 +mz_databases 3 +mz_dataflow_addresses_per_worker 1 +mz_dataflow_addresses_per_worker 1 +mz_dataflow_addresses_per_worker 1 +mz_dataflow_addresses_per_worker 1 +mz_dataflow_addresses_per_worker 1 +mz_dataflow_addresses_per_worker 1 +mz_dataflow_addresses_per_worker 2 +mz_dataflow_addresses_per_worker 2 +mz_dataflow_addresses_per_worker 2 +mz_dataflow_addresses_per_worker 2 +mz_dataflow_addresses_per_worker 2 +mz_dataflow_addresses_per_worker 2 +mz_dataflow_channels_per_worker 1 +mz_dataflow_channels_per_worker 1 +mz_dataflow_channels_per_worker 1 +mz_dataflow_channels_per_worker 1 +mz_dataflow_channels_per_worker 1 +mz_dataflow_channels_per_worker 1 +mz_dataflow_channels_per_worker 2 +mz_dataflow_channels_per_worker 2 +mz_dataflow_channels_per_worker 2 +mz_dataflow_channels_per_worker 2 +mz_dataflow_channels_per_worker 2 +mz_dataflow_channels_per_worker 2 +mz_dataflow_operator_reachability_raw 1 +mz_dataflow_operator_reachability_raw 1 +mz_dataflow_operator_reachability_raw 1 +mz_dataflow_operator_reachability_raw 1 +mz_dataflow_operator_reachability_raw 1 +mz_dataflow_operator_reachability_raw 1 +mz_dataflow_operator_reachability_raw 2 +mz_dataflow_operator_reachability_raw 2 +mz_dataflow_operator_reachability_raw 2 +mz_dataflow_operator_reachability_raw 2 +mz_dataflow_operator_reachability_raw 2 +mz_dataflow_operator_reachability_raw 2 +mz_dataflow_operator_reachability_raw 3 +mz_dataflow_operator_reachability_raw 3 +mz_dataflow_operator_reachability_raw 3 +mz_dataflow_operator_reachability_raw 3 +mz_dataflow_operator_reachability_raw 3 +mz_dataflow_operator_reachability_raw 3 +mz_dataflow_operator_reachability_raw 4 +mz_dataflow_operator_reachability_raw 4 +mz_dataflow_operator_reachability_raw 4 +mz_dataflow_operator_reachability_raw 4 +mz_dataflow_operator_reachability_raw 4 +mz_dataflow_operator_reachability_raw 4 +mz_dataflow_operator_reachability_raw 5 +mz_dataflow_operator_reachability_raw 5 +mz_dataflow_operator_reachability_raw 5 +mz_dataflow_operator_reachability_raw 5 +mz_dataflow_operator_reachability_raw 5 +mz_dataflow_operator_reachability_raw 5 +mz_dataflow_operator_reachability_raw 6 +mz_dataflow_operator_reachability_raw 6 +mz_dataflow_operator_reachability_raw 6 +mz_dataflow_operator_reachability_raw 6 +mz_dataflow_operator_reachability_raw 6 +mz_dataflow_operator_reachability_raw 6 +mz_dataflow_operators_per_worker 1 +mz_dataflow_operators_per_worker 1 +mz_dataflow_operators_per_worker 1 +mz_dataflow_operators_per_worker 1 +mz_dataflow_operators_per_worker 1 +mz_dataflow_operators_per_worker 1 +mz_dataflow_operators_per_worker 2 +mz_dataflow_operators_per_worker 2 +mz_dataflow_operators_per_worker 2 +mz_dataflow_operators_per_worker 2 +mz_dataflow_operators_per_worker 2 +mz_dataflow_operators_per_worker 2 +mz_frontiers 1 +mz_hydration_statuses 1 +mz_hydration_statuses 2 +mz_indexes 1 +mz_kafka_sources 1 +mz_materialized_views 1 +mz_message_batch_counts_received_raw 1 +mz_message_batch_counts_received_raw 1 +mz_message_batch_counts_received_raw 1 +mz_message_batch_counts_received_raw 1 +mz_message_batch_counts_received_raw 1 +mz_message_batch_counts_received_raw 1 +mz_message_batch_counts_received_raw 2 +mz_message_batch_counts_received_raw 2 +mz_message_batch_counts_received_raw 2 +mz_message_batch_counts_received_raw 2 +mz_message_batch_counts_received_raw 2 +mz_message_batch_counts_received_raw 2 +mz_message_batch_counts_received_raw 3 +mz_message_batch_counts_received_raw 3 +mz_message_batch_counts_received_raw 3 +mz_message_batch_counts_received_raw 3 +mz_message_batch_counts_received_raw 3 +mz_message_batch_counts_received_raw 3 +mz_message_batch_counts_sent_raw 1 +mz_message_batch_counts_sent_raw 1 +mz_message_batch_counts_sent_raw 1 +mz_message_batch_counts_sent_raw 1 +mz_message_batch_counts_sent_raw 1 +mz_message_batch_counts_sent_raw 1 +mz_message_batch_counts_sent_raw 2 +mz_message_batch_counts_sent_raw 2 +mz_message_batch_counts_sent_raw 2 +mz_message_batch_counts_sent_raw 2 +mz_message_batch_counts_sent_raw 2 +mz_message_batch_counts_sent_raw 2 +mz_message_batch_counts_sent_raw 3 +mz_message_batch_counts_sent_raw 3 +mz_message_batch_counts_sent_raw 3 +mz_message_batch_counts_sent_raw 3 +mz_message_batch_counts_sent_raw 3 +mz_message_batch_counts_sent_raw 3 +mz_message_counts_received_raw 1 +mz_message_counts_received_raw 1 +mz_message_counts_received_raw 1 +mz_message_counts_received_raw 1 +mz_message_counts_received_raw 1 +mz_message_counts_received_raw 1 +mz_message_counts_received_raw 2 +mz_message_counts_received_raw 2 +mz_message_counts_received_raw 2 +mz_message_counts_received_raw 2 +mz_message_counts_received_raw 2 +mz_message_counts_received_raw 2 +mz_message_counts_received_raw 3 +mz_message_counts_received_raw 3 +mz_message_counts_received_raw 3 +mz_message_counts_received_raw 3 +mz_message_counts_received_raw 3 +mz_message_counts_received_raw 3 +mz_message_counts_sent_raw 1 +mz_message_counts_sent_raw 1 +mz_message_counts_sent_raw 1 +mz_message_counts_sent_raw 1 +mz_message_counts_sent_raw 1 +mz_message_counts_sent_raw 1 +mz_message_counts_sent_raw 2 +mz_message_counts_sent_raw 2 +mz_message_counts_sent_raw 2 +mz_message_counts_sent_raw 2 +mz_message_counts_sent_raw 2 +mz_message_counts_sent_raw 2 +mz_message_counts_sent_raw 3 +mz_message_counts_sent_raw 3 +mz_message_counts_sent_raw 3 +mz_message_counts_sent_raw 3 +mz_message_counts_sent_raw 3 +mz_message_counts_sent_raw 3 +mz_notices 1 +mz_object_arrangement_size_history 2 +mz_object_arrangement_size_history 4 +mz_object_arrangement_sizes 1 +mz_object_dependencies 1 +mz_object_history 1 +mz_object_lifetimes 1 +mz_object_transitive_dependencies 1 +mz_objects 3 +mz_peek_durations_histogram_raw 1 +mz_peek_durations_histogram_raw 1 +mz_peek_durations_histogram_raw 1 +mz_peek_durations_histogram_raw 1 +mz_peek_durations_histogram_raw 1 +mz_peek_durations_histogram_raw 1 +mz_peek_durations_histogram_raw 2 +mz_peek_durations_histogram_raw 2 +mz_peek_durations_histogram_raw 2 +mz_peek_durations_histogram_raw 2 +mz_peek_durations_histogram_raw 2 +mz_peek_durations_histogram_raw 2 +mz_peek_durations_histogram_raw 3 +mz_peek_durations_histogram_raw 3 +mz_peek_durations_histogram_raw 3 +mz_peek_durations_histogram_raw 3 +mz_peek_durations_histogram_raw 3 +mz_peek_durations_histogram_raw 3 +mz_recent_activity_log_thinned 22 +mz_recent_sql_text 1 +mz_recent_storage_usage 1 +mz_roles 1 +mz_scheduling_elapsed_raw 1 +mz_scheduling_elapsed_raw 1 +mz_scheduling_elapsed_raw 1 +mz_scheduling_elapsed_raw 1 +mz_scheduling_elapsed_raw 1 +mz_scheduling_elapsed_raw 1 +mz_scheduling_elapsed_raw 2 +mz_scheduling_elapsed_raw 2 +mz_scheduling_elapsed_raw 2 +mz_scheduling_elapsed_raw 2 +mz_scheduling_elapsed_raw 2 +mz_scheduling_elapsed_raw 2 +mz_scheduling_parks_histogram_raw 1 +mz_scheduling_parks_histogram_raw 1 +mz_scheduling_parks_histogram_raw 1 +mz_scheduling_parks_histogram_raw 1 +mz_scheduling_parks_histogram_raw 1 +mz_scheduling_parks_histogram_raw 1 +mz_scheduling_parks_histogram_raw 2 +mz_scheduling_parks_histogram_raw 2 +mz_scheduling_parks_histogram_raw 2 +mz_scheduling_parks_histogram_raw 2 +mz_scheduling_parks_histogram_raw 2 +mz_scheduling_parks_histogram_raw 2 +mz_scheduling_parks_histogram_raw 3 +mz_scheduling_parks_histogram_raw 3 +mz_scheduling_parks_histogram_raw 3 +mz_scheduling_parks_histogram_raw 3 +mz_scheduling_parks_histogram_raw 3 +mz_scheduling_parks_histogram_raw 3 +mz_schemas 3 +mz_secrets 4 +mz_show_all_objects 1 +mz_show_cluster_replicas 1 +mz_show_clusters 1 +mz_show_columns 1 +mz_show_connections 1 +mz_show_databases 1 +mz_show_indexes 7 +mz_show_materialized_views 4 +mz_show_roles 1 +mz_show_schemas 1 +mz_show_secrets 1 +mz_show_sinks 5 +mz_show_sources 5 +mz_show_tables 1 +mz_show_types 1 +mz_show_views 1 +mz_sink_statistics 1 +mz_sink_statistics 2 +mz_sink_status_history 2 +mz_sink_statuses 1 +mz_sinks 1 +mz_source_statistics 1 +mz_source_statistics 2 +mz_source_statistics_with_history 1 +mz_source_statistics_with_history 2 +mz_source_status_history 2 +mz_source_statuses 1 +mz_sources 1 +mz_tables 3 +mz_types 3 +mz_views 3 +mz_wallclock_global_lag_recent_history 1 +mz_webhook_sources 1 +pg_attrdef_all_databases 1 +pg_attrdef_all_databases 2 +pg_attrdef_all_databases 3 +pg_attrdef_all_databases 4 +pg_attrdef_all_databases 5 +pg_attribute_all_databases 1 +pg_attribute_all_databases 2 +pg_attribute_all_databases 3 +pg_attribute_all_databases 4 +pg_attribute_all_databases 5 +pg_attribute_all_databases 6 +pg_attribute_all_databases 8 +pg_attribute_all_databases 9 +pg_attribute_all_databases 10 +pg_attribute_all_databases 11 +pg_attribute_all_databases 12 +pg_attribute_all_databases 13 +pg_attribute_all_databases 14 +pg_attribute_all_databases 15 +pg_authid_core 2 +pg_class_all_databases 2 +pg_description_all_databases 1 +pg_description_all_databases 2 +pg_description_all_databases 3 +pg_description_all_databases 4 +pg_description_all_databases 5 +pg_description_all_databases 6 +pg_namespace_all_databases 2 +pg_type_all_databases 1 + +# Not supported by Materialize. +onlyif cockroach query TT colnames SELECT relname, information_schema._pg_expandarray(indkey) FROM pg_class, pg_index WHERE pg_class.oid = pg_index.indrelid ORDER BY relname, x, n ---- @@ -955,7 +1605,7 @@ vals (2,2) vals (3,1) # The following query needs indclass to become an oidvector. -# See bug materialize#26504. +# See bug #26504. # query III # SELECT # indexrelid, @@ -973,6 +1623,8 @@ CREATE TABLE j(x INT PRIMARY KEY, y JSON); (1, '{"a":123,"b":456}'), (2, '{"c":111,"d":222}') +# Not supported by Materialize. +onlyif cockroach query IT rowsort SELECT x, y->>json_object_keys(y) FROM j ---- @@ -991,14 +1643,12 @@ SELECT tbl, idx, (i.keys).n JOIN pg_class ct2 ON ix.indexrelid = ct2.oid) AS i ORDER BY 1,2,3 ---- -tbl idx n -vals primary 1 -vals woo 1 -vals woo 2 +tbl idx n + subtest dbviz_example_query -# DbVisualizer query from materialize#24649 listed in materialize#16971. +# DbVisualizer query from #24649 listed in #16971. query TTI SELECT a.attname, a.atttypid, atttypmod FROM pg_catalog.pg_class ct @@ -1015,12 +1665,12 @@ SELECT a.attname, a.atttypid, atttypmod AND i.indisprimary ORDER BY a.attnum ---- -x 20 -1 + subtest metabase_confluent_example_query -# Test from metabase listed on materialize#16971. -# Also Kafka Confluent sink query from materialize#25854. +# Test from metabase listed on #16971. +# Also Kafka Confluent sink query from #25854. query TTTTIT SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM, @@ -1040,13 +1690,13 @@ SELECT NULL AS TABLE_CAT, WHERE true AND ct.relname = 'j' AND i.indisprimary ORDER BY table_name, pk_name, key_seq ---- -NULL public j x 1 primary + subtest liquibase_example_query -# # Test from materialize#24713 (Liquibase) listed on materialize#16971. +# # Test from #24713 (Liquibase) listed on #16971. # # TODO(knz) Needs support for pg_get_indexdef with 3 arguments, -# # see database-issues#7870. +# # see #26629. # query TTTBTTIITTTTT # SELECT NULL AS table_cat, # n.nspname AS table_schem, @@ -1107,8 +1757,12 @@ unnest (1,2) (3,4) -query error pq: type tuple{int, int} is not composite +query II colnames SELECT (unnest(ARRAY[(1,2),(3,4)])).* +---- +f1 f2 +1 2 +3 4 query T colnames SELECT * FROM unnest(ARRAY[(1,2),(3,4)]) @@ -1123,3 +1777,217 @@ SELECT t.* FROM unnest(ARRAY[(1,2),(3,4)]) AS t t (1,2) (3,4) + + +subtest variadic_unnest + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT unnest(ARRAY[1,2], ARRAY['a','b']) +---- +(1,a) +(2,b) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT unnest(ARRAY[1,2], ARRAY['a'], ARRAY[1.1, 2.2, 3.3]) +---- +(1,a,1.1) +(2,,2.2) +(,,3.3) + +# Not supported by Materialize. +onlyif cockroach +query IT colnames +SELECT * FROM unnest(ARRAY[1,2], ARRAY['a', 'b']) +---- +unnest unnest +1 a +2 b + +# Not supported by Materialize. +onlyif cockroach +query ITT colnames +SELECT * FROM unnest(ARRAY[1,2], ARRAY['a'], ARRAY[1.1, 2.2, 3.3]) +---- +unnest unnest unnest +1 a 1.1 +2 NULL 2.2 +NULL NULL 3.3 + +# Not supported by Materialize. +onlyif cockroach +query II colnames +SELECT * FROM unnest(array[1,2], array[3,4,5]) AS t(a, b); +---- +a b +1 3 +2 4 +NULL 5 + +query I rowsort +SELECT unnest(ARRAY[1,2,3]) FROM unnest(ARRAY[4,5,6]) +---- +1 +1 +1 +2 +2 +2 +3 +3 +3 + +query I rowsort +SELECT unnest(ARRAY[NULL,2,3]) FROM unnest(ARRAY[NULL,NULL,NULL]) +---- +NULL +NULL +NULL +2 +2 +2 +3 +3 +3 + +query I rowsort +SELECT unnest(ARRAY[1,2,NULL]) FROM unnest(ARRAY[NULL,NULL,NULL]) +---- +1 +1 +1 +2 +2 +2 +NULL +NULL +NULL + +query I rowsort +SELECT unnest(ARRAY[NULL,NULL,NULL]) FROM unnest(ARRAY[NULL,NULL,NULL]) +---- +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL + +statement ok +CREATE TABLE xy (x INT PRIMARY KEY, y INT) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO xy (VALUES (1,1), (2,2), (3,4), (4,8), (5,NULL)) + +query II rowsort +SELECT * FROM xy WHERE x IN (SELECT unnest(ARRAY[NULL,x])) +---- + + +query II rowsort +SELECT * FROM xy +WHERE EXISTS +(SELECT t + FROM unnest(ARRAY[NULL,2,NULL,4,5,x]) + AS f(t) + WHERE t=y +) +---- + + +query IT rowsort +SELECT unnest(ARRAY[1,2,3,4]), unnest(ARRAY['one','two']) +---- +1 one +2 two +3 NULL +4 NULL + +query error type "varbit" does not exist +SELECT unnest(ARRAY[1,2,3::varbit(3)]) + +query error type "varbit" does not exist +SELECT unnest(ARRAY[NULL,2,3::varbit(3)]) + +query error function unnest\(unknown, unknown\) does not exist +SELECT unnest(NULL, NULL) + +query error function unnest\(integer\[\], unknown\) does not exist +SELECT unnest(ARRAY[1,2], NULL) + +query error function unnest\(unknown, unknown\) does not exist +SELECT * FROM unnest(NULL, NULL) + +query error function unnest\(integer\[\], integer\[\]\) does not exist +SELECT unnest FROM unnest(array[1,2], array[3,4,5]) + +# Regression test for #58438 - handle the case when unnest outputs a tuple with +# labels. The unnest should not panic. +statement ok +CREATE TABLE t58438(a INT, b INT); + +statement ok +INSERT INTO t58438 VALUES (1, 2), (3, 4), (5, 6); + +query T rowsort +SELECT unnest(ARRAY[t58438.*]) FROM t58438; +---- +(1,2) +(3,4) +(5,6) + +query II rowsort +SELECT (x).* FROM (SELECT unnest(ARRAY[t58438.*]) FROM t58438) v(x); +---- +1 2 +3 4 +5 6 + +subtest redundant_zip_expression + +statement ok +SET testing_optimizer_disable_rule_probability = 1.0; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t95615 (c1 INET PRIMARY KEY) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t95615 VALUES ('192.168.0.1'::INET) + +# Not supported by Materialize. +onlyif cockroach +# Test that a redundant function call in a ProjectSet doesn't crash due to +# being built into more than one zip expression. +query TTTI +SELECT * FROM t95615, LATERAL ROWS FROM (hostmask(c1), hostmask(c1)) WITH ORDINALITY +---- +192.168.0.1 0.0.0.0 0.0.0.0 1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f95615() RETURNS FLOAT IMMUTABLE LEAKPROOF LANGUAGE SQL AS 'SELECT 1.1' + +# Not supported by Materialize. +onlyif cockroach +# A redundant UDF call should be added only once in a zip expression and not +# error out. +query TFFI +SELECT * FROM t95615, LATERAL ROWS FROM (f95615(), f95615()) WITH ORDINALITY +---- +192.168.0.1 1.1 1.1 1 + +statement ok +RESET testing_optimizer_disable_rule_probability diff --git a/test/sqllogictest/cockroach/statement_source.slt b/test/sqllogictest/cockroach/statement_source.slt index 3612fc620ebf3..717b1abe1e998 100644 --- a/test/sqllogictest/cockroach/statement_source.slt +++ b/test/sqllogictest/cockroach/statement_source.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,60 +9,76 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/statement_source +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/statement_source # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - statement ok CREATE TABLE a (a INT PRIMARY KEY, b INT) +# Not supported by Materialize. +onlyif cockroach query error statement source "INSERT INTO a VALUES \(1, 2\)" does not return any columns SELECT 1 FROM [INSERT INTO a VALUES (1, 2)] +# Not supported by Materialize. +onlyif cockroach query error statement source "DELETE FROM a" does not return any columns SELECT 1 FROM [DELETE FROM a] +# Not supported by Materialize. +onlyif cockroach query II -SELECT @1, a+b FROM [INSERT INTO a VALUES (1,2) RETURNING b,a] +SELECT b, a+b FROM [INSERT INTO a VALUES (1,2) RETURNING b,a] ---- 2 3 +# Not supported by Materialize. +onlyif cockroach # Check that LIMIT does not apply to mutation statements query II WITH a AS (INSERT INTO a VALUES (2,3), (3,4) RETURNING a,b) SELECT * FROM a LIMIT 0 ---- +# Not supported by Materialize. +onlyif cockroach query II SELECT * FROM [INSERT INTO a VALUES (4,5), (5,6) RETURNING a,b] LIMIT 0 ---- +# Not supported by Materialize. +onlyif cockroach query II WITH a AS (UPSERT INTO a VALUES (2,3), (6,7) RETURNING a,b) SELECT * FROM a LIMIT 0 ---- +# Not supported by Materialize. +onlyif cockroach query II SELECT * FROM [UPSERT INTO a VALUES (4,5), (7,8) RETURNING a,b] LIMIT 0 ---- +# Not supported by Materialize. +onlyif cockroach query II WITH a AS (UPDATE a SET a = -a WHERE b % 2 = 1 RETURNING a,b) SELECT * FROM a LIMIT 0 ---- +# Not supported by Materialize. +onlyif cockroach query II SELECT * FROM [UPDATE a SET a = a*100 WHERE b < 3 RETURNING a,b] LIMIT 0 ---- @@ -70,19 +86,17 @@ SELECT * FROM [UPDATE a SET a = a*100 WHERE b < 3 RETURNING a,b] LIMIT 0 query II SELECT * FROM a ORDER BY b ---- -100 2 --2 3 -3 4 --4 5 -5 6 --6 7 -7 8 + +# Not supported by Materialize. +onlyif cockroach query II WITH a AS (DELETE FROM a WHERE b IN (4,5) RETURNING a,b) SELECT * FROM a LIMIT 0 ---- +# Not supported by Materialize. +onlyif cockroach query II SELECT * FROM [DELETE FROM a WHERE b IN (6,7) RETURNING a,b] LIMIT 0 ---- @@ -91,26 +105,37 @@ SELECT * FROM [DELETE FROM a WHERE b IN (6,7) RETURNING a,b] LIMIT 0 query II SELECT * FROM a ORDER BY b ---- -100 2 --2 3 -7 8 -# Regression for cockroach#30936: ensure that wrapped planNodes with non-needed columns work ok + +# Regression for #30936: ensure that wrapped planNodes with non-needed columns work ok statement ok -CREATE TABLE b (a int, b int) +CREATE TABLE b (a int, b int); +# Not supported by Materialize. +onlyif cockroach query II -SELECT * FROM b WHERE EXISTS (SELECT * FROM [INSERT INTO b VALUES (1,2) RETURNING a,b]); +SELECT * FROM (VALUES (1, 2)) WHERE EXISTS (SELECT * FROM [INSERT INTO b VALUES (1,2) RETURNING a,b]); ---- 1 2 +# Not supported by Materialize. +onlyif cockroach query I SELECT 1 FROM [INSERT INTO b VALUES(2,3) RETURNING b] JOIN [INSERT INTO b VALUES(4,5) RETURNING b] ON true; ---- 1 +# Not supported by Materialize. +onlyif cockroach query III SELECT * FROM [INSERT INTO b VALUES(2,3) RETURNING b] JOIN [INSERT INTO b VALUES(4,5) RETURNING b, a] ON true; ---- 3 5 4 + +subtest unsupported_47333 + +# Not supported by Materialize. +onlyif cockroach +query error unimplemented: cannot use SHOW SAVEPOINT STATUS as a statement source +SELECT * FROM [SHOW SAVEPOINT STATUS] diff --git a/test/sqllogictest/cockroach/storing.slt b/test/sqllogictest/cockroach/storing.slt new file mode 100644 index 0000000000000..6993ccc6ee7a8 --- /dev/null +++ b/test/sqllogictest/cockroach/storing.slt @@ -0,0 +1,268 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/storing +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE t ( + a INT PRIMARY KEY, + b INT, + c INT, + d INT, + INDEX b_idx (b) STORING (c, d), + UNIQUE INDEX c_idx (c) STORING (b, d) +) + +# Not supported by Materialize. +onlyif cockroach +query TTBITTTBBB colnames +SHOW INDEXES FROM t +---- +table_name index_name non_unique seq_in_index column_name definition direction storing implicit visible +t b_idx true 1 b b ASC false false true +t b_idx true 2 c c N/A true false true +t b_idx true 3 d d N/A true false true +t b_idx true 4 a a ASC false true true +t c_idx false 1 c c ASC false false true +t c_idx false 2 b b N/A true false true +t c_idx false 3 d d N/A true false true +t c_idx false 4 a a ASC true true true +t t_pkey false 1 a a ASC false false true +t t_pkey false 2 b b N/A true false true +t t_pkey false 3 c c N/A true false true +t t_pkey false 4 d d N/A true false true + +statement ok +INSERT INTO t VALUES (1, 2, 3, 4) + +# Not supported by Materialize. +onlyif cockroach +query IIII +SELECT a, b, c, d FROM t@b_idx +---- +1 2 3 4 + +# Not supported by Materialize. +onlyif cockroach +query IIII +SELECT a, b, c, d FROM t@c_idx +---- +1 2 3 4 + +# Test index backfill for UNIQUE and non-UNIQUE indexes with STORING columns. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX d_idx ON t (d) STORING ( b) + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT a, b, d FROM t@d_idx +---- +1 2 4 + +statement error Expected end of statement, found identifier "storing" +CREATE INDEX error ON t (d) STORING (d) + +statement error Expected end of statement, found identifier "storing" +CREATE INDEX error ON t (d) STORING (a) + +# Not supported by Materialize. +onlyif cockroach +statement error index "b_idx" already contains column "a" +CREATE TABLE t30984 ( + a INT PRIMARY KEY, + b INT, + c INT, + INDEX b_idx (b) STORING (c, a) +) + +# Not supported by Materialize. +onlyif cockroach +statement error index "b_idx" already contains column "a" +CREATE TABLE t30984 ( + a INT PRIMARY KEY, + b INT, + c INT, + UNIQUE INDEX b_idx (b) STORING (c, a) +) + +# Not supported by Materialize. +onlyif cockroach +statement error index "b_idx" already contains column "d" +CREATE TABLE t30984 ( + a INT, + b INT, + c INT, + d INT, + PRIMARY KEY (a, d), + UNIQUE INDEX b_idx (b) STORING (c, d) +) + +statement ok +CREATE UNIQUE INDEX a_idx ON t (a) STORING (b) + +# Regression test for #14601. + +statement ok +CREATE TABLE t14601 (a STRING, b BOOL) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX i14601 ON t14601 (a) STORING (b) + +statement ok +INSERT INTO t14601 VALUES + ('a', FALSE), + ('b', FALSE), + ('c', FALSE) + +statement ok +DELETE FROM t14601 WHERE a > 'a' AND a < 'c' + +query T +SELECT a FROM t14601 ORDER BY a +---- +a +c + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX i14601 + +query T +SELECT a FROM t14601 ORDER BY a +---- +a +c + +# Updates were broken too. + +statement ok +CREATE TABLE t14601a ( + a STRING, + b BOOL, + c INT, + FAMILY f1 (a), + FAMILY f2 (b), + FAMILY f3 (c) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX i14601a ON t14601a (a) STORING (b, c) + +statement ok +INSERT INTO t14601a VALUES + ('a', FALSE, 1), + ('b', TRUE, 2), + ('c', FALSE, 3) + +statement ok +UPDATE t14601a SET b = NOT b WHERE a > 'a' AND a < 'c' + +query TB +SELECT a, b FROM t14601a ORDER BY a +---- +a false +b false +c false + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX i14601a + +query TB +SELECT a, b FROM t14601a ORDER BY a +---- +a false +b false +c false + +statement ok +DELETE FROM t14601a + +statement ok +CREATE UNIQUE INDEX i14601a ON t14601a (a) STORING (b) + +statement ok +INSERT INTO t14601a VALUES + ('a', FALSE), + ('b', TRUE), + ('c', FALSE) + +statement ok +UPDATE t14601a SET b = NOT b WHERE a > 'a' AND a < 'c' + +query TB +SELECT a, b FROM t14601a ORDER BY a +---- +a false +b false +c false + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX i14601a CASCADE + +query TB +SELECT a, b FROM t14601a ORDER BY a +---- +a false +b false +c false + +# Test that unspecified storing values are treated like NULL values. +statement ok +INSERT INTO t (a) VALUES (2) + +statement ok +INSERT INTO t VALUES (3) + +# Regression test for #30984: indirectly ensure that index descriptors don't +# get recreated every time any other schema change occurs. + +statement ok +CREATE TABLE a(a INT, b INT, c INT, PRIMARY KEY(a, b)) + +statement ok +CREATE UNIQUE INDEX foo ON a(a) STORING(c) + +statement ok +INSERT INTO a VALUES(1,2,3) + +statement ok +CREATE UNIQUE INDEX ON a(a) STORING(c) + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT * FROM a@foo +---- +1 2 3 diff --git a/test/sqllogictest/cockroach/suboperators.slt b/test/sqllogictest/cockroach/suboperators.slt index 4583e01b87f41..8205829254cfd 100644 --- a/test/sqllogictest/cockroach/suboperators.slt +++ b/test/sqllogictest/cockroach/suboperators.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,12 +9,15 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/suboperators +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/suboperators # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach @@ -82,21 +85,29 @@ SELECT 1 = ANY(ARRAY[2, NULL]) ---- NULL +# Not supported by Materialize. +onlyif cockroach query T SELECT 1 = ANY(ARRAY[NULL, NULL]) ---- NULL +# Not supported by Materialize. +onlyif cockroach query B SELECT 1 = ANY(ARRAY[1,2] || 3) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 1 = ANY(ARRAY[2,3] || 1) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 1 = ANY(ARRAY[2,3] || 4) ---- @@ -121,14 +132,22 @@ query III SELECT * FROM abc WHERE a = ANY(ARRAY[4, NULL]) ---- +# Not supported by Materialize. +onlyif cockroach query III SELECT * FROM abc WHERE a = ANY(ARRAY[NULL, NULL]) ---- -query error unsupported comparison operator: 1 = ANY ARRAY\['foo', 'bar'\] +query error operator does not exist: integer = text SELECT 1 = ANY(ARRAY['foo', 'bar']) -query error unsupported comparison operator: = ANY +query error operator does not exist: text\[\] \|\| text +SELECT 1 = ANY(ARRAY['foo'] || 'bar'::string) + +# Note that this relatively poor error message is caused by the fact that +# strings are constant castable to string arrays. Postgres also makes this +# same minor mistake in error generation. +query error unsupported binary operator: || (desired ) SELECT 1 = ANY(ARRAY['foo'] || 'bar') # ANY/SOME with subqueries. @@ -184,7 +203,7 @@ SELECT 1 = ANY(SELECT * FROM unnest(ARRAY[2, NULL])) NULL query T -SELECT 1 = ANY(SELECT * FROM unnest(ARRAY[NULL, NULL])) +SELECT 1 = ANY(SELECT * FROM unnest(ARRAY[NULL, NULL]::int[])) ---- NULL @@ -233,10 +252,10 @@ SELECT * FROM abc WHERE a = ANY(SELECT * FROM unnest(ARRAY[4, NULL])) ---- query III -SELECT * FROM abc WHERE a = ANY(SELECT * FROM unnest(ARRAY[NULL, NULL])) +SELECT * FROM abc WHERE a = ANY(SELECT * FROM unnest(ARRAY[NULL, NULL]::int[])) ---- -query error unsupported comparison operator: = ANY +query error operator does not exist: integer = text SELECT 1 = ANY(SELECT * FROM unnest(ARRAY['foo', 'bar'])) # ALL with arrays. @@ -276,16 +295,22 @@ SELECT 1 = ALL(ARRAY[1, NULL]) ---- NULL +# Not supported by Materialize. +onlyif cockroach query T SELECT 1 = ALL(ARRAY[NULL, NULL]) ---- NULL +# Not supported by Materialize. +onlyif cockroach query B SELECT 5 > ALL(ARRAY[1, 2] || 3) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 5 > ALL(ARRAY[6, 7] || 8) ---- @@ -305,15 +330,17 @@ query III SELECT * FROM abc WHERE a > ALL(ARRAY[1, NULL]) ---- +# Not supported by Materialize. +onlyif cockroach query III SELECT * FROM abc WHERE a > ALL(ARRAY[NULL, NULL]) ---- -query error unsupported comparison operator: 1 = ALL ARRAY\['foo', 'bar'\] +query error operator does not exist: integer = text SELECT 1 = ALL(ARRAY['foo', 'bar']) -query error unsupported comparison operator: = ALL -SELECT 1 = ALL(ARRAY['foo'] || 'bar') +query error operator does not exist: text\[\] \|\| text +SELECT 1 = ALL(ARRAY['foo'] || 'bar'::text) # ALL with subqueries. @@ -348,7 +375,7 @@ SELECT 1 = ALL(SELECT * FROM unnest(ARRAY[1, NULL])) NULL query T -SELECT 1 = ALL(SELECT * FROM unnest(ARRAY[NULL, NULL])) +SELECT 1 = ALL(SELECT * FROM unnest(ARRAY[NULL, NULL]::int[])) ---- NULL @@ -373,71 +400,140 @@ SELECT * FROM abc WHERE a > ALL(SELECT * FROM unnest(ARRAY[1, NULL])) ---- query III -SELECT * FROM abc WHERE a > ALL(SELECT * FROM unnest(ARRAY[NULL, NULL])) +SELECT * FROM abc WHERE a > ALL(SELECT * FROM unnest(ARRAY[NULL, NULL]::int[])) ---- -query error unsupported comparison operator: = ALL +query error operator does not exist: integer = text SELECT 1 = ALL(SELECT * FROM unnest(ARRAY['foo', 'bar'])) # ANY/ALL with tuples. +# Not supported by Materialize. +onlyif cockroach query B SELECT 1 = ANY (1, 2, 3) ---- true -query error unsupported comparison operator: = +query error ANY requires a single expression or subquery, not an expression list SELECT 1 = ANY (1, 2, 3.3, 'foo') +# Not supported by Materialize. +onlyif cockroach query B SELECT 1 = ANY (((1, 2, 3))) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 1 = ANY (2, 3, 4) ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 1 = ANY (((2, 3, 4))) ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT 1 = ANY (1, 1.1) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 1::decimal = ANY (1, 1.1) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 1 = ANY (1.0, 1.1) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 1 = ANY (((1.0, 1.1))) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 1::decimal = ANY (1.0, 1.1) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT 1::decimal = ANY (((1.0, 1.1))) ---- true -query error unsupported comparison operator: = +query error ANY requires a single expression or subquery, not an expression list SELECT 1 = ANY (1, 'hello', 3) +# Not supported by Materialize. +onlyif cockroach query B SELECT 1 = ANY ROW() ---- false + +# Regression test for #37793 - don't fold sub-operators with untyped NULL +# operands during type-checking. +query B +SELECT NULL = ANY(ARRAY []::INTEGER[]); +---- +false + +query B +SELECT NULL = SOME(ARRAY []::INTEGER[]); +---- +false + +query B +SELECT NULL = ALL(ARRAY []::INTEGER[]); +---- +true + +query B +SELECT NULL = ANY(ARRAY [1]::INTEGER[]); +---- +NULL + +query B +SELECT NULL = SOME(ARRAY [1]::INTEGER[]); +---- +NULL + +query B +SELECT NULL = ALL(ARRAY [1]::INTEGER[]); +---- +NULL + +query B +SELECT NULL = ANY(NULL::INTEGER[]); +---- +false + +query B +SELECT NULL = SOME(NULL::INTEGER[]); +---- +false + +query B +SELECT NULL = ALL(NULL::INTEGER[]); +---- +true diff --git a/test/sqllogictest/cockroach/subquery.slt b/test/sqllogictest/cockroach/subquery.slt index 28a424d9ee6dd..8177169900257 100644 --- a/test/sqllogictest/cockroach/subquery.slt +++ b/test/sqllogictest/cockroach/subquery.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/subquery +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/subquery # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - # Tests for subqueries (SELECT statements which are part of a bigger statement). query I @@ -59,22 +57,26 @@ SELECT (1, 2, 3) IN (SELECT 1, 2, 3) ---- true -# TODO(ggevay): scalar subquery returning multiple columns. We could add support for this. -# (same for many of the following commented out queries) -# query B -# SELECT (1, 2, 3) = (SELECT 1, 2, 3) -# ---- -# true -# -# query B -# SELECT (1, 2, 3) != (SELECT 1, 2, 3) -# ---- -# false -# -# query B -# SELECT (SELECT 1, 2, 3) = (SELECT 1, 2, 3) -# ---- -# true +# Not supported by Materialize. +onlyif cockroach +query B +SELECT (1, 2, 3) = (SELECT 1, 2, 3) +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT (1, 2, 3) != (SELECT 1, 2, 3) +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT (SELECT 1, 2, 3) = (SELECT 1, 2, 3) +---- +true query B SELECT (SELECT 1) IN (SELECT 1) @@ -91,48 +93,55 @@ true # supporting the specific Postgres behavior appears onerous. Fingers # crossed this doesn't bite us down the road. -# TODO(ggevay): Materialize error msg is unclear to me. -# # Postgres cannot handle this query (but MySQL can), even though it -# # seems sensical: -# # ERROR: subquery must return only one column -# # LINE 1: select (select 1, 2) IN (select 1, 2); -# # ^ -# query B -# SELECT (SELECT 1, 2) IN (SELECT 1, 2) -# ---- -# true -# -# # Postgres cannot handle this query, even though it seems sensical: -# # ERROR: subquery must return only one column -# # LINE 1: select (select 1, 2) IN ((1, 2)); -# # ^ -# query B -# SELECT (SELECT 1, 2) IN ((1, 2)) -# ---- -# true -# -# # Postgres cannot handle this query, even though it seems sensical: -# # ERROR: subquery has too many columns -# # LINE 1: select (select (1, 2)) IN (select 1, 2); -# # ^ -# query B -# SELECT (SELECT (1, 2)) IN (SELECT 1, 2) -# ---- -# true +# Not supported by Materialize. +onlyif cockroach +# Postgres cannot handle this query (but MySQL can), even though it +# seems sensical: +# ERROR: subquery must return only one column +# LINE 1: select (select 1, 2) IN (select 1, 2); +# ^ +query B +SELECT (SELECT 1, 2) IN (SELECT 1, 2) +---- +true + +# Not supported by Materialize. +onlyif cockroach +# Postgres cannot handle this query, even though it seems sensical: +# ERROR: subquery must return only one column +# LINE 1: select (select 1, 2) IN ((1, 2)); +# ^ +query B +SELECT (SELECT 1, 2) IN ((1, 2)) +---- +true + +# Not supported by Materialize. +onlyif cockroach +# Postgres cannot handle this query, even though it seems sensical: +# ERROR: subquery has too many columns +# LINE 1: select (select (1, 2)) IN (select 1, 2); +# ^ +query B +SELECT (SELECT (1, 2)) IN (SELECT 1, 2) +---- +true query B SELECT (SELECT (1, 2)) IN ((1, 2)) ---- true -# # Postgres cannot handle this query, even though it seems sensical: -# # ERROR: subquery must return only one column -# # LINE 1: select (select 1, 2) in (select (1, 2)); -# # ^ -# query B -# SELECT (SELECT 1, 2) IN (SELECT (1, 2)) -# ---- -# true +# Not supported by Materialize. +onlyif cockroach +# Postgres cannot handle this query, even though it seems sensical: +# ERROR: subquery must return only one column +# LINE 1: select (select 1, 2) in (select (1, 2)); +# ^ +query B +SELECT (SELECT 1, 2) IN (SELECT (1, 2)) +---- +true query B SELECT (SELECT (1, 2)) IN (SELECT (1, 2)) @@ -169,7 +178,7 @@ SELECT (1, 2) = ALL(SELECT 1, 2) ---- true -query error pgcode 42601 db error: ERROR: Expected subselect to return 1 column, got 2 columns +query error pgcode 42601 Expected subselect to return 1 column, got 2 columns SELECT (SELECT 1, 2) query error subquery1 has 2 columns available but 1 columns specified @@ -184,6 +193,10 @@ CREATE TABLE abc (a INT PRIMARY KEY, b INT, c INT) statement ok INSERT INTO abc VALUES (1, 2, 3), (4, 5, 6) +# TODO(nvanbenschoten): until we have conditional logic in these files, disable +# this statement so that we can continue to test this file with the 3node-tenant +# config. +# # statement ok # ALTER TABLE abc SPLIT AT VALUES ((SELECT 1)) @@ -246,38 +259,24 @@ SELECT * FROM xyz statement ok INSERT INTO xyz (x, y, z) VALUES (10, 11, 12) -# Materialize doesn't allow subqueries in `SET`. -# statement ok -# UPDATE xyz SET z = (SELECT 10) WHERE x = 7 - +# Not supported by Materialize. +onlyif cockroach statement ok -UPDATE xyz SET z = 10 WHERE x = 7 +UPDATE xyz SET z = (SELECT 10) WHERE x = 7 query III rowsort SELECT * FROM xyz ---- -1 2 3 -4 5 6 -7 8 10 -10 11 12 +1 2 3 +10 11 12 +4 5 6 +7 8 9 -# statement error value type tuple{int, int} doesn't match type int of column "z" -# UPDATE xyz SET z = (SELECT (10, 11)) WHERE x = 7 -# -# statement error [subquery must return 2 columns, found 1 | number of columns (2) does not match number of values (1)] -# UPDATE xyz SET (y, z) = (SELECT (11, 12)) WHERE x = 7 +statement error SET clause does not allow subqueries +UPDATE xyz SET z = (SELECT (10, 11)) WHERE x = 7 -#regression, see database-issues#2135 -#statement ok -#UPDATE xyz SET (y, z) = (SELECT 11, 12) WHERE x = 7 -# -#query III rowsort -#SELECT * FROM xyz -#---- -#1 2 3 -#4 5 6 -#7 11 12 -#10 11 12 +statement error Expected identifier, found left parenthesis +UPDATE xyz SET (y, z) = (SELECT (11, 12)) WHERE x = 7 query B SELECT 1 IN (SELECT x FROM xyz ORDER BY x DESC) @@ -297,7 +296,20 @@ SELECT * FROM xyz WHERE x = (SELECT max(x) FROM xyz) query III SELECT * FROM xyz WHERE x = (SELECT max(x) FROM xyz WHERE EXISTS(SELECT * FROM xyz WHERE z=x+3)) ---- -10 11 12 + + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE xyz SET (y, z) = (SELECT 11, 12) WHERE x = 7 + +query III rowsort +SELECT * FROM xyz +---- +1 2 3 +10 11 12 +4 5 6 +7 8 9 statement ok CREATE TABLE kv (k INT PRIMARY KEY, v STRING) @@ -441,24 +453,28 @@ SELECT x FROM xyz WHERE x IN (SELECT x FROM xyz WHERE x = 7) ---- 7 -# TODO(ggevay): Materialize doesn't allow subqueries in _top-level_ LIMIT or OFFSET clauses. -# query I -# SELECT x FROM xyz WHERE x = 7 LIMIT (SELECT x FROM xyz WHERE x = 1) -# ---- -# 7 -# -# query I -# SELECT x FROM xyz ORDER BY x OFFSET (SELECT x FROM xyz WHERE x = 1) -# ---- -# 4 -# 7 -# 10 - -# TODO(ggevay): Materialize doesn't allow subqueries in RETURNING clause. -# query B -# INSERT INTO xyz (x, y, z) VALUES (13, 11, 12) RETURNING (y IN (SELECT y FROM xyz)) -# ---- -# true +# Not supported by Materialize. +onlyif cockroach +query I +SELECT x FROM xyz WHERE x = 7 LIMIT (SELECT x FROM xyz WHERE x = 1) +---- +7 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT x FROM xyz ORDER BY x OFFSET (SELECT x FROM xyz WHERE x = 1) +---- +4 +7 +10 + +# Not supported by Materialize. +onlyif cockroach +query B +INSERT INTO xyz (x, y, z) VALUES (13, 11, 12) RETURNING (y IN (SELECT y FROM xyz)) +---- +true # This test checks that the double sub-query plan expansion caused by a # sub-expression being shared by two or more plan nodes does not @@ -476,9 +492,236 @@ query I SELECT col0 FROM tab4 WHERE (col0 <= 0 AND col4 <= 5.38) OR (col4 IN (SELECT col1 FROM tab4 WHERE col1 > 8.27)) AND (col3 <= 5 AND (col3 BETWEEN 7 AND 9)) ---- +subtest correlated + +statement ok +CREATE TABLE corr ( + k INT PRIMARY KEY, + i INT +) + +statement ok +INSERT INTO corr VALUES (1, 10), (2, 22), (3, 30), (4, 40), (5, 50) + +query II rowsort +SELECT * FROM corr +WHERE CASE WHEN k < 5 THEN k*10 = (SELECT i FROM corr tmp WHERE k = corr.k) END +---- +1 10 +3 30 +4 40 + +query III colnames,rowsort +SELECT k, i, CASE WHEN k > 1 THEN (SELECT i FROM corr tmp WHERE k = corr.k-1) END AS prev_i +FROM corr +---- +k i prev_i +1 10 NULL +2 22 10 +3 30 22 +4 40 30 +5 50 40 + +# A test similar to the previous showing that the physical ordering requested by +# the ORDER BY is respected when re-optimizing the subquery. +query IIR colnames,rowsort +SELECT k, i, + CASE WHEN k > 1 THEN (SELECT i/1 FROM corr tmp WHERE i < corr.i ORDER BY i DESC LIMIT 1) END prev_i +FROM corr +---- +k i prev_i +1 10 NULL +2 22 10 +3 30 22 +4 40 30 +5 50 40 + +# Not supported by Materialize. +onlyif cockroach +# The same query as above, but as a prepared statement with placeholders in the +# subquery. +statement ok +PREPARE corr_s1(INT) AS +SELECT k, i, + CASE WHEN k > 1 THEN (SELECT i/$1 FROM corr tmp WHERE i < corr.i ORDER BY i DESC LIMIT $1) END prev_i +FROM corr + +# Not supported by Materialize. +onlyif cockroach +query IIR colnames,rowsort +EXECUTE corr_s1(1) +---- +k i prev_i +1 10 NULL +2 22 10 +3 30 22 +4 40 30 +5 50 40 + +# A subquery with a star-expansion. +query IIR colnames,rowsort +SELECT k, i, + CASE WHEN k > 1 THEN ( + SELECT * FROM (VALUES (33::DECIMAL)) v(i) + UNION ALL + SELECT i/1 FROM corr tmp WHERE i < corr.i + ORDER BY i DESC LIMIT 1 + ) END prev_i +FROM corr +---- +k i prev_i +1 10 NULL +2 22 33 +3 30 33 +4 40 33 +5 50 40 + +query II +SELECT * FROM corr +WHERE CASE WHEN k < 5 THEN EXISTS (SELECT i FROM corr tmp WHERE i = corr.k*10) END +---- +1 10 +3 30 +4 40 + +query IIB +SELECT *, + CASE WHEN k < 5 THEN EXISTS (SELECT i FROM corr tmp WHERE i = corr.k*10) END +FROM corr +---- +1 10 true +2 22 false +3 30 true +4 40 true +5 50 NULL + +# Not supported by Materialize. +onlyif cockroach +# TODO(mgartner): Execute correlated ANY subqueries. +statement error could not decorrelate subquery +SELECT * FROM corr +WHERE CASE WHEN k < 5 THEN k*10 = ANY (SELECT i FROM corr tmp WHERE k <= corr.k) END + +# Not supported by Materialize. +onlyif cockroach +# Correlated subqueries can reference outer with expressions. +query III colnames,rowsort +WITH w AS MATERIALIZED ( + (VALUES (1)) +) +SELECT k, i, + CASE WHEN k > 0 THEN (SELECT i+corr.i FROM corr tmp UNION ALL SELECT * FROM w LIMIT 1) END i_plus_first_i +FROM corr +---- +k i i_plus_first_i +1 10 20 +2 22 32 +3 30 40 +4 40 50 +5 50 60 + +# Not supported by Materialize. +onlyif cockroach +# Uncorrelated subqueries within correlated subqueries can reference outer with +# expressions. +query III colnames,rowsort +WITH w AS MATERIALIZED ( + (VALUES (1)) +) +SELECT k, i, + CASE WHEN k > 0 THEN (SELECT i+corr.i FROM corr tmp WHERE k = (SELECT * FROM w)) END i_plus_first_i +FROM corr +---- +k i i_plus_first_i +1 10 20 +2 22 32 +3 30 40 +4 40 50 +5 50 60 + +# Not supported by Materialize. +onlyif cockroach +# WITH within subquery that is shadowing outer WITH. +query III colnames,rowsort +WITH w(i) AS MATERIALIZED ( + (VALUES (1)) +) +SELECT k, i, + CASE WHEN k > 0 THEN ( + WITH w(i) AS MATERIALIZED ( + (VALUES (2)) + ) + SELECT * FROM w UNION ALL SELECT i+corr.i FROM corr tmp LIMIT 1 + ) END w +FROM corr +UNION ALL +SELECT NULL, NULL, i FROM w +---- +k i w +1 10 2 +2 22 2 +3 30 2 +4 40 2 +5 50 2 +NULL NULL 1 + +statement ok +CREATE TABLE corr2 (i INT); + +# Not supported by Materialize. +onlyif cockroach +# A NOT MATERIALIZED CTE with a mutation. +statement ok +WITH tmp AS NOT MATERIALIZED (INSERT INTO corr2 VALUES (1) RETURNING i) +SELECT * FROM corr +WHERE CASE WHEN k < 5 THEN k+1 = (SELECT i FROM tmp WHERE i = corr.k) END + +# The statement above should perform the INSERT only once. +query I +SELECT count(*) FROM corr2 +---- +0 + +# Uncorrelated EXISTS subqueries within correlated subqueries can be executed. +query I +SELECT i FROM (VALUES (1), (2)) v(i) +WHERE CASE + WHEN i < 3 THEN (SELECT 1/i = 1 FROM (VALUES (1)) WHERE EXISTS (SELECT * FROM corr)) + ELSE false +END +---- +1 + +# Correlated EXISTS subqueries within correlated subqueries can be executed. +query I +SELECT i FROM (VALUES (1), (10)) v(i) +WHERE CASE + WHEN i > 0 THEN ( + SELECT i/1 = j FROM (VALUES (1), (10)) w(j) + WHERE CASE + WHEN j > 0 THEN EXISTS (SELECT * FROM corr WHERE k/1 = j) + ELSE false + END + ) + ELSE false +END +---- +1 + + +subtest regressions + statement ok CREATE TABLE z (z INT PRIMARY KEY) +# Not supported by Materialize. +onlyif cockroach +# Regression test for #24171. +query I +SELECT * FROM z WHERE CAST(COALESCE((SELECT 'a' FROM crdb_internal.zones LIMIT 1 OFFSET 5), (SELECT 'b' FROM pg_catalog.pg_trigger)) AS BYTEA) <= 'a' +---- + +# Regression test for #24170. query I SELECT * FROM z WHERE CAST(COALESCE((SELECT 'a'), (SELECT 'a')) AS bytea) < 'a' ---- @@ -489,12 +732,12 @@ CREATE TABLE test (a INT PRIMARY KEY) statement ok CREATE TABLE test2(b INT PRIMARY KEY) -# Regression test for materialize#24225. +# Regression test for #24225. query I SELECT * FROM test2 WHERE 0 = CASE WHEN true THEN (SELECT a FROM test LIMIT 1) ELSE 10 END ---- -# Regression test for database-issues#8301. +# Regression test for #28335. query I SELECT (SELECT ARRAY(SELECT 1))[1] ---- @@ -508,50 +751,249 @@ false statement error unknown schema 'crdb_internal' SELECT * FROM xyz WHERE x IN (SELECT crdb_internal.force_error('', 'subqueryfail')) +# Not supported by Materialize. +onlyif cockroach statement ok -PREPARE a AS SELECT 1 = (SELECT $1::int) +PREPARE a AS SELECT 1 = (SELECT $1:::int) +# Not supported by Materialize. +onlyif cockroach query B EXECUTE a(1) ---- true +# Not supported by Materialize. +onlyif cockroach query B EXECUTE a(2) ---- false +# Not supported by Materialize. +onlyif cockroach statement ok -PREPARE b AS SELECT EXISTS (SELECT $1::int) +PREPARE b AS SELECT EXISTS (SELECT $1:::int) +# Not supported by Materialize. +onlyif cockroach query B EXECUTE b(3) ---- true -# Regression test for materialize#29205 - make sure the memory account for wrapped local +# Regression test for #29205 - make sure the memory account for wrapped local # planNode within subqueries is properly hooked up. statement ok CREATE TABLE a (a TEXT PRIMARY KEY) -# Materialize doesn't support this non-standard [...] syntax. -# statement ok -# SELECT (SELECT repeat(a::STRING, 2) FROM [INSERT INTO a VALUES('foo') RETURNING a]); - -# statement ok -# UPDATE abc SET a = 2, (b, c) = (SELECT 5, 6) WHERE a = 1; +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT (SELECT repeat(a::STRING, 2) FROM [INSERT INTO a VALUES('foo') RETURNING a]); +# Not supported by Materialize. +onlyif cockroach statement ok -UPDATE abc SET a = 2, b = 5, c = 6 WHERE a = 1; +UPDATE abc SET a = 2, (b, c) = (SELECT 5, 6) WHERE a = 1; -# # Failure in outer query with mutations in the subquery do not take effect. -# statement error pq: bar -# SELECT crdb_internal.force_error('foo', 'bar') FROM [INSERT INTO abc VALUES (11,12,13) RETURNING a] +# Failure in outer query with mutations in the subquery do not take effect. +statement error expected id +SELECT crdb_internal.force_error('foo', 'bar') FROM [INSERT INTO abc VALUES (11,12,13) RETURNING a] query III SELECT * FROM abc WHERE a = 11 ---- -# statement error pq: bar -# INSERT INTO abc VALUES (1,2, (SELECT crdb_internal.force_error('foo', 'bar'))) +statement error unknown schema 'crdb_internal' +INSERT INTO abc VALUES (1,2, (SELECT crdb_internal.force_error('foo', 'bar'))) + +# Regression test for #37263. +query B +SELECT 3::decimal IN (SELECT 1) +---- +false + +# Not supported by Materialize. +onlyif cockroach +query error unsupported comparison operator +SELECT 3::decimal IN (SELECT 1::int) + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 1 IN (SELECT '1'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #14554. +query ITIIIII +SELECT + t.oid, t.typname, t.typsend, t.typreceive, t.typoutput, t.typinput, t.typelem +FROM + pg_type AS t +WHERE + t.oid + NOT IN (SELECT (ARRAY[704, 11676, 10005, 3912, 11765, 59410, 11397])[i] FROM generate_series(1, 376) AS i) +---- + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #96441. +statement ok +CREATE TABLE t96441 ( + k INT PRIMARY KEY, + i INT, + CHECK (k IN (1, 2)) +); +INSERT INTO t96441 VALUES (1, 10); + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT * FROM (VALUES (0)) +FULL JOIN t96441 AS t1 +ON 1 IN (SELECT t1.i FROM t96441) +---- +NULL 1 10 +0 NULL NULL + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE abc INJECT STATISTICS '[ + { + "columns": ["a"], + "created_at": "2018-05-01 1:00:00.00000+00:00", + "row_count": 10000, + "distinct_count": 10000 + } +]' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE abc INJECT STATISTICS '[ + { + "columns": ["b"], + "created_at": "2018-05-01 1:00:00.00000+00:00", + "row_count": 10000, + "distinct_count": 10000 + } +]' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE xyz INJECT STATISTICS '[ + { + "columns": ["x"], + "created_at": "2018-05-01 1:00:00.00000+00:00", + "row_count": 1000, + "distinct_count": 1000 + } +]' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE xyz INJECT STATISTICS '[ + { + "columns": ["y"], + "created_at": "2018-05-01 1:00:00.00000+00:00", + "row_count": 1000, + "distinct_count": 1000 + } +]' + +statement ok +INSERT INTO xyz VALUES(5, 4, 7) + +statement ok +INSERT INTO abc VALUES(12, 13, 14) + +statement ok +CREATE INDEX abc_b ON abc(b) + +statement ok +CREATE INDEX xyz_y ON xyz(y) + +### Split Disjunctions Tests +query III rowsort +SELECT * FROM abc WHERE EXISTS (SELECT * FROM xyz WHERE abc.a = xyz.x OR abc.b = xyz.y) +---- +1 2 3 +4 5 6 +7 8 9 + +query III rowsort +SELECT * FROM abc WHERE EXISTS (SELECT * FROM xyz WHERE abc.a = xyz.y OR abc.b = xyz.x) +---- +4 5 6 + +query III rowsort +SELECT * FROM abc WHERE EXISTS (SELECT * FROM xyz WHERE (abc.a = xyz.x OR abc.b = xyz.y)and abc.a > 3 AND xyz.z > 10) +---- + + +query III rowsort +SELECT * FROM abc WHERE EXISTS (SELECT * FROM xyz WHERE (abc.a = xyz.y OR abc.b = xyz.x) AND abc.a > 3 AND xyz.z > 10) +---- + + +query III rowsort +SELECT * FROM abc WHERE NOT EXISTS (SELECT * FROM xyz WHERE abc.a = xyz.x OR abc.b = xyz.y) +---- +12 13 14 + +query III rowsort +SELECT * FROM abc WHERE NOT EXISTS (SELECT * FROM xyz WHERE abc.a = xyz.y OR abc.b = xyz.x) +---- +1 2 3 +12 13 14 +7 8 9 + +query III rowsort +SELECT * FROM abc WHERE NOT EXISTS (SELECT * FROM xyz WHERE (abc.a = xyz.x OR abc.b = xyz.y)and abc.a > 3 AND xyz.z > 10) +---- +1 2 3 +12 13 14 +4 5 6 +7 8 9 + +query III rowsort +SELECT * FROM abc WHERE NOT EXISTS (SELECT * FROM xyz WHERE (abc.a = xyz.y OR abc.b = xyz.x) AND abc.a > 3 AND xyz.z > 10) +---- +1 2 3 +12 13 14 +4 5 6 +7 8 9 + +query III rowsort +SELECT * FROM abc WHERE EXISTS (SELECT * FROM xyz WHERE (abc.a = xyz.x OR abc.b = xyz.y) AND (abc.a = xyz.y OR abc.b = xyz.y)) +---- +1 2 3 +4 5 6 +7 8 9 + +query III rowsort +SELECT * FROM abc WHERE NOT EXISTS (SELECT * FROM xyz WHERE (abc.a = xyz.x OR abc.b = xyz.y) AND (abc.a = xyz.y OR abc.b = xyz.y)) +---- +12 13 14 + +### End Split Disjunctions Tests + +# Regression test for SHOW session_id in a subquery. +# See https://github.com/cockroachdb/cockroach/issues/93739 +let $session_id +SHOW session_id + +# Not supported by Materialize. +onlyif cockroach +query B +select lower((select session_id from [show session_id])) = lower('$session_id') +---- +true diff --git a/test/sqllogictest/cockroach/subquery_correlated.slt b/test/sqllogictest/cockroach/subquery_correlated.slt index de0569601b1b2..4fcbd7df9587c 100644 --- a/test/sqllogictest/cockroach/subquery_correlated.slt +++ b/test/sqllogictest/cockroach/subquery_correlated.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,26 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/subquery_correlated +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/subquery_correlated # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_foreign_key = true ----- -COMPLETE 0 - # ------------------------------------------------------------------------------ # Create a simple schema that models customers and orders. Each customer has an # id (c_id), and has zero or more orders that are related via a foreign key of @@ -37,26 +30,20 @@ COMPLETE 0 # enough to provide many interesting correlated subquery variations. # ------------------------------------------------------------------------------ statement ok -CREATE TABLE c (c_id INT PRIMARY KEY, bill TEXT) - -statement ok -CREATE TABLE o (o_id INT PRIMARY KEY, c_id INT, ship TEXT) - -statement ok +CREATE TABLE c (c_id INT PRIMARY KEY, bill TEXT); +CREATE TABLE o (o_id INT PRIMARY KEY, c_id INT, ship TEXT); INSERT INTO c VALUES (1, 'CA'), (2, 'TX'), (3, 'MA'), (4, 'TX'), (5, NULL), - (6, 'FL') - -statement ok + (6, 'FL'); INSERT INTO o VALUES (10, 1, 'CA'), (20, 1, 'CA'), (30, 1, 'CA'), (40, 2, 'CA'), (50, 2, 'TX'), (60, 2, NULL), (70, 4, 'WY'), (80, 4, NULL), - (90, 6, 'WA') + (90, 6, 'WA'); # ------------------------------------------------------------------------------ # Subqueries in select filters. @@ -377,6 +364,7 @@ WHERE EXISTS 2 TX 4 TX +# Customers with each of their orders numbered. query II rowsort SELECT c_id, generate_series(1, (SELECT count(*) FROM o WHERE o.c_id=c.c_id)) FROM c ---- @@ -390,9 +378,7 @@ SELECT c_id, generate_series(1, (SELECT count(*) FROM o WHERE o.c_id=c.c_id)) FR 4 2 6 1 - # Customers that have no orders with a NULL ship state. -# Note: Result differs from Cockroach but matches Postgres. query IT rowsort SELECT * FROM c @@ -423,6 +409,49 @@ FROM c WHERE (SELECT o_id FROM o WHERE o.c_id=c.c_id AND ship='WY')=4; ---- +# Try to find customers other than customer #2 that have at most one order that +# is shipping to 'CA'. However, since there is more than one order shipping to +# 'CA' corresponding to customers other than #2, this attempt fails with an +# error. +query error Evaluation error: more than one record produced in subquery +SELECT * FROM c WHERE c_id=(SELECT c_id FROM o WHERE ship='CA' AND c.c_id<>2) + +# Find customers other than customer #1 that have at most one order that is +# shipping to 'CA' and a billing state equal to 'TX'. Since there is only one +# other customer who is shipping to 'CA', and this customer has only a single +# order, this attempt is successful. +query IT +SELECT * FROM c WHERE c_id=(SELECT c_id FROM o WHERE ship='CA' AND c_id<>1 AND bill='TX') +---- +2 TX + +# Find customers with billing state equal to 'FL' that have at most one order +# that is shipping to 'WA'. Since there is only one order shipping to 'WA', this +# attempt is successful. +query IT +SELECT * FROM c WHERE c_id=(SELECT c_id FROM o WHERE ship='WA' AND bill='FL') +---- +6 FL + +# Try to find customers that have at most one order that is also shipping to +# 'WA'. However, since there are customers that have more than one order, this +# attempt fails with an error. +query error Evaluation error: more than one record produced in subquery +SELECT * FROM c WHERE (SELECT ship FROM o WHERE o.c_id=c.c_id AND ship IS NOT NULL)='WA' + +# Add clause to filter out customers that have more than one order. Find +# remaining customers with at least one order shipping to 'WA'. +query IT +SELECT * +FROM c +WHERE ( + SELECT ship + FROM o + WHERE o.c_id=c.c_id AND ship IS NOT NULL AND (SELECT count(*) FROM o WHERE o.c_id=c.c_id)<=1 +)='WA' +---- +6 FL + # ------------------------------------------------------------------------------ # Subqueries in projection lists. # Although the queries are similar to those above, they are often compiled @@ -791,7 +820,6 @@ ORDER BY c_id; 6 1 # Count bill/ship addresses in each state. -# Note: Result differs from Cockroach but matches Postgres. query TI SELECT s.st, @@ -799,12 +827,12 @@ SELECT FROM (SELECT c.bill AS st FROM c UNION SELECT o.ship AS st FROM o) s ORDER BY s.st; ---- -CA 5 -FL 1 -MA 1 -TX 3 -WA 1 -WY 1 +CA 5 +FL 1 +MA 1 +TX 3 +WA 1 +WY 1 NULL 0 # Customer orders grouped by ship state, compared with count of all orders @@ -855,7 +883,6 @@ ORDER BY c.c_id, o.o_id # Customers, with boolean indicating whether they have at least one order with a # NULL ship state. -# Note: Result differs from Cockroach but matches Postgres. query IB SELECT c.c_id, @@ -887,6 +914,22 @@ ORDER BY c_id 5 NULL 6 false +# Not supported by Materialize. +onlyif cockroach +query T +SELECT (SELECT concat_agg(ship || ' ') + FROM + (SELECT c_id AS o_c_id, ship FROM o ORDER BY ship) + WHERE o_c_id=c.c_id) +FROM c ORDER BY c_id +---- +CA CA CA +CA TX +NULL +WY +NULL +WA + query T SELECT (SELECT string_agg(ship, ', ') FROM @@ -915,38 +958,40 @@ WY NULL WA -query ITI +query ITI colnames SELECT * FROM - (SELECT c_id AS c_c_id, bill FROM c) s1, - LATERAL (SELECT o_id FROM o WHERE c_id = c_c_id) s2 -ORDER BY c_c_id, bill, o_id ----- -1 CA 10 -1 CA 20 -1 CA 30 -2 TX 40 -2 TX 50 -2 TX 60 -4 TX 70 -4 TX 80 -6 FL 90 - -query TI + (SELECT c_id AS c_c_id, bill FROM c), + LATERAL (SELECT row_number() OVER () AS rownum FROM o WHERE c_id = c_c_id) +ORDER BY c_c_id, bill, rownum +---- +c_c_id bill rownum +1 CA 1 +1 CA 2 +1 CA 3 +2 TX 1 +2 TX 2 +2 TX 3 +4 TX 1 +4 TX 2 +6 FL 1 + +query TI colnames,rowsort SELECT * FROM - (SELECT bill FROM c) s1, - LATERAL (SELECT o_id FROM o WHERE ship = bill) s2 -ORDER BY bill, o_id ----- -CA 10 -CA 20 -CA 30 -CA 40 -TX 50 -TX 50 + (SELECT bill FROM c), + LATERAL (SELECT row_number() OVER (PARTITION BY bill) AS rownum FROM o WHERE ship = bill) +ORDER BY bill, rownum +---- +bill rownum +CA 1 +CA 2 +CA 3 +CA 4 +TX 1 +TX 1 # ------------------------------------------------------------------------------ # Subqueries in other interesting locations. @@ -959,7 +1004,7 @@ SELECT count(*) AS cust_cnt FROM c GROUP BY (SELECT count(*) FROM o WHERE o.c_id=c.c_id) -ORDER BY (SELECT count(*) FROM o WHERE o.c_id=c.c_id) DESC +ORDER BY (SELECT count(*) FROM o WHERE o.c_id=c.c_id) DESC; ---- 3 2 2 1 @@ -987,173 +1032,355 @@ ON c.c_id=o.c_id AND EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id AND ship IS NULL 4 70 4 80 -# TODO(justin): Not supported by Materialize. -# query error more than one row returned by a subquery -# SELECT c.c_id, o.o_id -# FROM c -# INNER JOIN o -# ON c.c_id=o.c_id AND o.ship = (SELECT o.ship FROM o WHERE o.c_id=c.c_id); - -# TODO(justin): Not supported by Materialize. -# # Subquery in ARRAY(...) -# query ITT -# SELECT -# c_id, -# ARRAY(SELECT o_id FROM o WHERE o.c_id = c.c_id ORDER BY o_id), -# ARRAY(SELECT o_id FROM o WHERE o.ship = c.bill ORDER BY o_id) -# FROM c ORDER BY c_id -# ---- -# 1 {10,20,30} {10,20,30,40} -# 2 {40,50,60} {50} -# 3 {} {} -# 4 {70,80} {50} -# 5 {} {} -# 6 {90} {} -# -# query IT -# SELECT -# c_id, -# ARRAY(SELECT o_id FROM o WHERE o.c_id = c.c_id ORDER BY o_id) -# FROM c ORDER BY c_id -# ---- -# 1 {10,20,30} -# 2 {40,50,60} -# 3 {} -# 4 {70,80} -# 5 {} -# 6 {90} - -# Regression for issue database-issues#7343: missing support for correlated subquery in JSON +query error Evaluation error: more than one record produced in subquery +SELECT c.c_id, o.o_id +FROM c +INNER JOIN o +ON c.c_id=o.c_id AND o.ship = (SELECT o.ship FROM o WHERE o.c_id=c.c_id); + +statement error Expected right parenthesis, found AS +SELECT (SELECT c_id FROM o AS OF SYSTEM TIME '-1us') +FROM c +WHERE EXISTS(SELECT * FROM o WHERE o.c_id=c.c_id) + +# Subquery in ARRAY(...) +query ITT +SELECT + c_id, + ARRAY(SELECT o_id FROM o WHERE o.c_id = c.c_id ORDER BY o_id), + ARRAY(SELECT o_id FROM o WHERE o.ship = c.bill ORDER BY o_id) +FROM c ORDER BY c_id +---- +1 {10,20,30} {10,20,30,40} +2 {40,50,60} {50} +3 {} {} +4 {70,80} {50} +5 {} {} +6 {90} {} + +query IT +SELECT + c_id, + ARRAY(SELECT o_id FROM o WHERE o.c_id = c.c_id ORDER BY o_id) +FROM c ORDER BY c_id +---- +1 {10,20,30} +2 {40,50,60} +3 {} +4 {70,80} +5 {} +6 {90} + +# Not supported by Materialize. +onlyif cockroach +# Regression for issue #24676: missing support for correlated subquery in JSON # operator. statement ok CREATE TABLE groups( - id INT PRIMARY KEY, + id SERIAL PRIMARY KEY, data JSONB -) +); +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO groups(id, data) VALUES(1, '{"name": "Group 1", "members": [{"name": "admin", "type": "USER"}, {"name": "user", "type": "USER"}]}') +INSERT INTO groups(data) VALUES('{"name": "Group 1", "members": [{"name": "admin", "type": "USER"}, {"name": "user", "type": "USER"}]}'); +INSERT INTO groups(data) VALUES('{"name": "Group 2", "members": [{"name": "admin2", "type": "USER"}]}'); -statement ok -INSERT INTO groups(id, data) VALUES(2, '{"name": "Group 2", "members": [{"name": "admin2", "type": "USER"}]}') - -# database-issues#544 -# query TT -# SELECT -# g.data->>'name' AS group_name, -# jsonb_array_elements( (SELECT gg.data->'members' FROM groups gg WHERE gg.data->>'name' = g.data->>'name') ) -# FROM -# groups g -# ---- -# Group 1 {"name": "admin", "type": "USER"} -# Group 1 {"name": "user", "type": "USER"} -# Group 2 {"name": "admin2", "type": "USER"} - -# query TT -# SELECT -# data->>'name', -# members -# FROM -# groups AS g, -# jsonb_array_elements( -# ( -# SELECT -# gg.data->'members' AS members -# FROM -# groups AS gg -# WHERE -# gg.data->>'name' = g.data->>'name' -# ) -# ) AS members -# ---- -# Group 1 {"name": "admin", "type": "USER"} -# Group 1 {"name": "user", "type": "USER"} -# Group 2 {"name": "admin2", "type": "USER"} +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT + g.data->>'name' AS group_name, + jsonb_array_elements( (SELECT gg.data->'members' FROM groups gg WHERE gg.data->>'name' = g.data->>'name') ) +FROM + groups g +ORDER BY g.data->>'name' +---- +Group 1 {"name": "admin", "type": "USER"} +Group 1 {"name": "user", "type": "USER"} +Group 2 {"name": "admin2", "type": "USER"} + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT + data->>'name', + members +FROM + groups AS g, + jsonb_array_elements( + ( + SELECT + gg.data->'members' AS members + FROM + groups AS gg + WHERE + gg.data->>'name' = g.data->>'name' + ) + ) AS members +ORDER BY g.data->>'name' +---- +Group 1 {"name": "admin", "type": "USER"} +Group 1 {"name": "user", "type": "USER"} +Group 2 {"name": "admin2", "type": "USER"} # ------------------------------------------------------------------------------ # Regression test cases. # ------------------------------------------------------------------------------ -# Regression for issue 35437. +# Regression for issue 32786. statement ok -CREATE TABLE users ( - id INT NOT NULL, - name VARCHAR(50), - PRIMARY KEY (id) -) +CREATE TABLE t32786 (id UUID PRIMARY KEY, parent_id UUID, parent_path text) + +statement ok +INSERT INTO t32786 VALUES ('3AAA2577-DBC3-47E7-9E85-9CC7E19CF48A', null) +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO users(id, name) VALUES (1, 'user1') +UPDATE t32786 as node +SET parent_path=concat((SELECT parent.parent_path + FROM t32786 parent + WHERE parent.id=node.parent_id), + node.id::varchar, '/') + +statement ok +INSERT INTO t32786 VALUES ('5AE7EAFD-8277-4F41-83DE-0FD4B4482169', '3AAA2577-DBC3-47E7-9E85-9CC7E19CF48A') + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE t32786 as node +SET parent_path=concat((SELECT parent.parent_path + FROM t32786 parent + WHERE parent.id=node.parent_id), + node.id::varchar, '/') + +query T +SELECT parent_path FROM t32786 ORDER BY id +---- +NULL +NULL + +# Regression test for #32723. +query I +SELECT + generate_series(a + 1, a + 1) +FROM + (SELECT a FROM ((SELECT 1 AS a, 1) EXCEPT ALL (SELECT 0, 0))) +---- +2 + +# Regression for issue 35437. +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO users(id, name) VALUES (2, 'user2') +CREATE TABLE users ( + id INT8 NOT NULL DEFAULT unique_rowid(), + name VARCHAR(50), + PRIMARY KEY (id) +); +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO users(id, name) VALUES (3, 'user3') +INSERT INTO users(id, name) VALUES (1, 'user1'); +INSERT INTO users(id, name) VALUES (2, 'user2'); +INSERT INTO users(id, name) VALUES (3, 'user3'); +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE stuff ( - id INT NOT NULL, + id INT8 NOT NULL DEFAULT unique_rowid(), date DATE, - user_id INT, + user_id INT8, PRIMARY KEY (id), FOREIGN KEY (user_id) REFERENCES users (id) -) +); +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO stuff(id, date, user_id) VALUES (1, '2007-10-15'::DATE, 1) - +INSERT INTO stuff(id, date, user_id) VALUES (1, '2007-10-15'::DATE, 1); +INSERT INTO stuff(id, date, user_id) VALUES (2, '2007-12-15'::DATE, 1); +INSERT INTO stuff(id, date, user_id) VALUES (3, '2007-11-15'::DATE, 1); +INSERT INTO stuff(id, date, user_id) VALUES (4, '2008-01-15'::DATE, 2); +INSERT INTO stuff(id, date, user_id) VALUES (5, '2007-06-15'::DATE, 3); +INSERT INTO stuff(id, date, user_id) VALUES (6, '2007-03-15'::DATE, 3); + +# Not supported by Materialize. +onlyif cockroach +query ITITI +SELECT + users.id AS users_id, + users.name AS users_name, + stuff_1.id AS stuff_1_id, + stuff_1.date AS stuff_1_date, + stuff_1.user_id AS stuff_1_user_id +FROM + users + LEFT JOIN stuff AS stuff_1 + ON + users.id = stuff_1.user_id + AND stuff_1.id + = ( + SELECT + stuff_2.id + FROM + stuff AS stuff_2 + WHERE + stuff_2.user_id = users.id + ORDER BY + stuff_2.date DESC + LIMIT + 1 + ) +ORDER BY + users.name; +---- +1 user1 2 2007-12-15 00:00:00 +0000 +0000 1 +2 user2 4 2008-01-15 00:00:00 +0000 +0000 2 +3 user3 5 2007-06-15 00:00:00 +0000 +0000 3 + +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO stuff(id, date, user_id) VALUES (2, '2007-12-15'::DATE, 1) +DROP TABLE stuff; +DROP TABLE users; -statement ok -INSERT INTO stuff(id, date, user_id) VALUES (3, '2007-11-15'::DATE, 1) +# Regression test for #38867. +query T +SELECT ( + SELECT + ARRAY ( + SELECT c.relname + FROM pg_inherits AS i JOIN pg_class AS c ON c.oid = i.inhparent + WHERE i.inhrelid = rel.oid + ORDER BY inhseqno + ) +) +FROM pg_class AS rel +LIMIT 5; +---- +{} +{} +{} +{} +{} + +# Customers, their billing address, and all orders not going to their billing address +query ITT rowsort +SELECT + c_id, bill, states +FROM + c + JOIN LATERAL ( + SELECT + COALESCE(array_agg(o.ship), '{}') AS states + FROM + o + WHERE + o.c_id = c.c_id AND o.ship != c.bill + ) ON true; +---- +1 CA {} +3 MA {} +4 TX {WY} +5 NULL {} +6 FL {WA} +2 TX {CA} + +# Customers that have billing addresses and all orders not going to their billing address +query IT rowsort +SELECT + c_id, states +FROM + c + LEFT JOIN LATERAL ( + SELECT + COALESCE(array_agg(o.ship), '{}') AS states + FROM + o + WHERE + o.c_id = c.c_id AND o.ship != c.bill + ) ON true +WHERE + bill IS NOT NULL; +---- +1 {} +3 {} +2 {CA} +4 {WY} +6 {WA} +# Regression test for #48638. statement ok -INSERT INTO stuff(id, date, user_id) VALUES (4, '2008-01-15'::DATE, 2) +CREATE TABLE IF NOT EXISTS t_48638 ( + key INTEGER NOT NULL, + value INTEGER NOT NULL, + PRIMARY KEY (key, value)) statement ok -INSERT INTO stuff(id, date, user_id) VALUES (5, '2007-06-15'::DATE, 3) +INSERT INTO t_48638 values (1, 4); +INSERT INTO t_48638 values (4, 3); +INSERT INTO t_48638 values (3, 2); +INSERT INTO t_48638 values (4, 1); +INSERT INTO t_48638 values (1, 2); +INSERT INTO t_48638 values (6, 5); +INSERT INTO t_48638 values (7, 8); + +query II rowsort +SELECT * +FROM t_48638 +WHERE key IN ( + WITH v AS ( + SELECT + level1.value AS value, level1.key AS level1, level2.key AS level2, level3.key AS level3 + FROM + t_48638 AS level2 + RIGHT JOIN (SELECT * FROM t_48638 WHERE value = 4) AS level1 ON level1.value = level2.key + LEFT JOIN (SELECT * FROM t_48638) AS level3 ON level3.key = level2.value + ) + SELECT v.level1 FROM v WHERE v.level1 IS NOT NULL + UNION ALL SELECT v.level2 FROM v WHERE v.level2 IS NOT NULL + UNION ALL SELECT v.level3 FROM v WHERE v.level3 IS NOT NULL +) +---- +1 2 +1 4 +3 2 +4 1 +4 3 +# Regression test for #98691. statement ok -INSERT INTO stuff(id, date, user_id) VALUES (6, '2007-03-15'::DATE, 3) - -# database-issues#949 -# query ITITI -# SELECT -# users.id AS users_id, -# users.name AS users_name, -# stuff_1.id AS stuff_1_id, -# stuff_1.date AS stuff_1_date, -# stuff_1.user_id AS stuff_1_user_id -# FROM -# users -# LEFT JOIN stuff AS stuff_1 -# ON -# users.id = stuff_1.user_id -# AND stuff_1.id -# = ( -# SELECT -# stuff_2.id -# FROM -# stuff AS stuff_2 -# WHERE -# stuff_2.user_id = users.id -# ORDER BY -# stuff_2.date DESC -# LIMIT -# 1 -# ) -# ORDER BY -# users.name; -# ---- -# 1 user1 2 2007-12-15 00:00:00 +0000 +0000 1 -# 2 user2 4 2008-01-15 00:00:00 +0000 +0000 2 -# 3 user3 5 2007-06-15 00:00:00 +0000 +0000 3 +CREATE TABLE t98691 ( + a INT, + b INT +) statement ok -DROP TABLE stuff; +INSERT INTO t98691 VALUES (1, 10) + +query B +SELECT (NULL, NULL) = ANY ( + SELECT a, b FROM t98691 WHERE a > i +) FROM (VALUES (0), (0)) v(i) +---- +NULL +NULL statement ok -DROP TABLE users; +INSERT INTO t98691 VALUES (NULL, NULL) + +query B +SELECT (2, 20) = ANY ( + SELECT a, b FROM t98691 WHERE a > i OR a IS NULL +) FROM (VALUES (0), (0)) v(i) +---- +NULL +NULL diff --git a/test/sqllogictest/cockroach/table.slt b/test/sqllogictest/cockroach/table.slt deleted file mode 100644 index 24a1cfa2bdb09..0000000000000 --- a/test/sqllogictest/cockroach/table.slt +++ /dev/null @@ -1,510 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/table -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - -statement ok -SET DATABASE = "" - -statement error no database specified -CREATE TABLE a (id INT PRIMARY KEY) - -statement error invalid table name: test."" -CREATE TABLE test."" (id INT PRIMARY KEY) - -statement ok -CREATE TABLE test.a (id INT PRIMARY KEY) - -statement error pgcode 42P07 relation "a" already exists -CREATE TABLE test.a (id INT PRIMARY KEY) - -statement ok -SET DATABASE = test - -statement error invalid table name: "" -CREATE TABLE "" (id INT PRIMARY KEY) - -statement error pgcode 42P07 relation "a" already exists -CREATE TABLE a (id INT PRIMARY KEY) - -statement error duplicate column name: "id" -CREATE TABLE b (id INT PRIMARY KEY, id INT) - -statement error multiple primary keys for table "b" are not allowed -CREATE TABLE b (id INT PRIMARY KEY, id2 INT PRIMARY KEY) - -statement error index \"primary\" contains duplicate column \"a\" -CREATE TABLE dup_primary (a int, primary key (a,a)) - -statement error index \"dup_unique_a_a_key\" contains duplicate column \"a\" -CREATE TABLE dup_unique (a int, unique (a,a)) - -statement ok -CREATE TABLE IF NOT EXISTS a (id INT PRIMARY KEY) - -statement ok -COMMENT ON TABLE a IS 'a_comment' - -query T colnames -SHOW TABLES FROM test ----- -table_name -a - -statement ok -CREATE TABLE b (id INT PRIMARY KEY) - -statement ok -CREATE TABLE c ( - id INT PRIMARY KEY, - foo INT, - bar INT, - INDEX c_foo_idx (foo), - INDEX (foo), - INDEX c_foo_bar_idx (foo ASC, bar DESC), - UNIQUE (bar) -) - -query TTBITTBB colnames -SHOW INDEXES ON c ----- -table_name index_name non_unique seq_in_index column_name direction storing implicit -c primary false 1 id ASC false false -c c_foo_idx true 1 foo ASC false false -c c_foo_idx true 2 id ASC false true -c c_foo_idx1 true 1 foo ASC false false -c c_foo_idx1 true 2 id ASC false true -c c_foo_bar_idx true 1 foo ASC false false -c c_foo_bar_idx true 2 bar DESC false false -c c_foo_bar_idx true 3 id ASC false true -c c_bar_key false 1 bar ASC false false -c c_bar_key false 2 id ASC false true - -# primary keys can never be null - -statement ok -CREATE TABLE d ( - id INT PRIMARY KEY NULL -) - -query TTBTTTB colnames -SHOW COLUMNS FROM d ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -id INT8 false NULL · {primary} false - -statement ok -CREATE TABLE e ( - id INT NULL PRIMARY KEY -) - -query TTBTTTB colnames -SHOW COLUMNS FROM e ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -id INT8 false NULL · {primary} false - -statement ok -CREATE TABLE f ( - a INT, - b INT, - c INT, - PRIMARY KEY (a, b, c) -) - -query TTBTTTB colnames -SHOW COLUMNS FROM f ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -a INT8 false NULL · {primary} false -b INT8 false NULL · {primary} false -c INT8 false NULL · {primary} false - -query TT -SHOW TABLES FROM test WITH COMMENT ----- -a a_comment -b · -c · -d · -e · -f · - -statement ok -SET DATABASE = "" - -query error pgcode 42P01 relation "users" does not exist -SHOW COLUMNS FROM users - -query error pgcode 42P01 relation "test.users" does not exist -SHOW COLUMNS FROM test.users - -query error pgcode 42P01 relation "users" does not exist -SHOW INDEXES ON users - -query error pgcode 42P01 relation "test.users" does not exist -SHOW INDEXES ON test.users - -statement ok -CREATE TABLE test.users ( - id INT PRIMARY KEY, - name VARCHAR NOT NULL, - title VARCHAR, - nickname STRING CHECK (length(nickname) < 10), - username STRING(10), - email VARCHAR(100) NULL, - INDEX foo (name), - CHECK (length(nickname) < length(name)), - UNIQUE INDEX bar (id, name), - FAMILY "primary" (id, name), - FAMILY fam_1_title (title), - FAMILY fam_2_nickname (nickname), - FAMILY fam_3_username_email (username, email) -) - -query TTBTTTB colnames -SHOW COLUMNS ON test.users ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -id INT8 false NULL · {primary,foo,bar} false -name VARCHAR false NULL · {foo,bar} false -title VARCHAR true NULL · {} false -nickname STRING true NULL · {} false -username STRING(10) true NULL · {} false -email VARCHAR(100) true NULL · {} false - -query TTBITTBB colnames -SHOW INDEXES ON test.users ----- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users primary false 1 id ASC false false -users foo true 1 name ASC false false -users foo true 2 id ASC false true -users bar false 1 id ASC false false -users bar false 2 name ASC false false - -statement error precision for type float must be at least 1 bit -CREATE TABLE test.precision (x FLOAT(0)) - -statement error scale \(2\) must be between 0 and precision \(0\) at or near "\)" -CREATE TABLE test.precision (x DECIMAL(0, 2)) - -statement error scale \(4\) must be between 0 and precision \(2\) at or near "\)" -CREATE TABLE test.precision (x DECIMAL(2, 4)) - -query TT -SHOW CREATE TABLE test.users ----- -test.public.users CREATE TABLE users ( - id INT8 NOT NULL, - name VARCHAR NOT NULL, - title VARCHAR NULL, - nickname STRING NULL, - username STRING(10) NULL, - email VARCHAR(100) NULL, - CONSTRAINT "primary" PRIMARY KEY (id ASC), - INDEX foo (name ASC), - UNIQUE INDEX bar (id ASC, name ASC), - FAMILY "primary" (id, name), - FAMILY fam_1_title (title), - FAMILY fam_2_nickname (nickname), - FAMILY fam_3_username_email (username, email), - CONSTRAINT check_nickname_name CHECK (length(nickname) < length(name)), - CONSTRAINT check_nickname CHECK (length(nickname) < 10) -) - -statement ok -CREATE TABLE test.dupe_generated ( - foo INT CHECK (foo > 1), - bar INT CHECK (bar > 2), - CHECK (foo > 2), - CHECK (foo < 10) -) - -query TTTTB colnames -SHOW CONSTRAINTS FROM test.dupe_generated ----- -table_name constraint_name constraint_type details validated -dupe_generated check_bar CHECK CHECK (bar > 2) true -dupe_generated check_foo CHECK CHECK (foo > 2) true -dupe_generated check_foo1 CHECK CHECK (foo < 10) true -dupe_generated check_foo2 CHECK CHECK (foo > 1) true - -statement ok -CREATE TABLE test.named_constraints ( - id INT CONSTRAINT pk PRIMARY KEY, - name VARCHAR CONSTRAINT nn NOT NULL, - title VARCHAR CONSTRAINT def DEFAULT 'VP of Something', - nickname STRING CONSTRAINT ck1 CHECK (length(nickname) < 10), - username STRING(10) CONSTRAINT nl NULL, - email VARCHAR(100) CONSTRAINT uq UNIQUE, - INDEX foo (name), - CONSTRAINT uq2 UNIQUE (username), - CONSTRAINT ck2 CHECK (length(nickname) < length(name)), - UNIQUE INDEX bar (id, name), - FAMILY "primary" (id, name), - FAMILY fam_1_title (title), - FAMILY fam_2_nickname (nickname), - FAMILY fam_3_username_email (username, email) -) - -query TT -SHOW CREATE TABLE test.named_constraints ----- -test.public.named_constraints CREATE TABLE named_constraints ( - id INT8 NOT NULL, - name VARCHAR NOT NULL, - title VARCHAR NULL DEFAULT 'VP of Something':::STRING, - nickname STRING NULL, - username STRING(10) NULL, - email VARCHAR(100) NULL, - CONSTRAINT pk PRIMARY KEY (id ASC), - UNIQUE INDEX uq (email ASC), - INDEX foo (name ASC), - UNIQUE INDEX uq2 (username ASC), - UNIQUE INDEX bar (id ASC, name ASC), - FAMILY "primary" (id, name), - FAMILY fam_1_title (title), - FAMILY fam_2_nickname (nickname), - FAMILY fam_3_username_email (username, email), - CONSTRAINT ck2 CHECK (length(nickname) < length(name)), - CONSTRAINT ck1 CHECK (length(nickname) < 10) -) - -query TTTTB colnames -SHOW CONSTRAINTS FROM test.named_constraints ----- -table_name constraint_name constraint_type details validated -named_constraints bar UNIQUE UNIQUE (id ASC, name ASC) true -named_constraints ck1 CHECK CHECK (length(nickname) < 10) true -named_constraints ck2 CHECK CHECK (length(nickname) < length(name)) true -named_constraints pk PRIMARY KEY PRIMARY KEY (id ASC) true -named_constraints uq UNIQUE UNIQUE (email ASC) true -named_constraints uq2 UNIQUE UNIQUE (username ASC) true - -statement error duplicate constraint name: "pk" -CREATE TABLE test.dupe_named_constraints ( - id INT CONSTRAINT pk PRIMARY KEY, - title VARCHAR CONSTRAINT one CHECK (1>1), - name VARCHAR CONSTRAINT pk UNIQUE -) - -statement error duplicate constraint name: "one" -CREATE TABLE test.dupe_named_constraints ( - id INT CONSTRAINT pk PRIMARY KEY, - title VARCHAR CONSTRAINT one CHECK (1>1), - name VARCHAR CONSTRAINT one UNIQUE -) - -statement error duplicate constraint name: "one" -CREATE TABLE test.dupe_named_constraints ( - id INT CONSTRAINT pk PRIMARY KEY, - title VARCHAR CONSTRAINT one CHECK (1>1), - name VARCHAR CONSTRAINT one REFERENCES test.named_constraints (username), - INDEX (name) -) - -statement error duplicate constraint name: "one" -CREATE TABLE test.dupe_named_constraints ( - id INT CONSTRAINT pk PRIMARY KEY, - title VARCHAR CONSTRAINT one CHECK (1>1) CONSTRAINT one CHECK (1<1) -) - -statement ok -SET database = test - -statement ok -CREATE TABLE alltypes ( - cbigint BIGINT, - cbigserial BIGSERIAL, - cblob BLOB, - cbool BOOL, - cbit BIT, - cbit12 BIT(12), - cvarbit VARBIT, - cvarbit12 VARBIT(12), - cbytea BYTEA, - cbytes BYTES, - cchar CHAR, - cchar12 CHAR(12), - cdate DATE, - cdec DEC, - cdec1 DEC(1), - cdec21 DEC(2,1), - cdecimal DECIMAL, - cdecimal1 DECIMAL(1), - cdecimal21 DECIMAL(2,1), - cdoubleprecision DOUBLE PRECISION, - cfloat FLOAT, - cfloat4 FLOAT4, - cfloat8 FLOAT8, - cint INT, - cint2 INT2, - cint4 INT4, - cint64 INT64, - cint8 INT8, - cinteger INTEGER, - cinterval INTERVAL, - cjson JSONB, - cnumeric NUMERIC, - cnumeric1 NUMERIC(1), - cnumeric21 NUMERIC(2,1), - cqchar "char", - creal REAL, - cserial SERIAL, - csmallint SMALLINT, - csmallserial SMALLSERIAL, - cstring STRING, - cstring12 STRING(12), - ctext TEXT, - ctimestamp TIMESTAMP, - ctimestampwtz TIMESTAMPTZ, - cvarchar VARCHAR, - cvarchar12 VARCHAR(12) - ) - -query TTBTTTB colnames -SHOW COLUMNS FROM alltypes ----- -column_name data_type is_nullable column_default generation_expression indices is_hidden -cbigint INT8 true NULL · {} false -cbigserial INT8 false unique_rowid() · {} false -cblob BYTES true NULL · {} false -cbool BOOL true NULL · {} false -cbit BIT true NULL · {} false -cbit12 BIT(12) true NULL · {} false -cvarbit VARBIT true NULL · {} false -cvarbit12 VARBIT(12) true NULL · {} false -cbytea BYTES true NULL · {} false -cbytes BYTES true NULL · {} false -cchar CHAR true NULL · {} false -cchar12 CHAR(12) true NULL · {} false -cdate DATE true NULL · {} false -cdec DECIMAL true NULL · {} false -cdec1 DECIMAL(1) true NULL · {} false -cdec21 DECIMAL(2,1) true NULL · {} false -cdecimal DECIMAL true NULL · {} false -cdecimal1 DECIMAL(1) true NULL · {} false -cdecimal21 DECIMAL(2,1) true NULL · {} false -cdoubleprecision FLOAT8 true NULL · {} false -cfloat FLOAT8 true NULL · {} false -cfloat4 FLOAT4 true NULL · {} false -cfloat8 FLOAT8 true NULL · {} false -cint INT8 true NULL · {} false -cint2 INT2 true NULL · {} false -cint4 INT4 true NULL · {} false -cint64 INT8 true NULL · {} false -cint8 INT8 true NULL · {} false -cinteger INT8 true NULL · {} false -cinterval INTERVAL true NULL · {} false -cjson JSONB true NULL · {} false -cnumeric DECIMAL true NULL · {} false -cnumeric1 DECIMAL(1) true NULL · {} false -cnumeric21 DECIMAL(2,1) true NULL · {} false -cqchar "char" true NULL · {} false -creal FLOAT4 true NULL · {} false -cserial INT8 false unique_rowid() · {} false -csmallint INT2 true NULL · {} false -csmallserial INT8 false unique_rowid() · {} false -cstring STRING true NULL · {} false -cstring12 STRING(12) true NULL · {} false -ctext STRING true NULL · {} false -ctimestamp TIMESTAMP true NULL · {} false -ctimestampwtz TIMESTAMPTZ true NULL · {} false -cvarchar VARCHAR true NULL · {} false -cvarchar12 VARCHAR(12) true NULL · {} false -rowid INT8 false unique_rowid() · {primary} true - -statement ok -CREATE DATABASE IF NOT EXISTS smtng - -statement ok -CREATE TABLE IF NOT EXISTS smtng.something ( -ID SERIAL PRIMARY KEY -) - -statement ok -ALTER TABLE smtng.something ADD COLUMN IF NOT EXISTS OWNER_ID INT - -statement ok -ALTER TABLE smtng.something ADD COLUMN IF NOT EXISTS MODEL_ID INT - -statement ok -ALTER TABLE smtng.something ADD COLUMN IF NOT EXISTS NAME STRING - -statement ok -CREATE DATABASE IF NOT EXISTS smtng - -statement ok -CREATE TABLE IF NOT EXISTS smtng.something ( -ID SERIAL PRIMARY KEY -) - -statement ok -ALTER TABLE smtng.something ADD COLUMN IF NOT EXISTS OWNER_ID INT - -statement ok -ALTER TABLE smtng.something ADD COLUMN IF NOT EXISTS MODEL_ID INT - -statement ok -ALTER TABLE smtng.something ADD COLUMN IF NOT EXISTS NAME STRING - -# Regression test for database-issues#3922 -statement ok -CREATE TABLE test.empty () - -statement ok -SELECT * FROM test.empty - -# Issue materialize#14308: support tables with DEFAULT NULL columns. -statement ok -CREATE TABLE test.null_default ( - ts timestamp NULL DEFAULT NULL -) - -query TT -SHOW CREATE TABLE test.null_default ----- -test.public.null_default CREATE TABLE null_default ( - ts TIMESTAMP NULL DEFAULT NULL, - FAMILY "primary" (ts, rowid) -) - -# Issue materialize#13873: don't permit invalid default columns -statement error could not parse "blah" as type decimal -CREATE TABLE test.t1 (a DECIMAL DEFAULT (DECIMAL 'blah')); - -statement error could not parse "blah" as type decimal -create table test.t1 (c decimal default if(false, 1, 'blah'::decimal)); - -statement ok -CREATE DATABASE a; CREATE TABLE a.c(d INT); INSERT INTO a.public.c(d) VALUES (1) - -query I -SELECT a.public.c.d FROM a.public.c ----- -1 diff --git a/test/sqllogictest/cockroach/target_names.slt b/test/sqllogictest/cockroach/target_names.slt index 107b2b3f071bd..c77c9b059df6b 100644 --- a/test/sqllogictest/cockroach/target_names.slt +++ b/test/sqllogictest/cockroach/target_names.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,12 +9,15 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/target_names +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/target_names # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach @@ -22,12 +25,16 @@ mode cockroach statement ok CREATE TABLE t(a INT[], t STRING); +# Not supported by Materialize. +onlyif cockroach # Simple expressions get the underlying column name as name. query ITTIIT colnames SELECT *, a, a[0], (((((((((a))))))))), t COLLATE "en_US" FROM t ---- a t a a a t +# Not supported by Materialize. +onlyif cockroach # Functions and function-like expressions get the function name. query ITTTTBTT colnames SELECT array_length(a, 1), @@ -46,9 +53,11 @@ array_length nullif row coalesce iferror iserror if current_user query ITRBBT colnames SELECT 123, '123', 123.0, TRUE, FALSE, NULL ---- -?column? ?column? ?column? bool bool ?column? -123 123 123.0 true false NULL +?column? ?column? ?column? bool bool ?column? +123 123 123 true false NULL +# Not supported by Materialize. +onlyif cockroach # Casts get the underlying expression name if there is one, # otherwise the name of the type. query IITI colnames @@ -56,6 +65,8 @@ SELECT t::INT, '123'::INT, t:::STRING, '123':::INT FROM t ---- t int8 t int8 +# Not supported by Materialize. +onlyif cockroach # Field access gets the field name. query T colnames SELECT (pg_get_keywords()).word FROM t @@ -66,7 +77,7 @@ word query TT colnames SELECT array[1,2,3], array(select 1) ---- -array array +array ?column? {1,2,3} {1} # EXISTS in subqueries called "exists" @@ -93,5 +104,5 @@ SELECT (SELECT 123 AS a), (VALUES (cos(1)::INT)), (SELECT cos(0)::INT) ---- -a column1 cos -123 0 1 +a column1 cos +123 1 1 diff --git a/test/sqllogictest/cockroach/temp_table_txn.slt b/test/sqllogictest/cockroach/temp_table_txn.slt new file mode 100644 index 0000000000000..25723f0dc9421 --- /dev/null +++ b/test/sqllogictest/cockroach/temp_table_txn.slt @@ -0,0 +1,48 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/temp_table_txn +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Tests creating temp tables in an explicit transaction and whilst retrying the +# transactions. +# This tests the stack behavior with SET LOCAL and must be done on a +# new connection as this will populate the temp_table structure for the +# first time. + +statement ok +SET experimental_enable_temp_tables=true + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +CREATE TEMP TABLE tbl (a int primary key); +INSERT INTO tbl VALUES (1); +SELECT crdb_internal.force_retry('1s'); +COMMIT + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT * FROM tbl +---- +1 diff --git a/test/sqllogictest/cockroach/time.slt b/test/sqllogictest/cockroach/time.slt index 7177417d6c02e..f1bce79450c4e 100644 --- a/test/sqllogictest/cockroach/time.slt +++ b/test/sqllogictest/cockroach/time.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,64 +9,76 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/time +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/time # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - # Note that the odd '0000-01-01 hh:mi:ss +0000 UTC' result format is an # artifact of how pq displays TIMEs. +# Not supported by Materialize. +onlyif cockroach query T SELECT '12:00:00':::TIME; ---- 0000-01-01 12:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '12:00:00.456':::TIME; ---- 0000-01-01 12:00:00.456 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '00:00:00':::TIME; ---- 0000-01-01 00:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '23:59:59.999999':::TIME; ---- 0000-01-01 23:59:59.999999 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T select ('24:00'::TIME)::STRING ---- 24:00:00 +# Not supported by Materialize. +onlyif cockroach query T SELECT ('24:00:00'::TIME)::STRING ---- 24:00:00 -statement error could not parse +statement error invalid input syntax for type time: HOUR must be \[0, 23\], got 124: "124:00" SELECT '124:00'::TIME; -statement error could not parse +statement error invalid input syntax for type time: HOUR must be \[0, 23\], got 24: "24:00:01" SELECT '24:00:01'::TIME; -statement error could not parse +statement error invalid input syntax for type time: HOUR must be \[0, 23\], got 24: "24:00:00\.001" SELECT '24:00:00.001'::TIME; +# Not supported by Materialize. +onlyif cockroach # Timezone should be ignored. query T SELECT '12:00:00-08:00':::TIME; @@ -76,45 +88,59 @@ SELECT '12:00:00-08:00':::TIME; query T SELECT TIME '12:00:00'; ---- -0000-01-01 12:00:00 +0000 UTC +12:00:00 # Casting query T SELECT '12:00:00'::TIME; ---- -0000-01-01 12:00:00 +0000 UTC +12:00:00 +# Not supported by Materialize. +onlyif cockroach query T select '12:00:00':::STRING::TIME; ---- 0000-01-01 12:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '12:00:00' COLLATE de::TIME; ---- 0000-01-01 12:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '2017-01-01 12:00:00':::TIMESTAMP::TIME; ---- 0000-01-01 12:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '2017-01-01 12:00:00-05':::TIMESTAMPTZ::TIME; ---- -0000-01-01 12:00:00 +0000 UTC +0000-01-01 17:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '12h':::INTERVAL::TIME; ---- 0000-01-01 12:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '12:00:00':::TIME::INTERVAL; ---- 12:00:00 +# Not supported by Materialize. +onlyif cockroach query T SELECT '12:00:00':::TIME::STRING; ---- @@ -122,66 +148,92 @@ SELECT '12:00:00':::TIME::STRING; # Comparison +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME = '12:00:00':::TIME ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME = '12:00:00.000000':::TIME ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME = '12:00:00.000001':::TIME ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME < '12:00:00.000001':::TIME ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME < '12:00:00':::TIME ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME < '11:59:59.999999':::TIME ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME > '11:59:59.999999':::TIME ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME > '12:00:00':::TIME ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME > '12:00:00.000001':::TIME ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME <= '12:00:00':::TIME ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME >= '12:00:00':::TIME ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME IN ('12:00:00'); ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT '12:00:00':::TIME IN ('00:00:00'); ---- @@ -189,61 +241,85 @@ false # Arithmetic +# Not supported by Materialize. +onlyif cockroach query T SELECT '12:00:00':::TIME + '1s':::INTERVAL ---- 0000-01-01 12:00:01 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '23:59:59':::TIME + '1s':::INTERVAL ---- 0000-01-01 00:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '12:00:00':::TIME + '1d':::INTERVAL ---- 0000-01-01 12:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '1s':::INTERVAL + '12:00:00':::TIME ---- 0000-01-01 12:00:01 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '12:00:00':::TIME - '1s':::INTERVAL ---- 0000-01-01 11:59:59 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '00:00:00':::TIME - '1s':::INTERVAL ---- 0000-01-01 23:59:59 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '12:00:00':::TIME - '1d':::INTERVAL ---- 0000-01-01 12:00:00 +0000 UTC +# Not supported by Materialize. +onlyif cockroach query T SELECT '12:00:00':::TIME - '11:59:59':::TIME ---- 00:00:01 +# Not supported by Materialize. +onlyif cockroach query T SELECT '11:59:59':::TIME - '12:00:00':::TIME ---- -00:00:01 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2017-01-01':::DATE + '12:00:00':::TIME ---- 2017-01-01 12:00:00 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '12:00:00':::TIME + '2017-01-01':::DATE ---- 2017-01-01 12:00:00 +0000 +0000 +# Not supported by Materialize. +onlyif cockroach query T SELECT '2017-01-01':::DATE - '12:00:00':::TIME ---- @@ -266,16 +342,18 @@ INSERT INTO times VALUES query T SELECT * FROM times ORDER BY t ---- -0000-01-01 00:00:00 +0000 UTC -0000-01-01 00:00:00.000001 +0000 UTC -0000-01-01 11:59:59.999999 +0000 UTC -0000-01-01 12:00:00 +0000 UTC -0000-01-01 12:00:00.000001 +0000 UTC -0000-01-01 23:59:59.999999 +0000 UTC +00:00:00 +00:00:00.000001 +11:59:59.999999 +12:00:00 +12:00:00.000001 +23:59:59.999999 statement ok CREATE TABLE arrays (times TIME[]) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO arrays VALUES (ARRAY[]), @@ -286,10 +364,7 @@ INSERT INTO arrays VALUES query T rowsort SELECT * FROM arrays ---- -{} -{00:00:00} -{00:00:00,12:00:00.000001} -{13:00:00} + # Built-ins @@ -318,38 +393,368 @@ SELECT date_trunc('microsecond', time '12:01:02.345678') ---- 12:01:02.345678 +# Not supported by Materialize. +onlyif cockroach query error pgcode 22023 date_trunc\(\): unsupported timespan: day SELECT date_trunc('day', time '12:01:02.345') -query I +query R SELECT extract(hour from time '12:01:02.345678') ---- 12 -query I +query R SELECT extract(minute from time '12:01:02.345678') ---- 1 -query I +query R SELECT extract(second from time '12:01:02.345678') ---- -2 +2.345678 -query I +query R SELECT extract(millisecond from time '12:01:02.345678') ---- -345 +2345.678 -query I +query R SELECT extract(microsecond from time '12:01:02.345678') ---- -345678 +2345678 -query I +query R SELECT extract(epoch from time '12:00:00') ---- 43200 -query error pgcode 22023 extract\(\): unsupported timespan: day +query error pgcode 22023 unit 'day' not supported for type time SELECT extract(day from time '12:00:00') + +query R +SELECT extract('microsecond' from time '12:01:02.345678') +---- +2345678 + +query R +SELECT extract('EPOCH' from time '12:00:00') +---- +43200 + +query error pgcode 22023 unit 'day' not supported for type time +SELECT extract('day' from time '12:00:00') + +query error pgcode 22023 unit 'day' not supported for type time +SELECT extract('DAY' from time '12:00:00') + +subtest precision_tests + +# Not supported by Materialize. +onlyif cockroach +query error precision 7 out of range +select '1:00:00.001':::TIME(7) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE time_precision_test ( + id integer PRIMARY KEY, + t TIME(5) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO time_precision_test VALUES + (1,'12:00:00.123456+03:00'), + (2,'12:00:00.12345+03:00'), + (3,'12:00:00.1234+03:00'), + (4,'12:00:00.123+03:00'), + (5,'12:00:00.12+03:00'), + (6,'12:00:00.1+03:00'), + (7,'12:00:00+03:00') + +# Not supported by Materialize. +onlyif cockroach +query IT +SELECT * FROM time_precision_test ORDER BY id ASC +---- +1 0000-01-01 12:00:00.12346 +0000 UTC +2 0000-01-01 12:00:00.12345 +0000 UTC +3 0000-01-01 12:00:00.1234 +0000 UTC +4 0000-01-01 12:00:00.123 +0000 UTC +5 0000-01-01 12:00:00.12 +0000 UTC +6 0000-01-01 12:00:00.1 +0000 UTC +7 0000-01-01 12:00:00 +0000 UTC + +# Not supported by Materialize. +onlyif cockroach +query TT +select column_name, data_type FROM [SHOW COLUMNS FROM time_precision_test] ORDER BY column_name +---- +id INT8 +t TIME(5) + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE time_precision_test ALTER COLUMN t TYPE time(6) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO time_precision_test VALUES + (100,'12:00:00.123456+03:00') + +# Not supported by Materialize. +onlyif cockroach +query IT +SELECT * FROM time_precision_test ORDER BY id ASC +---- +1 0000-01-01 12:00:00.12346 +0000 UTC +2 0000-01-01 12:00:00.12345 +0000 UTC +3 0000-01-01 12:00:00.1234 +0000 UTC +4 0000-01-01 12:00:00.123 +0000 UTC +5 0000-01-01 12:00:00.12 +0000 UTC +6 0000-01-01 12:00:00.1 +0000 UTC +7 0000-01-01 12:00:00 +0000 UTC +100 0000-01-01 12:00:00.123456 +0000 UTC + +# Not supported by Materialize. +onlyif cockroach +query TT +select column_name, data_type FROM [SHOW COLUMNS FROM time_precision_test] ORDER BY column_name +---- +id INT8 +t TIME(6) + +subtest localtime_test + +# Not supported by Materialize. +onlyif cockroach +query B +select localtime(3) - localtime <= '1ms'::interval +---- +true + +# Not supported by Materialize. +onlyif cockroach +query TTTT +select pg_typeof(localtime), pg_typeof(current_time), pg_typeof(localtime(3)), pg_typeof(current_time(3)) +---- +time without time zone time with time zone time without time zone time with time zone + +subtest regression_42749 + +# Not supported by Materialize. +onlyif cockroach +# cast to string to prove it is 24:00 +query T +SELECT '0000-01-01 24:00:00'::time::string +---- +24:00:00 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '2001-01-01 01:24:00'::time +---- +0000-01-01 01:24:00 +0000 UTC + +subtest current_time_tests + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE current_time_test ( + id INTEGER PRIMARY KEY, + a TIME(3) DEFAULT CURRENT_TIME, + b TIME DEFAULT CURRENT_TIME +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO current_time_test (id) VALUES (1) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO current_time_test (id, a, b) VALUES + (2, current_time, current_time), + (3, current_time, current_time(3)), + (4, localtime, localtime(3)) + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT id FROM current_time_test WHERE + ('1970-01-01 ' || b::string)::timestamp - + ('1970-01-01 ' || a::string)::timestamp +> '1ms'::interval ORDER BY id ASC +---- + +# Not supported by Materialize. +onlyif cockroach +# test that current_time is correct in different timezones. +statement ok +set time zone +3 + +statement ok +create table current_time_tzset_test (id integer, a time, b time) + +# Not supported by Materialize. +onlyif cockroach +statement ok +insert into current_time_tzset_test (id, a) values (1, current_time), (2, localtime) + +# Not supported by Materialize. +onlyif cockroach +statement ok +set time zone 0 + +# Not supported by Materialize. +onlyif cockroach +statement ok +update current_time_tzset_test set b = current_time where id = 1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +update current_time_tzset_test set b = localtime where id = 2 + +# a was written at an interval 3 hours ahead, and should persist that way. +# make sure they're roughly 3 hours apart. +# note time can overflow and result in negative duration, +# so test both 3 hour and -21 hour cases. +query I +select id from current_time_tzset_test WHERE + ((a - b) BETWEEN interval '2hr 59m' and interval '3h') OR + ((a - b) BETWEEN interval '-21hr -1m' and interval '-21hr') +ORDER BY id ASC +---- + + +# Check default types and expressions get truncated on insert / update. +subtest regression_44774 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE regression_44774 ( + a time(3) DEFAULT '12:13:14.123456' +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO regression_44774 VALUES (default), ('19:21:57.261286') + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT a FROM regression_44774 ORDER BY a +---- +0000-01-01 12:13:14.123 +0000 UTC +0000-01-01 19:21:57.261 +0000 UTC + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE regression_44774 +SET a = '13:14:15.123456'::time + '1 sec'::interval +WHERE 1 = 1 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT a FROM regression_44774 ORDER BY a +---- +0000-01-01 13:14:16.123 +0000 UTC +0000-01-01 13:14:16.123 +0000 UTC + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE regression_44774 + +subtest regression_46973 + +statement ok +CREATE TABLE regression_46973 (a TIME UNIQUE) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO regression_46973 VALUES ('23:59:59.999999'), ('24:00') + +query T +SELECT * FROM regression_46973 WHERE a != '23:59:59.999999' +---- + + +query T +SELECT * FROM regression_46973 WHERE a != '24:00' +---- + + +statement ok +DROP TABLE regression_46973 + +subtest regression_88128 + +statement ok +CREATE TABLE t88128 (t TIME) + +statement ok +INSERT INTO t88128 VALUES ('20:00:00') + +# Ensure that the optimizer does not simplify the filter by adding the constant +# subtrahend to the right side of the comparison when the addition would +# overflow. +query B +SELECT t - '05:00:00'::INTERVAL < '23:59:00'::TIME FROM t88128 +---- +true + +# Ensure that the optimizer does not simplify the filter by adding the constant +# subtrahend to the right side of the comparison when the addition would +# underflow. +query B +SELECT t - '-2:00:00'::INTERVAL > '01:00:00'::TIME FROM t88128 +---- +true + +# Ensure that the optimizer does not simplify the filter by subtracting the +# constant addend to the right side of the comparison when the subtraction would +# underflow. +query B +SELECT t + '02:00:00'::INTERVAL > '01:00:00'::TIME FROM t88128 +---- +true + +# Ensure that the optimizer does not simplify the filter by subtracting the +# constant addend to the right side of the comparison when the subtraction would +# overflow. +query B +SELECT t + '-18:00:00'::INTERVAL < '07:00:00'::TIME FROM t88128 +---- +true + +subtest regression_90053 + +# Not supported by Materialize. +onlyif cockroach +# Regression tests for #90053. Do not normalize comparisons with constants when +# addition/subtraction of the types involved could overflow without an error. +query B +SELECT '00:01:40.01+09:00:00' < (col::TIMETZ + '-83 years -1 mons -38 days -10:32:23.707137') +FROM (VALUES ('03:16:01.252182+01:49:00')) v(col); +---- +true + +query B +SELECT t::TIME + '-11 hrs'::INTERVAL > '01:00'::TIME +FROM (VALUES ('03:00')) v(t) +---- +true diff --git a/test/sqllogictest/cockroach/timestamp.slt b/test/sqllogictest/cockroach/timestamp.slt index 17eebfbe9cafa..9d27044e9de02 100644 --- a/test/sqllogictest/cockroach/timestamp.slt +++ b/test/sqllogictest/cockroach/timestamp.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,31 +9,963 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/timestamp +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/timestamp # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach +# Not supported by Materialize. +onlyif cockroach query T -SELECT TIMESTAMP '2000-05-05 10:00:00' +SELECT '2000-05-05 10:00:00+03':::TIMESTAMP ---- -2000-05-05 10:00:00 +2000-05-05 10:00:00 +0000 +0000 statement ok -CREATE TABLE a (a int); +CREATE TABLE a (a int); INSERT INTO a VALUES(1) +# Ensure that timestamp serialization doesn't break even if the computation is +# distributed: #28110. + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT '2000-05-05 10:00:00+03':::TIMESTAMP FROM a +---- +2000-05-05 10:00:00 +0000 +0000 + +# Not supported by Materialize. +onlyif cockroach +query T +select '2001-1-18 1:00:00.001-8':::TIMESTAMPTZ +---- +2001-01-18 09:00:00.001 +0000 UTC + +# Test timezone() and ... AT TIME ZONE functions. +subtest timezone + +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO a VALUES(1) +SET TIME ZONE 'PST8PDT' -# Ensure that timestamp serialization doesn't break even if the computation is -# distributed: materialize#28110. +query TT +SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'MST', timezone('MST', TIMESTAMP '2001-02-16 20:38:40') +---- +2001-02-17␠03:38:40+00 2001-02-17␠03:38:40+00 + +query TT +SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST', timezone('MST', TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05') +---- +2001-02-16␠18:38:40 2001-02-16␠18:38:40 + +query TT +SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'MST', timezone('MST', TIMESTAMP '2001-02-16 20:38:40') +---- +2001-02-17␠03:38:40+00 2001-02-17␠03:38:40+00 + +# Test timestamp precisions +subtest timestamp_precision + +# Not supported by Materialize. +onlyif cockroach +query error precision 7 out of range +select '2001-1-18 1:00:00.001':::TIMESTAMP(7) + +# Not supported by Materialize. +onlyif cockroach +query error precision 7 out of range +select '2001-1-18 1:00:00.001':::TIMESTAMPTZ(7) + +# Not supported by Materialize. +onlyif cockroach +query T +select '2001-1-18 1:00:00.001':::TIMESTAMP(0) +---- +2001-01-18 01:00:00 +0000 +0000 + +# Not supported by Materialize. +onlyif cockroach +query T +select '2001-1-18 1:00:00.001':::TIMESTAMP(6) +---- +2001-01-18 01:00:00.001 +0000 +0000 + +# Not supported by Materialize. +onlyif cockroach +query T +select '2001-1-18 1:00:00.001':::TIMESTAMP +---- +2001-01-18 01:00:00.001 +0000 +0000 + +# Not supported by Materialize. +onlyif cockroach +query T +select '2001-1-18 1:00:00.001-8':::TIMESTAMPTZ(0) +---- +2001-01-18 01:00:00 -0800 PST + +# Not supported by Materialize. +onlyif cockroach +query T +select '2001-1-18 1:00:00.001-8':::TIMESTAMPTZ(6) +---- +2001-01-18 01:00:00.001 -0800 PST + +# Not supported by Materialize. +onlyif cockroach +query B +select current_timestamp(3) - current_timestamp <= '1ms'::interval +---- +true + +statement ok +CREATE TABLE timestamp_test ( + id integer PRIMARY KEY, + t TIMESTAMP(5), + ttz TIMESTAMPTZ(4) +) + +statement ok +INSERT INTO timestamp_test VALUES + (1, '2001-01-01 12:00:00.123456', '2001-01-01 12:00:00.123456+4'), + (2, '2001-01-01 12:00:00.12345', '2001-01-01 12:00:00.12345+4'), + (3, '2001-01-01 12:00:00.1234', '2001-01-01 12:00:00.1234+4'), + (4, '2001-01-01 12:00:00.123', '2001-01-01 12:00:00.123+4'), + (5, '2001-01-01 12:00:00.12', '2001-01-01 12:00:00.12+4'), + (6, '2001-01-01 12:00:00.1', '2001-01-01 12:00:00.1+4'), + (7, '2001-01-01 12:00:00', '2001-01-01 12:00:00+4') + +query ITT +SELECT * FROM timestamp_test ORDER BY id ASC +---- +1 2001-01-01␠12:00:00.12346 2001-01-01␠08:00:00.1235+00 +2 2001-01-01␠12:00:00.12345 2001-01-01␠08:00:00.1235+00 +3 2001-01-01␠12:00:00.1234 2001-01-01␠08:00:00.1234+00 +4 2001-01-01␠12:00:00.123 2001-01-01␠08:00:00.123+00 +5 2001-01-01␠12:00:00.12 2001-01-01␠08:00:00.12+00 +6 2001-01-01␠12:00:00.1 2001-01-01␠08:00:00.1+00 +7 2001-01-01␠12:00:00 2001-01-01␠08:00:00+00 + +# Not supported by Materialize. +onlyif cockroach +query TT +select column_name, data_type FROM [SHOW COLUMNS FROM timestamp_test] ORDER BY column_name +---- +id INT8 +t TIMESTAMP(5) +ttz TIMESTAMPTZ(4) + +query ITTTT +SELECT id, t::timestamp(0), t::timestamp(3), ttz::timestamptz(0), ttz::timestamptz(3) FROM timestamp_test ORDER BY id +---- +1 2001-01-01␠12:00:00 2001-01-01␠12:00:00.123 2001-01-01␠08:00:00+00 2001-01-01␠08:00:00.124+00 +2 2001-01-01␠12:00:00 2001-01-01␠12:00:00.123 2001-01-01␠08:00:00+00 2001-01-01␠08:00:00.124+00 +3 2001-01-01␠12:00:00 2001-01-01␠12:00:00.123 2001-01-01␠08:00:00+00 2001-01-01␠08:00:00.123+00 +4 2001-01-01␠12:00:00 2001-01-01␠12:00:00.123 2001-01-01␠08:00:00+00 2001-01-01␠08:00:00.123+00 +5 2001-01-01␠12:00:00 2001-01-01␠12:00:00.12 2001-01-01␠08:00:00+00 2001-01-01␠08:00:00.12+00 +6 2001-01-01␠12:00:00 2001-01-01␠12:00:00.1 2001-01-01␠08:00:00+00 2001-01-01␠08:00:00.1+00 +7 2001-01-01␠12:00:00 2001-01-01␠12:00:00 2001-01-01␠08:00:00+00 2001-01-01␠08:00:00+00 + +# Not supported by Materialize. +onlyif cockroach +# Altering type to more units of precision should work. +statement ok +ALTER TABLE timestamp_test ALTER COLUMN t TYPE timestamp + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE timestamp_test ALTER COLUMN ttz TYPE timestamptz(5) + +statement ok +INSERT INTO timestamp_test VALUES + (100, '2001-01-01 12:00:00.123456', '2001-01-01 12:00:00.123456+4') + +query ITT +SELECT * FROM timestamp_test ORDER BY id ASC +---- +1 2001-01-01␠12:00:00.12346 2001-01-01␠08:00:00.1235+00 +2 2001-01-01␠12:00:00.12345 2001-01-01␠08:00:00.1235+00 +3 2001-01-01␠12:00:00.1234 2001-01-01␠08:00:00.1234+00 +4 2001-01-01␠12:00:00.123 2001-01-01␠08:00:00.123+00 +5 2001-01-01␠12:00:00.12 2001-01-01␠08:00:00.12+00 +6 2001-01-01␠12:00:00.1 2001-01-01␠08:00:00.1+00 +7 2001-01-01␠12:00:00 2001-01-01␠08:00:00+00 +100 2001-01-01␠12:00:00.12346 2001-01-01␠08:00:00.1235+00 + +# Not supported by Materialize. +onlyif cockroach +query TT +select column_name, data_type FROM [SHOW COLUMNS FROM timestamp_test] ORDER BY column_name +---- +id INT8 +t TIMESTAMP +ttz TIMESTAMPTZ(5) + +subtest regression_timestamp_comparison + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE -5 + +query B +SELECT '2001-01-01'::date = '2001-01-01 00:00:00'::timestamp +---- +true + +query B +SELECT '2001-01-01'::date = '2001-01-01 00:00:00-5'::timestamptz +---- +false + +query B +SELECT '2001-01-01 00:00:00'::timestamp = '2001-01-01 01:00:00-4'::timestamptz +---- +false + +subtest regression_django-cockroachdb_47 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE -3 + +query R +SELECT extract(hour FROM '2001-01-01 13:00:00+01'::timestamptz) +---- +12 + +query R +SELECT extract(hour FROM '2001-01-01 13:00:00'::timestamp) +---- +13 + +# Not supported by Materialize. +onlyif cockroach +query R +SELECT extract(timezone FROM '2001-01-01 13:00:00+01:15'::timestamptz) +---- +-10800 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE +3 + +query R +SELECT extract(hour FROM '2001-01-01 13:00:00+01'::timestamptz) +---- +12 + +query R +SELECT extract(hour FROM '2001-01-01 13:00:00'::timestamp) +---- +13 + +# Not supported by Materialize. +onlyif cockroach +query R +SELECT extract(timezone FROM '2001-01-01 13:00:00+01:15'::timestamptz) +---- +10800 + +subtest regression_41776 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE 'GMT+1' + +query T +SELECT '2001-01-01 00:00:00'::TIMESTAMP::TIMESTAMPTZ +---- +2001-01-01 00:00:00+00 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE '+1:00' + +query T +SELECT '2001-01-01 00:00:00'::TIMESTAMP::TIMESTAMPTZ +---- +2001-01-01 00:00:00+00 + + +# test that current_timestamp is correct in different timezones. +subtest current_timestamp_correct_in_timezone + +# Not supported by Materialize. +onlyif cockroach +statement ok +set time zone +3 + +statement ok +create table current_timestamp_test (a timestamp, b timestamptz) + +statement ok +insert into current_timestamp_test values (current_timestamp, current_timestamp) + +# Not supported by Materialize. +onlyif cockroach +statement ok +set time zone 0 + +# Not supported by Materialize. +onlyif cockroach +# a was written at an interval 3 hours ahead, and should persist that way. +# b will remember the timezone, so should be "constant" for comparison's sake. +query TT +select * from current_timestamp_test WHERE a - interval '3h' <> b +---- +2026-07-06␠18:48:34.093 2026-07-06␠18:48:34.093+00 + +subtest localtimestamp_test + +# Not supported by Materialize. +onlyif cockroach +query TTTT +select pg_typeof(localtimestamp), pg_typeof(current_timestamp), pg_typeof(localtimestamp(3)), pg_typeof(current_timestamp(3)) +---- +timestamp without time zone timestamp with time zone timestamp without time zone timestamp with time zone + +# Not supported by Materialize. +onlyif cockroach +query B +select localtimestamp(3) - localtimestamp <= '1ms'::interval +---- +true + +# When doing daylight savings comparisons, ensure they compare correctly. +# Test day before and after DST. +subtest regression_django-cockroachdb_120 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE 'America/Chicago' + +query T +SELECT '1882-05-23T00:00:00-05:51'::timestamptz::text +---- +1882-05-23 05:51:00+00 + +query B +SELECT '2011-03-13'::date = '2011-03-13'::timestamp +---- +true + +query B +SELECT '2011-03-13'::date = '2011-03-13'::timestamptz +---- +true + +query B +SELECT '2011-03-13'::timestamp = '2011-03-13'::timestamptz +---- +true + +query B +SELECT '2011-03-14'::date = '2011-03-14'::timestamp +---- +true + +query B +SELECT '2011-03-14'::date = '2011-03-14'::timestamptz +---- +true + +query B +SELECT '2011-03-14'::timestamp = '2011-03-14'::timestamptz +---- +true + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE '-00:10:15' + +query T +SELECT '1882-05-23T00:00:00-05:51'::timestamptz::text +---- +1882-05-23 05:51:00+00 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE 0 + +# Check default types and expressions get truncated on insert / update. +subtest regression_44774 + +statement ok +CREATE TABLE regression_44774 ( + a timestamp(3) DEFAULT '1970-02-03 12:13:14.123456', + b timestamptz(3) DEFAULT '1970-02-03 12:13:14.123456' +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO regression_44774 VALUES (default, default), ('2020-02-05 19:21:57.261286', '2020-02-05 19:21:57.261286') + +query TT +SELECT a, b FROM regression_44774 ORDER BY a +---- + + +statement ok +UPDATE regression_44774 +SET a = '1970-03-04 13:14:15.123456'::timestamp + '1 sec'::interval, b = '1970-03-04 13:14:15.123456'::timestamptz + '1 sec'::interval +WHERE 1 = 1 +query TT +SELECT a, b FROM regression_44774 ORDER BY a +---- + + +statement ok +DROP TABLE regression_44774 + +# Test for timestamptz math with interval involving DST. +subtest regression-cockroachdb/django-cockroachdb_57 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE 'America/Chicago' + +query T +WITH a(a) AS ( VALUES + ('2010-11-06 23:59:00'::timestamptz + '24 hours'::interval), -- no offset specified + ('2010-11-06 23:59:00'::timestamptz + '1 day'::interval), + ('2010-11-06 23:59:00'::timestamptz + '1 month'::interval), + ('2010-11-07 23:59:00'::timestamptz - '24 hours'::interval), + ('2010-11-07 23:59:00'::timestamptz - '1 day'::interval), + ('2010-11-07 23:59:00'::timestamptz - '1 month'::interval), + ('2010-11-06 23:59:00-05'::timestamptz + '24 hours'::interval), -- offset at time zone + ('2010-11-06 23:59:00-05'::timestamptz + '1 day'::interval), + ('2010-11-06 23:59:00-05'::timestamptz + '1 month'::interval), + ('2010-11-07 23:59:00-06'::timestamptz - '24 hours'::interval), + ('2010-11-07 23:59:00-06'::timestamptz - '1 day'::interval), + ('2010-11-07 23:59:00-06'::timestamptz - '1 month'::interval), + ('2010-11-06 23:59:00-04'::timestamptz + '24 hours'::interval), -- different offset + ('2010-11-06 23:59:00-04'::timestamptz + '1 day'::interval), + ('2010-11-06 23:59:00-04'::timestamptz + '1 month'::interval), + ('2010-11-07 23:59:00-04'::timestamptz - '24 hours'::interval), + ('2010-11-07 23:59:00-04'::timestamptz - '1 day'::interval), + ('2010-11-07 23:59:00-04'::timestamptz - '1 month'::interval) +) select * from a; +---- +2010-12-07 03:59:00+00 +2010-11-08 03:59:00+00 +2010-11-08 03:59:00+00 +2010-10-08 03:59:00+00 +2010-11-07 03:59:00+00 +2010-11-07 03:59:00+00 +2010-10-08 05:59:00+00 +2010-11-07 05:59:00+00 +2010-11-07 05:59:00+00 +2010-12-06 23:59:00+00 +2010-11-07 23:59:00+00 +2010-11-07 23:59:00+00 +2010-10-07 23:59:00+00 +2010-11-06 23:59:00+00 +2010-11-06 23:59:00+00 +2010-12-07 04:59:00+00 +2010-11-08 04:59:00+00 +2010-11-08 04:59:00+00 + +statement ok +CREATE TABLE example (a timestamptz) + +statement ok +INSERT INTO example VALUES + ('2010-11-06 23:59:00'), + ('2010-11-07 23:59:00') + +query TTTTTTTTT +SELECT + a + '24 hours'::interval, a + '1 day'::interval, a + '1 month'::interval, + a - '24 hours'::interval, a - '1 day'::interval, a - '1 month'::interval, + a - '2010-11-06 23:59:00'::timestamptz, + a - '2010-11-07 23:59:00'::timestamptz, + a::string +FROM example +ORDER BY a +---- +2010-11-07␠23:59:00+00 2010-11-07␠23:59:00+00 2010-12-06␠23:59:00+00 2010-11-05␠23:59:00+00 2010-11-05␠23:59:00+00 2010-10-06␠23:59:00+00 00:00:00 -24:00:00 2010-11-06␠23:59:00+00 +2010-11-08␠23:59:00+00 2010-11-08␠23:59:00+00 2010-12-07␠23:59:00+00 2010-11-06␠23:59:00+00 2010-11-06␠23:59:00+00 2010-10-07␠23:59:00+00 24:00:00 00:00:00 2010-11-07␠23:59:00+00 + +statement ok +DROP TABLE example + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TIME ZONE 0 + +subtest regression_46973 + +statement ok +CREATE TABLE regression_46973(c0 TIMESTAMP UNIQUE, c1 TIMESTAMPTZ UNIQUE) + +statement ok +INSERT INTO regression_46973 VALUES ('1970-01-01 00:00:00', '1970-01-01 00:00:00') + +statement error WHERE clause error: CAST does not support casting from bigint to timestamp without time zone +SELECT * FROM regression_46973 WHERE (-9223372036854775808)::TIMESTAMP!=regression_46973.c0 + +statement error WHERE clause error: CAST does not support casting from bigint to timestamp with time zone +SELECT * FROM regression_46973 WHERE (-9223372036854775808)::TIMESTAMPTZ!=regression_46973.c1 + +statement error invalid input syntax for type timestamp: expected_dur_like_tokens can only be called with HOUR, MINUTE, SECOND; got YEAR: "294276\-12\-31 23:59:59\.999999" +SELECT '294276-12-31 23:59:59.999999'::TIMESTAMP(0) + +statement ok +DROP TABLE regression_46973 + +subtest regression_extract_epoch_timestamptz + +# Not supported by Materialize. +onlyif cockroach +query R +set time zone 'Europe/Berlin'; select extract(epoch from TIMESTAMP WITH TIME ZONE '2010-11-06 23:59:00-05:00') +---- +1.28910594e+09 + +# Not supported by Materialize. +onlyif cockroach +query R +set time zone 'UTC'; select extract(epoch from TIMESTAMP WITH TIME ZONE '2010-11-06 23:59:00-05:00') +---- +1.28910594e+09 + +# database-issues#6283 (https://github.com/MaterializeInc/database-issues/issues/6283): +# Materialize does not day-justify timestamp subtraction, so the result is a flat +# hour count rather than "N days HH:MM:SS", and EXTRACT(DAY ...) on it returns 0. +# The age()/subtraction regression block below is skipped because it also depends +# on SET TIME ZONE (SQL-501), so this minimal record captures the divergence. +# PG: 2 days 06:00:00 +query T +SELECT ('2001-01-03 06:00:00'::timestamp - '2001-01-01 00:00:00'::timestamp)::text +---- +54:00:00 + +# Not supported by Materialize. +onlyif cockroach +query TTTTTT +SET TIME ZONE 'Europe/Berlin'; SELECT + age(a::timestamptz, b::timestamptz), + age(b::timestamptz, a::timestamptz), + a::timestamptz - b::timestamptz, + b::timestamptz - a::timestamptz, + a::timestamp - b::timestamp, + b::timestamp - a::timestamp +FROM (VALUES + ('2020-05-06 11:12:13', '2015-06-07 13:14:15'), + ('2020-05-06 15:00:00.112233', '2020-04-03 16:00:00.001122'), + ('2020-02-29 00:02:05', '2019-02-28 18:19:01'), + ('2020-02-29 00:02:05', '2020-01-28 18:19:01'), + ('2020-02-29 00:02:05', '2020-03-28 18:19:01'), + ('2021-02-27 00:02:05.333333', '2019-02-28 18:19:01.444444'), + ('2021-02-27 00:02:05', '2021-01-28 18:19:01'), + ('2021-02-27 00:02:05', '2021-03-28 18:19:01'), + ('2020-02-28 00:02:05', '2020-02-28 18:19:01'), + ('2020-06-30 11:11:11.111111', '2020-06-29 12:12:12.222222') +) regression_age_tests(a, b) +---- +4 years 10 mons 28 days 21:57:58 -4 years -10 mons -28 days -21:57:58 1794 days 21:57:58 -1794 days -21:57:58 1794 days 21:57:58 -1794 days -21:57:58 +1 mon 2 days 23:00:00.111111 -1 mons -2 days -23:00:00.111111 32 days 23:00:00.111111 -32 days -23:00:00.111111 32 days 23:00:00.111111 -32 days -23:00:00.111111 +1 year 05:43:04 -1 years -05:43:04 365 days 05:43:04 -365 days -05:43:04 365 days 05:43:04 -365 days -05:43:04 +1 mon 05:43:04 -1 mons -05:43:04 31 days 05:43:04 -31 days -05:43:04 31 days 05:43:04 -31 days -05:43:04 +-28 days -18:16:56 28 days 18:16:56 -28 days -18:16:56 28 days 18:16:56 -28 days -18:16:56 28 days 18:16:56 +1 year 11 mons 26 days 05:43:03.888889 -1 years -11 mons -26 days -05:43:03.888889 729 days 05:43:03.888889 -729 days -05:43:03.888889 729 days 05:43:03.888889 -729 days -05:43:03.888889 +29 days 05:43:04 -29 days -05:43:04 29 days 05:43:04 -29 days -05:43:04 29 days 05:43:04 -29 days -05:43:04 +-1 mons -1 days -17:16:56 1 mon 1 day 17:16:56 -29 days -17:16:56 29 days 17:16:56 -29 days -18:16:56 29 days 18:16:56 +-18:16:56 18:16:56 -18:16:56 18:16:56 -18:16:56 18:16:56 +22:58:58.888889 -22:58:58.888889 22:58:58.888889 -22:58:58.888889 22:58:58.888889 -22:58:58.888889 + +# Not supported by Materialize. +onlyif cockroach +query T +SET TIME ZONE 'AuStralIA/SyDNEY'; SELECT '2000-05-15 00:00:00'::timestamptz +---- +2000-05-15 00:00:00 +1000 AEST + +# Not supported by Materialize. +onlyif cockroach +query T +SET TIME ZONE 'Europe/Bucharest'; +SELECT t FROM (VALUES + ('2020-10-25 03:00+3'::TIMESTAMPTZ + '0 hour'::interval), + ('2020-10-25 03:00+3'::TIMESTAMPTZ + '1 hour'::interval), + ('2020-10-25 03:00+2'::TIMESTAMPTZ + '0 hour'::interval), + ('2020-10-25 03:00+2'::TIMESTAMPTZ + '1 hour'::interval) +) interval_math_regression_64772(t) +---- +2020-10-25 03:00:00 +0300 EEST +2020-10-25 03:00:00 +0200 EET +2020-10-25 03:00:00 +0200 EET +2020-10-25 04:00:00 +0200 EET + +# Not supported by Materialize. +onlyif cockroach +query TT +SET TIME ZONE 'Europe/Bucharest'; +SELECT date_trunc('day', t), date_trunc('hour', t) FROM (VALUES + ('2020-10-25 03:00+03:00'::timestamptz), + ('2020-10-25 03:00+02:00'::timestamptz) +) date_trunc_regression_64772(t) +---- +2020-10-25 00:00:00 +0300 EEST 2020-10-25 03:00:00 +0300 EEST +2020-10-25 00:00:00 +0300 EEST 2020-10-25 03:00:00 +0200 EET + + +# Test for to_timestamp +statement ok +SET TIME ZONE 'UTC' + +## Test for to_timestamp without implicit type conversion +query TTT +SELECT to_timestamp(1646906263.123456), to_timestamp(1646906263), to_timestamp('1646906263.123456') +---- +2022-03-10␠09:57:43.123456+00 2022-03-10␠09:57:43+00 2022-03-10␠09:57:43.123456+00 + +# Not supported by Materialize. +onlyif cockroach +## Test for to_timestamp with positive and negative infinities +query TT +SELECT to_timestamp('infinity'), to_timestamp('-infinity') +---- +294276-12-31 23:59:59.999999 +0000 UTC -4713-11-24 00:00:00 +0000 UTC + +## Test for to_timestamp with NULL +query T +SELECT to_timestamp(NULL) +---- +NULL + +# Regression test for #83094 (vectorized engine incorrectly formatting an +# interval). +statement ok +CREATE TABLE t (t1 timestamptz, t2 timestamptz); +INSERT INTO t VALUES ('2022-01-01 00:00:00.000000+00:00', '2022-01-02 00:00:00.000000+00:00'); + +query T +SELECT (t2 - t1) FROM t +---- +24:00:00 + +# Not supported by Materialize. +onlyif cockroach +# Rough translation of the to_char tests from PostgreSQL. +statement ok +CREATE TABLE TIMESTAMPTZ_TBL (id SERIAL, d1 timestamp(2) with time zone); +INSERT INTO TIMESTAMPTZ_TBL (d1) VALUES + ('1997-06-10 17:32:01 -07:00'), + ('2001-09-22T18:19:20'); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'DAY Day day DY Dy dy MONTH Month month MON Mon mon') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +wednesday Wednesday wednesday wed Wed wed JUNE June june JUN Jun jun +saturday Saturday saturday sat Sat sat SEPTEMBER September september SEP Sep sep + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +wednesday Wednesday wednesday JUNE June june +saturday Saturday saturday SEPTEMBER September september + +# Not supported by Materialize. +onlyif cockroach query T -SELECT TIMESTAMP '2000-05-05 10:00:00' FROM a +SELECT to_char(d1, 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +1,997 1997 997 97 7 20 2 06 24 162 11 4 2450611 +2,001 2001 001 01 1 21 3 09 38 265 22 7 2452175 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMD FMJ') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +1,997 1997 997 97 7 20 2 6 24 162 11 4 2450611 +2,001 2001 1 1 1 21 3 9 38 265 22 7 2452175 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1::timestamp, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMD FMJ') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +1,997 1997 997 97 7 20 2 6 24 162 11 4 2450611 +2,001 2001 1 1 1 21 3 9 38 265 22 7 2452175 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'HH HH12 HH24 MI SS SSSS') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +12 12 00 32 01 1921 +06 06 18 19 20 65960 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, E'"HH:MI:SS is" HH:MI:SS "\\"text between quote marks\\""') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +HH:MI:SS is 12:32:01 "text between quote marks" +HH:MI:SS is 06:19:20 "text between quote marks" + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'HH24--text--MI--text--SS') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +00--text--32--text--01 +18--text--19--text--20 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'YYYYTH YYYYth Jth') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +1997TH 1997th 2450611th +2001ST 2001st 2452175th + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'YYYY A.D. YYYY a.d. YYYY bc HH:MI:SS P.M. HH:MI:SS p.m. HH:MI:SS pm') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +1997 A.D. 1997 a.d. 1997 ad 12:32:01 A.M. 12:32:01 a.m. 12:32:01 am +2001 A.D. 2001 a.d. 2001 ad 06:19:20 P.M. 06:19:20 p.m. 06:19:20 pm + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'IYYY IYY IY I IW IDDD ID') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +1997 997 97 7 24 164 3 +2001 001 01 1 38 265 6 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID') + FROM TIMESTAMPTZ_TBL ORDER BY id +---- +1997 997 97 7 24 164 3 +2001 1 1 1 38 265 6 + +# SQL-488 (https://linear.app/materializeinc/issue/SQL-488): Materialize does not +# implement the FF1-FF6 fractional-second patterns and copies them into the output +# literally. PG expands them (e.g. the .78901234 row would give "7 78 789 7890 +# 78901 789012 ..." instead of "FF1 FF2 ..."). MS and US work. +query T +SELECT to_char(d, 'FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 MS US') + FROM (VALUES + ('2018-11-02 12:34:56'::timestamptz), + ('2018-11-02 12:34:56.78'::timestamptz), + ('2018-11-02 12:34:56.78901'::timestamptz), + ('2018-11-02 12:34:56.78901234'::timestamptz) + ) d(d) +---- +FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 000 000000 +FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 780 780000 +FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 789 789010 +FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 789 789012 + +# Not supported by Materialize. +onlyif cockroach +query T +SET timezone = '00:00'; +SELECT ARRAY[ + '2018-11-02 12:34:56.78901234'::timestamptz, + '2018-11-02 12:34:56.78901234-07'::timestamptz +] +---- +{"2018-11-02 12:34:56.789012+00","2018-11-02 19:34:56.789012+00"} + +# Not supported by Materialize. +onlyif cockroach +query T +SET timezone = 'Australia/Sydney'; +SELECT ARRAY[ + '2018-11-02 12:34:56.78901234'::timestamptz, + '2018-11-02 12:34:56.78901234-07'::timestamptz +] +---- +{"2018-11-02 12:34:56.789012+11","2018-11-03 06:34:56.789012+11"} + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '00:00'; +SELECT to_char(now(), 'OF') as of_t, to_char(now(), 'TZH:TZM') as "TZH:TZM"; +---- ++00 +00:00 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '+02:00'; +SELECT to_char(now(), 'OF') as of_t, to_char(now(), 'TZH:TZM') as "TZH:TZM"; +---- +-02 -02:00 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '-13:00'; +SELECT to_char(now(), 'OF') as of_t, to_char(now(), 'TZH:TZM') as "TZH:TZM"; +---- ++13 +13:00 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '-00:30'; +SELECT to_char(now(), 'OF') as of_t, to_char(now(), 'TZH:TZM') as "TZH:TZM"; +---- ++00:30 +00:30 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '00:30'; +SELECT to_char(now(), 'OF') as of_t, to_char(now(), 'TZH:TZM') as "TZH:TZM"; +---- +-00:30 -00:30 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '-04:30'; +SELECT to_char(now(), 'OF') as of_t, to_char(now(), 'TZH:TZM') as "TZH:TZM"; +---- ++04:30 +04:30 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '04:30'; +SELECT to_char(now(), 'OF') as of_t, to_char(now(), 'TZH:TZM') as "TZH:TZM"; +---- +-04:30 -04:30 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '-04:15'; +SELECT to_char(now(), 'OF') as of_t, to_char(now(), 'TZH:TZM') as "TZH:TZM"; +---- ++04:15 +04:15 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '04:15'; +SELECT to_char(now(), 'OF') as of_t, to_char(now(), 'TZH:TZM') as "TZH:TZM"; +---- +-04:15 -04:15 + +# Not supported by Materialize. +onlyif cockroach +query TT +RESET timezone; +-- Check of, tzh, tzm with various zone offsets. +SET timezone = '00:00'; +SELECT to_char(now(), 'of') as of_t, to_char(now(), 'tzh:tzm') as "tzh:tzm"; +---- ++00 +00:00 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '+02:00'; +SELECT to_char(now(), 'of') as of_t, to_char(now(), 'tzh:tzm') as "tzh:tzm"; +---- +-02 -02:00 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '-13:00'; +SELECT to_char(now(), 'of') as of_t, to_char(now(), 'tzh:tzm') as "tzh:tzm"; +---- ++13 +13:00 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '-00:30'; +SELECT to_char(now(), 'of') as of_t, to_char(now(), 'tzh:tzm') as "tzh:tzm"; +---- ++00:30 +00:30 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '00:30'; +SELECT to_char(now(), 'of') as of_t, to_char(now(), 'tzh:tzm') as "tzh:tzm"; +---- +-00:30 -00:30 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '-04:30'; +SELECT to_char(now(), 'of') as of_t, to_char(now(), 'tzh:tzm') as "tzh:tzm"; +---- ++04:30 +04:30 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '04:30'; +SELECT to_char(now(), 'of') as of_t, to_char(now(), 'tzh:tzm') as "tzh:tzm"; +---- +-04:30 -04:30 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '-04:15'; +SELECT to_char(now(), 'of') as of_t, to_char(now(), 'tzh:tzm') as "tzh:tzm"; +---- ++04:15 +04:15 + +# Not supported by Materialize. +onlyif cockroach +query TT +SET timezone = '04:15'; +SELECT to_char(now(), 'of') as of_t, to_char(now(), 'tzh:tzm') as "tzh:tzm"; ---- -2000-05-05 10:00:00 +-04:15 -04:15 diff --git a/test/sqllogictest/cockroach/truncate.slt b/test/sqllogictest/cockroach/truncate.slt index 4ca5ffe23ab3c..1d8bac7846292 100644 --- a/test/sqllogictest/cockroach/truncate.slt +++ b/test/sqllogictest/cockroach/truncate.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/truncate +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/truncate # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach statement ok @@ -50,7 +50,7 @@ SELECT * FROM kview 5 6 7 8 -statement error "kview" is not a table +statement error Expected a keyword at the beginning of a statement, found identifier "truncate" TRUNCATE TABLE kview query II rowsort @@ -61,22 +61,36 @@ SELECT * FROM kview 5 6 7 8 +# Not supported by Materialize. +onlyif cockroach statement ok TRUNCATE TABLE kv query II SELECT * FROM kv ---- +1 2 +3 4 +5 6 +7 8 query II SELECT * FROM kview ---- - -query TT -SELECT status, running_status FROM [SHOW JOBS] WHERE job_type = 'SCHEMA CHANGE' +1 2 +3 4 +5 6 +7 8 + +# Not supported by Materialize. +onlyif cockroach +query T retry +SELECT status FROM [SHOW JOBS] WHERE job_type = 'SCHEMA CHANGE GC' ---- -running waiting for GC TTL +running +# Not supported by Materialize. +onlyif cockroach # Ensure that TRUNCATE works with a self referential FK. statement ok CREATE TABLE selfref ( @@ -84,113 +98,192 @@ CREATE TABLE selfref ( Z INT REFERENCES selfref (y) ) +# Not supported by Materialize. +onlyif cockroach statement ok TRUNCATE table selfref +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO selfref VALUES (1, NULL); +# Not supported by Materialize. +onlyif cockroach statement ok DROP TABLE selfref -subtest truncate_interleave +subtest truncate_29010 +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE a (a INT PRIMARY KEY) +CREATE SEQUENCE foo; +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE b (a INT, b INT, PRIMARY KEY (a, b), UNIQUE INDEX(b)) INTERLEAVE IN PARENT a(a) - -statement error "a" is interleaved by table "b" -TRUNCATE a +CREATE TABLE bar ( + id INT NOT NULL DEFAULT nextval('foo':::STRING), + description STRING NULL, + CONSTRAINT "primary" PRIMARY KEY (id ASC), + FAMILY "primary" (id, description) +); +# Not supported by Materialize. +onlyif cockroach statement ok -TRUNCATE a CASCADE +TRUNCATE bar +# Not supported by Materialize. +onlyif cockroach statement ok -TRUNCATE b +DROP TABLE bar; -statement ok -TRUNCATE b CASCADE +subtest truncate_30547 +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE c (c INT PRIMARY KEY, d INT REFERENCES b(b)) - -statement error "b" is referenced by foreign key from table "c" -TRUNCATE a, b +CREATE TABLE tt AS SELECT 'foo' statement ok -INSERT INTO b VALUES(1, 2) +SET vectorize=on -statement ok -INSERT INTO c VALUES(1, 2) +# Not supported by Materialize. +onlyif cockroach +query T +EXPLAIN TRUNCATE TABLE tt +---- +distribution: local +vectorized: true +· +• truncate statement ok -TRUNCATE a CASCADE +RESET vectorize -query II -SELECT * FROM c +# Not supported by Materialize. +onlyif cockroach +# Verify that EXPLAIN did not cause the truncate to be performed. +query T +SELECT * FROM tt ---- +foo -statement ok -CREATE TABLE d (c INT PRIMARY KEY) INTERLEAVE IN PARENT c(c); +# Tests for comments getting moved during truncate. +subtest comments +# Not supported by Materialize. +onlyif cockroach statement ok -TRUNCATE a, b, c, d +CREATE TABLE t ( + x INT, + y INT, + z INT, + INDEX i1 (x), + INDEX i2 (y), + INDEX i3 (z) +); +COMMENT ON COLUMN t.x IS '''hi''); DROP TABLE t;'; +COMMENT ON COLUMN t.z IS 'comm"en"t2'; +COMMENT ON INDEX t@i2 IS 'comm''ent3'; +TRUNCATE t -statement error "c" is interleaved by table "d" -TRUNCATE a, b, c +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT column_name, comment FROM [SHOW COLUMNS FROM t WITH COMMENT] ORDER BY column_name +---- +rowid NULL +x 'hi'); DROP TABLE t; +y NULL +z comm"en"t2 -statement error "c" is interleaved by table "d" -TRUNCATE a, b, c +# Not supported by Materialize. +onlyif cockroach +query TT rowsort +SELECT distinct(index_name), comment FROM [SHOW INDEXES FROM t WITH COMMENT] +---- +t_pkey NULL +i1 NULL +i2 comm'ent3 +i3 NULL + +# Not supported by Materialize. +onlyif cockroach +# Ensure that truncate comment reasignment works when index and column IDs +# don't all start from 1. statement ok -INSERT INTO b VALUES(1, 2) +DROP TABLE t; statement ok -INSERT INTO c VALUES(1, 2) +CREATE TABLE t (x INT, y INT, z INT); +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO d VALUES (1) +ALTER TABLE t DROP COLUMN y; +# Not supported by Materialize. +onlyif cockroach statement ok -TRUNCATE a CASCADE +ALTER TABLE t ADD COLUMN y INT; -query I -SELECT * FROM d ----- +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t DROP COLUMN y; -subtest truncate_29010 +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t ADD COLUMN y INT; statement ok -CREATE SEQUENCE foo; +CREATE INDEX i ON t (x); +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE bar ( - id INT NOT NULL DEFAULT nextval('foo':::STRING), - description STRING NULL, - CONSTRAINT "primary" PRIMARY KEY (id ASC), - FAMILY "primary" (id, description) -); +DROP INDEX t@i; +# Not supported by Materialize. +onlyif cockroach statement ok -TRUNCATE bar +CREATE INDEX i ON t (x); +# Not supported by Materialize. +onlyif cockroach statement ok -DROP TABLE bar; +DROP INDEX t@i; -subtest truncate_30547 +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX i ON t (x); +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE tt AS SELECT 'foo' +COMMENT ON COLUMN t.y IS 'hello1'; +COMMENT ON INDEX t@i IS 'hello2' -query TTT -EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR TRUNCATE TABLE tt +# Not supported by Materialize. +onlyif cockroach +query TT rowsort +SELECT column_name, comment FROM [SHOW COLUMNS FROM t WITH COMMENT] ---- -truncate · · - -# Verify that EXPLAIN did not cause the truncate to be performed. -query T -SELECT * FROM tt +rowid NULL +x NULL +y hello1 +z NULL + +# Not supported by Materialize. +onlyif cockroach +query TT rowsort +SELECT distinct(index_name), comment FROM [SHOW INDEXES FROM t WITH COMMENT] ---- -foo +t_pkey NULL +i hello2 diff --git a/test/sqllogictest/cockroach/tsvector.slt b/test/sqllogictest/cockroach/tsvector.slt new file mode 100644 index 0000000000000..a364cd49cc5ac --- /dev/null +++ b/test/sqllogictest/cockroach/tsvector.slt @@ -0,0 +1,587 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/tsvector +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +query BB +SELECT 'foo:1,2 bar:3'::tsvector @@ 'foo <-> bar'::tsquery, 'foo <-> bar'::tsquery @@ 'foo:1,2 bar:3'::tsvector +---- +true true + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE a (v tsvector, q tsquery) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO a VALUES('foo:1,2 bar:4B'::tsvector, 'foo <2> bar'::tsquery) + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT * FROM a +---- +'bar':4B 'foo':1,2 'foo' <2> 'bar' + +# Not supported by Materialize. +onlyif cockroach +query BB +SELECT 'foo:1,2 bar:4B'::tsvector @@ 'foo <2> bar'::tsquery, 'foo:1,2 bar:4B' @@ 'foo <-> bar'::tsquery +---- +true false + +# Not supported by Materialize. +onlyif cockroach +query BB +SELECT v @@ 'foo <2> bar'::tsquery, v @@ 'foo <-> bar'::tsquery FROM a +---- +true false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT v @@ q FROM a +---- +true + +# Test column modifiers. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE b (a INT PRIMARY KEY DEFAULT 1, v tsvector DEFAULT 'foo:1' ON UPDATE 'bar:2', v2 tsvector AS (v) STORED, v3 tsvector AS (v) VIRTUAL) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE c (a INT PRIMARY KEY DEFAULT 1, q tsquery DEFAULT 'foo' ON UPDATE 'bar', q2 tsquery AS (q) STORED, q3 tsquery AS (q) VIRTUAL) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO b DEFAULT VALUES + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO c DEFAULT VALUES + +# Not supported by Materialize. +onlyif cockroach +query ITTT +SELECT * FROM b +---- +1 'foo':1 'foo':1 'foo':1 + +# Not supported by Materialize. +onlyif cockroach +query ITTT +SELECT * FROM c +---- +1 'foo' 'foo' 'foo' + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE b SET a = 2 WHERE a = 1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE c SET a = 2 WHERE a = 1 + +# Not supported by Materialize. +onlyif cockroach +query ITTT +SELECT * FROM b +---- +2 'bar':2 'bar':2 'bar':2 + +# Not supported by Materialize. +onlyif cockroach +query ITTT +SELECT * FROM c +---- +2 'bar' 'bar' 'bar' + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO b VALUES (3, 'foo:1,5 zoop:3') + +statement error unknown catalog item 'b' +SELECT * FROM b ORDER BY v + +statement error unknown catalog item 'c' +SELECT * FROM c ORDER BY q + +statement error type "tsvector" does not exist +CREATE TABLE tsarray(a tsvector[]) + +statement error type "tsquery" does not exist +CREATE TABLE tsarray(a tsquery[]) + +statement error unknown catalog item 'b' +SELECT a, v FROM b WHERE v > 'bar:2'::tsvector + +statement error unknown catalog item 'c' +SELECT a, q FROM c WHERE q > 'abc'::tsquery + +# Not supported by Materialize. +onlyif cockroach +query IT +SELECT a, v FROM b WHERE v = 'bar:2'::tsvector +---- +2 'bar':2 + +# Not supported by Materialize. +onlyif cockroach +query IT +SELECT a, q FROM c WHERE q = 'bar'::tsquery +---- +2 'bar' + +# Not supported by Materialize. +onlyif cockroach +# Ensure truncation of long position lists. +query T +SELECT ('foo:' || string_agg(g::TEXT,','))::tsvector from generate_series(1,280) g(g); +---- +'foo':1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256 + +# Not supported by Materialize. +onlyif cockroach +# Ensure truncation of large positions. +query T +SELECT 'foo:293847298347'::tsvector +---- +'foo':16383 + +query error type "tsvector" does not exist +SELECT repeat('a', 2047)::tsvector + +query error type "tsquery" does not exist +SELECT repeat('a', 2047)::tsquery + +query error type "tsquery" does not exist +SELECT 'foo <23842937> bar'::tsquery + +query error type "tsvector" does not exist +SELECT repeat('a', 1<<20)::tsvector + +query error type "tsquery" does not exist +SELECT repeat('a', 1<<20)::tsquery + +# Not supported by Materialize. +onlyif cockroach +# TSVECTOR should convert to a JSON element as a string. +query T +VALUES ( json_build_array('''D'':236A,377C,622A ''SDfdZ'' ''aIjQScIT'':213A,418A,827A ''pHhJoarX'':106C,486C ''pjApqSC'' ''qXLpyjUM'':547C ''uWSPY'':10A,822B':::TSVECTOR)::JSONB + ) +---- +["'D':236A,377C,622A 'SDfdZ' 'aIjQScIT':213A,418A,827A 'pHhJoarX':106C,486C 'pjApqSC' 'qXLpyjUM':547C 'uWSPY':10A,822B"] + +# Not supported by Materialize. +onlyif cockroach +# TSQUERY should convert to a JSON element as a string. +query T +VALUES ( json_build_array($$'cat' & 'rat'$$:::TSQUERY)::JSONB) +---- +["'cat' & 'rat'"] + +# Not supported by Materialize. +onlyif cockroach +# Test tsvector inverted indexes. +statement ok +DROP TABLE a; +CREATE TABLE a ( + a TSVECTOR, + b TSQUERY, + INVERTED INDEX(a) +); +INSERT INTO a VALUES('foo:3 bar:4,5'), ('baz:1'), ('foo:3'), ('bar:2') + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT a FROM a@a_a_idx WHERE a @@ 'foo' +---- +'bar':4,5 'foo':3 +'foo':3 + +statement error Expected end of statement, found operator "@" +SELECT a FROM a@a_a_idx WHERE a @@ '!foo' + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT a FROM a@a_a_idx WHERE a @@ 'foo' OR a @@ 'bar' +---- +'bar':4,5 'foo':3 +'foo':3 +'bar':2 + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT a FROM a@a_a_idx WHERE a @@ 'foo | bar' +---- +'bar':4,5 'foo':3 +'foo':3 +'bar':2 + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT a FROM a@a_a_idx WHERE a @@ 'foo | bar' OR a @@ 'baz' +---- +'bar':4,5 'foo':3 +'baz':1 +'foo':3 +'bar':2 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT a FROM a@a_a_idx WHERE a @@ 'foo & bar' +---- +'bar':4,5 'foo':3 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT a FROM a@a_a_idx WHERE a @@ 'foo <-> bar' +---- +'bar':4,5 'foo':3 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT a FROM a@a_a_idx WHERE a @@ 'bar <-> foo' +---- + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT a FROM a@a_a_idx WHERE a @@ 'foo <-> !bar' +---- +'foo':3 + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT a FROM a@a_a_idx WHERE a @@ '!baz <-> bar' +---- +'bar':4,5 'foo':3 +'bar':2 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT a FROM a@a_a_idx WHERE a @@ 'foo & !bar' +---- +'foo':3 + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT a FROM a@a_a_idx WHERE a @@ 'ba:*' +---- +'bar':4,5 'foo':3 +'baz':1 +'bar':2 + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT a FROM a@a_a_idx WHERE a @@ 'ba:* | foo' +---- +'bar':4,5 'foo':3 +'baz':1 +'foo':3 +'bar':2 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT a FROM a@a_a_idx WHERE a @@ 'ba:* & foo' +---- +'bar':4,5 'foo':3 + +# Test that tsvector indexes can't accelerate the @@ operator with no constant +# columns. +statement error Expected end of statement, found operator "@" +EXPLAIN SELECT * FROM a@a_a_idx WHERE a @@ b + +# Not supported by Materialize. +onlyif cockroach +# Regression test for incorrectly marking TSVector type as composite (#95680). +statement ok +CREATE TABLE t95680 (c1 FLOAT NOT NULL, c2 TSVECTOR NOT NULL, INVERTED INDEX (c1 ASC, c2 ASC)); +INSERT INTO t95680 VALUES (1.0::FLOAT, e'\'kCrLZNl\' \'sVDj\' \'yO\' \'z\':54C,440B,519C,794B':::TSVECTOR); + +# Not supported by Materialize. +onlyif cockroach +# More tests for these functions live in pkg/util/tsearch/testdata +query IT +SELECT * FROM ts_parse('default', 'Hello this is a parsi-ng t.est 1.234 4 case324') +---- +1 Hello +1 this +1 is +1 a +1 parsi +1 ng +1 t +1 est +1 1 +1 234 +1 4 +1 case324 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM to_tsvector('simple', 'Hello this is a parsi-ng t.est 1.234 4 case324') +---- +'1':9 '234':10 '4':11 'a':4 'case324':12 'est':8 'hello':1 'is':3 'ng':6 'parsi':5 't':7 'this':2 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM phraseto_tsquery('simple', 'Hello this is a parsi-ng t.est 1.234 4 case324') +---- +'hello' <-> 'this' <-> 'is' <-> 'a' <-> 'parsi' <-> 'ng' <-> 't' <-> 'est' <-> '1' <-> '234' <-> '4' <-> 'case324' + + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT phraseto_tsquery('No hardcoded configuration') +---- +'hardcod' <-> 'configur' + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT plainto_tsquery('No hardcoded configuration') +---- +'hardcod' & 'configur' + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_tsquery('No | hardcoded | configuration') +---- +'hardcod' | 'configur' + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM to_tsquery('simple', 'a | b & c <-> d') +---- +'a' | 'b' & 'c' <-> 'd' + +query error function "to_tsquery" does not exist +SELECT * FROM to_tsquery('simple', 'Hello this is a parsi-ng t.est 1.234 4 case324') + +# Test default variants of the to_ts* functions. + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW default_text_search_config +---- +pg_catalog.english + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_tsvector('Hello I am a potato') +---- +'hello':1 'potato':5 + +statement error unrecognized configuration parameter "default_text_search_config" +SET default_text_search_config = 'blah' + +statement ok +SET default_text_search_config = 'spanish' + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT to_tsvector('Hello I am a potato') +---- +'am':3 'hell':1 'i':2 'potat':5 + +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT to_tsvector('english', ''), to_tsvector('english', 'and the') +---- +· · + +statement error function "to_tsquery" does not exist +SELECT to_tsquery('english', 'the') + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE sentences (sentence text, v TSVECTOR AS (to_tsvector('english', sentence)) STORED, INVERTED INDEX (v)); +INSERT INTO sentences VALUES + ('Future users of large data banks must be protected from having to know how the data is organized in the machine (the internal representation).'), + ('A prompting service which supplies such information is not a satisfactory solution.'), + ('Activities of users at terminals and most application programs should remain unaffected when the internal representation of data is changed and even when some aspects of the external representation + are changed.'), + ('Changes in data representation will often be needed as a result of changes in query, update, and report traffic and natural growth in the types of stored information.'), + ('Existing noninferential, formatted data systems provide users with tree-structured files or slightly more general network models of the data.'), + ('In Section 1, inadequacies of these models are discussed.'), + ('A model based on n-ary relations, a normal form for data base relations, and the concept of a universal data sublanguage are introduced.'), + ('In Section 2, certain operations on relations (other than logical inference) are discussed and applied to the problems of redundancy and consistency in the user’s model.') + +# Not supported by Materialize. +onlyif cockroach +query FFFFT +SELECT +ts_rank(v, query) AS rank, +ts_rank(ARRAY[0.2, 0.3, 0.5, 0.9]:::FLOAT[], v, query) AS wrank, +ts_rank(v, query, 2|8) AS nrank, +ts_rank(ARRAY[0.3, 0.4, 0.6, 0.95]:::FLOAT[], v, query, 1|2|4|8|16|32) AS wnrank, +v +FROM sentences, to_tsquery('english', 'relation') query +WHERE query @@ v +ORDER BY rank DESC +LIMIT 10 +---- +0.075990885 0.15198177 0.00042217158 8.555783e-05 'ari':6 'base':3,13 'concept':17 'data':12,21 'form':10 'introduc':24 'model':2 'n':5 'normal':9 'relat':7,14 'sublanguag':22 'univers':20 +0.06079271 0.12158542 0.0003101669 6.095758e-05 '2':3 'appli':15 'certain':4 'consist':22 'discuss':13 'infer':11 'logic':10 'model':27 'oper':5 'problem':18 'redund':20 'relat':7 'section':2 'user':25 + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #99334. Truncate arrays longer than 4 elements that are +# passed to ts_rank to avoid an internal error. +query F +SELECT + ts_rank(ARRAY[1.0039,2.37098,-0.022,0.4277,0.00387]::FLOAT8[], '''AoS'' ''HXfAX'' ''HeWdr'' ''MIHLoJM'' ''UfIQOM'' ''bw'' ''o'''::TSVECTOR, '''QqJVCgwp'''::TSQUERY) +LIMIT + 2 +---- +0 + +subtest 98804_regression_test + +statement ok +RESET default_text_search_config + +statement ok +CREATE TABLE ab (a TEXT, b TEXT) + +statement ok +INSERT INTO ab VALUES('fat rats', 'fat cats chased fat, out of shape rats'); + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT a @@ b FROM ab +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT b @@ a FROM ab +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'fat rats' @@ b FROM ab +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT b @@ 'fat rats' FROM ab +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT a @@ 'fat cats ate fat bats' FROM ab +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'fat cats ate fat bats' @@ a FROM ab +---- +false + +statement error pgcode 22023 type "tsvector" does not exist +SELECT b @@ a::tsvector FROM ab + +statement error pgcode 22023 type "tsvector" does not exist +SELECT a::tsvector @@ b FROM ab + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'fat bat cat' @@ 'bats fats' +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'bats fats' @@ 'fat bat cat' +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'fat' @@ 'fat rats'::tsvector +---- +true + +# TODO(#75101): The error should be "syntax error in TSQuery". +statement error pgcode 22023 type "tsvector" does not exist +SELECT 'fat cats chased fat, out of shape rats' @@ 'fat rats'::tsvector + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'fat rats'::tsvector @@ 'fat' +---- +true + +# TODO(#75101): The error should be "syntax error in TSQuery". +statement error pgcode 22023 type "tsvector" does not exist +SELECT 'fat rats'::tsvector @@ 'fat cats chased fat, out of shape rats' diff --git a/test/sqllogictest/cockroach/tuple.slt b/test/sqllogictest/cockroach/tuple.slt index 21ddff27b20b1..aafe9dadaa99f 100644 --- a/test/sqllogictest/cockroach/tuple.slt +++ b/test/sqllogictest/cockroach/tuple.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,26 +9,21 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/tuple +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/tuple # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - -statement ok -CREATE TABLE tb(unused INT) - statement ok -INSERT INTO tb VALUES (1) +CREATE TABLE tb(unused INT); INSERT INTO tb VALUES (1) subtest empty_tuple @@ -37,38 +32,33 @@ SELECT 1 IN (SELECT * FROM tb LIMIT 0) ---- false -# NOTE(benesch): empty IN and ANY lists are a CockroachDB-ism that we are not -# current planning to support. -# -# query B -# SELECT 1 IN () -# ---- -# false -# -# query B -# SELECT 1 = ANY () -# ---- -# false +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 1 IN () +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 1 = ANY () +---- +false subtest unlabeled_tuple -# TODO(bram): We don't pretty print tuples the same way as postgres. See cockroach#25522. +# TODO(bram): We don't pretty print tuples the same way as postgres. See #25522. query TT colnames SELECT (1, 2, 'hello', NULL, NULL) AS t, (true, NULL, (false, 6.6, false)) AS u FROM tb ---- t u (1,2,hello,,) (t,,"(f,6.6,f)") -mode standard - -query T multiline +query T SELECT (1, e'hello\nworld') ---- -(1,"hello -world") -EOF - -mode cockroach +(1,"hello⏎world") query BBBBBBBBB colnames SELECT @@ -177,7 +167,7 @@ SELECT a b c d true NULL false NULL -statement error invalid input syntax for type integer +statement error Evaluation error: invalid input syntax for type integer: invalid digit found in string: "hi" SELECT (1, 2) > (1, 'hi') FROM tb statement error unequal number of entries in row expressions @@ -204,15 +194,15 @@ a b c 2 3 1 3 1 2 -# NOTE(benesch): Cockroach mishandles this. This test has been adapted to match -# PostgreSQL. -query III colnames,rowsort +# Not supported by Materialize. +onlyif cockroach +query T colnames,rowsort SELECT (t.*) AS a FROM t ---- -a b c -2 3 1 -3 1 2 -1 2 3 +a +(2,3,1) +(3,1,2) +(1,2,3) query BB colnames SELECT ((1, 2), 'equal') = ((1, 2.0), 'equal') AS a, @@ -230,23 +220,23 @@ a false query B colnames -SELECT (ROW(1 + 9), 'a' || 'b') = (ROW(sqrt(100.0)), 'ab') AS a +SELECT (ROW(pow(1, 10.0) + 9), 'a' || 'b') = (ROW(sqrt(100.0)), 'ab') AS a FROM tb ---- a true query B colnames -SELECT (ROW(sqrt(100.0)), 'ab') = (ROW(1 + 9), 'a' || 'b') AS a +SELECT (ROW(sqrt(100.0)), 'ab') = (ROW(pow(1, 10.0) + 9), 'a' || 'b') AS a FROM tb ---- a true -query error invalid input syntax for type integer +query error Evaluation error: invalid input syntax for type integer: invalid digit found in string: "huh" SELECT ((1, 2), 'equal') = ((1, 'huh'), 'equal') FROM tb -# Issue materialize#3568 +# Issue #3568 statement ok CREATE TABLE kv ( @@ -270,7 +260,7 @@ k v statement ok DROP TABLE kv -# Issue database-issues#3567 +# Issue #12295 query B colnames SELECT 'foo' IN (x, 'aaa') AS r FROM (SELECT 'foo' AS x FROM tb) @@ -313,7 +303,7 @@ true statement ok DROP TABLE t -# Issue materialize#12302 +# Issue #12302 query B colnames SELECT 1 IN (2, NULL) AS r @@ -322,8 +312,10 @@ SELECT 1 IN (2, NULL) AS r r NULL +# Not supported by Materialize. +onlyif cockroach query B colnames -SELECT 1 IN (2, x) AS r FROM (SELECT NULL::int AS x FROM tb) +SELECT 1 IN (2, x) AS r FROM (SELECT NULL AS x FROM tb) ---- r NULL @@ -347,347 +339,331 @@ statement ok CREATE TABLE uvw ( u INT, v INT, - w INT + w INT, + INDEX (u,v,w) ) -statement ok -CREATE INDEX uvw_idx ON uvw (u, v, w) - statement ok INSERT INTO uvw SELECT u, v, w FROM generate_series(0, 3) AS u, generate_series(0, 3) AS v, - generate_series(0, 3) AS w - -statement ok -UPDATE uvw SET u = NULL WHERE u = 0 - -statement ok -UPDATE uvw SET v = NULL WHERE v = 0 - -statement ok + generate_series(0, 3) AS w; +UPDATE uvw SET u = NULL WHERE u = 0; +UPDATE uvw SET v = NULL WHERE v = 0; UPDATE uvw SET w = NULL WHERE w = 0 -# Note: Result differs from Cockroach but matches Postgres. query III colnames SELECT * FROM uvw ORDER BY u, v, w ---- -u v w -1 1 1 -1 1 2 -1 1 3 -1 1 NULL -1 2 1 -1 2 2 -1 2 3 -1 2 NULL -1 3 1 -1 3 2 -1 3 3 -1 3 NULL -1 NULL 1 -1 NULL 2 -1 NULL 3 -1 NULL NULL -2 1 1 -2 1 2 -2 1 3 -2 1 NULL -2 2 1 -2 2 2 -2 2 3 -2 2 NULL -2 3 1 -2 3 2 -2 3 3 -2 3 NULL -2 NULL 1 -2 NULL 2 -2 NULL 3 -2 NULL NULL -3 1 1 -3 1 2 -3 1 3 -3 1 NULL -3 2 1 -3 2 2 -3 2 3 -3 2 NULL -3 3 1 -3 3 2 -3 3 3 -3 3 NULL -3 NULL 1 -3 NULL 2 -3 NULL 3 -3 NULL NULL -NULL 1 1 -NULL 1 2 -NULL 1 3 -NULL 1 NULL -NULL 2 1 -NULL 2 2 -NULL 2 3 -NULL 2 NULL -NULL 3 1 -NULL 3 2 -NULL 3 3 -NULL 3 NULL +u v w +1 1 1 +1 1 2 +1 1 3 +1 1 NULL +1 2 1 +1 2 2 +1 2 3 +1 2 NULL +1 3 1 +1 3 2 +1 3 3 +1 3 NULL +1 NULL 1 +1 NULL 2 +1 NULL 3 +1 NULL NULL +2 1 1 +2 1 2 +2 1 3 +2 1 NULL +2 2 1 +2 2 2 +2 2 3 +2 2 NULL +2 3 1 +2 3 2 +2 3 3 +2 3 NULL +2 NULL 1 +2 NULL 2 +2 NULL 3 +2 NULL NULL +3 1 1 +3 1 2 +3 1 3 +3 1 NULL +3 2 1 +3 2 2 +3 2 3 +3 2 NULL +3 3 1 +3 3 2 +3 3 3 +3 3 NULL +3 NULL 1 +3 NULL 2 +3 NULL 3 +3 NULL NULL +NULL 1 1 +NULL 1 2 +NULL 1 3 +NULL 1 NULL +NULL 2 1 +NULL 2 2 +NULL 2 3 +NULL 2 NULL +NULL 3 1 +NULL 3 2 +NULL 3 3 +NULL 3 NULL NULL NULL 1 NULL NULL 2 NULL NULL 3 NULL NULL NULL -# Note: Result differs from Cockroach but matches Postgres. query III colnames SELECT * FROM uvw WHERE (u, v, w) >= (1, 2, 3) ORDER BY u, v, w ---- -u v w -1 2 3 -1 3 1 -1 3 2 -1 3 3 -1 3 NULL -2 1 1 -2 1 2 -2 1 3 -2 1 NULL -2 2 1 -2 2 2 -2 2 3 -2 2 NULL -2 3 1 -2 3 2 -2 3 3 -2 3 NULL +u v w +1 2 3 +1 3 1 +1 3 2 +1 3 3 +1 3 NULL +2 1 1 +2 1 2 +2 1 3 +2 1 NULL +2 2 1 +2 2 2 +2 2 3 +2 2 NULL +2 3 1 +2 3 2 +2 3 3 +2 3 NULL 2 NULL 1 2 NULL 2 2 NULL 3 2 NULL NULL -3 1 1 -3 1 2 -3 1 3 -3 1 NULL -3 2 1 -3 2 2 -3 2 3 -3 2 NULL -3 3 1 -3 3 2 -3 3 3 -3 3 NULL +3 1 1 +3 1 2 +3 1 3 +3 1 NULL +3 2 1 +3 2 2 +3 2 3 +3 2 NULL +3 3 1 +3 3 2 +3 3 3 +3 3 NULL 3 NULL 1 3 NULL 2 3 NULL 3 3 NULL NULL -# Note: Result differs from Cockroach but matches Postgres. query III colnames SELECT * FROM uvw WHERE (u, v, w) > (2, 1, 1) ORDER BY u, v, w ---- -u v w -2 1 2 -2 1 3 -2 2 1 -2 2 2 -2 2 3 -2 2 NULL -2 3 1 -2 3 2 -2 3 3 -2 3 NULL -3 1 1 -3 1 2 -3 1 3 -3 1 NULL -3 2 1 -3 2 2 -3 2 3 -3 2 NULL -3 3 1 -3 3 2 -3 3 3 -3 3 NULL +u v w +2 1 2 +2 1 3 +2 2 1 +2 2 2 +2 2 3 +2 2 NULL +2 3 1 +2 3 2 +2 3 3 +2 3 NULL +3 1 1 +3 1 2 +3 1 3 +3 1 NULL +3 2 1 +3 2 2 +3 2 3 +3 2 NULL +3 3 1 +3 3 2 +3 3 3 +3 3 NULL 3 NULL 1 3 NULL 2 3 NULL 3 3 NULL NULL -# Note: Result differs from Cockroach but matches Postgres. query III colnames SELECT * FROM uvw WHERE (u, v, w) <= (2, 3, 1) ORDER BY u, v, w ---- -u v w -1 1 1 -1 1 2 -1 1 3 -1 1 NULL -1 2 1 -1 2 2 -1 2 3 -1 2 NULL -1 3 1 -1 3 2 -1 3 3 -1 3 NULL +u v w +1 1 1 +1 1 2 +1 1 3 +1 1 NULL +1 2 1 +1 2 2 +1 2 3 +1 2 NULL +1 3 1 +1 3 2 +1 3 3 +1 3 NULL 1 NULL 1 1 NULL 2 1 NULL 3 1 NULL NULL -2 1 1 -2 1 2 -2 1 3 -2 1 NULL -2 2 1 -2 2 2 -2 2 3 -2 2 NULL -2 3 1 - -# Note: Result differs from Cockroach but matches Postgres. +2 1 1 +2 1 2 +2 1 3 +2 1 NULL +2 2 1 +2 2 2 +2 2 3 +2 2 NULL +2 3 1 + query III colnames SELECT * FROM uvw WHERE (u, v, w) < (2, 2, 2) ORDER BY u, v, w ---- -u v w -1 1 1 -1 1 2 -1 1 3 -1 1 NULL -1 2 1 -1 2 2 -1 2 3 -1 2 NULL -1 3 1 -1 3 2 -1 3 3 -1 3 NULL +u v w +1 1 1 +1 1 2 +1 1 3 +1 1 NULL +1 2 1 +1 2 2 +1 2 3 +1 2 NULL +1 3 1 +1 3 2 +1 3 3 +1 3 NULL 1 NULL 1 1 NULL 2 1 NULL 3 1 NULL NULL -2 1 1 -2 1 2 -2 1 3 -2 1 NULL -2 2 1 +2 1 1 +2 1 2 +2 1 3 +2 1 NULL +2 2 1 -# Note: Result differs from Cockroach but matches Postgres. query III colnames SELECT * FROM uvw WHERE (u, v, w) != (1, 2, 3) ORDER BY u, v, w ---- -u v w -1 1 1 -1 1 2 -1 1 3 -1 1 NULL -1 2 1 -1 2 2 -1 3 1 -1 3 2 -1 3 3 -1 3 NULL -1 NULL 1 -1 NULL 2 -2 1 1 -2 1 2 -2 1 3 -2 1 NULL -2 2 1 -2 2 2 -2 2 3 -2 2 NULL -2 3 1 -2 3 2 -2 3 3 -2 3 NULL -2 NULL 1 -2 NULL 2 -2 NULL 3 -2 NULL NULL -3 1 1 -3 1 2 -3 1 3 -3 1 NULL -3 2 1 -3 2 2 -3 2 3 -3 2 NULL -3 3 1 -3 3 2 -3 3 3 -3 3 NULL -3 NULL 1 -3 NULL 2 -3 NULL 3 -3 NULL NULL -NULL 1 1 -NULL 1 2 -NULL 1 3 -NULL 1 NULL -NULL 2 1 -NULL 2 2 -NULL 3 1 -NULL 3 2 -NULL 3 3 -NULL 3 NULL +u v w +1 1 1 +1 1 2 +1 1 3 +1 1 NULL +1 2 1 +1 2 2 +1 3 1 +1 3 2 +1 3 3 +1 3 NULL +1 NULL 1 +1 NULL 2 +2 1 1 +2 1 2 +2 1 3 +2 1 NULL +2 2 1 +2 2 2 +2 2 3 +2 2 NULL +2 3 1 +2 3 2 +2 3 3 +2 3 NULL +2 NULL 1 +2 NULL 2 +2 NULL 3 +2 NULL NULL +3 1 1 +3 1 2 +3 1 3 +3 1 NULL +3 2 1 +3 2 2 +3 2 3 +3 2 NULL +3 3 1 +3 3 2 +3 3 3 +3 3 NULL +3 NULL 1 +3 NULL 2 +3 NULL 3 +3 NULL NULL +NULL 1 1 +NULL 1 2 +NULL 1 3 +NULL 1 NULL +NULL 2 1 +NULL 2 2 +NULL 3 1 +NULL 3 2 +NULL 3 3 +NULL 3 NULL NULL NULL 1 NULL NULL 2 -# Note: Result differs from Cockroach but matches Postgres. query III colnames SELECT * FROM uvw WHERE (u, v, w) >= (1, NULL, 3) ORDER BY u, v, w ---- -u v w -2 1 1 -2 1 2 -2 1 3 -2 1 NULL -2 2 1 -2 2 2 -2 2 3 -2 2 NULL -2 3 1 -2 3 2 -2 3 3 -2 3 NULL +u v w +2 1 1 +2 1 2 +2 1 3 +2 1 NULL +2 2 1 +2 2 2 +2 2 3 +2 2 NULL +2 3 1 +2 3 2 +2 3 3 +2 3 NULL 2 NULL 1 2 NULL 2 2 NULL 3 2 NULL NULL -3 1 1 -3 1 2 -3 1 3 -3 1 NULL -3 2 1 -3 2 2 -3 2 3 -3 2 NULL -3 3 1 -3 3 2 -3 3 3 -3 3 NULL +3 1 1 +3 1 2 +3 1 3 +3 1 NULL +3 2 1 +3 2 2 +3 2 3 +3 2 NULL +3 3 1 +3 3 2 +3 3 3 +3 3 NULL 3 NULL 1 3 NULL 2 3 NULL 3 3 NULL NULL -# Note: Result differs from Cockroach but matches Postgres. query III colnames SELECT * FROM uvw WHERE (u, v, w) < (2, NULL, 3) ORDER BY u, v, w ---- -u v w -1 1 1 -1 1 2 -1 1 3 -1 1 NULL -1 2 1 -1 2 2 -1 2 3 -1 2 NULL -1 3 1 -1 3 2 -1 3 3 -1 3 NULL +u v w +1 1 1 +1 1 2 +1 1 3 +1 1 NULL +1 2 1 +1 2 2 +1 2 3 +1 2 NULL +1 3 1 +1 3 2 +1 3 3 +1 3 NULL 1 NULL 1 1 NULL 2 1 NULL 3 @@ -698,33 +674,295 @@ DROP TABLE uvw subtest tuple_placeholders -# TODO(benesch): support the statement form of PREPARE and EXECUTE. -# -# statement ok -# PREPARE x AS SELECT $1 = (1,2) AS r FROM tb -# -# statement ok -# PREPARE y AS SELECT (1,2) = $1 AS r FROM tb -# -# query B colnames -# EXECUTE x((1,2)) -# ---- -# r -# true -# -# query B colnames -# EXECUTE y((1,2)) -# ---- -# r -# true -# -# query error expected EXECUTE parameter expression to have type tuple\{int, int\}, but '\(1, 2, 3\)' has type tuple\{int, int, int\} -# EXECUTE x((1,2,3)) +statement ok +PREPARE x AS SELECT $1 = (1,2) AS r FROM tb + +statement ok +PREPARE y AS SELECT (1,2) = $1 AS r FROM tb + +# Not supported by Materialize. +onlyif cockroach +query B colnames +EXECUTE x((1,2)) +---- +r +true + +# Not supported by Materialize. +onlyif cockroach +query B colnames +EXECUTE y((1,2)) +---- +r +true + +query error operator does not exist: text = record\(f1: integer,f2: integer\) +EXECUTE x((1,2,3)) + +subtest labeled_tuple + +# Not supported by Materialize. +onlyif cockroach +# Selecting two tuples +query TT colnames +SELECT ((1, 2, 'hello', NULL, NULL) AS a1, b2, c3, d4, e5) AS r, + ((true, NULL, (false, 6.6, false)) AS a1, b2, c3) AS s + FROM tb +---- +r s +(1,2,hello,,) (t,,"(f,6.6,f)") + +# Not supported by Materialize. +onlyif cockroach +# Duplicate tuple labels are allowed (but access fails when a duplicated label is accessed, +# see the labeled_tuple_column_access_errors subtest) +query T colnames +SELECT ((1, '2') AS a, a) FROM tb +---- +?column? +(1,2) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT ((1, '2', true) AS a, a, b) FROM tb +---- +(1,2,t) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT ((1, '2', true) AS a, b, a) FROM tb +---- +(1,2,t) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT ((1, 'asd', true) AS b, a, a) FROM tb +---- +(1,asd,t) + +# Not supported by Materialize. +onlyif cockroach +query TT colnames +SELECT ((1, 2, 'hello', NULL, NULL) AS a, a, a, a, a) AS r, + ((true, NULL, (false, 6.6, false)) AS a, a, a) AS s + FROM tb +---- +r s +(1,2,hello,,) (t,,"(f,6.6,f)") + +# Not supported by Materialize. +onlyif cockroach +# Comparing tuples +query BBB colnames +SELECT ((2, 2) AS a, b) < ((1, 1) AS c, d) AS r + ,((2, 2) AS a, b) < (1, 2) AS s + ,(2, 2) < ((1, 3) AS c, d) AS t + FROM tb +---- +r s t +false false false + +statement error Expected right parenthesis, found AS +SELECT ((1, 2) AS a, b) > ((1, 'hi') AS c, d) FROM tb + +statement error Expected right parenthesis, found AS +SELECT ((1, 2) AS a, b, c) > ((1, 2, 3) AS a, b, c) FROM tb + +# Not supported by Materialize. +onlyif cockroach +query BBBBBBBBBBBBBBBB colnames +SELECT ((((1, 2) AS a, b), 'value') AS c, d) = ((((1, 2) AS e, f), 'value') AS g, h) AS nnnn + ,((((1, 2) AS a, b), 'value') AS c, d) = (((1, 2) AS e, f), 'value') AS nnnu + ,((((1, 2) AS a, b), 'value') AS c, d) = (((1, 2), 'value') AS g, h) AS nnun + ,((((1, 2) AS a, b), 'value') AS c, d) = ((1, 2), 'value') AS nnuu + ,(((1, 2) AS a, b), 'value') = ((((1, 2) AS e, f), 'value') AS g, h) AS nunn + ,(((1, 2) AS a, b), 'value') = (((1, 2) AS e, f), 'value') AS nunu + ,(((1, 2) AS a, b), 'value') = (((1, 2), 'value') AS g, h) AS nuun + ,(((1, 2) AS a, b), 'value') = ((1, 2), 'value') AS nuuu + ,(((1, 2), 'value') AS c, d) = ((((1, 2) AS e, f), 'value') AS g, h) AS unnn + ,(((1, 2), 'value') AS c, d) = (((1, 2) AS e, f), 'value') AS unnu + ,(((1, 2), 'value') AS c, d) = (((1, 2), 'value') AS g, h) AS unun + ,(((1, 2), 'value') AS c, d) = ((1, 2), 'value') AS unuu + ,((1, 2), 'value') = ((((1, 2) AS e, f), 'value') AS g, h) AS uunn + ,((1, 2), 'value') = (((1, 2) AS e, f), 'value') AS uunu + ,((1, 2), 'value') = (((1, 2), 'value') AS g, h) AS uuun + ,((1, 2), 'value') = ((1, 2), 'value') AS uuuu + FROM tb +---- +nnnn nnnu nnun nnuu nunn nunu nuun nuuu unnn unnu unun unuu uunn uunu uuun uuuu +true true true true true true true true true true true true true true true true + +# Not supported by Materialize. +onlyif cockroach +query BB colnames +SELECT (((ROW(pow(1, 10.0) + 9) AS t1), 'a' || 'b') AS t2, t3) = (((ROW(sqrt(100.0)) AS t4), 'ab') AS t5, t6) AS a + ,(ROW(pow(1, 10.0) + 9), 'a' || 'b') = (((ROW(sqrt(100.0)) AS t4), 'ab') AS t5, t6) AS b + FROM tb +---- +a b +true true + +subtest labeled_tuple_errors + +query error Expected right parenthesis, found AS +SELECT ((((1, 2) AS a, b), 'equal') AS c, d) = ((((1, 'huh') AS e, f), 'equal') AS g, h) FROM tb + +# Ensure the number of labels matches the number of expressions +query error Expected right parenthesis, found AS +SELECT ((1, '2') AS a) FROM tb + +query error Expected right parenthesis, found AS +SELECT (ROW(1) AS a, b) FROM tb + +# Not supported by Materialize. +onlyif cockroach +# But inner tuples can reuse labels +query T colnames +SELECT (( + ( + (((1, '2', 3) AS a, b, c), + ((4,'5') AS a, b), + (ROW(6) AS a)) + AS a, b, c), + ((7, 8) AS a, b), + (ROW('9') AS a)) + AS a, b, c + ) AS r + FROM tb +---- +r +("(""(1,2,3)"",""(4,5)"",""(6)"")","(7,8)","(9)") + +subtest labeled_tuple_column_access + +## base working case + +# Accessing a specific column +query error Expected right parenthesis, found AS +SELECT (((1,2,3) AS a,b,c)).x FROM tb + +# Not supported by Materialize. +onlyif cockroach +query ITBITB colnames +SELECT (((1,'2',true) AS a,b,c)).a + ,(((1,'2',true) AS a,b,c)).b + ,(((1,'2',true) AS a,b,c)).c + ,((ROW(1,'2',true) AS a,b,c)).a + ,((ROW(1,'2',true) AS a,b,c)).b + ,((ROW(1,'2',true) AS a,b,c)).c + FROM tb +---- +a b c a b c +1 2 true 1 2 true + +subtest labeled_tuple_column_access_errors + +# column doesn't exist +query error Expected right parenthesis, found AS +SELECT (((1,2,3) AS a,b,c)).x FROM tb + +# Missing extra parentheses +query error Expected right parenthesis, found AS +SELECT ((1,2,3) AS a,b,c).x FROM tb + +query error Expected right parenthesis, found AS +SELECT ((1,2,3) AS a,b,c).* FROM tb + +# Accessing duplicate labels +query error Expected right parenthesis, found AS +SELECT (((1,2,3) AS a,b,a)).a FROM tb + +query error function unnest\(integer\[\], integer\[\]\) does not exist +SELECT ((unnest(ARRAY[1,2], ARRAY[1,2]))).unnest; + +# No labels +query error field x not found in data type record\(f1: integer,f2: integer,f3: integer\) +SELECT ((1,2,3)).x FROM tb + +# Not supported by Materialize. +onlyif cockroach +query I colnames +SELECT ((1,2,3)).@2 FROM tb +---- +?column? +2 + +query III colnames +SELECT ((1,2,3)).* FROM tb +---- +f1 f2 f3 +1 2 3 + +# Accessing all the columns -# NOTE(benesch): many tests related to a CockroachDB extension called "labeled -# tuples" were removed from this test file. The labeled tuple extension looks -# like a bad hack to work around CockroachDB's missing support for true -# composite types, and I do not expect us to ever support it. +# Not supported by Materialize. +onlyif cockroach +query ITB colnames +SELECT (((1,'2',true) AS a,b,c)).* FROM tb +---- +a b c +1 2 true + +# Not supported by Materialize. +onlyif cockroach +query ITB colnames +SELECT ((ROW(1,'2',true) AS a,b,c)).* FROM tb +---- +a b c +1 2 true + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT (((ROW(1,'2',true) AS a,b,c)).*, 456) FROM tb +---- +("(1,2,t)",456) + +# Not supported by Materialize. +onlyif cockroach +query I colnames +SELECT ((ROW(1) AS a)).* FROM tb +---- +a +1 + + +subtest literal_labeled_tuple_in_subquery + +# Not supported by Materialize. +onlyif cockroach +query ITB colnames +SELECT (x).e, (x).f, (x).g +FROM ( + SELECT ((1,'2',true) AS e,f,g) AS x FROM tb +) +---- +e f g +1 2 true + +# Not supported by Materialize. +onlyif cockroach +query ITB colnames +SELECT (x).* +FROM ( + SELECT ((1,'2',true) AS e,f,g) AS x FROM tb +) +---- +e f g +1 2 true + +subtest labeled_tuples_derived_from_relational_subquery_schema + +# Not supported by Materialize. +onlyif cockroach +query IT + SELECT (x).a, (x).b + FROM (SELECT (ROW(a, b) AS a, b) AS x FROM (VALUES (1, 'one')) AS t(a, b)) +---- +1 one statement ok CREATE TABLE t (a int, b string) @@ -732,14 +970,18 @@ CREATE TABLE t (a int, b string) statement ok INSERT INTO t VALUES (1, 'one'), (2, 'two') +# Not supported by Materialize. +onlyif cockroach query IT - SELECT (x).f1, (x).f2 - FROM (SELECT (ROW(a, b)) AS x FROM t) + SELECT (x).a, (x).b + FROM (SELECT (ROW(a, b) AS a, b) AS x FROM t) ORDER BY 1 LIMIT 1 ---- 1 one +subtest labeled_column_access_from_table + query IT colnames SELECT (t.*).* FROM t ORDER BY 1,2 ---- @@ -747,17 +989,379 @@ a b 1 one 2 two -query I colnames rowsort +query I rowsort SELECT (t).a FROM t ---- -a 1 2 +query T rowsort +SELECT t FROM t +---- +(1,one) +(2,two) + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT row_to_json(t) FROM t +---- +{"a": 1, "b": "one"} +{"a": 2, "b": "two"} + +statement ok +DROP TABLE t + query B SELECT (1, 2, 3) IS NULL AS r ---- false -query error Expected an expression, found right parenthesis +subtest regression_for_34262 + +# Not supported by Materialize. +onlyif cockroach +query B SELECT () = () +---- +true + +# Regression tests for #58439. Ensure there are no errors when accessing columns +# of a null tuple. +subtest regression_58439 + +statement ok +CREATE TABLE t58439 (a INT, b INT); +INSERT INTO t58439 VALUES (1, 10), (2, 20), (3, 30); + +query II +SELECT (ARRAY[t58439.*][0]).* FROM t58439 +---- +NULL NULL +NULL NULL +NULL NULL + +query II +SELECT (ARRAY[t58439.*][2]).* FROM t58439 +---- +NULL NULL +NULL NULL +NULL NULL + +# Regression test for #68308. Do not internally error with a cast of unknown to +# unknown in a tuple. +subtest regression_68308 + +query T +SELECT (1::INT2, NULL) +UNION +SELECT (1::INT, NULL) +---- +(1,) + +# Regression test for #40297: make sure tuples and nulls type-check when +# used together in a "same-typed expression" such as function arguments. +subtest regression_40297 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t(x INT); +CREATE TABLE t40297 AS SELECT g FROM generate_series(NULL, NULL) AS g + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT COALESCE((SELECT ()), NULL) FROM t40297 +---- + +# Not supported by Materialize. +onlyif cockroach +# Adding a cast shouldn't affect the type-checking. +query I +SELECT COALESCE((SELECT ())::record, NULL) FROM t40297 +---- + +# Tuples must be the same length. +statement error Expected an expression, found right parenthesis +SELECT COALESCE((SELECT ()), (SELECT ROW (1))) FROM t40297 + +# Adding a cast here should still work too. +statement error Expected an expression, found right parenthesis +SELECT COALESCE((SELECT ()), (SELECT ROW (1))::t) FROM t40297 + +# If a NULL is casted, then it no longer can be coerced to the right type. +statement error Expected an expression, found right parenthesis +SELECT COALESCE((SELECT ()), NULL::t) FROM t40297 + +# Not supported by Materialize. +onlyif cockroach +# Type-checking should still work for non-empty tuples. +query I +SELECT COALESCE((SELECT '(1)'::t), NULL::t) FROM t40297 +---- + +# (SELECT (1)) is interpreted as an INT. +statement error type "t" does not exist +SELECT COALESCE((SELECT (1)), NULL::t) FROM t40297 + +# Not supported by Materialize. +onlyif cockroach +# Adding ROW allows it to be interpreted as a tuple. +query I +SELECT COALESCE((SELECT ROW (1)), NULL::t) FROM t40297 +---- + +# An anonymous tuple type only works if it is used with a tuple of the correct length. +statement error type "t" does not exist +SELECT COALESCE((SELECT ROW (1, 2)), NULL::t) FROM t40297 + +# It should still type-check correctly without using a subquery. +statement error type "t" does not exist +SELECT COALESCE(ROW (1, 2), NULL::t) FROM t40297 + +# Regression test for #70767. Make sure we avoid encoding arrays where the +# array content type is AnyTuple. +subtest regression_70767 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT + col +FROM + (VALUES ((ARRAY[]::RECORD[])), ((ARRAY[()]))) + AS t(col) +ORDER BY + col ASC +---- +{} +{()} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT + col +FROM + (VALUES (NULL), ((ARRAY[]::RECORD[])), ((ARRAY[()]))) + AS t(col) +ORDER BY + col ASC +---- +NULL +{} +{()} + +# ARRAY[(1)] is type-checked as an int[] -- this also matches Postgres. +statement error cannot reference pseudo type pg_catalog\.record +SELECT + col +FROM + (VALUES ((ARRAY[]::RECORD[])), ((ARRAY[(1)]))) + AS t(col) +ORDER BY + col ASC + +statement error cannot reference pseudo type pg_catalog\.record +SELECT + col +FROM + (VALUES ((ARRAY[]::RECORD[])), ((ARRAY[(1,2)])), ((ARRAY[(1,'cat')]))) + AS t(col) +ORDER BY + col ASC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT + col +FROM + (VALUES ((ARRAY[]::RECORD[])), ((ARRAY[(1,2)]))) + AS t(col) +ORDER BY + col ASC +---- +{} +{"(1,2)"} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT + col +FROM + (VALUES ((ARRAY[(1,2)])), ((ARRAY[]::RECORD[]))) + AS t(col) +ORDER BY + col ASC +---- +{} +{"(1,2)"} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT + col +FROM + (VALUES ((ARRAY[]::RECORD[])), ((ARRAY[(1,2), (3,4)]))) + AS t(col) +ORDER BY + col ASC +---- +{} +{"(1,2)","(3,4)"} + +statement error cannot reference pseudo type pg_catalog\.record +SELECT + col +FROM + (VALUES ((ARRAY[]::RECORD[])), ((ARRAY[(1,2), (3,4), (3,4,5)]))) + AS t(col) +ORDER BY + col ASC + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT + col +FROM + (VALUES ((ARRAY[]::RECORD[])), ((ARRAY[(1,'cat')]))) + AS t(col) +ORDER BY + col ASC +---- +{} +{"(1,cat)"} + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT + t2.c4 +FROM + ( + VALUES + (NULL, (1:::DECIMAL, ARRAY[]:::record[])), + (NULL, (2:::DECIMAL, ARRAY[(1::INT8, 2::INT8)])) + ) + AS t2 (c3, c4) +---- +(1,{}) +(2,"{""(1,2)""}") + +statement error Expected a data type name, found colon +SELECT + t2.c4 +FROM + ( + VALUES + (NULL, (1:::DECIMAL, ARRAY[]:::record[])), + (NULL, (2:::DECIMAL, ARRAY[(1::INT8, 2::INT8, 3::INT8)])), + (NULL, (2:::DECIMAL, ARRAY[(1::INT8, 2::INT8)])) + ) + AS t2 (c3, c4) + +statement error Expected a data type name, found colon +SELECT + t2.c4 +FROM + ( + VALUES + (NULL, (1:::DECIMAL, ARRAY[]:::record[])), + (NULL, (2:::DECIMAL, ARRAY[(1::INT8, 2::INT8)])), + (NULL, (2:::DECIMAL, ARRAY[(1::INT8, 2::INT8, 3::INT8)])) + ) + AS t2 (c3, c4) + +# Regression test #74729. Correctly handle NULLs annotated as a tuple type. +subtest regression_74729 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT CASE WHEN true THEN ('a', 2) ELSE NULL:::RECORD END + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t74729 AS SELECT g % 2 = 1 AS _bool FROM generate_series(1, 5) AS g + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT CASE WHEN _bool THEN (1, ('a', 2)) ELSE (3, NULL) END FROM t74729 + +# Regression test for #78159. Column access of NULL should not cause an internal +# error. +subtest 78159 + +statement ok +CREATE TABLE t78159 (b BOOL) + +statement ok +INSERT INTO t78159 VALUES (false) + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT (CASE WHEN b THEN ((ROW(1) AS a)) ELSE NULL END).a from t78159 +---- +NULL + +# Regression test for #78515. Propagate tuple labels when type-checking +# expressions with multiple matching tuple types. +subtest 78515 + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT (CASE WHEN false THEN (ROW(1) AS a) ELSE (ROW(2) AS a) END).a; + +# Not supported by Materialize. +onlyif cockroach +# The label of the first tuple is used in the type of the CASE expression. This +# is similar to Postgres, but not exactly the same - Postgres uses the labels of +# the last tuple. This difference should be addressed in the future when we try +# to adhere more closely to Postgres's type conversion behavior (see #75101). +statement ok +SELECT (CASE WHEN false THEN (ROW(1) AS a) ELSE (ROW(2) AS b) END).a; + +statement error Expected right parenthesis, found AS +SELECT (CASE WHEN false THEN (ROW(1) AS a) ELSE (ROW(2) AS b) END).b; + +subtest end + +# Regression test for #79484. Verify that type-checking is smart enough +# to handle tuples of arrays of tuples in the VALUES clause. +subtest 79484 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM ( + VALUES + ((ARRAY[15181:::INT8], ARRAY[]:::RECORD[])), + ( + (ARRAY[1534:::INT8], ARRAY[('infinity':::DATE, 'cat':::TEXT)]) + ), + (NULL) +) AS tab(col) +---- +({15181},{}) +({1534},"{""(infinity,cat)""}") +NULL + +subtest end + +# Regression test for incorrect handling of tree.ParenExprs during type-checking +# (#94092). +statement ok +CREATE TABLE t94092 (c INT); +INSERT INTO t94092 VALUES (1); + +query error Expected an expression, found right parenthesis +SELECT (c, 1) != (()) FROM t94092; diff --git a/test/sqllogictest/cockroach/tuple_local.slt b/test/sqllogictest/cockroach/tuple_local.slt new file mode 100644 index 0000000000000..ef644c00c6f5c --- /dev/null +++ b/test/sqllogictest/cockroach/tuple_local.slt @@ -0,0 +1,37 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/tuple_local +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: !fakedist !fakedist-vec-off !fakedist-disk !3node-tenant + +# At the moment, the query below results in an internal error when executed in +# a distributed fashion. We should fix that and merge this file into 'tuple' +# (tracked in #94970). + +# Regression test for not using CompareError when dealing with tuples (#93396). +statement ok +CREATE TABLE t93396 (c1 TIME PRIMARY KEY, c2 INT8); +INSERT INTO t93396 VALUES ('0:0:0'::TIME, 0); + +query error WHERE clause error: Expected subselect to return 1 column, got 2 columns +SELECT * FROM t93396 WHERE (c1, c2) = (SELECT 0.0, 0); diff --git a/test/sqllogictest/cockroach/txn_as_of.slt b/test/sqllogictest/cockroach/txn_as_of.slt new file mode 100644 index 0000000000000..888436bd317d2 --- /dev/null +++ b/test/sqllogictest/cockroach/txn_as_of.slt @@ -0,0 +1,370 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/txn_as_of +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# This test makes use of 'kv.gc_ttl.strict_enforcement.enabled = false', which +# is not available to tenants. We use a cluster option instead. +# cluster-opt: ignore-tenant-strict-gc-enforcement + +statement ok +CREATE TABLE t (i INT) + +statement ok +INSERT INTO t VALUES (2) + +# Verify that transactions can be used for historical reads using BEGIN +# or SET TRANSACTION + +# Not supported by Materialize. +onlyif cockroach +# We're reading from timestamps that precede the GC thresholds, disable strict +# enforcement. +statement ok +SET CLUSTER SETTING kv.gc_ttl.strict_enforcement.enabled = false + +statement error pgcode 3D000 Expected end of statement, found AS +BEGIN AS OF SYSTEM TIME '-1h'; SELECT * FROM t + +statement ok +COMMIT + +statement error pgcode 3D000 Expected transaction mode, found AS +BEGIN; SET TRANSACTION AS OF SYSTEM TIME '-1h'; SELECT * FROM t + +statement ok +COMMIT + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN AS OF SYSTEM TIME '-1us' + +query I +SELECT * FROM t +---- +2 + +statement ok +COMMIT + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; SET TRANSACTION AS OF SYSTEM TIME '-1us' + +query I +SELECT * FROM t +---- +2 + +statement ok +COMMIT + +# Subqueries are only allowed if the exact same timestamp is used. +# This first two fails because '-1h' is computed for each statement based on +# statement time so the timestamps will not be identical. The following two +# tests which use a matching, fixed timestamp should be semantically valid +# leading to a failure due to the relation not existing. + +statement error Expected transaction mode, found AS +BEGIN; SET TRANSACTION AS OF SYSTEM TIME '-1h'; SELECT * FROM t AS OF SYSTEM TIME '-1h' + +statement ok +COMMIT + +statement error Expected end of statement, found AS +BEGIN AS OF SYSTEM TIME '-1h'; SELECT * FROM t AS OF SYSTEM TIME '-1h' + +statement ok +COMMIT + +statement error pgcode 3D000 Expected end of statement, found AS +BEGIN AS OF SYSTEM TIME '2018-12-30'; SELECT * FROM t AS OF SYSTEM TIME '2018-12-30' + +statement ok +COMMIT + +statement error pgcode 3D000 Expected transaction mode, found AS +BEGIN; SET TRANSACTION AS OF SYSTEM TIME '2018-12-30'; SELECT * FROM t AS OF SYSTEM TIME '2018-12-30' + +statement ok +COMMIT + +# Verify transactions with a historical timestamps imply READ ONLY. + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; SET TRANSACTION AS OF SYSTEM TIME '-1us' + +# Not supported by Materialize. +onlyif cockroach +statement error pq: cannot execute INSERT in a read-only transaction +INSERT INTO t VALUES (3) + +statement ok +COMMIT + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN AS OF SYSTEM TIME '-1us' + +# Not supported by Materialize. +onlyif cockroach +statement error pq: cannot execute INSERT in a read-only transaction +INSERT INTO t VALUES (3) + +statement ok +COMMIT + +# Verify setting the timestamp after beginning with a timestamp overwrites +# the previous value. + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN AS OF SYSTEM TIME '-1h'; SET TRANSACTION AS OF SYSTEM TIME '-1us'; + +query I +SELECT * FROM t +---- +2 + +statement ok +COMMIT + +# Verify that setting other parts of a transaction mode does not overwrite +# the AOST from the BEGIN. + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN AS OF SYSTEM TIME '-1h'; SET TRANSACTION PRIORITY HIGH; + +# Not supported by Materialize. +onlyif cockroach +statement error pgcode 3D000 pq: database "test" does not exist +SELECT * FROM t + +statement ok +COMMIT + +# Verify that setting a TRANSACTION READ WRITE is an error if the transaction +# has a historical timestamp. + +statement error Expected end of statement, found AS +BEGIN AS OF SYSTEM TIME '-1h'; SET TRANSACTION READ WRITE; + +statement ok +COMMIT + +statement error Expected end of statement, found AS +BEGIN AS OF SYSTEM TIME '-1h', READ WRITE + +statement ok +BEGIN + +statement error Expected transaction mode, found AS +SET TRANSACTION AS OF SYSTEM TIME '-1h', READ WRITE + +statement ok +COMMIT + +# Verify that the TxnTimestamp used to generate now() and current_timestamp() is +# set to the historical timestamp. + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN AS OF SYSTEM TIME '2018-01-01'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM (SELECT now()) AS OF SYSTEM TIME '2018-01-01' +---- +2018-01-01 00:00:00 +0000 UTC + +statement ok +COMMIT + +# Verify that the the historical timestamp used in a SET TRANSACTION can +# overwrite the timestamp set in a BEGIN. + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN AS OF SYSTEM TIME '2019-01-01' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TRANSACTION AS OF SYSTEM TIME '2018-01-01' + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM (SELECT now()) +---- +2026-07-06 18:48:56.219+00 + +statement ok +COMMIT + +# Verify that a historical timestamp is preserved after a ROLLBACK to a +# SAVEPOINT for a historical transaction initiated in the BEGIN. + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN AS OF SYSTEM TIME '2019-01-01' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SAVEPOINT cockroach_restart; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM (SELECT now()) +---- +2026-07-06 18:48:56.221+00 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ROLLBACK TO SAVEPOINT cockroach_restart; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM (SELECT now()) +---- +2026-07-06 18:48:56.223+00 + +# Not supported by Materialize. +onlyif cockroach +statement ok +RELEASE SAVEPOINT cockroach_restart + +statement ok +COMMIT; + +# Verify that a historical timestamp is preserved after a ROLLBACK to a +# SAVEPOINT for a historical transaction initiated in SET TRANSACTION + +statement ok +BEGIN; + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TRANSACTION AS OF SYSTEM TIME '2019-01-01' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SAVEPOINT cockroach_restart; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM (SELECT now()) +---- +2026-07-06 18:48:56.225+00 + +# Not supported by Materialize. +onlyif cockroach +statement ok +ROLLBACK TO SAVEPOINT cockroach_restart; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM (SELECT now()) +---- +2026-07-06 18:48:56.225+00 + +# Not supported by Materialize. +onlyif cockroach +statement ok +RELEASE SAVEPOINT cockroach_restart + +statement ok +COMMIT; + +# Verify that rolling back after a syntax error which moves the conn to the +# aborted state maintains the transaction timestamp. + +statement ok +BEGIN; + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET TRANSACTION AS OF SYSTEM TIME '2019-01-01' + +# Not supported by Materialize. +onlyif cockroach +statement ok +SAVEPOINT cockroach_restart; + +statement error Expected a keyword at the beginning of a statement, found identifier "selct" +SELCT; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ROLLBACK TO SAVEPOINT cockroach_restart; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT * FROM (SELECT now()) +---- +2019-01-01 00:00:00 +0000 UTC + +# Not supported by Materialize. +onlyif cockroach +statement ok +RELEASE SAVEPOINT cockroach_restart + +statement ok +COMMIT + +# Ensure that errors evaluating AOST clauses in BEGIN and SET TRANSACTION do not +# cause problems. + +statement error Expected end of statement, found AS +BEGIN AS OF SYSTEM TIME '0' + +statement ok +BEGIN + +statement error Expected transaction mode, found AS +SET TRANSACTION AS OF SYSTEM TIME '0' + +statement ok +ROLLBACK diff --git a/test/sqllogictest/cockroach/type_privileges.slt b/test/sqllogictest/cockroach/type_privileges.slt new file mode 100644 index 0000000000000..27cd19aef9515 --- /dev/null +++ b/test/sqllogictest/cockroach/type_privileges.slt @@ -0,0 +1,174 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/type_privileges +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Types created in the public schema have usage provided to public. +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT CREATE, DROP ON DATABASE test TO testuser; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TYPE test AS ENUM ('hello'); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE for_view(x test); + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT SELECT on for_view TO testuser; + +# Ensure a user without explicit privileges can use the type if it is +# the public schema. +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t(x test) + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE t + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE USAGE ON TYPE test FROM public; + +user testuser + +statement error type "test" does not exist +CREATE TABLE t(x test) + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT 'hello'::test + +statement error type "test" does not exist +CREATE VIEW vx1 as SELECT 'hello'::test + +statement error unknown catalog item 'for_view' +CREATE VIEW vx2 as SELECT x FROM for_view + +# Granting usage on a type to a specific user should allow the user to +# create objects that depend on the type. +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT USAGE ON TYPE test TO testuser + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t(x test); + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW vx1 as SELECT 'hello'::test + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW vx2 as SELECT x FROM for_view + +# Need to be owner of a type to alter it. +statement error Expected OWNER, found RENAME +ALTER TYPE test RENAME TO not_test + +# Need to be owner of a type to drop it. +statement error type "test" does not exist +DROP TYPE test + +user root + +# SELECT, INSERT, DELETE, UPDATE, ZONECONFIG privileges +# should not be grantable on types. + +statement error type "test" does not exist +GRANT SELECT ON type TEST to testuser + +statement error type "test" does not exist +GRANT INSERT ON type TEST to testuser + +statement error type "test" does not exist +GRANT DELETE ON type TEST to testuser + +statement error type "test" does not exist +GRANT UPDATE ON type TEST to testuser + +statement error Expected TO, found ON +GRANT ZONECONFIG ON type TEST to testuser + +# ALL, and GRANT should be grantable to enums. + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT ALL ON type TEST to testuser + +# Not supported by Materialize. +onlyif cockroach +# Grant ownership to testuser to allow testuser to drop and alter the type. +statement ok +GRANT root TO testuser + +# Not supported by Materialize. +onlyif cockroach +# Drop objects that dependent on type in preparation for dropping the type, +# since we do not support drop type cascade yet. +statement ok +DROP VIEW vx1; +DROP VIEW vx2; +DROP TABLE t; +DROP TABLE for_view; + +user testuser + +# Not supported by Materialize. +onlyif cockroach +# testuser should be able to alter the type now. +statement ok +ALTER TYPE test RENAME to test1 + +# Not supported by Materialize. +onlyif cockroach +# testuser should be able to drop the type now. +statement ok +DROP TYPE test1 diff --git a/test/sqllogictest/cockroach/typing.slt b/test/sqllogictest/cockroach/typing.slt index 5d142ec2875f4..90171c87574a5 100644 --- a/test/sqllogictest/cockroach/typing.slt +++ b/test/sqllogictest/cockroach/typing.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,12 +9,15 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/typing +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/typing # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach @@ -23,33 +26,30 @@ statement ok CREATE TABLE f (x FLOAT) statement ok -INSERT INTO f(x) VALUES (1e10000 * 1e-9999), (3/2), (1) +INSERT INTO f(x) VALUES (3/2), (1) query R rowsort SELECT * FROM f ---- -10 -1.5 +1 1 statement ok CREATE TABLE i (x INT) -statement error value type decimal doesn't match type int of column "x" -INSERT INTO i(x) VALUES (4.5) +statement error column "x" is of type integer but expression is of type timestamp with time zone +INSERT INTO i(x) VALUES ('1970-01-01'::timestamptz) statement ok -INSERT INTO i(x) VALUES (((9 / 3) * (1 / 3))), (2.0), (2.4 + 4.6) +INSERT INTO i(x) VALUES (2.0) -statement error numeric constant out of int64 range +statement error "9223372036854775809" integer out of range INSERT INTO i(x) VALUES (9223372036854775809) query I rowsort SELECT * FROM i ---- -1 2 -7 statement ok CREATE TABLE d (x DECIMAL) @@ -60,8 +60,8 @@ INSERT INTO d(x) VALUES (((9 / 3) * (1 / 3))), (2.0), (2.4 + 4.6) query R rowsort SELECT * FROM d ---- -1 -2.0 +0 +2 7 statement ok @@ -70,128 +70,143 @@ UPDATE d SET x = x + 1 WHERE x + sqrt(x) >= 2 + .1 query R rowsort SELECT * FROM d ---- -1 -3.0 +0 +3 8 statement ok CREATE TABLE s (x STRING) +# Not supported by Materialize. +onlyif cockroach query T SELECT * FROM s WHERE x > b'\x00' ---- +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO s(x) VALUES (b'qwe'), ('start' || b'end') +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO s(x) VALUES (b'\xfffefd') query IT rowsort SELECT length(x), encode(x::bytes, 'escape') from s ---- -3 qwe -8 startend -5 \377fefd + +# Not supported by Materialize. +onlyif cockroach statement error incompatible COALESCE expressions: could not parse "foo" as type int INSERT INTO s VALUES (COALESCE(1, 'foo')) +# Not supported by Materialize. +onlyif cockroach statement error incompatible COALESCE expressions: could not parse "foo" as type int INSERT INTO i VALUES (COALESCE(1, 'foo')) +# Not supported by Materialize. +onlyif cockroach query error incompatible COALESCE expressions: could not parse "foo" as type int SELECT COALESCE(1, 'foo') +# Not supported by Materialize. +onlyif cockroach query error incompatible COALESCE expressions: could not parse "foo" as type int SELECT COALESCE(1::INT, 'foo') -query R +# Not supported by Materialize. +onlyif cockroach +query error expected 2.3 to be of type int, found type decimal SELECT greatest(-1, 1, 2.3, 123456789, 3 + 5, -(-4)) + +query I +SELECT greatest(-1, 1, 2, 123456789, 3 + 5, -(-4)) ---- 123456789 query T SELECT greatest('2010-09-29', '2010-09-28'::TIMESTAMP) ---- -2010-09-29 00:00:00 +0000 +0000 +2010-09-29 00:00:00 +# Not supported by Materialize. +onlyif cockroach query T SELECT greatest('PT12H2M', 'PT12H2M'::INTERVAL, '1s') ---- 12:02:00 -# This is a current limitation where a nested constant that does not get folded (eg. abs(-9)) -# will not be exposed to the same constant type resolution rules as other constants, meaning that -# it may miss out on being upcast. The limitation could be addressed by either improving the -# scope of constant folding or improving homogeneous type resolution. -# TODO(nvanbenschoten) We may be able to address this by desiring the commonNumericConstantType -# of all constants for the first resolvableExpr in typeCheckSameTypedExprs when the parent -# expression has no desired type. -query error greatest\(\): expected -1.123 to be of type int, found type decimal -SELECT greatest(-1.123, 1.21313, 2.3, 123456789.321, 3 + 5.3213, -(-4.3213), abs(-9)) - query R -SELECT greatest(-1, 1, 2.3, 123456789, 3 + 5, -(-4), abs(-9.0)) +SELECT greatest(-1.123, 1.21313, 2.3, 123456789.321, 3 + 5.3213, -(-4.3213), abs(-9)) ---- -123456789 +123456789.321 statement ok CREATE TABLE untyped (b bool, n INT, f FLOAT, e DECIMAL, d DATE, ts TIMESTAMP, tz TIMESTAMPTZ, i INTERVAL) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO untyped VALUES ('f', '42', '4.2', '4.20', '2010-09-28', '2010-09-28 12:00:00.1', '2010-09-29 12:00:00.1', 'PT12H2M') query BIRRTTTT SELECT * FROM untyped ---- -false 42 4.2 4.20 2010-09-28 00:00:00 +0000 +0000 2010-09-28 12:00:00.1 +0000 +0000 2010-09-29 12:00:00.1 +0000 UTC 12:02:00 -# Issue materialize#14527: support string literal coercion during overload resolution + +# Issue #14527: support string literal coercion during overload resolution query T SELECT ts FROM untyped WHERE ts != '2015-09-18 00:00:00' ---- -2010-09-28 12:00:00.1 +0000 +0000 -# Regression tests for materialize#15050 -statement error unsupported comparison operator: < +# Regression tests for #15050 + +# Not supported by Materialize. +onlyif cockroach +statement error pq: parsing as type timestamp: could not parse "Not Timestamp" CREATE TABLE t15050a (c DECIMAL DEFAULT CASE WHEN now() < 'Not Timestamp' THEN 2 ELSE 2 END); -statement error unsupported comparison operator: < +statement error function "if" does not exist CREATE TABLE t15050b (c DECIMAL DEFAULT IF(now() < 'Not Timestamp', 2, 2)); -# Regression tests for materialize#15632 +# Regression tests for #15632 -statement error incompatible IFNULL expressions: could not parse "foo" as type bool +statement error function "ifnull" does not exist SELECT IFNULL('foo', false) -statement error incompatible IFNULL expressions: could not parse "foo" as type bool +statement error function "ifnull" does not exist SELECT IFNULL(true, 'foo') +# Not supported by Materialize. +onlyif cockroach query B SELECT IFNULL(false, 'true') ---- false +# Not supported by Materialize. +onlyif cockroach query B SELECT IFNULL('true', false) ---- true -# Regression tests for materialize#19770 +# Regression tests for #19770 query B SELECT 1 in (SELECT 1) ---- true -# The heuristic planner and the optimizer give different errors for this query. -# Accept them both. -statement error (unsupported comparison operator: IN |could not parse "a" as type int) +statement error operator does not exist: integer = text SELECT 1 IN (SELECT 'a') -statement error unsupported comparison operator: IN +statement error operator does not exist: integer = record\(f1: integer,f2: integer\) SELECT 1 IN (SELECT (1, 2)) query B @@ -199,6 +214,8 @@ SELECT (1, 2) IN (SELECT 1, 2) ---- true +# Not supported by Materialize. +onlyif cockroach query B SELECT (1, 2) IN (SELECT (1, 2)) ---- @@ -218,4 +235,97 @@ INSERT INTO t1 VALUES (DATE '2018-01-01'); INSERT INTO t2 VALUES (TIMESTAMPTZ '2 query TT SELECT * FROM t1, t2 WHERE a = b AND age(b, TIMESTAMPTZ '2017-01-01') > INTERVAL '1 day' ---- -2018-01-01 00:00:00 +0000 +0000 2018-01-01 00:00:00 +0000 UTC +2018-01-01 2018-01-01␠00:00:00+00 + +# Regression test for #44181: allow left side of BETWEEN to be typed +# differently in the two comparisons. +query B +SELECT '' BETWEEN ''::BYTES AND ''; +---- +true + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #44632: NULLIF should have the type of the first argument. +query I +SELECT NULLIF(NULL, 0) + NULLIF(NULL, 0) +---- +NULL + +query I +SELECT NULLIF(0, 0) + NULLIF(0, 0) +---- +NULL + +query I +SELECT NULLIF(0, NULL) + NULLIF(0, NULL) +---- +0 + +# Regression test for #46196. +query T +SELECT max(t0.c0) FROM (VALUES (NULL), (NULL)) t0(c0) +---- +NULL + +query T +SELECT max(NULL) FROM (VALUES (NULL), (NULL)) t0(c0) +---- +NULL + +# Test qualified type references. +query IITR +SELECT 1::pg_catalog.int4, 1::pg_catalog.int8, 'aa'::pg_catalog.text, 4.2::pg_catalog.float4 +---- +1 1 aa 4.2 + +# Test fixed-length types. + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT VARCHAR(4) 'foo', CHAR(2) 'bar', STRING(1) 'cat' +---- +foo ba c + +# Test that we error out referencing unknown types in pg_catalog. +query error type "pg_catalog\.special_int" does not exist +SELECT 1::pg_catalog.special_int + +# Test that we error out trying to reference types in schemas that +# don't have types. +query error unknown schema 'crdb_internal' +SELECT 1::crdb_internal.mytype + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #50978. +query T +SELECT CASE WHEN true THEN 1234:::OID ELSE COALESCE(NULL, NULL) END +---- +1234 + +# Regression test for #51099. +query B rowsort +SELECT CASE WHEN x > 1 THEN true ELSE NULL AND true END FROM (VALUES (1), (2)) AS v(x) +---- +NULL +true + +query B rowsort +SELECT CASE WHEN x > 1 THEN true ELSE NULL OR false END FROM (VALUES (1), (2)) AS v(x) +---- +NULL +true + +# Error "cannot determine type of empty array" should apply no matter the +# operator, `>`, or `<`. +query error SOME requires a single expression or subquery, not an expression list +SELECT ARRAY[]::TIMESTAMPTZ[] > + SOME (ARRAY[TIMESTAMPTZ '1969-12-29T21:20:13+01'], ARRAY[NULL]); + +# Error "cannot determine type of empty array" should apply no matter the +# operator, `>`, or `<`. +query error SOME requires a single expression or subquery, not an expression list +SELECT ARRAY[]::TIMESTAMPTZ[] < + SOME (ARRAY[TIMESTAMPTZ '1969-12-29T21:20:13+01'], ARRAY[NULL]); diff --git a/test/sqllogictest/cockroach/udf_in_constraints.slt b/test/sqllogictest/cockroach/udf_in_constraints.slt new file mode 100644 index 0000000000000..9da5d7517b173 --- /dev/null +++ b/test/sqllogictest/cockroach/udf_in_constraints.slt @@ -0,0 +1,530 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/udf_in_constraints +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f1(a INT) RETURNS INT LANGUAGE SQL AS $$ SELECT a + 1 $$; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW v_checks AS +SELECT + id, + jsonb_pretty( + crdb_internal.pb_to_json( + 'cockroach.sql.sqlbase.Descriptor', + descriptor, + false + )->'table'->'checks' + ) as checks +FROM system.descriptor + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION get_checks(table_id INT) RETURNS STRING +LANGUAGE SQL +AS $$ + SELECT checks + FROM v_checks + WHERE id = table_id +$$; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE VIEW v_fn_depended_on_by AS +SELECT + id, + jsonb_pretty( + crdb_internal.pb_to_json( + 'cockroach.sql.sqlbase.Descriptor', + descriptor, + false + )->'function'->'dependedOnBy' + ) as depended_on_by +FROM system.descriptor + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION get_fn_depended_on_by(function_id INT) RETURNS STRING +LANGUAGE SQL +AS $$ + SELECT depended_on_by + FROM v_fn_depended_on_by + WHERE id = function_id +$$; + +# Not supported by Materialize. +onlyif cockroach +# Make sure that check constraint expression is properly serialized and +# deserialized. +statement ok +CREATE TABLE t1( + a INT PRIMARY KEY, + b INT CHECK (f1(b) > 1), + FAMILY fam_0 (a, b) +); + +let $tbl_id +SELECT id FROM system.namespace WHERE name = 't1'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_checks($tbl_id); +---- +[ + { + "columnIds": [ + 2 + ], + "constraintId": 2, + "expr": "[FUNCTION 100106](b) \u003e 1:::INT8", + "name": "check_b" + } +] + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t1]; +---- +CREATE TABLE public.t1 ( + a INT8 NOT NULL, + b INT8 NULL, + CONSTRAINT t1_pkey PRIMARY KEY (a ASC), + FAMILY fam_0 (a, b), + CONSTRAINT check_b CHECK (public.f1(b) > 1:::INT8) +) + +# Make sure back references are tracked properly. +let $fn_id +SELECT oid::int - 100000 FROM pg_catalog.pg_proc WHERE proname = 'f1'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_fn_depended_on_by($fn_id) +---- +[ + { + "constraintIds": [ + 2 + ], + "id": 111 + } +] + +# Not supported by Materialize. +onlyif cockroach +# Make sure ADD CONSTRAINT works as expected. +statement ok +ALTER TABLE t1 ADD CONSTRAINT cka CHECK (f1(a) > 1); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_checks($tbl_id); +---- +[ + { + "columnIds": [ + 2 + ], + "constraintId": 2, + "expr": "[FUNCTION 100106](b) \u003e 1:::INT8", + "name": "check_b" + }, + { + "columnIds": [ + 1 + ], + "constraintId": 3, + "expr": "[FUNCTION 100106](a) \u003e 1:::INT8", + "name": "cka" + } +] + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_fn_depended_on_by($fn_id) +---- +[ + { + "constraintIds": [ + 2, + 3 + ], + "id": 111 + } +] + +# Not supported by Materialize. +onlyif cockroach +# Make sure references from different tables are tracked properly. +statement ok +CREATE TABLE t2( + a INT PRIMARY KEY, + b INT CHECK (f1(b) > 1), + CONSTRAINT cka CHECK (f1(a) > 1) +); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_fn_depended_on_by($fn_id) +---- +[ + { + "constraintIds": [ + 2, + 3 + ], + "id": 111 + }, + { + "constraintIds": [ + 2, + 3 + ], + "id": 112 + } +] + +# Not supported by Materialize. +onlyif cockroach +# Make sure DROP CONSTRAINT remove references properly. +statement ok +ALTER TABLE t2 DROP CONSTRAINT check_b; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_fn_depended_on_by($fn_id) +---- +[ + { + "constraintIds": [ + 2, + 3 + ], + "id": 111 + }, + { + "constraintIds": [ + 2 + ], + "id": 112 + } +] + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t2 DROP CONSTRAINT cka; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_fn_depended_on_by($fn_id) +---- +[ + { + "constraintIds": [ + 2, + 3 + ], + "id": 111 + } +] + +# Not supported by Materialize. +onlyif cockroach +# Make sure that DROP TABLE remove references properly. +statement ok +DROP TABLE t1; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_fn_depended_on_by($fn_id) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +# Make sure function cannot be dropped if used in constraints +statement ok +CREATE TABLE t1( + a INT PRIMARY KEY, + b INT CHECK (f1(b) > 1), + FAMILY fam_0 (a, b) +); + +statement error Unsupported DROP on FUNCTION +DROP FUNCTION f1; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER TABLE t1 DROP CONSTRAINT check_b; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP FUNCTION f1; + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP TABLE t1; + +# Not supported by Materialize. +onlyif cockroach +# Make sure that CREATE FUNCTION and CREATE TABLE works in one txn. +statement ok +BEGIN; +CREATE FUNCTION f1(a INT) RETURNS INT LANGUAGE SQL AS $$ SELECT a + 1 $$; +CREATE TABLE t1( + a INT PRIMARY KEY, + b INT CHECK (f1(b) > 1), + FAMILY fam_0 (a, b) +); +END; + +let $tbl_id +SELECT id FROM system.namespace WHERE name = 't1'; + +let $fn_id +SELECT oid::int - 100000 FROM pg_catalog.pg_proc WHERE proname = 'f1'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_checks($tbl_id); +---- +[ + { + "columnIds": [ + 2 + ], + "constraintId": 2, + "expr": "[FUNCTION 100114](b) \u003e 1:::INT8", + "name": "check_b" + } +] + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_fn_depended_on_by($fn_id); +---- +[ + { + "constraintIds": [ + 2 + ], + "id": 115 + } +] + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +DROP TABLE t1; +DROP FUNCTION f1; +END; + +# Make sure that CREATE FUNCTION and ADD CONSTRAINT works in one txn. +statement ok +CREATE TABLE t1 ( + a INT PRIMARY KEY, + b INT, + FAMILY fam_0 (a, b) +); + +# Not supported by Materialize. +onlyif cockroach +statement ok +BEGIN; +CREATE FUNCTION f1(a INT) RETURNS INT LANGUAGE SQL AS $$ SELECT a + 1 $$; +ALTER TABLE t1 ADD CONSTRAINT check_b CHECK (f1(b) > 1); +END; + +let $tbl_id +SELECT id FROM system.namespace WHERE name = 't1'; + +let $fn_id +SELECT oid::int - 100000 FROM pg_catalog.pg_proc WHERE proname = 'f1'; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_checks($tbl_id); +---- +[ + { + "columnIds": [ + 2 + ], + "constraintId": 2, + "expr": "[FUNCTION 100117](b) \u003e 1:::INT8", + "name": "check_b" + } +] + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT get_fn_depended_on_by($fn_id); +---- +[ + { + "constraintIds": [ + 2 + ], + "id": 116 + } +] + +skipif config local-legacy-schema-changer +statement ok +SET use_declarative_schema_changer = 'unsafe_always'; + +# Record disabled, not supported by Materialize: +# # In legacy schema changer, constraints are formally dropped in jobs. +# # So by the point we do DROP FUNCTION, constraints are still there. +# skipif config local-legacy-schema-changer +# statement ok +# BEGIN; +# ALTER TABLE t1 DROP CONSTRAINT check_b; +# DROP FUNCTION f1; +# END; + +statement ok +DROP TABLE t1; + +skipif config local-legacy-schema-changer +statement ok +SET use_declarative_schema_changer = 'on'; + +# Make sure check constraint actually validates. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE OR REPLACE FUNCTION f1(a INT) RETURNS INT LANGUAGE SQL AS $$ SELECT a + 1 $$; +CREATE TABLE t1 ( + a INT PRIMARY KEY, + b INT CHECK (f1(b) > 1), + FAMILY fam_0 (a, b) +); + +statement error unknown catalog item 't1' +INSERT INTO t1 VALUES (1,0); + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t1 VALUES (1,1); + +statement error Expected COLUMN, found CONSTRAINT +ALTER TABLE t1 ADD CONSTRAINT cka CHECK (f1(a) > 10); + +# Not supported by Materialize. +onlyif cockroach +# Make sure that constraint still works after a function is renamed. +statement ok +ALTER TABLE t1 ADD CONSTRAINT cka CHECK (f1(a) > 1); + +statement error unknown catalog item 't1' +INSERT INTO t1 VALUES (2, -1); + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER FUNCTION f1 RENAME to f2; + +statement error unknown catalog item 't1' +INSERT INTO t1 VALUES (2, -1); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t1] +---- +CREATE TABLE public.t1 ( + a INT8 NOT NULL, + b INT8 NULL, + CONSTRAINT t1_pkey PRIMARY KEY (a ASC), + FAMILY fam_0 (a, b), + CONSTRAINT check_b CHECK (public.f2(b) > 1:::INT8), + CONSTRAINT cka CHECK (public.f2(a) > 1:::INT8) +) + +# Make sure that schema prefix is preserved through serialization and +# deserialization. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE DATABASE db1; +USE db1; +CREATE SCHEMA sc1; +CREATE FUNCTION sc1.f1(a INT) RETURNS INT LANGUAGE SQL AS $$ SELECT a + 1 $$; +CREATE FUNCTION sc1.f1() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$; +CREATE TABLE t( + a INT PRIMARY KEY, + b INT CHECK (sc1.f1(b) > 1), + FAMILY fam_0_b_a (b, a) +); + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT create_statement FROM [SHOW CREATE TABLE t] +---- +CREATE TABLE public.t ( + a INT8 NOT NULL, + b INT8 NULL, + CONSTRAINT t_pkey PRIMARY KEY (a ASC), + FAMILY fam_0_b_a (b, a), + CONSTRAINT check_b CHECK (sc1.f1(b) > 1:::INT8) +) + +# Not supported by Materialize. +onlyif cockroach +# Make sure dependency circle is not allowed. +statement ok +CREATE TABLE t_circle(a INT PRIMARY KEY, b INT); +CREATE FUNCTION f_circle() RETURNS INT LANGUAGE SQL AS $$ SELECT a FROM t_circle $$; + +statement error Expected COLUMN, found CONSTRAINT +ALTER TABLE t_circle ADD CONSTRAINT ckb CHECK (b + f_circle() > 1); diff --git a/test/sqllogictest/cockroach/udf_oid_ref.slt b/test/sqllogictest/cockroach/udf_oid_ref.slt new file mode 100644 index 0000000000000..121b510e3280c --- /dev/null +++ b/test/sqllogictest/cockroach/udf_oid_ref.slt @@ -0,0 +1,206 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/udf_oid_ref +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Not supported by Materialize. +onlyif cockroach +# 1074 is the OID of builtin function "string_to_array" with signature +# "string_to_array(str: string, delimiter: string) -> string[]". +query T +SELECT [FUNCTION 1074]('hello,world', ',') +---- +{hello,world} + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t1(a INT PRIMARY KEY, b STRING DEFAULT ([FUNCTION 1074]('hello,world', ','))) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t1(a) VALUES (1) + +# Not supported by Materialize. +onlyif cockroach +query IT +SELECT * FROM t1 +---- +1 {hello,world} + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO t1 VALUES (2, 'hello,new,world') + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX idx ON t1([FUNCTION 1074](b,',')) + +# Not supported by Materialize. +onlyif cockroach +query IT +SELECT * FROM t1@idx WHERE [FUNCTION 1074](b, ',') = ARRAY['hello','new','world'] +---- +2 hello,new,world + +# Not supported by Materialize. +onlyif cockroach +# 814 is the OID of builtin function "length" with signature +# "length(val: string) -> int". +statement ok +ALTER TABLE t1 ADD CONSTRAINT c_len CHECK ([FUNCTION 814](b) > 2) + +statement error unknown catalog item 't1' +INSERT INTO t1 VALUES (3, 'a') + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f1() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$ + +let $fn_oid +SELECT oid FROM pg_catalog.pg_proc WHERE proname = 'f1' + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT [FUNCTION $fn_oid]() +---- +1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f2(a STRING) RETURNS STRING LANGUAGE SQL AS $$ SELECT a $$ + +let $fn_oid +SELECT oid FROM pg_catalog.pg_proc WHERE proname = 'f2' + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT [FUNCTION $fn_oid]('hello world') +---- +hello world + +# Make sure that argument types are still checked even we know which function +# overload to use. +statement error unterminated dollar\-quoted string +SELECT [FUNCTION $fn_oid](123) + +# Not supported by Materialize. +onlyif cockroach +# Make sure that renaming does not break the reference. +statement ok +ALTER FUNCTION f2(STRING) RENAME TO f2_new; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT [FUNCTION $fn_oid]('hello world') +---- +hello world + +statement ok +CREATE SCHEMA sc1; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER FUNCTION f2_new(STRING) SET SCHEMA sc1; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT [FUNCTION $fn_oid]('hello world') +---- +hello world + +# Not supported by Materialize. +onlyif cockroach +# Make sure that function dropped cannot be resolved. +statement ok +DROP FUNCTION sc1.f2_new(STRING); + +statement error unterminated dollar\-quoted string +SELECT [FUNCTION $fn_oid]('maybe') + +# Referencing UDF OID within a UDF + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_in_udf() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$; + +let $fn_oid +SELECT oid FROM pg_catalog.pg_proc WHERE proname = 'f_in_udf' + +# TODO(chengxiong,mgartner): Fix this test when we enable support of calling UDFs from UDFs. +statement error Expected DATABASE, SCHEMA, ROLE, TYPE, INDEX, SINK, SOURCE, \[TEMPORARY\] TABLE, SECRET, \[OR REPLACE\] \[TEMPORARY\] VIEW, or \[OR REPLACE\] MATERIALIZED VIEW after CREATE, found FUNCTION +CREATE FUNCTION f_using_udf() RETURNS INT LANGUAGE SQL AS $$ SELECT [FUNCTION $fn_oid]() $$; + +# Not supported by Materialize. +onlyif cockroach +# 814 is the OID of builtin function "length" with signature, and it's ok to +# call it from a UDF. +statement ok +CREATE FUNCTION f_using_udf() RETURNS INT LANGUAGE SQL AS $$ SELECT [FUNCTION 814]('abc') $$; + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT f_using_udf(); +---- +3 + +# Make sure cross-db reference by OID is ok + +statement ok +CREATE DATABASE db1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE db1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_cross_db() RETURNS INT LANGUAGE SQL AS $$ SELECT 321 $$; + +let $fn_oid +SELECT oid FROM pg_catalog.pg_proc WHERE proname = 'f_cross_db' + +# Not supported by Materialize. +onlyif cockroach +statement ok +USE test + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT [FUNCTION $fn_oid]() +---- +321 diff --git a/test/sqllogictest/cockroach/udf_setof.slt b/test/sqllogictest/cockroach/udf_setof.slt new file mode 100644 index 0000000000000..6f79e7d330b2f --- /dev/null +++ b/test/sqllogictest/cockroach/udf_setof.slt @@ -0,0 +1,258 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/udf_setof +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# Tests for set-returning user-defined functions. + +statement ok +CREATE TABLE ab ( + a INT PRIMARY KEY, + b INT +) + +statement ok +INSERT INTO ab SELECT i, i*10 FROM generate_series(1, 4) g(i) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION empty() RETURNS SETOF INT LANGUAGE SQL AS $$ + SELECT a FROM ab WHERE a < 0 +$$ + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT * FROM empty() +---- + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT b, empty() FROM ab +---- + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION all_a() RETURNS SETOF INT LANGUAGE SQL AS $$ + SELECT a FROM ab ORDER BY a +$$ + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT * FROM all_a() +---- +1 +2 +3 +4 + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +select b, all_a() from ab +---- +10 1 +10 2 +10 3 +10 4 +20 1 +20 2 +20 3 +20 4 +30 1 +30 2 +30 3 +30 4 +40 1 +40 2 +40 3 +40 4 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION some_a() RETURNS SETOF INT LANGUAGE SQL AS $$ + SELECT a FROM ab WHERE a < 3 ORDER BY a +$$ + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +select b, all_a(), some_a() from ab +---- +10 1 1 +10 2 2 +10 3 NULL +10 4 NULL +20 1 1 +20 2 2 +20 3 NULL +20 4 NULL +30 1 1 +30 2 2 +30 3 NULL +30 4 NULL +40 1 1 +40 2 2 +40 3 NULL +40 4 NULL + +# Not supported by Materialize. +onlyif cockroach +# Note: This query errors in Postgres with "ERROR: 42804: argument of IN must +# not return a set". We've allowed built-in, set-returning functions as +# arguments to IN, so we allow set-returning UDFs as well. +query B rowsort +SELECT 1 IN (all_a()) +---- +true +false +false +false + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION all_a_lt(i INT) RETURNS SETOF INT LANGUAGE SQL AS $$ + SELECT a FROM ab WHERE a < i ORDER BY a +$$ + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT * FROM all_a_lt(3) +---- +1 +2 + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT a, all_a_lt(a) FROM ab +---- +2 1 +3 1 +3 2 +4 1 +4 2 +4 3 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION all_a_desc() RETURNS SETOF INT STABLE LANGUAGE SQL AS $$ + SELECT a FROM ab ORDER BY a DESC +$$ + +# Not supported by Materialize. +onlyif cockroach +# The order of a set-returning UDF should be maintained. +query T +SELECT array_agg(a) FROM all_a_desc() g(a) +---- +{4,3,2,1} + +# Nested set-returning functions are not yet supported. +statement error function "all_a_lt" does not exist +SELECT all_a_lt(all_a()) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION all_a_strict(INT) RETURNS SETOF INT STRICT LANGUAGE SQL AS $$ + SELECT a FROM ab +$$ + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT * FROM all_a_strict(NULL) +---- + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT * FROM all_a_strict(3) +---- +1 +2 +3 +4 + +statement ok +CREATE TABLE n (n INT); +INSERT INTO n VALUES (NULL), (3); + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT all_a_strict(n) FROM n +---- +1 +2 +3 +4 + +statement error pgcode 42P13 Expected DATABASE, SCHEMA, ROLE, TYPE, INDEX, SINK, SOURCE, \[TEMPORARY\] TABLE, SECRET, \[OR REPLACE\] \[TEMPORARY\] VIEW, or \[OR REPLACE\] MATERIALIZED VIEW after CREATE, found FUNCTION +CREATE FUNCTION err(INT) RETURNS SETOF INT STRICT LANGUAGE SQL AS $$ + SELECT a, b FROM ab ORDER BY a +$$ + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION all_ab() RETURNS SETOF ab LANGUAGE SQL AS $$ + SELECT a, b FROM ab +$$ + +# Not supported by Materialize. +onlyif cockroach +# TODO(mgartner): This should return separate columns, not a tuple. See #97059. +query T rowsort +SELECT * FROM all_ab() +---- +(1,10) +(2,20) +(3,30) +(4,40) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION all_ab_tuple() RETURNS SETOF ab LANGUAGE SQL AS $$ + SELECT (a, b) FROM ab +$$ + +# Not supported by Materialize. +onlyif cockroach +# TODO(mgartner): This should return separate columns, not a tuple. See #97059. +query T rowsort +SELECT * FROM all_ab_tuple() +---- +(1,10) +(2,20) +(3,30) +(4,40) diff --git a/test/sqllogictest/cockroach/udf_star.slt b/test/sqllogictest/cockroach/udf_star.slt new file mode 100644 index 0000000000000..17492df10bb96 --- /dev/null +++ b/test/sqllogictest/cockroach/udf_star.slt @@ -0,0 +1,328 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/udf_star +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE t_onecol (a INT); +INSERT INTO t_onecol VALUES (1) + +statement ok +CREATE TABLE t_twocol (a INT, b INT); +INSERT INTO t_twocol VALUES (1,2) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_unqualified_onecol() RETURNS INT AS +$$ + SELECT * FROM t_onecol; +$$ LANGUAGE SQL; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_subquery() RETURNS INT AS +$$ + SELECT * FROM (SELECT a FROM (SELECT * FROM t_onecol) AS foo) AS bar; +$$ LANGUAGE SQL; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_subquery_unaliased() RETURNS INT AS +$$ + SELECT * FROM (SELECT a FROM (SELECT * FROM t_onecol)); +$$ LANGUAGE SQL; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_unqualified_twocol() RETURNS t_twocol AS +$$ + SELECT * FROM t_twocol; +$$ LANGUAGE SQL; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_allcolsel() RETURNS t_twocol AS +$$ + SELECT t_twocol.* FROM t_twocol; +$$ LANGUAGE SQL; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_allcolsel_alias() RETURNS t_twocol AS +$$ + SELECT t1.* FROM t_twocol AS t1, t_twocol AS t2 WHERE t1.a = t2.a; +$$ LANGUAGE SQL; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_tuplestar() RETURNS t_twocol AS +$$ + SELECT (t_twocol.*).* FROM t_twocol; +$$ LANGUAGE SQL; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_unqualified_multicol() RETURNS INT AS +$$ + SELECT *, a FROM t_onecol; + SELECT 1; +$$ LANGUAGE SQL; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_unqualified_doublestar() RETURNS INT AS +$$ + SELECT *, * FROM t_onecol; + SELECT 1; +$$ LANGUAGE SQL; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_exprstar() RETURNS STRING AS +$$ + SELECT word FROM (SELECT (pg_get_keywords()).* ORDER BY word LIMIT 1) AS foo; +$$ LANGUAGE SQL; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f_anon_subqueries() RETURNS INT AS +$$ + SELECT * FROM (SELECT a FROM t_onecol) JOIN (SELECT a FROM t_twocol) ON true; + SELECT 1; +$$ LANGUAGE SQL; + +statement error Expected DATABASE, SCHEMA, ROLE, TYPE, INDEX, SINK, SOURCE, \[TEMPORARY\] TABLE, SECRET, \[OR REPLACE\] \[TEMPORARY\] VIEW, or \[OR REPLACE\] MATERIALIZED VIEW after CREATE, found FUNCTION +CREATE FUNCTION f_ambiguous() RETURNS INT AS +$$ + SELECT a FROM (SELECT * FROM (SELECT a FROM t_onecol) AS foo JOIN (SELECT a FROM t_twocol) AS bar ON true) AS baz; + SELECT 1; +$$ LANGUAGE SQL; + +# Not supported by Materialize. +onlyif cockroach +query TTT +SELECT oid, proname, prosrc +FROM pg_catalog.pg_proc WHERE proname LIKE 'f\_%' ORDER BY oid; +---- +100108 f_unqualified_onecol SELECT t_onecol.a FROM test.public.t_onecol; +100109 f_subquery SELECT bar.a FROM (SELECT a FROM (SELECT t_onecol.a FROM test.public.t_onecol) AS foo) AS bar; +100110 f_subquery_unaliased SELECT "?subquery1?".a FROM (SELECT a FROM (SELECT t_onecol.a FROM test.public.t_onecol) AS "?subquery2?") AS "?subquery1?"; +100111 f_unqualified_twocol SELECT t_twocol.a, t_twocol.b FROM test.public.t_twocol; +100112 f_allcolsel SELECT t_twocol.a, t_twocol.b FROM test.public.t_twocol; +100113 f_allcolsel_alias SELECT t1.a, t1.b FROM test.public.t_twocol AS t1, test.public.t_twocol AS t2 WHERE t1.a = t2.a; +100114 f_tuplestar SELECT t_twocol.a, t_twocol.b FROM test.public.t_twocol; +100115 f_unqualified_multicol SELECT t_onecol.a, a FROM test.public.t_onecol; + SELECT 1; +100116 f_unqualified_doublestar SELECT t_onecol.a, t_onecol.a FROM test.public.t_onecol; + SELECT 1; +100117 f_exprstar SELECT word FROM (SELECT (pg_get_keywords()).word, (pg_get_keywords()).catcode, (pg_get_keywords()).catdesc ORDER BY word LIMIT 1) AS foo; +100118 f_anon_subqueries SELECT "?subquery1?".a, "?subquery2?".a FROM (SELECT a FROM test.public.t_onecol) AS "?subquery1?" JOIN (SELECT a FROM test.public.t_twocol) AS "?subquery2?" ON true; + SELECT 1; + + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE FUNCTION f_subquery +---- +f_subquery CREATE FUNCTION public.f_subquery() + RETURNS INT8 + VOLATILE + NOT LEAKPROOF + CALLED ON NULL INPUT + LANGUAGE SQL + AS $$ + SELECT bar.a FROM (SELECT a FROM (SELECT t_onecol.a FROM test.public.t_onecol) AS foo) AS bar; + $$ + +# Not supported by Materialize. +onlyif cockroach +query TT +SHOW CREATE FUNCTION f_allcolsel_alias +---- +f_allcolsel_alias CREATE FUNCTION public.f_allcolsel_alias() + RETURNS T_TWOCOL + VOLATILE + NOT LEAKPROOF + CALLED ON NULL INPUT + LANGUAGE SQL + AS $$ + SELECT t1.a, t1.b FROM test.public.t_twocol AS t1, test.public.t_twocol AS t2 WHERE t1.a = t2.a; + $$ + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT f_unqualified_onecol() +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT f_subquery() +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT f_exprstar() +---- +abort + +# Not supported by Materialize. +onlyif cockroach +# Adding a column to a table should not change the UDFs that reference it. +statement ok +ALTER TABLE t_onecol ADD COLUMN b INT DEFAULT 5; + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT f_unqualified_onecol() +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT f_subquery() +---- +1 + +# Not supported by Materialize. +onlyif cockroach +# It's ok to drop a column that was not used by the original UDF. +statement ok +ALTER TABLE t_onecol DROP COLUMN b; + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT f_unqualified_twocol() +---- +(1,2) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT f_allcolsel() +---- +(1,2) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT f_allcolsel_alias() +---- +(1,2) + +# Not supported by Materialize. +onlyif cockroach +# Return an error after adding a column when the table is used as the return +# type. Note that this behavior is ok for late binding. +statement ok +ALTER TABLE t_twocol ADD COLUMN c INT DEFAULT 5; + +statement error function "f_unqualified_twocol" does not exist +SELECT f_unqualified_twocol() + +# Not supported by Materialize. +onlyif cockroach +# Dropping the new column renders the function usable again. +statement ok +ALTER TABLE t_twocol DROP COLUMN c; + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT f_unqualified_twocol() + +# Altering a column type is not allowed in postgres or CRDB. +statement error Expected one of SET or RENAME or OWNER or RESET or ADD, found ALTER +ALTER TABLE t_twocol ALTER b TYPE FLOAT; + +# TODO(harding): Postgres allows column renaming when only referenced by UDFs. +statement error Expected TO, found COLUMN +ALTER TABLE t_twocol RENAME COLUMN a TO d; + +# Not supported by Materialize. +onlyif cockroach +# TODO(harding): Postgres allows table renaming when only referenced by UDFs. +statement error pq: cannot rename relation "t_twocol" because function "f_unqualified_twocol" depends on it +ALTER TABLE t_twocol RENAME TO t_twocol_prime; + +# Dropping a column a UDF depends on is not allowed. +statement error Expected one of SET or RENAME or OWNER or RESET or ADD, found DROP +ALTER TABLE t_twocol DROP COLUMN b; + +# Not supported by Materialize. +onlyif cockroach +# Drop all but one of the functions with an implicit record return value. +# TODO(96368): Allow these UDFs to be dropped in the CASCADE when the cross- +# references are fixed instead. +statement ok +DROP FUNCTION f_tuplestar; +DROP FUNCTION f_allcolsel_alias; + +# Record disabled, not supported by Materialize: +# # Dropping a column using CASCADE is ok, +# # although the legacy schema changer has troubles with it, +# # see: https://github.com/cockroachdb/cockroach/issues/97546 +# skipif config local-legacy-schema-changer +# statement ok +# ALTER TABLE t_twocol DROP COLUMN b CASCADE; + +statement ok +DROP TABLE t_onecol CASCADE; + +# Record disabled, not supported by Materialize: +# # The only remaining function should not reference the tables. +# # NB: remove the skipif directive when #97546 is resolved. +# skipif config local-legacy-schema-changer +# query TTT +# SELECT oid, proname, prosrc +# FROM pg_catalog.pg_proc WHERE proname LIKE 'f\_%' ORDER BY oid; +# ---- +# 100117 f_exprstar SELECT word FROM (SELECT (pg_get_keywords()).word, (pg_get_keywords()).catcode, (pg_get_keywords()).catdesc ORDER BY word LIMIT 1) AS foo; + +# Remove this when #97546 is resolved. +onlyif config local-legacy-schema-changer +query TTT +SELECT oid, proname, prosrc +FROM pg_catalog.pg_proc WHERE proname LIKE 'f\_%' ORDER BY oid; +---- +100111 f_unqualified_twocol SELECT t_twocol.a, t_twocol.b FROM test.public.t_twocol; +100112 f_allcolsel SELECT t_twocol.a, t_twocol.b FROM test.public.t_twocol; +100117 f_exprstar SELECT word FROM (SELECT (pg_get_keywords()).word, (pg_get_keywords()).catcode, (pg_get_keywords()).catdesc ORDER BY word LIMIT 1) AS foo; diff --git a/test/sqllogictest/cockroach/udf_volatility_check.slt b/test/sqllogictest/cockroach/udf_volatility_check.slt new file mode 100644 index 0000000000000..f3bfdc8823801 --- /dev/null +++ b/test/sqllogictest/cockroach/udf_volatility_check.slt @@ -0,0 +1,136 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/udf_volatility_check +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +SET allow_ordinal_column_references=true + +statement ok +CREATE TABLE t1(a INT PRIMARY KEY, b INT); +CREATE TABLE t2(a INT PRIMARY KEY, b INT); + +statement error Expected DATABASE, SCHEMA, ROLE, TYPE, INDEX, SINK, SOURCE, \[TEMPORARY\] TABLE, SECRET, \[OR REPLACE\] \[TEMPORARY\] VIEW, or \[OR REPLACE\] MATERIALIZED VIEW after CREATE, found FUNCTION +CREATE FUNCTION f() RETURNS FLOAT LANGUAGE SQL IMMUTABLE AS $$ SELECT a FROM t1 $$; + +statement error Expected DATABASE, SCHEMA, ROLE, TYPE, INDEX, SINK, SOURCE, \[TEMPORARY\] TABLE, SECRET, \[OR REPLACE\] \[TEMPORARY\] VIEW, or \[OR REPLACE\] MATERIALIZED VIEW after CREATE, found FUNCTION +CREATE FUNCTION f() RETURNS FLOAT LANGUAGE SQL IMMUTABLE AS $$ SELECT random() $$; + +statement error Expected DATABASE, SCHEMA, ROLE, TYPE, INDEX, SINK, SOURCE, \[TEMPORARY\] TABLE, SECRET, \[OR REPLACE\] \[TEMPORARY\] VIEW, or \[OR REPLACE\] MATERIALIZED VIEW after CREATE, found FUNCTION +CREATE FUNCTION f() RETURNS TIMESTAMP LANGUAGE SQL IMMUTABLE AS $$ SELECT statement_timestamp() $$; + +statement error Expected DATABASE, SCHEMA, ROLE, TYPE, INDEX, SINK, SOURCE, \[TEMPORARY\] TABLE, SECRET, \[OR REPLACE\] \[TEMPORARY\] VIEW, or \[OR REPLACE\] MATERIALIZED VIEW after CREATE, found FUNCTION +CREATE FUNCTION f() RETURNS FLOAT LANGUAGE SQL STABLE AS $$ SELECT random() $$; + +statement error Expected DATABASE, SCHEMA, ROLE, TYPE, INDEX, SINK, SOURCE, \[TEMPORARY\] TABLE, SECRET, \[OR REPLACE\] \[TEMPORARY\] VIEW, or \[OR REPLACE\] MATERIALIZED VIEW after CREATE, found FUNCTION +CREATE FUNCTION f() RETURNS FLOAT LANGUAGE SQL IMMUTABLE AS $$ SELECT @1 FROM random() $$; + +statement error Expected DATABASE, SCHEMA, ROLE, TYPE, INDEX, SINK, SOURCE, \[TEMPORARY\] TABLE, SECRET, \[OR REPLACE\] \[TEMPORARY\] VIEW, or \[OR REPLACE\] MATERIALIZED VIEW after CREATE, found FUNCTION +CREATE FUNCTION f() RETURNS INT LANGUAGE SQL IMMUTABLE AS $$ + SELECT t1.a + FROM t1 + JOIN t2 ON t1.a = t2.a + random()::INT +$$; + +statement error Expected DATABASE, SCHEMA, ROLE, TYPE, INDEX, SINK, SOURCE, \[TEMPORARY\] TABLE, SECRET, \[OR REPLACE\] \[TEMPORARY\] VIEW, or \[OR REPLACE\] MATERIALIZED VIEW after CREATE, found FUNCTION +CREATE FUNCTION f() RETURNS INT LANGUAGE SQL IMMUTABLE AS $$ + SELECT a + FROM t1 + WHERE b = 1 + random() +$$; + +subtest replace_func_volatility + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE FUNCTION f() RETURNS INT LANGUAGE SQL IMMUTABLE AS $$ SELECT 1 $$; + +statement error Expected \[TEMPORARY\] VIEW, or MATERIALIZED VIEW after CREATE OR REPLACE, found FUNCTION +CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL IMMUTABLE AS $$ SELECT a FROM t1 $$; + +statement error Expected \[TEMPORARY\] VIEW, or MATERIALIZED VIEW after CREATE OR REPLACE, found FUNCTION +CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL IMMUTABLE AS $$ SELECT random()::INT $$; + +statement error Expected \[TEMPORARY\] VIEW, or MATERIALIZED VIEW after CREATE OR REPLACE, found FUNCTION +CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL IMMUTABLE AS $$ SELECT statement_timestamp()::INT $$; + +statement error Expected \[TEMPORARY\] VIEW, or MATERIALIZED VIEW after CREATE OR REPLACE, found FUNCTION +CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL STABLE AS $$ SELECT random() $$; + +statement error Expected \[TEMPORARY\] VIEW, or MATERIALIZED VIEW after CREATE OR REPLACE, found FUNCTION +CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL IMMUTABLE AS $$ SELECT @1 FROM random() $$; + +statement error Expected \[TEMPORARY\] VIEW, or MATERIALIZED VIEW after CREATE OR REPLACE, found FUNCTION +CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL IMMUTABLE AS $$ + SELECT t1.a + FROM t1 + JOIN t2 ON t1.a = t2.a + random()::INT +$$; + +statement error Expected \[TEMPORARY\] VIEW, or MATERIALIZED VIEW after CREATE OR REPLACE, found FUNCTION +CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL IMMUTABLE AS $$ + SELECT a + FROM t1 + WHERE b = 1 + random() +$$; + +subtest alter_func_volatility + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL IMMUTABLE AS $$ SELECT 1 $$; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER FUNCTION f STABLE + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER FUNCTION f VOLATILE + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL STABLE AS $$ SELECT statement_timestamp()::INT $$; + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER FUNCTION f VOLATILE + +statement error Unsupported ALTER on FUNCTION +ALTER FUNCTION f IMMUTABLE + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL VOLATILE AS $$ SELECT random()::INT $$; + +statement error Unsupported ALTER on FUNCTION +ALTER FUNCTION f STABLE + +statement error Unsupported ALTER on FUNCTION +ALTER FUNCTION f IMMUTABLE diff --git a/test/sqllogictest/cockroach/union.slt b/test/sqllogictest/cockroach/union.slt index d8cbbd4704611..f173d990b61b0 100644 --- a/test/sqllogictest/cockroach/union.slt +++ b/test/sqllogictest/cockroach/union.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/union +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/union # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - query I rowsort VALUES (1), (1), (1), (2), (2) UNION VALUES (1), (3), (1) ---- @@ -82,75 +80,82 @@ VALUES (1), (1), (1), (2), (2) UNION ALL VALUES (1), (3), (1) ORDER BY 1 DESC LI 3 2 -# TODO(benesch): uncomment if we improve UNION type matching. PostgreSQL doesn't -# support these, so it's not high priority. -# -# # UNION with NULL columns in operands works. -# query I -# VALUES (1) UNION ALL VALUES (NULL) ORDER BY 1 -# ---- -# NULL -# 1 -# -# query I -# VALUES (NULL) UNION ALL VALUES (1) ORDER BY 1 -# ---- -# NULL -# 1 -# -# query I -# VALUES (NULL) UNION ALL VALUES (NULL) -# ---- -# NULL -# NULL - -# TODO(benesch): uncomment when we have support for pg_typeof and column -# aliases. -# -# query IT rowsort -# SELECT x, pg_typeof(y) FROM (SELECT 1, NULL UNION ALL SELECT 2, 4) AS t(x, y) -# ---- -# 1 unknown -# 2 int -# -# query IT rowsort -# SELECT x, pg_typeof(y) FROM (SELECT 1, 3 UNION ALL SELECT 2, NULL) AS t(x, y) -# ---- -# 1 int -# 2 unknown - -# TODO(benesch): uncomment if we improve UNION type matching. PostgreSQL doesn't -# support these, so it's not high priority. -# +# Not supported by Materialize. +onlyif cockroach +# UNION with NULL columns in operands works. +query I +VALUES (1) UNION ALL VALUES (NULL) ORDER BY 1 +---- +NULL +1 + +# Not supported by Materialize. +onlyif cockroach +query I +VALUES (NULL) UNION ALL VALUES (1) ORDER BY 1 +---- +NULL +1 + +query I +VALUES (NULL) UNION ALL VALUES (NULL) +---- +NULL +NULL + +# Not supported by Materialize. +onlyif cockroach +query IT rowsort +SELECT x, pg_typeof(y) FROM (SELECT 1, NULL UNION ALL SELECT 2, 4) AS t(x, y) +---- +1 unknown +2 bigint + +# Not supported by Materialize. +onlyif cockroach +query IT rowsort +SELECT x, pg_typeof(y) FROM (SELECT 1, 3 UNION ALL SELECT 2, NULL) AS t(x, y) +---- +1 bigint +2 unknown + +# Not supported by Materialize. +onlyif cockroach # INTERSECT with NULL columns in operands works. -# query I -# VALUES (1) INTERSECT VALUES (NULL) ORDER BY 1 -# ---- -# -# query I -# VALUES (NULL) INTERSECT VALUES (1) ORDER BY 1 -# ---- -# -# query I -# VALUES (NULL) INTERSECT VALUES (NULL) -# ---- -# NULL -# -# # EXCEPT with NULL columns in operands works. -# query I -# VALUES (1) EXCEPT VALUES (NULL) ORDER BY 1 -# ---- -# 1 -# -# query I -# VALUES (NULL) EXCEPT VALUES (1) ORDER BY 1 -# ---- -# NULL -# -# query I -# VALUES (NULL) EXCEPT VALUES (NULL) -# ---- -# +query I +VALUES (1) INTERSECT VALUES (NULL) ORDER BY 1 +---- + +# Not supported by Materialize. +onlyif cockroach +query I +VALUES (NULL) INTERSECT VALUES (1) ORDER BY 1 +---- + +query I +VALUES (NULL) INTERSECT VALUES (NULL) +---- +NULL + +# Not supported by Materialize. +onlyif cockroach +# EXCEPT with NULL columns in operands works. +query I +VALUES (1) EXCEPT VALUES (NULL) ORDER BY 1 +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +VALUES (NULL) EXCEPT VALUES (1) ORDER BY 1 +---- +NULL + +query I +VALUES (NULL) EXCEPT VALUES (NULL) +---- + statement ok CREATE TABLE uniontest ( k INT, @@ -242,21 +247,24 @@ SELECT 1, 2 INTERSECT SELECT 3 query error pgcode 42601 each EXCEPT query must have the same number of columns: 2 vs 1 SELECT 1, 2 EXCEPT SELECT 3 -query error pgcode 42804 UNION types integer and text cannot be matched -SELECT 1 UNION SELECT '3' +# These work with the optimizer on, but not with it off. Skip for now. +# TODO(jordan,radu): re-enable when optimizer=off goes away. -query error pgcode 42804 INTERSECT types integer and text cannot be matched -SELECT 1 INTERSECT SELECT '3' - -query error pgcode 42804 EXCEPT types integer and text cannot be matched -SELECT 1 EXCEPT SELECT '3' +# query error pgcode 42804 UNION types int and string cannot be matched +# SELECT 1 UNION SELECT '3' +# +# query error pgcode 42804 INTERSECT types int and string cannot be matched +# SELECT 1 INTERSECT SELECT '3' +# +# query error pgcode 42804 EXCEPT types int and string cannot be matched +# SELECT 1 EXCEPT SELECT '3' +# +# query error UNION types int\[] and string\[] cannot be matched +# SELECT ARRAY[1] UNION ALL SELECT ARRAY['foo'] -query error pgcode 42703 column "z" does not exist +query error pgcode 42703 column \"z\" does not exist SELECT 1 UNION SELECT 3 ORDER BY z -query error UNION types integer\[] and text\[] cannot be matched -SELECT ARRAY[1] UNION ALL SELECT ARRAY['foo'] - # Check that UNION permits columns of different visible types statement ok @@ -267,7 +275,7 @@ CREATE TABLE b (a INTEGER PRIMARY KEY) query I SELECT * FROM a UNION ALL SELECT * FROM b ----- + # Make sure that UNION ALL doesn't crash when its two children have different # post-processing stages. @@ -318,3 +326,454 @@ SELECT a FROM (SELECT a FROM c UNION ALL SELECT a FROM a) WHERE a > 0 AND a < 3 ---- 1 1 + +query I +SELECT 1 FROM (SELECT a FROM a WHERE a > 3 UNION ALL SELECT a FROM c) +---- +1 +1 + +query R +SELECT * from ((values (1.0::decimal)) EXCEPT (values (1.00::decimal))) WHERE column1::string != '1.00'; +---- + +# Regression test for 41973 (union operator with no output columns). +statement ok +CREATE TABLE tab41973 () + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO tab41973 (rowid) VALUES (1), (2), (3) + +query I +SELECT 1 FROM ((SELECT * FROM tab41973) UNION ALL (SELECT * FROM tab41973)) +---- + + +statement ok +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 (j JSONB); +CREATE TABLE t2 (j JSONB); +INSERT INTO t1 VALUES ('{"a": "b"}'), ('{"foo": "bar"}'), (NULL); +INSERT INTO t2 VALUES ('{"c": "d"}'), ('{"foo": "bar"}'), (NULL); + +query T rowsort +(SELECT j FROM t1) UNION (SELECT j FROM t2) +---- +NULL +{"a":"b"} +{"c":"d"} +{"foo":"bar"} + +statement ok +DROP TABLE IF EXISTS t1, t2; + +statement ok +CREATE TABLE t1 (a INT[]); +CREATE TABLE t2 (b INT[]); +INSERT INTO t1 VALUES (ARRAY[1]), (ARRAY[2]), (NULL); +INSERT INTO t2 VALUES (ARRAY[2]), (ARRAY[3]), (NULL); + +query T rowsort +(SELECT a FROM t1) UNION (SELECT b FROM t2) +---- +{1} +{2} +NULL +{3} + +# Allow UNION of hidden and non-hidden columns. +statement ok +CREATE TABLE ab (a INT, b INT); + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT a, b, rowid FROM ab UNION VALUES (1, 2, 3); + +statement ok +DROP TABLE ab; + +# Regression test for #59148. +statement ok +CREATE TABLE ab (a INT4, b INT8); + +statement ok +INSERT INTO ab VALUES (1, 1), (1, 2), (2, 1), (2, 2); + +query I rowsort +SELECT a FROM ab UNION SELECT b FROM ab +---- +1 +2 + +query I rowsort +SELECT b FROM ab UNION SELECT a FROM ab +---- +1 +2 + +statement ok +DROP TABLE ab; + +# Regression test for the vectorized engine not being able to handle a UNION +# between NULL and a tuple (#59611). +statement ok +CREATE TABLE t59611 (a INT); + +statement ok +INSERT INTO t59611 VALUES (1) + +# Not supported by Materialize. +onlyif cockroach +query T +WITH + cte (cte_col) + AS ( + SELECT + * + FROM + (VALUES ((SELECT NULL FROM t59611 LIMIT 1:::INT8))) + UNION SELECT * FROM (VALUES ((1, 2))) + ) +SELECT + NULL +FROM + cte +---- +NULL +NULL + +statement ok +CREATE TABLE t34524 (a INT PRIMARY KEY) + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #34524. +query I +(SELECT NULL FROM t34524) EXCEPT (VALUES((SELECT 1 FROM t34524 LIMIT 1)), (1)) +---- + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE ab (a INT PRIMARY KEY, b INT, INDEX (b, a)); +INSERT INTO ab VALUES + (1, 1), + (2, 2), + (3, 1), + (4, 2), + (5, 1), + (6, 2), + (7, 3) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE xy (x INT PRIMARY KEY, y INT, INDEX (y, x)); +INSERT INTO xy VALUES + (1, 1), + (2, 3), + (3, 2), + (4, 3), + (5, 1), + (6, 3) + +# Not supported by Materialize. +onlyif cockroach +# Regression tests for #41245, #40797. Ensure we can plan ordered set ops +# without a sort. +query II +SELECT a, b FROM ab UNION SELECT x AS a, y AS b FROM xy ORDER BY b, a +---- +1 1 +3 1 +5 1 +2 2 +3 2 +4 2 +6 2 +2 3 +4 3 +6 3 +7 3 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT a FROM ab UNION ALL SELECT x AS a FROM xy ORDER BY a +---- +1 +1 +2 +2 +3 +3 +4 +4 +5 +5 +6 +6 +7 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT a, b FROM ab INTERSECT SELECT x AS a, y AS b FROM xy ORDER BY b, a +---- +1 1 +5 1 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT b FROM ab INTERSECT ALL SELECT y AS b FROM xy ORDER BY b +---- +1 +1 +2 +3 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT b, a FROM ab EXCEPT SELECT y AS b, x AS a FROM xy ORDER BY b, a +---- +1 3 +2 2 +2 4 +2 6 +3 7 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT b FROM ab EXCEPT ALL SELECT y AS b FROM xy ORDER BY b +---- +1 +2 +2 + +# Not supported by Materialize. +onlyif cockroach +# Regression tests for #64062. Use a streaming set operation even though the +# ordering is not required. +query II rowsort +SELECT a, b FROM ab UNION SELECT x AS a, y AS b FROM xy +---- +1 1 +2 2 +2 3 +3 1 +3 2 +4 2 +4 3 +5 1 +6 2 +6 3 +7 3 + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT a, b FROM ab INTERSECT SELECT x AS a, y AS b FROM xy +---- +1 1 +5 1 + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT b FROM ab INTERSECT ALL SELECT y AS b FROM xy +---- +1 +1 +2 +3 + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT b, a FROM ab EXCEPT SELECT y AS b, x AS a FROM xy +---- +1 3 +2 2 +2 4 +2 6 +3 7 + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +SELECT b FROM ab EXCEPT ALL SELECT y AS b FROM xy +---- +1 +2 +2 + +# Not supported by Materialize. +onlyif cockroach +# UNION ALL doesn't need to use a streaming operation. +query I rowsort +SELECT a FROM ab UNION ALL SELECT x AS a FROM xy +---- +1 +1 +2 +2 +3 +3 +4 +4 +5 +5 +6 +6 +7 + +# Not supported by Materialize. +onlyif cockroach +# If the ordering is only required on a subset of the columns, ensure that we +# still produce the correct ordering. +statement ok +TRUNCATE ab; +TRUNCATE xy; + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO ab VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); +INSERT INTO xy VALUES (1, 1), (3, 3), (5, 5), (7, 7); + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT a, b FROM ab UNION SELECT x, y FROM xy ORDER BY a +---- +1 1 +2 2 +3 3 +4 4 +5 5 +7 7 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT a, b FROM ab UNION ALL SELECT x, y FROM xy ORDER BY a +---- +1 1 +1 1 +2 2 +3 3 +3 3 +4 4 +5 5 +5 5 +7 7 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT a, b FROM ab INTERSECT SELECT x, y FROM xy ORDER BY a +---- +1 1 +3 3 +5 5 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT a, b FROM ab INTERSECT ALL SELECT x, y FROM xy ORDER BY a +---- +1 1 +3 3 +5 5 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT a, b FROM ab EXCEPT SELECT x, y FROM xy ORDER BY a +---- +2 2 +4 4 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT a, b FROM ab EXCEPT ALL SELECT x, y FROM xy ORDER BY a +---- +2 2 +4 4 + +# Regression test for #64181. Ensure that a projection on top of an ordered +# UNION ALL correctly projects away ordering columns. +query TT +WITH q (x, y) AS ( + SELECT * FROM (VALUES ('a', 'a'), ('b', 'b'), ('c', 'c')) + UNION ALL + SELECT * FROM (VALUES ('d', 'd')) +) +SELECT 'e', y FROM q +ORDER BY x +---- +e a +e b +e c +e d + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #69497. Ensure streaming set ops return correct results +# when some input columns are in descending order. +statement ok +CREATE TABLE abc (a INT, b INT, c INT, INDEX (a, b, c DESC)); +INSERT INTO abc VALUES (1, 1, 1), (1, 2, 2), (1, 2, 3), (2, 2, 2), (2, 2, 3); +CREATE TABLE def (d INT PRIMARY KEY, e INT, f INT); +INSERT INTO def VALUES (1, 1, 1), (2, 2, 2), (3, 2, 3), (4, 2, 2), (5, 2, 3); + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT d, e, f FROM def EXCEPT SELECT a, b, c FROM abc ORDER by d, e +---- +3 2 3 +4 2 2 +5 2 3 + +# Not supported by Materialize. +onlyif cockroach +# Example where the interesting orderings do not include all columns. +statement ok +CREATE TABLE abcd (a INT, b INT, c INT, d INT, INDEX (a, b, c DESC) STORING (d)); +INSERT INTO abcd VALUES (1, 1, 1, 1), (1, 2, 2, 2), (1, 2, 3, 3), (2, 2, 2, 2), (2, 2, 3, 3); +CREATE TABLE efgh (e INT PRIMARY KEY, f INT, g INT, h INT); +INSERT INTO efgh VALUES (1, 1, 1, 1), (2, 2, 2, 2), (3, 2, 3, 3), (4, 2, 2, 2), (5, 2, 3, 3); + +# Not supported by Materialize. +onlyif cockroach +query IIII +SELECT e, f, g, h FROM efgh EXCEPT SELECT a, b, c, d FROM abcd ORDER by e, f +---- +3 2 3 3 +4 2 2 2 +5 2 3 3 + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #68702. Ensure correct behavior when a column is projected +# twice on the left side. +query III +SELECT a, b AS b1, b AS b2 FROM abc EXCEPT SELECT a, b, c FROM abc ORDER by a, b1 +---- + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT a, b AS b1, b AS b2 FROM abc INTERSECT SELECT a, c, b FROM abc ORDER by a, b2 +---- +1 1 1 +1 2 2 +2 2 2 diff --git a/test/sqllogictest/cockroach/update.slt b/test/sqllogictest/cockroach/update.slt deleted file mode 100644 index eef06847d0107..0000000000000 --- a/test/sqllogictest/cockroach/update.slt +++ /dev/null @@ -1,596 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/update -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -mode cockroach - -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - -statement ok -CREATE TABLE kv ( - k INT PRIMARY KEY, - v INT -) - -# statement error value type tuple\{int, int\} doesn't match type int of column "v" -# UPDATE kv SET v = (SELECT (10, 11)) - -# statement error value type decimal doesn't match type int of column "v" -# UPDATE kv SET v = 3.2 - -# statement error value type decimal doesn't match type int of column "v" -# UPDATE kv SET (k, v) = (3, 3.2) - -# statement error value type decimal doesn't match type int of column "v" -# UPDATE kv SET (k, v) = (SELECT 3, 3.2) - -statement count 4 -INSERT INTO kv VALUES (1, 2), (3, 4), (5, 6), (7, 8) - -statement count 2 -UPDATE kv SET v = 9 WHERE k IN (1, 3) - -query II rowsort -SELECT * FROM kv ----- -1 9 -3 9 -5 6 -7 8 - -statement count 4 -UPDATE kv SET v = k + v - -query II rowsort -SELECT * FROM kv ----- -1 10 -3 12 -5 11 -7 15 - -statement error pgcode 42703 unknown column m -UPDATE kv SET m = 9 WHERE k IN (1, 3) - -# statement error unimplemented at or near "k" -# UPDATE kv SET kv.k = 9 - -# statement error unimplemented at or near "*" -# UPDATE kv SET k.* = 9 - -# statement error unimplemented at or near "v" -# UPDATE kv SET k.v = 9 - -statement ok -CREATE VIEW kview as SELECT k,v from kv - -query II rowsort -SELECT * FROM kview ----- -1 10 -3 12 -5 11 -7 15 - -# statement error "kview" is not a table -# UPDATE kview SET v = 99 WHERE k IN (1, 3) - -query II rowsort -SELECT * FROM kview ----- -1 10 -3 12 -5 11 -7 15 - -statement ok -CREATE TABLE kv2 ( - k CHAR PRIMARY KEY, - v CHAR, - UNIQUE (v) -) - -statement count 4 -INSERT INTO kv2 VALUES ('a', 'b'), ('c', 'd'), ('e', 'f'), ('f', 'g') - -query TT rowsort -SELECT * FROM kv2 ----- -a b -c d -e f -f g - -# TODO: enforce primary keys. -# statement error duplicate key value violates unique constraint "kv2_v_key" -# UPDATE kv2 SET v = 'g' WHERE k IN ('a') - -statement count 1 -UPDATE kv2 SET v = 'i' WHERE k IN ('a') - -query TT rowsort -SELECT * FROM kv2 ----- -a i -c d -e f -f g - -statement count 1 -UPDATE kv2 SET v = 'b' WHERE k IN ('a') - -query TT rowsort -SELECT * FROM kv2 ----- -a b -c d -e f -f g - -statement ok -CREATE TABLE kv3 ( - k CHAR PRIMARY KEY, - v CHAR NOT NULL -) - -statement count 1 -INSERT INTO kv3 VALUES ('a', 'b') - -statement error null value in column "v" violates not-null constraint -UPDATE kv3 SET v = NULL WHERE k = 'a' - -query TT -SELECT * FROM kv3 ----- -a b - -statement error column "nonexistent" does not exist -UPDATE kv3 SET v = NULL WHERE nonexistent = 'a' - -# TODO(benesch): support the rest of this file. -halt - -statement ok -CREATE TABLE abc ( - a INT PRIMARY KEY, - b INT, - c INT, - UNIQUE INDEX d (c) -) - -statement count 1 -INSERT INTO abc VALUES (1, 2, 3) - -statement error number of columns \(2\) does not match number of values \(1\) -UPDATE abc SET (b, c) = (4) - -statement error DEFAULT can only appear in a VALUES list within INSERT or on the right side of a SET -UPDATE abc SET (b, c) = (SELECT (VALUES (DEFAULT, DEFAULT))) - -statement count 1 -UPDATE abc SET (b, c) = (4, 5) - -query III -SELECT * FROM abc ----- -1 4 5 - -statement count 1 -UPDATE abc SET a = 1, (b, c) = (SELECT 1, 2) - -query III colnames -UPDATE abc SET (b, c) = (8, 9) RETURNING abc.b, c, 4 AS d ----- -b c d -8 9 4 - -query III colnames -UPDATE abc SET (b, c) = (8, 9) RETURNING b as col1, c as col2, 4 as col3 ----- -col1 col2 col3 -8 9 4 - -query I colnames -UPDATE abc SET (b, c) = (8, 9) RETURNING a ----- -a -1 - -query IIII colnames -UPDATE abc SET (b, c) = (5, 6) RETURNING a, b, c, 4 AS d ----- -a b c d -1 5 6 4 - -query III colnames -UPDATE abc SET (b, c) = (7, 8) RETURNING * ----- -a b c -1 7 8 - -query IIII colnames -UPDATE abc SET (b, c) = (7, 8) RETURNING *, 4 AS d ----- -a b c d -1 7 8 4 - -query III colnames -UPDATE abc SET (b, c) = (8, 9) RETURNING abc.* ----- -a b c -1 8 9 - -statement error pq: "abc.*" cannot be aliased -UPDATE abc SET (b, c) = (8, 9) RETURNING abc.* as x - -query III -SELECT * FROM abc ----- -1 8 9 - -statement count 1 -INSERT INTO abc VALUES (4, 5, 6) - -statement error duplicate key value \(a\)=\(4\) violates unique constraint "primary" -UPDATE abc SET a = 4, b = 3 - -statement error duplicate key value \(c\)=\(6\) violates unique constraint "d" -UPDATE abc SET a = 2, c = 6 - -query III -UPDATE abc SET a = 2, b = 3 WHERE a = 1 RETURNING * ----- -2 3 9 - -query III rowsort -SELECT * FROM abc ----- -2 3 9 -4 5 6 - -query III -SELECT * FROM abc@d WHERE c = 9 ----- -2 3 9 - -statement error multiple assignments to the same column "b" -UPDATE abc SET b = 10, b = 11 - -statement error multiple assignments to the same column "b" -UPDATE abc SET (b, b) = (10, 11) - -statement error multiple assignments to the same column "b" -UPDATE abc SET (b, c) = (10, 11), b = 12 - -statement ok -CREATE TABLE xyz ( - x INT PRIMARY KEY, - y INT, - z INT -) - -statement count 1 -INSERT INTO xyz VALUES (111, 222, 333) - - -# TODO(jordan): re-enable post cockroach#28716 -# statement count 1 -# UPDATE xyz SET (z, y) = (SELECT 666, 777), x = (SELECT 2) -# -# query III -# SELECT * from xyz -# ---- -# 2 777 666 - -statement ok -CREATE TABLE lots ( - k1 INT, - k2 INT, - k3 INT, - k4 INT, - k5 INT -) - -statement count 1 -INSERT INTO lots VALUES (1, 2, 3, 4, 5) - -statement count 1 -UPDATE lots SET (k1, k2) = (6, 7), k3 = 8, (k4, k5) = (9, 10) - -query IIIII -SELECT * FROM lots ----- -6 7 8 9 10 - -statement count 1 -UPDATE lots SET (k5, k4, k3, k2, k1) = (SELECT * FROM lots) - -query IIIII -SELECT * FROM lots ----- -10 9 8 7 6 - -statement ok -CREATE TABLE pks ( - k1 INT, - k2 INT, - v INT, - PRIMARY KEY (k1, k2), - UNIQUE INDEX i (k2, v), - FAMILY (k1, k2), - FAMILY (v) -) - -statement count 2 -INSERT INTO pks VALUES (1, 2, 3), (4, 5, 3) - -statement error duplicate key value \(k2,v\)=\(5,3\) violates unique constraint "i" -UPDATE pks SET k2 = 5 where k1 = 1 - -# Test updating only one of the columns of a multi-column primary key. - -statement count 1 -UPDATE pks SET k1 = 2 WHERE k1 = 1 - -query III rowsort -SELECT * FROM pks ----- -2 2 3 -4 5 3 - -# Check that UPDATE properly supports ORDER BY (MySQL extension) - -statement count 0 -TRUNCATE kv - -statement count 4 -INSERT INTO kv VALUES (1, 9), (8, 2), (3, 7), (6, 4) - -query II -UPDATE kv SET v = v + 1 ORDER BY v DESC LIMIT 3 RETURNING k,v ----- -1 10 -3 8 -6 5 - -# Check that UPDATE properly supports LIMIT (MySQL extension) - -statement count 3 -TRUNCATE kv; INSERT INTO kv VALUES (1, 2), (2, 3), (3, 4) - -query II -UPDATE kv SET v = v - 1 WHERE k < 10 ORDER BY k LIMIT 1 RETURNING k, v ----- -1 1 - -query II rowsort -SELECT * FROM kv ----- -1 1 -2 3 -3 4 - -# Check that updates on tables with multiple column families behave as -# they should. - -statement ok -CREATE TABLE tu (a INT PRIMARY KEY, b INT, c INT, d INT, FAMILY (a), FAMILY (b), FAMILY (c,d)); - INSERT INTO tu VALUES (1, 2, 3, 4) - -statement ok -UPDATE tu SET b = NULL, c = NULL, d = NULL - -query IIII rowsort -SELECT * FROM tu ----- -1 NULL NULL NULL - -subtest contraint_check_validation_ordering - -# Verification of column constraints vs CHECK handling. The column -# constraint verification must take place first. -# -# This test requires that the error message for a CHECK constraint -# validation error be different than a column validation error. So we -# test the former first, as a sanity check. -statement ok -CREATE TABLE tn(x INT NULL CHECK(x IS NOT NULL), y CHAR(4) CHECK(length(y) < 4)); - INSERT INTO tn(x, y) VALUES (123, 'abc'); - -statement error failed to satisfy CHECK constraint -UPDATE tn SET x = NULL - -statement error failed to satisfy CHECK constraint -UPDATE tn SET y = 'abcd' - -# Now we test that the column validation occurs before the CHECK constraint. -statement ok -CREATE TABLE tn2(x INT NOT NULL CHECK(x IS NOT NULL), y CHAR(3) CHECK(length(y) < 4)); - INSERT INTO tn2(x, y) VALUES (123, 'abc'); - -statement error null value in column "x" violates not-null constraint -UPDATE tn2 SET x = NULL - -statement error value too long for type CHAR\(3\) -UPDATE tn2 SET y = 'abcd' - -subtest fk_contraint_check_validation_ordering - -# Verify that column constraints and CHECK handling occur before -# foreign key validation. -statement ok -CREATE TABLE src(x VARCHAR PRIMARY KEY); - INSERT INTO src(x) VALUES ('abc'); - CREATE TABLE derived(x CHAR(3) REFERENCES src(x), - y VARCHAR CHECK(length(y) < 4) REFERENCES src(x)); - INSERT INTO derived(x, y) VALUES ('abc', 'abc') - -# Sanity check that the FK constraints gets actually validated -statement error foreign key violation -UPDATE derived SET x = 'xxx' - -statement error value too long for type CHAR\(3\) -UPDATE derived SET x = 'abcd' - -statement error failed to satisfy CHECK constraint -UPDATE derived SET y = 'abcd' - -subtest regression_29494 - -statement ok -CREATE TABLE t29494(x INT PRIMARY KEY); INSERT INTO t29494 VALUES (12) - -statement ok -BEGIN; ALTER TABLE t29494 ADD COLUMN y INT NOT NULL DEFAULT 123 - -# Check that the new column is not visible -query T -SELECT create_statement FROM [SHOW CREATE t29494] ----- -CREATE TABLE t29494 ( - x INT8 NOT NULL, - CONSTRAINT "primary" PRIMARY KEY (x ASC), - FAMILY "primary" (x) -) - -# Check that the new column is not usable in RETURNING -statement error column "y" does not exist -UPDATE t29494 SET x = 123 RETURNING y - -# Check the new column is not assignable. We need to restart -# the txn because the error above trashed it. -statement ok -ROLLBACK; BEGIN; ALTER TABLE t29494 ADD COLUMN y INT NOT NULL DEFAULT 123 - -# Returning * doesn't return y -query I -UPDATE t29494 SET x = 124 WHERE x = 12 RETURNING * ----- -124 - -statement error column "y" does not exist -UPDATE t29494 SET y = 123 - -# Check the new column is not usable in assignments. We need to -# restart the txn because the error above trashed it. -statement ok -ROLLBACK; BEGIN; ALTER TABLE t29494 ADD COLUMN y INT NOT NULL DEFAULT 123 - -statement error column "y" is being backfilled -UPDATE t29494 SET x = y - -statement ok -COMMIT - -# Use delete-only mutation columns with default and computed expressions. -statement ok -CREATE TABLE mutation (m INT PRIMARY KEY, n INT) - -statement ok -INSERT INTO mutation VALUES (1, 1) - -statement ok -BEGIN; ALTER TABLE mutation add COLUMN o INT DEFAULT(10), ADD COLUMN p INT AS (o + n) STORED - -statement ok -UPDATE mutation SET m=2 WHERE n=1 - -statement ok -COMMIT TRANSACTION - -query IIII colnames -SELECT * FROM mutation ----- -m n o p -2 1 10 11 - -#regression test for cockroach#32477 -subtest reject_special_funcs_inset - -statement ok -CREATE TABLE t32477(x) AS SELECT 1 - -statement error aggregate functions are not allowed in UPDATE SET -UPDATE t32477 SET x = count(x) - -statement error window functions are not allowed in UPDATE SET -UPDATE t32477 SET x = rank() OVER () - -statement error generator functions are not allowed in UPDATE SET -UPDATE t32477 SET x = generate_series(1,2) - -#regression test for cockroach#32054 -subtest empty_update_subquery - -statement ok -CREATE TABLE t32054(x,y) AS SELECT 1,2 - -statement ok -CREATE TABLE t32054_empty(x INT, y INT) - -statement ok -UPDATE t32054 SET (x,y) = (SELECT x,y FROM t32054_empty) - -query II -SELECT * FROM t32054 ----- -NULL NULL - -# ------------------------------------------------------------------------------ -# Regression for cockroach#35364. -# ------------------------------------------------------------------------------ -subtest regression_35364 - -statement ok -CREATE TABLE t35364(x DECIMAL(1,0) CHECK (x >= 1)) - -statement ok -INSERT INTO t35364 VALUES (2) - -statement ok -UPDATE t35364 SET x=0.5 - -query T -SELECT x FROM t35364 ----- -1 - -# ------------------------------------------------------------------------------ -# Regression for cockroach#35970. -# ------------------------------------------------------------------------------ -statement ok -CREATE TABLE table35970 ( - a INT PRIMARY KEY, - b INT, - c INT8[], - FAMILY fam0 (a, b), - FAMILY fam1 (c) -) - -statement ok -INSERT INTO table35970 VALUES (1, 1, NULL); - -query I -UPDATE table35970 -SET c = c -RETURNING b ----- -1 diff --git a/test/sqllogictest/cockroach/update_from.slt b/test/sqllogictest/cockroach/update_from.slt new file mode 100644 index 0000000000000..f0f57ffdbf32b --- /dev/null +++ b/test/sqllogictest/cockroach/update_from.slt @@ -0,0 +1,234 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/update_from +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement ok +CREATE TABLE abc (a int primary key, b int, c int) + +statement ok +INSERT INTO abc VALUES (1, 20, 300), (2, 30, 400) + +# Not supported by Materialize. +onlyif cockroach +# Updating using self join. +statement ok +UPDATE abc SET b = other.b + 1, c = other.c + 1 FROM abc AS other WHERE abc.a = other.a + +query III rowsort +SELECT * FROM abc +---- +1 20 300 +2 30 400 + +# Not supported by Materialize. +onlyif cockroach +# Update only some columns. +statement ok +UPDATE abc SET b = other.b + 1 FROM abc AS other WHERE abc.a = other.a + +query III rowsort +SELECT * FROM abc +---- +1 20 300 +2 30 400 + +# Not supported by Materialize. +onlyif cockroach +# Update only some rows. +statement ok +UPDATE abc SET b = other.b + 1 FROM abc AS other WHERE abc.a = other.a AND abc.a = 1 + +query III rowsort +SELECT * FROM abc +---- +1 20 300 +2 30 400 + +# Update from another table. +statement ok +CREATE TABLE new_abc (a int, b int, c int) + +statement ok +INSERT INTO new_abc VALUES (1, 2, 3), (2, 3, 4) + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE abc SET b = new_abc.b, c = new_abc.c FROM new_abc WHERE abc.a = new_abc.a + +query III rowsort +SELECT * FROM abc +---- +1 20 300 +2 30 400 + +# Multiple matching values for a given row. When this happens, we pick +# the first matching value for the row (this is arbitrary). This behavior +# is consistent with Postgres. +statement ok +INSERT INTO new_abc VALUES (1, 1, 1) + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE abc SET b = new_abc.b, c = new_abc.c FROM new_abc WHERE abc.a = new_abc.a + +query III rowsort +SELECT * FROM abc +---- +1 20 300 +2 30 400 + +# Not supported by Materialize. +onlyif cockroach +# Returning old values. +query IIIII colnames,rowsort +UPDATE abc +SET + b = old.b + 1, c = old.c + 2 +FROM + abc AS old +WHERE + abc.a = old.a +RETURNING + abc.a, abc.b AS new_b, old.b as old_b, abc.c as new_c, old.c as old_c +---- +a new_b old_b new_c old_c +1 3 2 5 3 +2 4 3 6 4 + +# Not supported by Materialize. +onlyif cockroach +# Check if RETURNING * returns everything +query IIIIII colnames,rowsort +UPDATE abc SET b = old.b + 1, c = old.c + 2 FROM abc AS old WHERE abc.a = old.a RETURNING * +---- +a b c a b c +1 4 7 1 3 5 +2 5 8 2 4 6 + +# Not supported by Materialize. +onlyif cockroach +# Make sure UPDATE FROM works properly in the presence of check columns. +statement ok +CREATE TABLE abc_check (a int primary key, b int, c int, check (a > 0), check (b > 0 AND b < 10)) + +# Not supported by Materialize. +onlyif cockroach +statement ok +INSERT INTO abc_check VALUES (1, 2, 3), (2, 3, 4) + +# Not supported by Materialize. +onlyif cockroach +query III colnames,rowsort +UPDATE abc_check +SET + b = other.b, c = other.c +FROM + abc AS other +WHERE + abc_check.a = other.a +RETURNING + abc_check.a, abc_check.b, abc_check.c +---- +a b c +1 4 7 +2 5 8 + +query III rowsort +SELECT * FROM abc +---- +1 20 300 +2 30 400 + +# Not supported by Materialize. +onlyif cockroach +# Update values of table from values expression +statement ok +UPDATE abc SET b = other.b, c = other.c FROM (values (1, 2, 3), (2, 3, 4)) as other ("a", "b", "c") WHERE abc.a = other.a + +query III rowsort +SELECT * FROM abc +---- +1 20 300 +2 30 400 + +# Check if UPDATE ... FROM works with multiple tables. +statement ok +CREATE TABLE ab (a INT, b INT) + +statement ok +CREATE TABLE ac (a INT, c INT) + +statement ok +INSERT INTO ab VALUES (1, 200), (2, 300) + +statement ok +INSERT INTO ac VALUES (1, 300), (2, 400) + +# Not supported by Materialize. +onlyif cockroach +statement ok +UPDATE abc SET b = ab.b, c = ac.c FROM ab, ac WHERE abc.a = ab.a AND abc.a = ac.a + +query III rowsort +SELECT * FROM abc +---- +1 20 300 +2 30 400 + +# Not supported by Materialize. +onlyif cockroach +# Make sure UPDATE ... FROM works with LATERAL. +query IIIIIII colnames,rowsort +UPDATE abc +SET + b=ab.b, c = other.c +FROM + ab, LATERAL + (SELECT * FROM ac WHERE ab.a=ac.a) AS other +WHERE + abc.a=ab.a +RETURNING + * +---- +a b c a b a c +1 200 300 1 200 1 300 +2 300 400 2 300 2 400 + +# Make sure the FROM clause cannot reference the target table. +statement error Expected end of statement, found FROM +UPDATE abc SET a = other.a FROM (SELECT abc.a FROM abc AS x) AS other WHERE abc.a=other.a + +# Regression test for #89779. Do not update the same row twice when the target +# table has a hidden PK column. +statement ok +CREATE TABLE t89779 (a INT); +INSERT INTO t89779 VALUES (1) + +# Not supported by Materialize. +onlyif cockroach +query I +UPDATE t89779 SET a = 2 FROM (VALUES (1), (1)) v(i) WHERE a = i RETURNING a +---- +2 diff --git a/test/sqllogictest/cockroach/upsert.slt b/test/sqllogictest/cockroach/upsert.slt deleted file mode 100644 index b990c18c76902..0000000000000 --- a/test/sqllogictest/cockroach/upsert.slt +++ /dev/null @@ -1,983 +0,0 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. -# Copyright Materialize, Inc. and contributors. All rights reserved. -# -# Use of this software is governed by the Business Source License -# included in the LICENSE file at the root of this repository. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0. -# -# This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: -# -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/upsert -# -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the -# root of this repository. - -# not supported yet -halt - -mode cockroach - -subtest strict - -statement ok -CREATE TABLE ex( - foo INT PRIMARY KEY, - bar INT UNIQUE, - baz INT -) - -statement count 1 -INSERT INTO ex(foo,bar,baz) VALUES (1,1,1) - -statement count 0 -INSERT INTO ex(foo,bar,baz) VALUES (1,1,1) ON CONFLICT DO NOTHING - -statement count 0 -INSERT INTO ex(foo,bar,baz) VALUES (2,1,1) ON CONFLICT DO NOTHING - -# Do not insert conflicting first and last rows. -statement count 2 -INSERT INTO ex(foo,bar,baz) VALUES (1,2,1), (3,2,2), (6,6,2), (2,1,1) ON CONFLICT DO NOTHING - -query III colnames -SELECT * from ex ORDER BY foo ----- -foo bar baz -1 1 1 -3 2 2 -6 6 2 - -query III colnames -INSERT INTO ex(foo,bar,baz) VALUES (4,3,1), (5,2,1) ON CONFLICT DO NOTHING RETURNING * ----- -foo bar baz -4 3 1 - -statement ok -CREATE TABLE ex2( - a INT PRIMARY KEY, - b INT UNIQUE, - c INT, - d INT, - e INT, - UNIQUE (c,d) -) - -statement count 1 -INSERT INTO ex2(a,b,c,d,e) VALUES (0,0,0,0,0) - -statement count 0 -INSERT INTO ex2(a,b,c,d,e) VALUES (1,0,1,1,0), (2,4,0,0,5) ON CONFLICT DO NOTHING - -statement count 3 -INSERT INTO ex2(a,b,c,d,e) VALUES (3,4,5,6,7), (8,9,10,11,12), (13,14,15,16,17) ON CONFLICT DO NOTHING - -statement count 0 -INSERT INTO ex2(a,b,c,d,e) VALUES (3,4,5,6,7), (8,9,10,11,12) ON CONFLICT DO NOTHING - -statement ok -CREATE TABLE no_unique( - a INT, - b INT -) - -statement count 1 -INSERT INTO no_unique(a,b) VALUES (1,2) - -statement count 1 -INSERT INTO no_unique(a,b) VALUES (1,2) ON CONFLICT DO NOTHING - -statement count 3 -INSERT INTO no_unique(a,b) VALUES (1,2), (1,3), (3,2) ON CONFLICT DO NOTHING - -query II colnames -SELECT * from no_unique ORDER BY a, b ----- -a b -1 2 -1 2 -1 2 -1 3 -3 2 - -statement count 3 -INSERT INTO no_unique(a,b) VALUES (1,2), (1,2), (1,2) ON CONFLICT DO NOTHING - -subtest notstrict - -statement ok -CREATE TABLE kv ( - k INT PRIMARY KEY, - v INT -) - -statement count 3 -INSERT INTO kv VALUES (1, 1), (2, 2), (3, 3) ON CONFLICT (k) DO UPDATE SET v = excluded.v - -query II -SELECT * FROM kv ORDER BY (k, v) ----- -1 1 -2 2 -3 3 - -statement error multiple assignments to the same column -INSERT INTO kv VALUES (4, 4), (2, 5), (6, 6) ON CONFLICT (k) DO UPDATE SET v = 1, v = 1 - -statement count 3 -INSERT INTO kv VALUES (4, 4), (2, 5), (6, 6) ON CONFLICT (k) DO UPDATE SET v = excluded.v - -statement count 3 -UPSERT INTO kv VALUES (7, 7), (3, 8), (9, 9) - -statement count 1 -INSERT INTO kv VALUES (1, 10) ON CONFLICT (k) DO UPDATE SET v = (SELECT CAST(sum(k) AS INT) FROM kv) - -statement error column reference "v" is ambiguous \(candidates: excluded.v, kv.v\) -INSERT INTO kv VALUES (4, 10) ON CONFLICT (k) DO UPDATE SET v = v + 1 - -statement count 1 -INSERT INTO kv VALUES (4, 10) ON CONFLICT (k) DO UPDATE SET v = kv.v + 20 - -statement error there is no unique or exclusion constraint matching the ON CONFLICT specification -INSERT INTO kv VALUES (4, 10) ON CONFLICT DO UPDATE SET v = kv.v + 20 - -statement error duplicate key value \(k\)=\(3\) violates unique constraint "primary" -INSERT INTO kv VALUES (2, 10) ON CONFLICT (k) DO UPDATE SET k = 3, v = 10 - -statement count 1 -INSERT INTO kv VALUES (9, 9) ON CONFLICT (k) DO UPDATE SET (k, v) = (excluded.k + 2, excluded.v + 3) - -statement count 1 -UPSERT INTO kv VALUES (10, 10) - -statement count 2 -UPSERT INTO kv VALUES (10, 11), (10, 12) - -query II rowsort -UPSERT INTO kv VALUES (11, 11), (10, 13) RETURNING k, v ----- -11 11 -10 13 - -query I -UPSERT INTO kv VALUES (11) RETURNING k ----- -11 - -query I -UPSERT INTO kv VALUES (11, 12) RETURNING v ----- -12 - -statement count 1 -INSERT INTO kv VALUES (13, 13), (7, 8) ON CONFLICT (k) DO NOTHING RETURNING * - -statement count 0 -INSERT INTO kv VALUES (13, 13), (7, 8) ON CONFLICT DO NOTHING - -statement count 2 -INSERT INTO kv VALUES (14, 14), (13, 15) ON CONFLICT (k) DO UPDATE SET v = excluded.v + 1 - -statement count 2 -INSERT INTO kv VALUES (15, 15), (14, 16) ON CONFLICT (k) DO UPDATE SET k = excluded.k * 10 - -statement count 2 -INSERT INTO kv VALUES (16, 16), (15, 17) ON CONFLICT (k) DO UPDATE SET k = excluded.k * 10, v = excluded.v - -query II -SELECT * FROM kv ORDER BY (k, v) ----- -1 32 -2 5 -3 8 -4 24 -6 6 -7 7 -10 13 -11 12 -13 16 -16 16 -140 14 -150 17 - -# TODO(knz): Enable the 1st statement and remove the 2nd once cockroach#33313 is fixed. -#query II rowsort -#UPSERT INTO kv(k) VALUES (6), (8) RETURNING k,v -#---- -#6 6 -#8 NULL -query II rowsort -UPSERT INTO kv(k) VALUES (8) RETURNING k,v ----- -8 NULL - -query II rowsort -INSERT INTO kv VALUES (10, 10), (11, 11) ON CONFLICT (k) DO UPDATE SET v = excluded.v RETURNING * ----- -10 10 -11 11 - -query II rowsort -INSERT INTO kv VALUES (10, 2), (11, 3) ON CONFLICT (k) DO UPDATE SET v = excluded.v + kv.v RETURNING * ----- -10 12 -11 14 - -query II rowsort -INSERT INTO kv VALUES (10, 14), (15, 15) ON CONFLICT (k) DO NOTHING RETURNING * ----- -15 15 - -statement ok -CREATE TABLE abc ( - a INT, - b INT, - c INT DEFAULT 7, - PRIMARY KEY (a, b), - INDEX y (b), - UNIQUE INDEX z (c) -) - -statement error missing "b" primary key column -UPSERT INTO abc (a, c) VALUES (1, 1) - -statement error missing "a" primary key column -UPSERT INTO abc (b, c) VALUES (1, 1) - -statement count 1 -INSERT INTO abc VALUES (1, 2, 3) - -statement count 1 -INSERT INTO abc VALUES (1, 2, 3) ON CONFLICT (c) DO UPDATE SET a = 4 - -query III -SELECT * FROM abc ----- -4 2 3 - -statement count 1 -INSERT INTO abc VALUES (1, 2, 3) ON CONFLICT (c) DO UPDATE SET b = 5 - -statement count 1 -INSERT INTO abc VALUES (1, 2, 3) ON CONFLICT (c) DO UPDATE SET c = 6 - -query III -SELECT * FROM abc ----- -4 5 6 - -statement count 1 -INSERT INTO abc (a, b) VALUES (1, 2) ON CONFLICT (a, b) DO UPDATE SET a = 1, b = 2 - -statement count 1 -INSERT INTO abc (a, b) VALUES (4, 5) ON CONFLICT (a, b) DO UPDATE SET a = 7, b = 8 - -query III -SELECT * FROM abc ORDER BY (a, b, c) ----- -1 2 7 -7 8 6 - -statement count 1 -DELETE FROM abc where a = 1 - -statement count 1 -UPSERT INTO abc VALUES (1, 2) - -query III -SELECT * FROM abc ORDER BY (a, b, c) ----- -1 2 7 -7 8 6 - -statement count 1 -UPSERT INTO abc VALUES (1, 2, 5) - -query III -SELECT * FROM abc ORDER BY (a, b, c) ----- -1 2 5 -7 8 6 - -statement count 1 -UPSERT INTO abc VALUES (1, 2) - -query III -SELECT * FROM abc ORDER BY (a, b, c) ----- -1 2 7 -7 8 6 - -statement count 1 -DELETE FROM abc where a = 1 - -statement count 1 -INSERT INTO abc VALUES (7, 8, 9) ON CONFLICT (a, b) DO UPDATE SET c = DEFAULT - -query III -SELECT * FROM abc ORDER BY (a, b, c) ----- -7 8 7 - -statement ok -CREATE TABLE excluded (a INT PRIMARY KEY, b INT) - -statement error ambiguous source name: "excluded" -INSERT INTO excluded VALUES (1, 1) ON CONFLICT (a) DO UPDATE SET b = excluded.b - -# Tests for upsert/on conflict returning -statement ok -CREATE TABLE upsert_returning (a INT PRIMARY KEY, b INT, c INT, d INT DEFAULT -1) - -statement count 1 -INSERT INTO upsert_returning VALUES (1, 1, NULL) - -# Handle INSERT ... ON CONFLICT ... RETURNING -query IIII rowsort -INSERT INTO upsert_returning (a, c) VALUES (1, 1), (2, 2) ON CONFLICT (a) DO UPDATE SET c = excluded.c RETURNING * ----- -1 1 1 -1 -2 NULL 2 -1 - -# Handle INSERT ... ON CONFLICT DO NOTHING ... RETURNING -query IIII -INSERT INTO upsert_returning (a, c) VALUES (1, 1), (3, 3) ON CONFLICT (a) DO NOTHING RETURNING * ----- -3 NULL 3 -1 - -# Handle UPSERT ... RETURNING -query IIII rowsort -UPSERT INTO upsert_returning (a, c) VALUES (1, 10), (3, 30) RETURNING * ----- -1 1 10 -1 -3 NULL 30 -1 - -# Ensure returned values are inserted values after conflict resolution -query I -SELECT b FROM upsert_returning WHERE a = 1 ----- -1 - -query I -INSERT INTO upsert_returning (a, b) VALUES (1, 1) ON CONFLICT (a) DO UPDATE SET b = excluded.b + upsert_returning.b + 1 RETURNING b ----- -3 - -# Handle expressions within returning clause -query I rowsort -UPSERT INTO upsert_returning (a, b) VALUES (1, 2), (2, 3), (4, 3) RETURNING a+b+d ----- -2 -4 -6 - -# Handle upsert fast path with autocommit -query IIII rowsort -UPSERT INTO upsert_returning VALUES (1, 2, 3, 4), (5, 6, 7, 8) RETURNING * ----- -1 2 3 4 -5 6 7 8 - -# Handle upsert fast path without autocommit -statement ok -BEGIN - -query IIII rowsort -upsert INTO upsert_returning VALUES (1, 5, 4, 3), (6, 5, 4, 3) RETURNING * ----- -1 5 4 3 -6 5 4 3 - -statement ok -COMMIT - -# For materialize#22300. Test UPSERT ... RETURNING with UNION. -query I rowsort -SELECT a FROM [UPSERT INTO upsert_returning VALUES (7) RETURNING a] UNION VALUES (8) ----- -7 -8 - -# For materialize#6710. Add an unused column to disable the fast path which doesn't have this bug. -statement ok -CREATE TABLE issue_6710 (a INT PRIMARY KEY, b STRING, c INT) - -statement count 2 -INSERT INTO issue_6710 (a, b) VALUES (1, 'foo'), (2, 'bar') - -statement count 2 -UPSERT INTO issue_6710 (a, b) VALUES (1, 'test1'), (2, 'test2') - -query IT rowsort -SELECT a, b from issue_6710 ----- -1 test1 -2 test2 - -statement ok -CREATE TABLE issue_13962 (a INT PRIMARY KEY, b INT, c INT) - -statement count 1 -INSERT INTO issue_13962 VALUES (1, 1, 1) - -statement count 1 -INSERT INTO issue_13962 VALUES (1, 2, 2) ON CONFLICT (a) DO UPDATE SET b = excluded.b - -query III -SELECT * FROM issue_13962 ----- -1 2 1 - -statement ok -CREATE TABLE issue_14052 (a INT PRIMARY KEY, b INT, c INT) - -statement count 2 -INSERT INTO issue_14052 (a, b) VALUES (1, 1), (2, 2) - -statement count 2 -UPSERT INTO issue_14052 (a, c) (SELECT a, b from issue_14052) - -statement ok -CREATE TABLE issue_14052_2 ( - id SERIAL PRIMARY KEY, - name VARCHAR(255), - createdAt INT, - updatedAt INT -) - -statement count 1 -INSERT INTO issue_14052_2 (id, name, createdAt, updatedAt) VALUES - (1, 'original', 1, 1) - -# Make sure the fast path isn't taken (createdAt is not in the ON CONFLICT clause) -statement count 1 -INSERT INTO issue_14052_2 (id, name, createdAt, updatedAt) VALUES - (1, 'UPDATED', 2, 2) -ON CONFLICT (id) DO UPDATE - SET id = excluded.id, name = excluded.name, updatedAt = excluded.updatedAt - -query ITII -SELECT * FROM issue_14052_2; ----- -1 UPDATED 1 2 - -statement error multiple assignments to the same column -INSERT INTO issue_14052_2 (id, name, createdAt, updatedAt) VALUES - (1, 'FOO', 3, 3) -ON CONFLICT (id) DO UPDATE - SET id = excluded.id, name = excluded.name, name = excluded.name, name = excluded.name - -# Make sure the fast path isn't taken (all clauses in the set must be of the form x = excluded.x) -statement count 1 -INSERT INTO issue_14052_2 (id, name, createdAt, updatedAt) VALUES - (1, 'BAR', 4, 5) -ON CONFLICT (id) DO UPDATE - SET name = excluded.name, createdAt = excluded.updatedAt, updatedAt = excluded.updatedAt - -query ITII -SELECT * FROM issue_14052_2; ----- -1 BAR 5 5 - -# Make sure the column types are propagated when type checking the ON CONFLICT -# expressions. See materialize#16873. -statement ok -CREATE TABLE issue_16873 (col int PRIMARY KEY, date TIMESTAMP); - -# n.b. the fully-qualified names below are required, as there are two providers of -# the column named `col` here, the original table and the `excluded` pseudo-table. -statement count 1 -INSERT INTO issue_16873 VALUES (1,clock_timestamp()) -ON CONFLICT (col) DO UPDATE SET date = clock_timestamp() WHERE issue_16873.col = 1; - -statement count 1 -INSERT INTO issue_16873 VALUES (1,clock_timestamp()) -ON CONFLICT (col) DO UPDATE SET date = clock_timestamp() WHERE issue_16873.col = 1; - -# For materialize#17339. Support WHERE clause in ON CONFLICT handling. -statement ok -CREATE TABLE issue_17339 (a int primary key, b int); - -statement count 2 -INSERT INTO issue_17339 VALUES (1, 1), (2, 0); - -statement count 1 -INSERT INTO issue_17339 VALUES (1, 0), (2, 2) -ON CONFLICT (a) DO UPDATE SET b = excluded.b WHERE excluded.b > issue_17339.b; - -query II -SELECT * FROM issue_17339 ORDER BY a; ----- -1 1 -2 2 - -statement count 2 -INSERT INTO issue_17339 VALUES (1, 0), (2, 1) -ON CONFLICT (a) DO UPDATE SET b = excluded.b WHERE TRUE; - -query II -SELECT * FROM issue_17339 ORDER BY a; ----- -1 0 -2 1 - -# Regression test for materialize#25726. -# UPSERT over tables with column families, on the fast path, use the -# INSERT logic. This has special casing for column families of 1 -# column, and another special casing for column families of 2+ -# columns. The special casing is only for families that do not include -# the primary key. So we need a table with 3 families: 1 for the PK, 1 -# with just 1 col, and 1 with 2+ cols. -statement ok -CREATE TABLE tu (a INT PRIMARY KEY, b INT, c INT, d INT, FAMILY (a), FAMILY (b), FAMILY (c,d)); - INSERT INTO tu VALUES (1, 2, 3, 4) - -statement ok -UPSERT INTO tu VALUES (1, NULL, NULL, NULL) - -query IIII rowsort -SELECT * FROM tu ----- -1 NULL NULL NULL - -subtest check - -statement ok -CREATE TABLE ab( - a INT PRIMARY KEY, - b INT, CHECK (b < 1) -) - -statement count 1 -INSERT INTO ab(a, b) VALUES (1, 0); - -statement error pq: failed to satisfy CHECK constraint \(b < 1\) -INSERT INTO ab(a, b) VALUES (1, 0) ON CONFLICT(a) DO UPDATE SET b=12312313; - -statement count 1 -INSERT INTO ab(a, b) VALUES (1, 0) ON CONFLICT(a) DO UPDATE SET b=-1; - -statement ok -CREATE TABLE abc_check( - a INT PRIMARY KEY, - b INT, - c INT, - CHECK (b < 1), - CHECK (c > 1) -) - -statement count 1 -INSERT INTO abc_check(a, b, c) VALUES (1, 0, 2); - -statement error pq: failed to satisfy CHECK constraint \(b < 1\) -INSERT INTO abc_check(a, b, c) VALUES (1, 0, 2) ON CONFLICT(a) DO UPDATE SET b=12312313; - -statement error pq: failed to satisfy CHECK constraint \(b < 1\) -INSERT INTO abc_check(a, b, c) VALUES (1, 0, 2) ON CONFLICT(a) DO UPDATE SET (b, c) = (1, 1); - -statement error pq: failed to satisfy CHECK constraint \(c > 1\) -INSERT INTO abc_check(a, b, c) VALUES (1, 0, 2) ON CONFLICT(a) DO UPDATE SET (b, c) = (-1, 1); - -statement count 1 -INSERT INTO abc_check(a, b, c) VALUES (2, 0, 3); - -statement error pq: failed to satisfy CHECK constraint \(b < 1\) -INSERT INTO abc_check(c, a, b) VALUES (3, 2, 0) ON CONFLICT(a) DO UPDATE SET b=12312313; - -statement error pq: failed to satisfy CHECK constraint \(b < 1\) -INSERT INTO abc_check(a, c) VALUES (2, 3) ON CONFLICT(a) DO UPDATE SET b=12312313; - -statement error pq: failed to satisfy CHECK constraint \(c > 1\) -INSERT INTO abc_check(a, c) VALUES (2, 3) ON CONFLICT(a) DO UPDATE SET c=1; - -statement error pq: failed to satisfy CHECK constraint \(c > 1\) -INSERT INTO abc_check(c, a) VALUES (3, 2) ON CONFLICT(a) DO UPDATE SET c=1; - -statement error pq: failed to satisfy CHECK constraint \(b < 1\) -INSERT INTO abc_check(c, a) VALUES (3, 2) ON CONFLICT(a) DO UPDATE SET b=123123123; - -statement error pq: failed to satisfy CHECK constraint \(b < 1\) -INSERT INTO abc_check(c, a) VALUES (3, 2) ON CONFLICT(a) DO UPDATE SET b=123123123; - -subtest 29495 - -statement ok -CREATE TABLE IF NOT EXISTS example ( - id SERIAL PRIMARY KEY - ,value string NOT NULL -); - -query B -UPSERT INTO example (value) VALUES ('foo') RETURNING id > 0 ----- -true - -statement ok -DROP TABLE example - -subtest contraint_check_validation_ordering - -# Verification of column constraints vs CHECK handling. The column -# constraint verification must take place first. -# -# This test requires that the error message for a CHECK constraint -# validation error be different than a column validation error. So we -# test the former first, as a sanity check. -statement ok -CREATE TABLE tn(x INT NULL CHECK(x IS NOT NULL), y CHAR(4) CHECK(length(y) < 4)); - -statement error failed to satisfy CHECK constraint -UPSERT INTO tn(x) VALUES (NULL) - -statement error failed to satisfy CHECK constraint -UPSERT INTO tn(y) VALUES ('abcd') - -# Now we test that the column validation occurs before the CHECK constraint. -statement ok -CREATE TABLE tn2(x INT NOT NULL CHECK(x IS NOT NULL), y CHAR(3) CHECK(length(y) < 4)); - -statement error null value in column "x" violates not-null constraint -UPSERT INTO tn2(x) VALUES (NULL) - -statement error value too long for type CHAR\(3\) -UPSERT INTO tn2(x, y) VALUES (123, 'abcd') - -subtest regression_29494 - -statement ok -CREATE TABLE t29494(x INT); INSERT INTO t29494 VALUES (12) - -statement ok -BEGIN; ALTER TABLE t29494 ADD COLUMN y INT NOT NULL DEFAULT 123 - -# Check that the new column is not visible -query T -SELECT create_statement FROM [SHOW CREATE t29494] ----- -CREATE TABLE t29494 ( - x INT8 NULL, - FAMILY "primary" (x, rowid) -) - -# Check that the new column is not usable in RETURNING -statement error column "y" does not exist -UPSERT INTO t29494(x) VALUES (123) RETURNING y - -# Ditto for INSERT ON CONFLICT -statement ok -ROLLBACK; BEGIN; ALTER TABLE t29494 ADD COLUMN y INT NOT NULL DEFAULT 123 - -statement error column "y" does not exist -INSERT INTO t29494(x) VALUES (123) ON CONFLICT(rowid) DO UPDATE SET x = 400 RETURNING y - -statement ok -ROLLBACK - -statement ok -BEGIN; ALTER TABLE t29494 ADD COLUMN y INT NOT NULL DEFAULT 123 - -query I -UPSERT INTO t29494(x) VALUES (12) RETURNING * ----- -12 - -query I -UPSERT INTO t29494(x) VALUES (123) RETURNING * ----- -123 - -query I -INSERT INTO t29494(x) VALUES (123) ON CONFLICT(rowid) DO UPDATE SET x = 400 RETURNING * ----- -123 - -statement ok -COMMIT - -subtest regression_31255 - -statement ok -CREATE TABLE tc(x INT PRIMARY KEY, y INT AS (x+1) STORED) - -statement error cannot write directly to computed column "y" -INSERT INTO tc(x) VALUES (1) ON CONFLICT(x) DO UPDATE SET y = 123 - -statement error cannot write directly to computed column "y" -UPSERT INTO tc(x,y) VALUES (1,2) - -statement error cannot write directly to computed column "y" -UPSERT INTO tc VALUES (1,2) - -subtest regression_29497 - -statement ok -CREATE TABLE t29497(x INT PRIMARY KEY); BEGIN; ALTER TABLE t29497 ADD COLUMN y INT NOT NULL DEFAULT 123 - -statement error [UPSERT has more expressions than target columns | column "y" is being backfilled] -UPSERT INTO t29497 VALUES (1, 2) - -statement ok -ROLLBACK; BEGIN; ALTER TABLE t29497 ADD COLUMN y INT NOT NULL DEFAULT 123 - -statement error [column "y" does not exist | column "y" is being backfilled] -INSERT INTO t29497(x) VALUES (1) ON CONFLICT (x) DO UPDATE SET y = 456 - -statement ok -ROLLBACK - -subtest visible_returning_columns - -statement ok -BEGIN; ALTER TABLE tc DROP COLUMN y - -query I colnames,rowsort -UPSERT INTO tc VALUES (1), (2) RETURNING * ----- -x -1 -2 - -statement ok -COMMIT - -subtest regression_32762 - -statement ok -CREATE TABLE t32762(x INT, y INT, UNIQUE (x,y), CONSTRAINT y_not_null CHECK (y IS NOT NULL)) - -statement ok -INSERT INTO t32762(x,y) VALUES (1,2) ON CONFLICT (x,y) DO UPDATE SET x = t32762.x; - -statement ok -INSERT INTO t32762(x,y) VALUES (1,2) ON CONFLICT (x,y) DO UPDATE SET x = t32762.x - -subtest regression_33313 - -statement ok -CREATE TABLE ex33313(foo INT PRIMARY KEY, bar INT UNIQUE, baz INT); - INSERT INTO ex33313 VALUES (1,1,1); - -statement count 1 -INSERT INTO ex33313(foo,bar,baz) VALUES (1,2,1), (3,2,2) ON CONFLICT DO NOTHING; - -query III colnames -SELECT * FROM ex33313 ORDER BY foo ----- -foo bar baz -1 1 1 -3 2 2 - -# Use Upsert with indexed table, default columns, computed columns, and check -# columns. -statement ok -CREATE TABLE indexed ( - a DECIMAL PRIMARY KEY, - b DECIMAL, - c DECIMAL DEFAULT(10.0), - d DECIMAL AS (a + c) STORED, - UNIQUE INDEX secondary (d, b), - CHECK (c > 0) -) - -statement ok -INSERT INTO indexed VALUES (1, 1, 1); INSERT INTO indexed VALUES (2, 2, 2) - -# Use implicit target columns (should set default and computed values). -statement ok -UPSERT INTO indexed VALUES (1.0) - -query TTTT colnames -SELECT * FROM indexed@secondary ORDER BY d, b ----- -a b c d -2 2 2 4 -1 NULL 10.0 11.0 - -# Explicitly specify all target columns. Ensure that primary key is not updated, -# even though an alternate but equal decimal form is in use (1.0 vs. 1). -statement ok -UPSERT INTO indexed (a, b, c) VALUES (1.0, 1.0, 1.0) - -query TTTT colnames -SELECT * FROM indexed@secondary ORDER BY d, b ----- -a b c d -1 1.0 1.0 2.0 -2 2 2 4 - -# Ensure that explicit target column does not disturb existing "b" value, but -# does update the computed column. -statement ok -UPSERT INTO indexed (c, a) VALUES (2, 1) - -query TTTT colnames -SELECT * FROM indexed@secondary ORDER BY d, b ----- -a b c d -1 1.0 2 3 -2 2 2 4 - -# Final check to ensure that primary index is correct. -query TTTT colnames -SELECT * FROM indexed@primary ORDER BY a ----- -a b c d -1 1.0 2 3 -2 2 2 4 - -# Drop the secondary index, allowing the "blind upsert" path to run. -statement ok -DROP INDEX indexed@secondary CASCADE - -# Use implicit target columns (should set default and computed values). -statement ok -UPSERT INTO indexed VALUES (1, 1) - -query TTTT colnames,rowsort -SELECT * FROM indexed ----- -a b c d -1 1 10.0 11.0 -2 2 2 4 - -# Explicitly specify all target columns. -statement ok -UPSERT INTO indexed (a, b, c) SELECT 1, 2, 3 - -query TTTT colnames,rowsort -SELECT * FROM indexed ----- -a b c d -2 2 2 4 -1 2 3 4 - -# Ensure that explicit target column does not disturb existing "b" value, but -# does update the computed column. -query TTTT -UPSERT INTO indexed (c, a) VALUES (2.0, 1.0) RETURNING * ----- -1 2 2.0 3.0 - -query TTTT colnames,rowsort -SELECT * FROM indexed ----- -a b c d -1 2 2.0 3.0 -2 2 2 4 - -statement ok -DROP TABLE indexed - -subtest regression_35040 - -statement ok -CREATE TABLE test35040(a INT PRIMARY KEY, b INT NOT NULL, c INT2) - -statement ok -INSERT INTO test35040(a,b) VALUES(0,0) ON CONFLICT(a) DO UPDATE SET b = NULL - -statement error null value in column "b" violates not-null constraint -INSERT INTO test35040(a,b) VALUES(0,0) ON CONFLICT(a) DO UPDATE SET b = NULL - -statement error integer out of range for type int2 -INSERT INTO test35040(a,b) VALUES (0,1) ON CONFLICT(a) DO UPDATE SET c = 111111111; - -statement ok -DROP TABLE test35040 - -# ------------------------------------------------------------------------------ -# Regression for cockroach#35364. -# ------------------------------------------------------------------------------ -subtest regression_35364 - -statement ok -CREATE TABLE t35364(x INT PRIMARY KEY, y DECIMAL(10,1) CHECK(y >= 8.0), UNIQUE INDEX (y)) - -statement ok -INSERT INTO t35364(x, y) VALUES (1, 10.2) - -# 10.18 should be mapped to 10.2 before the left outer join so that the conflict -# can be detected, and 7.95 should be mapped to 8.0 so that check constraint -# will pass. -statement ok -INSERT INTO t35364(x, y) VALUES (2, 10.18) ON CONFLICT (y) DO UPDATE SET y=7.95 - -query IT -SELECT * FROM t35364 ----- -1 8.0 - -statement ok -DROP TABLE t35364 - -# Check UPSERT syntax. -statement ok -CREATE TABLE t35364( - x DECIMAL(10,0) CHECK (x >= 0) PRIMARY KEY, - y DECIMAL(10,0) CHECK (y >= 0) -) - -statement ok -UPSERT INTO t35364 (x) VALUES (-0.1) - -query TT -SELECT * FROM t35364 ----- --0 NULL - -statement ok -UPSERT INTO t35364 (x, y) VALUES (-0.2, -0.3) - -query TT -SELECT * FROM t35364 ----- --0 -0 - -statement ok -UPSERT INTO t35364 (x, y) VALUES (1.5, 2.5) - -query TT rowsort -SELECT * FROM t35364 ----- --0 -0 -2 3 - -statement ok -INSERT INTO t35364 (x) VALUES (1.5) ON CONFLICT (x) DO UPDATE SET x=2.5, y=3.5 - -query TT rowsort -SELECT * FROM t35364 ----- --0 -0 -3 4 - -# ------------------------------------------------------------------------------ -# Regression for cockroach#35970. -# ------------------------------------------------------------------------------ -statement ok -CREATE TABLE table35970 ( - a DECIMAL(10,1) PRIMARY KEY, - b DECIMAL(10,1), - c DECIMAL(10,0), - FAMILY fam0 (a, b), - FAMILY fam1 (c) -) - -query I -UPSERT INTO table35970 (a) VALUES (1.5) RETURNING b ----- -NULL - -query I -INSERT INTO table35970 VALUES (1.5, 1.5, NULL) -ON CONFLICT (a) -DO UPDATE SET c = table35970.a+1 -RETURNING b ----- -NULL diff --git a/test/sqllogictest/cockroach/user.slt b/test/sqllogictest/cockroach/user.slt new file mode 100644 index 0000000000000..9f02c2acf30fe --- /dev/null +++ b/test/sqllogictest/cockroach/user.slt @@ -0,0 +1,305 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/user +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# LogicTest: local 3node-tenant + +query T +SHOW is_superuser +---- +off + +# Not supported by Materialize. +onlyif cockroach +query TTT colnames +SHOW USERS +---- +username options member_of +admin · {} +root · {admin} +testuser · {} + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER user1 + +# Not supported by Materialize. +onlyif cockroach +query TTT colnames +SHOW USERS +---- +username options member_of +admin · {} +root · {admin} +testuser · {} +user1 · {} + +statement error pgcode 42710 CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER admin + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER IF NOT EXISTS admin + +statement error pgcode 42710 CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER user1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER IF NOT EXISTS user1 + +statement error pgcode 42710 CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER UsEr1 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER Ομηρος + +statement error pgcode 42939 CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER node + +statement error pgcode 42939 CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER public + +statement error pgcode 42939 CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER "none" + +statement error CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER test WITH PASSWORD '' + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER uSEr2 WITH PASSWORD 'cockroach' + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER user3 WITH PASSWORD '蟑螂' + +statement error CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER foo☂ + +statement error CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER "-foo" + +statement error CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER foo-bar + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER "foo-bar" + +# Not supported by Materialize. +onlyif cockroach +statement ok +PREPARE pcu AS CREATE USER foo WITH PASSWORD $1; + EXECUTE pcu('bar') + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER USER foo WITH PASSWORD 'somepass' + +# Not supported by Materialize. +onlyif cockroach +statement ok +PREPARE chpw AS ALTER USER foo WITH PASSWORD $1; + EXECUTE chpw('bar') + +statement error Expected literal string, found parameter "\$1" +PREPARE chpw2 AS ALTER USER blix WITH PASSWORD $1; + EXECUTE chpw2('baz') + +# Not supported by Materialize. +onlyif cockroach +query TTT colnames +SHOW USERS +---- +username options member_of +admin · {} +foo · {} +foo-bar · {} +root · {admin} +testuser · {} +user1 · {} +user2 · {} +user3 · {} +ομηρος · {} + +statement error CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER "" + +# Not supported by Materialize. +onlyif cockroach +query TTTTT +SELECT current_user, current_user(), session_user, session_user(), user +---- +root root root root root + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER testuser2; +GRANT admin TO testuser2 + +user testuser2 + +query T +SHOW is_superuser +---- +off + +user testuser + +query T +SHOW is_superuser +---- +off + +statement error CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER user4 + +statement error Unexpected keyword UPSERT at the beginning of a statement +UPSERT INTO system.users VALUES (user1, 'newpassword', false) + +# Not supported by Materialize. +onlyif cockroach +statement error pq: user testuser does not have SELECT privilege on relation user +SHOW USERS + +# Not supported by Materialize. +onlyif cockroach +query TTTTT +SELECT current_user, current_user(), session_user, session_user(), user +---- +testuser testuser testuser testuser testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET SESSION AUTHORIZATION DEFAULT + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW session_user +---- +testuser + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET SESSION AUTHORIZATION DEFAULT + +# Not supported by Materialize. +onlyif cockroach +query T +SHOW session_user +---- +root + +# Test CREATEROLE privilege. + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER USER testuser CREATEROLE + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE ROLE user4 CREATEROLE + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER user5 NOLOGIN + +user root + +# Not supported by Materialize. +onlyif cockroach +query TTTO +SELECT * FROM system.role_options +---- +testuser CREATEROLE NULL 100 +user4 CREATEROLE NULL 108 +user4 NOLOGIN NULL 108 +user5 NOLOGIN NULL 109 + +user testuser + +query T +SHOW is_superuser +---- +off + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP ROLE user4 + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP ROLE user5 + +subtest min_password_length + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +SET CLUSTER SETTING server.user_login.min_password_length = 12 + +statement error CREATE USER is not supported, for more information consult the documentation at https://materialize\.com/docs/sql/create\-role/#details +CREATE USER baduser WITH PASSWORD 'abc' + +statement error permission denied to alter password of role +ALTER USER testuser WITH PASSWORD 'abc' + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE USER userlongpassword WITH PASSWORD '012345678901' + +# Not supported by Materialize. +onlyif cockroach +statement ok +ALTER USER userlongpassword WITH PASSWORD '987654321021' + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP USER userlongpassword diff --git a/test/sqllogictest/cockroach/uuid.slt b/test/sqllogictest/cockroach/uuid.slt index 4740568145118..3bd9194962d05 100644 --- a/test/sqllogictest/cockroach/uuid.slt +++ b/test/sqllogictest/cockroach/uuid.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,17 +9,17 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/uuid +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/uuid # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach statement ok @@ -28,6 +28,8 @@ CREATE TABLE u (token uuid PRIMARY KEY, token3 uuid, UNIQUE INDEX i_token2 (token2)) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u VALUES ('63616665-6630-3064-6465-616462656562', '{63616665-6630-3064-6465-616462656563}', b'kafef00ddeadbeed'), @@ -37,43 +39,44 @@ INSERT INTO u VALUES query TTT SELECT * FROM u ORDER BY token ---- -63616665-6630-3064-6465-616462656562 63616665-6630-3064-6465-616462656563 6b616665-6630-3064-6465-616462656564 -63616665-6630-3064-6465-616462656564 63616665-6630-3064-6465-616462656565 6b616665-6630-3064-6465-616462656565 -63616665-6630-3064-6465-616462656566 63616665-6630-3064-6465-616462656567 6b616665-6630-3064-6465-616462656566 + query TTT SELECT * FROM u WHERE token < '63616665-6630-3064-6465-616462656564'::uuid ---- -63616665-6630-3064-6465-616462656562 63616665-6630-3064-6465-616462656563 6b616665-6630-3064-6465-616462656564 + query TTT SELECT * FROM u WHERE token <= '63616665-6630-3064-6465-616462656564'::uuid ORDER BY token ---- -63616665-6630-3064-6465-616462656562 63616665-6630-3064-6465-616462656563 6b616665-6630-3064-6465-616462656564 -63616665-6630-3064-6465-616462656564 63616665-6630-3064-6465-616462656565 6b616665-6630-3064-6465-616462656565 + +# Not supported by Materialize. +onlyif cockroach statement error duplicate key value INSERT INTO u VALUES ('63616665-6630-3064-6465-616462656566') +# Not supported by Materialize. +onlyif cockroach statement error duplicate key value INSERT INTO u VALUES ('63616665-6630-3064-6465-616462656569', '63616665-6630-3064-6465-616462656565') -statement error UUID must be exactly 16 bytes long, got 15 bytes +statement error type "b" does not exist INSERT INTO u VALUES (b'cafef00ddeadbee') -statement error UUID must be exactly 16 bytes long, got 17 bytes +statement error type "b" does not exist INSERT INTO u VALUES (b'cafef00ddeadbeefs') -statement error uuid: incorrect UUID length +statement error invalid input syntax for type uuid: invalid group length in group 4: expected 12, found 11: "63616665\-6630\-3064\-6465\-61646265656" INSERT INTO u VALUES ('63616665-6630-3064-6465-61646265656') -statement error uuid: incorrect UUID length +statement error invalid input syntax for type uuid: invalid group length in group 4: expected 12, found 13: "63616665\-6630\-3064\-6465\-6164626565620" INSERT INTO u VALUES ('63616665-6630-3064-6465-6164626565620') -statement error unsupported comparison operator: = +statement error type "b" does not exist SELECT token FROM u WHERE token=b'cafef00ddeadbeef'::bytes -statement error unsupported comparison operator: = +statement error WHERE clause error: operator does not exist: uuid = text SELECT token FROM u WHERE token='63616665-6630-3064-6465-616462656562'::string statement ok @@ -82,8 +85,10 @@ SELECT token FROM u WHERE token='63616665-6630-3064-6465-616462656562'::uuid query T SELECT token FROM u WHERE token='urn:uuid:63616665-6630-3064-6465-616462656562' ---- -63616665-6630-3064-6465-616462656562 + +# Not supported by Materialize. +onlyif cockroach query T SELECT token FROM u WHERE token=b'cafef00ddeadbeef' ---- @@ -92,13 +97,12 @@ SELECT token FROM u WHERE token=b'cafef00ddeadbeef' query T SELECT token2 FROM u WHERE token2='63616665-6630-3064-6465-616462656563' ---- -63616665-6630-3064-6465-616462656563 + query T SELECT token FROM u WHERE token IN ('63616665-6630-3064-6465-616462656562', '63616665-6630-3064-6465-616462656564') ORDER BY token ---- -63616665-6630-3064-6465-616462656562 -63616665-6630-3064-6465-616462656564 + statement ok INSERT INTO u VALUES ('63616665-6630-3064-6465-616462656567'::uuid) @@ -106,37 +110,140 @@ INSERT INTO u VALUES ('63616665-6630-3064-6465-616462656567'::uuid) statement ok INSERT INTO u VALUES ('urn:uuid:63616665-6630-3064-6465-616462656568'::uuid) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO u VALUES (uuid_v4()::uuid) -statement error value type bytes doesn't match type uuid +statement error column "token" is of type uuid but expression is of type bytea INSERT INTO u VALUES ('cafef00ddeadbeef'::bytes) -statement error value type text doesn't match type uuid +statement error column "token" is of type uuid but expression is of type text INSERT INTO u VALUES ('63616665-6630-3064-6465-616462656562'::string) -statement error value type bytes doesn't match type uuid +statement error function "uuid_v4" does not exist INSERT INTO u VALUES (uuid_v4()) +# Not supported by Materialize. +onlyif cockroach query T SELECT token::uuid FROM u WHERE token=b'cafef00ddeadbeef' ---- 63616665-6630-3064-6465-616462656566 +# Not supported by Materialize. +onlyif cockroach query T SELECT token::string FROM u WHERE token=b'cafef00ddeadbeef' ---- 63616665-6630-3064-6465-616462656566 +# Not supported by Materialize. +onlyif cockroach query T SELECT token::bytes FROM u WHERE token=b'cafef00ddeadbeef' ---- cafef00ddeadbeef -statement error invalid cast: uuid -> int +statement error CAST does not support casting from uuid to integer SELECT token::int FROM u +# Not supported by Materialize. +onlyif cockroach query T SELECT ('63616665-6630-3064-6465-616462656562' COLLATE en)::uuid ---- 63616665-6630-3064-6465-616462656562 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT uuid_nil() +---- +00000000-0000-0000-0000-000000000000 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT uuid_ns_dns() +---- +6ba7b810-9dad-11d1-80b4-00c04fd430c8 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT uuid_ns_url() +---- +6ba7b811-9dad-11d1-80b4-00c04fd430c8 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT uuid_ns_oid() +---- +6ba7b812-9dad-11d1-80b4-00c04fd430c8 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT uuid_ns_x500() +---- +6ba7b814-9dad-11d1-80b4-00c04fd430c8 + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT uuid_generate_v1() = uuid_generate_v1() +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT uuid_generate_v1mc() = uuid_generate_v1mc() +---- +false + +# Not supported by Materialize. +onlyif cockroach +# Verify that uuid_generate_v1 does not return deterministic output for the MAC +# address bits. +query B +SELECT substr(uuid_generate_v1()::TEXT, 24) = substr(uuid_generate_v1()::TEXT, 24) +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT substr(uuid_generate_v1mc()::TEXT, 24) = substr(uuid_generate_v1mc()::TEXT, 24) +---- +false + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT uuid_generate_v3(uuid_ns_x500(), 'cat') +---- +6505abc6-6166-351d-b8f6-ce179e9cf79d + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT uuid_generate_v5(uuid_ns_oid(), 'dog') +---- +9a8b57c4-73a4-5dfb-b888-6fff478edf63 + +# Not supported by Materialize. +onlyif cockroach +# Regression test for incorrect concatenation of a UUID with a STRING in the +# vectorized engine (#83093). +statement ok +CREATE TABLE t83093 (u) AS SELECT 'eb64afe6-ade7-40ce-8352-4bb5eec39075'::UUID + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT u || 'foo' FROM t83093 +---- +eb64afe6-ade7-40ce-8352-4bb5eec39075foo diff --git a/test/sqllogictest/cockroach/values.slt b/test/sqllogictest/cockroach/values.slt index 326ec94472534..95f8d2d79e096 100644 --- a/test/sqllogictest/cockroach/values.slt +++ b/test/sqllogictest/cockroach/values.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,12 +9,15 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/values +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/values # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach @@ -72,5 +75,13 @@ VALUES ((SELECT 1)), ((SELECT 2)) 1 2 -query error pgcode 42804 invalid input syntax for type integer +query error pgcode 42804 invalid input syntax for type integer: invalid digit found in string: "a" VALUES (NULL, 1), (2, NULL), (NULL, 'a') + +# subqueries in VALUES don't cause problems in EXPLAIN(DISTSQL), despite forcing +# execution on the gateway. + +# Not supported by Materialize. +onlyif cockroach +statement ok +EXPLAIN(DISTSQL) VALUES((SELECT 1), 3) diff --git a/test/sqllogictest/cockroach/views.slt b/test/sqllogictest/cockroach/views.slt index 96d3f94761be7..633ad7425b0cd 100644 --- a/test/sqllogictest/cockroach/views.slt +++ b/test/sqllogictest/cockroach/views.slt @@ -31,21 +31,31 @@ INSERT INTO t VALUES (1, 99), (2, 98), (3, 97) statement ok CREATE VIEW v1 AS SELECT a, b FROM t +# Not supported by Materialize. +onlyif cockroach statement error pgcode 42P07 relation "v1" already exists CREATE VIEW v1 AS SELECT a, b FROM t +# Not supported by Materialize. +onlyif cockroach statement error pgcode 42P07 relation "t" already exists CREATE VIEW t AS SELECT a, b FROM t statement ok CREATE VIEW v2 (x, y) AS SELECT a, b FROM t +# Not supported by Materialize. +onlyif cockroach statement error pgcode 42601 CREATE VIEW specifies 1 column name, but data source has 2 columns CREATE VIEW v3 (x) AS SELECT a, b FROM t +# Not supported by Materialize. +onlyif cockroach statement error pgcode 42601 CREATE VIEW specifies 3 column names, but data source has 2 columns CREATE VIEW v4 (x, y, z) AS SELECT a, b FROM t +# Not supported by Materialize. +onlyif cockroach statement error pgcode 42P01 relation "dne" does not exist CREATE VIEW v5 AS SELECT a, b FROM dne @@ -79,6 +89,8 @@ x y 2 98 3 97 +# Not supported by Materialize. +onlyif cockroach query II colnames SELECT * FROM v7 ---- @@ -111,6 +123,8 @@ SELECT y FROM v2 98 97 +# Not supported by Materialize. +onlyif cockroach query I SELECT x FROM v7 ---- @@ -140,9 +154,13 @@ SELECT * FROM v1 AS v1 INNER JOIN v2 AS v2 ON v1.a = v2.x 2 98 2 98 3 97 3 97 +# Not supported by Materialize. +onlyif cockroach statement error pgcode 42809 "v1" is not a table DROP TABLE v1 +# Not supported by Materialize. +onlyif cockroach statement error pgcode 42809 "t" is not a view DROP VIEW t @@ -156,9 +174,13 @@ DROP VIEW v6 statement ok DROP VIEW v2 +# Not supported by Materialize. +onlyif cockroach statement ok DROP VIEW v1 +# Not supported by Materialize. +onlyif cockroach statement error pgcode 42P01 relation "v1" does not exist DROP VIEW v1 @@ -188,37 +210,57 @@ DROP VIEW s3 statement ok DROP VIEW s1 +# Not supported by Materialize. +onlyif cockroach statement ok DROP TABLE t +# Not supported by Materialize. +onlyif cockroach # Check for memory leak (materialize#10466) statement ok CREATE VIEW foo AS SELECT catalog_name, schema_name, sql_path FROM information_schema.schemata +# Not supported by Materialize. +onlyif cockroach statement error pq: relation "foo" already exists CREATE VIEW foo AS SELECT catalog_name, schema_name, sql_path FROM information_schema.schemata +# Not supported by Materialize. +onlyif cockroach # Ensure views work with dates/timestamps (materialize#12420) statement ok CREATE TABLE t (d DATE, t TIMESTAMP) +# Not supported by Materialize. +onlyif cockroach statement ok CREATE VIEW dt AS SELECT d, t FROM t WHERE d > DATE '1988-11-12' AND t < TIMESTAMP '2017-01-01' +# Not supported by Materialize. +onlyif cockroach statement ok SELECT * FROM dt +# Not supported by Materialize. +onlyif cockroach statement ok CREATE VIEW dt2 AS SELECT d, t FROM t WHERE d > d + INTERVAL '10h' +# Not supported by Materialize. +onlyif cockroach statement ok SELECT * FROM dt2 +# Not supported by Materialize. +onlyif cockroach # Ensure that creating a view doesn't leak any session-level settings that # could affect subsequent AS OF SYSTEM TIME queries (materialize#13547). statement ok CREATE VIEW v AS SELECT d, t FROM t +# Not supported by Materialize. +onlyif cockroach statement error pq: AS OF SYSTEM TIME must be provided on a top-level statement CREATE TABLE t2 AS SELECT d, t FROM t AS OF SYSTEM TIME '2017-02-13 21:30:00' @@ -291,6 +333,8 @@ SELECT sum ("QuotedCaps15951". a) FROM "QuotedCaps15951" GROUP BY b ORDER BY b statement ok CREATE VIEW w AS WITH a AS (SELECT 1 AS x) SELECT x FROM a +# Not supported by Materialize. +onlyif cockroach query T SELECT create_statement FROM [SHOW CREATE w] ---- @@ -299,6 +343,8 @@ CREATE VIEW w (x) AS WITH a AS (SELECT 1 AS x) SELECT x FROM a statement ok CREATE VIEW w2 AS WITH t AS (SELECT x FROM w) SELECT x FROM t +# Not supported by Materialize. +onlyif cockroach query T SELECT create_statement FROM [SHOW CREATE w2] ---- @@ -307,6 +353,8 @@ CREATE VIEW w2 (x) AS WITH t AS (SELECT x FROM test.public.w) SELECT x FROM t statement ok CREATE VIEW w3 AS (WITH t AS (SELECT x FROM w) SELECT x FROM t) +# Not supported by Materialize. +onlyif cockroach query T SELECT create_statement FROM [SHOW CREATE w3] ---- @@ -317,14 +365,20 @@ CREATE VIEW w3 (x) AS (WITH t AS (SELECT x FROM test.public.w) SELECT x FROM t) statement ok CREATE TABLE t (a INT PRIMARY KEY, b INT) +# Not supported by Materialize. +onlyif cockroach statement ok CREATE VIEW crud_view AS SELECT a, b FROM [INSERT INTO t (a, b) VALUES (100, 100) RETURNING a, b] +# Not supported by Materialize. +onlyif cockroach statement ok GRANT SELECT ON crud_view TO testuser user testuser +# Not supported by Materialize. +onlyif cockroach query error user testuser does not have INSERT privilege on relation t SELECT * FROM crud_view diff --git a/test/sqllogictest/cockroach/virtual_table_privileges.slt b/test/sqllogictest/cockroach/virtual_table_privileges.slt new file mode 100644 index 0000000000000..c0c958efb3ccb --- /dev/null +++ b/test/sqllogictest/cockroach/virtual_table_privileges.slt @@ -0,0 +1,206 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/virtual_table_privileges +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +user testuser + +# Not supported by Materialize. +onlyif cockroach +# Public should have SELECT on virtual tables by default. +statement ok +SELECT * FROM crdb_internal.tables + +# Not supported by Materialize. +onlyif cockroach +statement ok + +query B +SELECT has_table_privilege('testuser', 'crdb_internal.tables', 'select'); +---- +true + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE SELECT ON crdb_internal.tables FROM public + +# Not supported by Materialize. +onlyif cockroach +query TTTTO +SELECT * FROM system.privileges +---- +public /vtable/crdb_internal/tables {} {} 4 + +# Not supported by Materialize. +onlyif cockroach +# Note that after granting SELECT to public, there should be no row +# since this is the default case, public with SELECT is represented as no row. +statement ok +GRANT SELECT ON crdb_internal.tables TO public + +# Not supported by Materialize. +onlyif cockroach +query TTTTO +SELECT * FROM system.privileges +---- + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM crdb_internal.tables + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE SELECT ON TABLE crdb_internal.tables FROM public + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_table_privilege('testuser', 'crdb_internal.tables', 'select'); +---- +false + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement error pq: user testuser does not have SELECT privilege on relation tables +SHOW TABLES + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT SELECT ON TABLE crdb_internal.tables TO public + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT has_table_privilege('testuser', 'crdb_internal.tables', 'select'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +statement ok +REVOKE SELECT ON TABLE crdb_internal.tables FROM public + +user testuser + +statement error unknown schema 'crdb_internal' +SELECT * FROM crdb_internal.tables + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +GRANT SELECT ON TABLE crdb_internal.tables TO public + +user testuser + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT * FROM crdb_internal.tables + +user root + +# Test that we can specify the database name. +statement ok +CREATE DATABASE test2 + +query T noticetrace +GRANT SELECT ON TABLE test2.information_schema.columns TO testuser +---- +NOTICE: virtual table privileges are not database specific + +# Not supported by Materialize. +onlyif cockroach +query TTTTO +SELECT * FROM system.privileges +---- +testuser /vtable/information_schema/columns {SELECT} {} 100 + +user testuser + +statement ok +SELECT * FROM test2.information_schema.columns + +# Not supported by Materialize. +onlyif cockroach +# We're in database test, this is okay. +statement ok +SELECT * FROM crdb_internal.cluster_sessions + +user root + +# Not supported by Materialize. +onlyif cockroach +statement ok +use test2 + +# virtual table privileges are not database specific so qualifying it should +# do nothing. + +# Not supported by Materialize. +onlyif cockroach +query B +select has_table_privilege('testuser', 'test2.crdb_internal.tables', 'select'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +statement ok +use test + +# Not supported by Materialize. +onlyif cockroach +query B +select has_table_privilege('testuser', 'test.crdb_internal.tables', 'select'); +---- +true + +# Not supported by Materialize. +onlyif cockroach +# Second select tests the cache. Rudimentary test to ensure the cache works. +statement ok +SELECT * FROM crdb_internal.tables + +statement error unknown schema 'crdb_internal' +GRANT USAGE ON TABLE crdb_internal.tables TO testuser + +statement error Expected TO, found ON +GRANT ZONECONFIG ON TABLE crdb_internal.tables TO testuser + +statement error invalid privilege types CREATE for VIEW "information_schema\.tables" +GRANT CREATE ON TABLE information_schema.tables TO testuser diff --git a/test/sqllogictest/cockroach/void.slt b/test/sqllogictest/cockroach/void.slt new file mode 100644 index 0000000000000..837007db58b25 --- /dev/null +++ b/test/sqllogictest/cockroach/void.slt @@ -0,0 +1,233 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/void +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +statement error type "void" does not exist +CREATE TABLE invalid_void_table(col void) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT 'this will be ignored'::void +---- +· + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #83791. row_to_json on a VOID should produce an +# empty string, unadorned with single quotes, as in done in postgres. +query T +SELECT row_to_json((''::VOID, null))::JSONB AS col_12295 +---- +{"f1": "", "f2": null} + +# Not supported by Materialize. +onlyif cockroach +query T +select row (''::void, 2::int) +---- +("",2) + +# Not supported by Materialize. +onlyif cockroach +query T +select row ('':::void, 2::int) +---- +("",2) + +statement error Expected a data type name, found colon +select row ('foo':::void, 2::int) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT ('this will disappear too'::text)::void +---- +· + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT ('gone'::void)::text +---- +· + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT crdb_internal.void_func() +---- +· + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #83754. Note that Postgres is inconsistent +# in evaluation. For example, `SELECT ''::VOID IS DISTINCT FROM NULL::UNKNOWN;` +# errors out, but `SELECT ''::VOID IS DISTINCT FROM NULL;` does not. +# This is due to normalization into an IS NOT NULL op when one operand is NULL. +# The NULL with type cast is not recognized as NULL. +query B +SELECT ''::VOID IS DISTINCT FROM NULL +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +SELECT ''::VOID IS DISTINCT FROM NULL::UNKNOWN +---- +true + +statement ok +SET vectorize=on + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #83754. Vectorized execution should not error out. +query T +SELECT + COALESCE(tab_115318.col_199168, NULL) AS col_199169 +FROM + (VALUES (''::VOID), (NULL), (NULL), (''::VOID)) AS tab_115318 (col_199168) +ORDER BY + tab_115318.col_199168 +---- +NULL +NULL +· +· + +# Regression test for #83754. Illegal type comparison should be caught in the +# parser. +statement error type "void" does not exist +SELECT NULLIF(tab_115318.a, tab_115318.b) AS col_199169 +FROM + (VALUES (''::VOID, NULL), (NULL, NULL)) AS tab_115318 (a, b) +ORDER BY + tab_115318.a; + +statement error type "void" does not exist +SELECT NULLIF(tab_115318.a, tab_115318.b) AS col_199169 +FROM + (VALUES (''::VOID, ''::VOID), (NULL, NULL)) AS tab_115318 (a, b) +ORDER BY + tab_115318.col_199168; + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #83754. Tuple type should be handled properly. +query T +SELECT + COALESCE(tab_115318.col_199168, NULL) AS col_199169 +FROM + (VALUES ((NULL, 1)), (NULL)) AS tab_115318 (col_199168) +ORDER BY + tab_115318.col_199168 +---- +NULL +(,1) + +statement ok +SET vectorize=off + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #83754. +# Non-vectorized and vectorized results should match. +query T +SELECT + COALESCE(tab_115318.col_199168, NULL) AS col_199169 +FROM + (VALUES (''::VOID), (NULL), (NULL), (''::VOID)) AS tab_115318 (col_199168) +ORDER BY + tab_115318.col_199168 +---- +NULL +NULL +· +· + +# Regression test for #83754. +# Non-vectorized and vectorized results should match. +statement error type "void" does not exist +SELECT NULLIF(tab_115318.a, tab_115318.b) AS col_199169 +FROM + (VALUES (''::VOID, NULL), (NULL, NULL)) AS tab_115318 (a, b) +ORDER BY + tab_115318.a; + +# Regression test for #83754. +# Non-vectorized and vectorized results should match. +statement error type "void" does not exist +SELECT NULLIF(tab_115318.a, tab_115318.b) AS col_199169 +FROM + (VALUES (''::VOID, ''::VOID), (NULL, NULL)) AS tab_115318 (a, b) +ORDER BY + tab_115318.col_199168; + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #83754. +# Non-vectorized and vectorized results should match. +query T +SELECT + COALESCE(tab_115318.col_199168, NULL) AS col_199169 +FROM + (VALUES ((NULL, 1)), (NULL)) AS tab_115318 (col_199168) +ORDER BY + tab_115318.col_199168 +---- +NULL +(,1) + +statement ok +RESET vectorize + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #93572. This should not fail with an internal error. +query B +WITH tab(x) AS (VALUES ('':::VOID)) SELECT x IS NULL FROM tab +---- +false + +# Not supported by Materialize. +onlyif cockroach +query B +WITH tab(x) AS (VALUES (NULL:::VOID)) SELECT x IS NULL FROM tab +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +WITH tab(x) AS (VALUES ('':::VOID)) SELECT x IS NOT NULL FROM tab +---- +true + +# Not supported by Materialize. +onlyif cockroach +query B +WITH tab(x) AS (VALUES (NULL:::VOID)) SELECT x IS NOT NULL FROM tab +---- +false diff --git a/test/sqllogictest/cockroach/where.slt b/test/sqllogictest/cockroach/where.slt index 4cd063e76b670..eb0bb2f2bd309 100644 --- a/test/sqllogictest/cockroach/where.slt +++ b/test/sqllogictest/cockroach/where.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,21 +9,19 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/where +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/where # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -simple conn=mz_system,user=mz_system -ALTER SYSTEM SET unsafe_enable_table_keys = true ----- -COMPLETE 0 - statement ok CREATE TABLE kv ( k INT PRIMARY KEY, @@ -35,8 +33,8 @@ INSERT INTO kv VALUES (1, 2), (3, 4), (5, 6), (7, 8) statement ok CREATE TABLE kvString ( - k TEXT PRIMARY KEY, - v TEXT + k STRING PRIMARY KEY, + v STRING ) statement ok @@ -90,11 +88,13 @@ SELECT 'hello' LIKE v FROM kvString WHERE k LIKE 'like%' ORDER BY k true false -# query B -# SELECT 'hello' SIMILAR TO v FROM kvString WHERE k SIMILAR TO 'like[1-2]' ORDER BY k -# ---- -# true -# false +# Not supported by Materialize. +onlyif cockroach +query B +SELECT 'hello' SIMILAR TO v FROM kvString WHERE k SIMILAR TO 'like[1-2]' ORDER BY k +---- +true +false query B SELECT 'hello' ~ replace(v, '%', '.*') FROM kvString WHERE k ~ 'like[1-2]' ORDER BY k @@ -110,7 +110,7 @@ SELECT * FROM kv WHERE k IN (1, 5.0, 9) 1 2 5 6 -# Regression tests for materialize#22670. +# Regression tests for #22670. statement ok CREATE TABLE ab (a INT, b INT) diff --git a/test/sqllogictest/cockroach/window.slt b/test/sqllogictest/cockroach/window.slt index a769a0c702b30..a6f04001f7269 100644 --- a/test/sqllogictest/cockroach/window.slt +++ b/test/sqllogictest/cockroach/window.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,19 +9,21 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/window +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/window # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. -# not supported yet -halt - mode cockroach +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE kv ( -- don't add column "a" @@ -32,296 +34,355 @@ CREATE TABLE kv ( d DECIMAL, s STRING, b BOOL, + i INTERVAL, FAMILY (k, v, w, f, b), FAMILY (d), FAMILY (s) ) +# Not supported by Materialize. +onlyif cockroach statement OK INSERT INTO kv VALUES -(1, 2, 3, 1.0, 1, 'a', true), -(3, 4, 5, 2, 8, 'a', true), -(5, NULL, 5, 9.9, -321, NULL, false), -(6, 2, 3, 4.4, 4.4, 'b', true), -(7, 2, 2, 6, 7.9, 'b', true), -(8, 4, 2, 3, 3, 'A', false) - -query error window functions are not allowed in GROUP BY +(1, 2, 3, 1.0, 1, 'a', true, '1min'), +(3, 4, 5, 2, 8, 'a', true, '2sec'), +(5, NULL, 5, 9.9, -321, NULL, false, NULL), +(6, 2, 3, 4.4, 4.4, 'b', true, '1ms'), +(7, 2, 2, 6, 7.9, 'b', true, '4 days'), +(8, 4, 2, 3, 3, 'A', false, '3 years') + +query error unknown catalog item 'kv' SELECT * FROM kv GROUP BY v, count(w) OVER () -query error window functions are not allowed in GROUP BY +query error unknown catalog item 'kv' SELECT count(w) OVER () FROM kv GROUP BY 1 -query error window functions are not allowed in RETURNING +query error unknown catalog item 'kv' INSERT INTO kv (k, v) VALUES (99, 100) RETURNING sum(v) OVER () -query error window functions are not allowed in LIMIT +query error unknown catalog item 'kv' SELECT sum(v) FROM kv GROUP BY k LIMIT sum(v) OVER () -query error window functions are not allowed in OFFSET +query error unknown catalog item 'kv' SELECT sum(v) FROM kv GROUP BY k LIMIT 1 OFFSET sum(v) OVER () -query error window functions are not allowed in VALUES +query error unknown catalog item 'kv' INSERT INTO kv (k, v) VALUES (99, count(1) OVER ()) -query error window functions are not allowed in WHERE +query error unknown catalog item 'kv' SELECT k FROM kv WHERE avg(k) OVER () > 1 -query error window functions are not allowed in HAVING +query error unknown catalog item 'kv' SELECT 1 FROM kv GROUP BY 1 HAVING sum(1) OVER (PARTITION BY 1) > 1 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER () FROM kv ORDER BY 1 ---- -5 -5 -5 -5 -5 -5 +5.0000000000000000000 +5.0000000000000000000 +5.0000000000000000000 +5.0000000000000000000 +5.0000000000000000000 +5.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (PARTITION BY v) FROM kv ORDER BY 1 ---- 4.6666666666666666667 4.6666666666666666667 4.6666666666666666667 -5 -5.5 -5.5 +5.0000000000000000000 +5.5000000000000000000 +5.5000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (PARTITION BY w) FROM kv ORDER BY 1 ---- -3.5 -3.5 -4 -4 -7.5 -7.5 +3.5000000000000000000 +3.5000000000000000000 +4.0000000000000000000 +4.0000000000000000000 +7.5000000000000000000 +7.5000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (PARTITION BY b) FROM kv ORDER BY 1 ---- -4.25 -4.25 -4.25 -4.25 -6.5 -6.5 +4.2500000000000000000 +4.2500000000000000000 +4.2500000000000000000 +4.2500000000000000000 +6.5000000000000000000 +6.5000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (PARTITION BY w, b) FROM kv ORDER BY 1 ---- -3 -3.5 -3.5 -5 -7 -8 +3.0000000000000000000 +3.5000000000000000000 +3.5000000000000000000 +5.0000000000000000000 +7.0000000000000000000 +8.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (PARTITION BY kv.*) FROM kv ORDER BY 1 ---- -1 -3 -5 -6 -7 -8 +1.0000000000000000000 +3.0000000000000000000 +5.0000000000000000000 +6.0000000000000000000 +7.0000000000000000000 +8.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (ORDER BY w) FROM kv ORDER BY 1 ---- -5 -5 -5.5 -5.5 -7.5 -7.5 +5.0000000000000000000 +5.0000000000000000000 +5.5000000000000000000 +5.5000000000000000000 +7.5000000000000000000 +7.5000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (ORDER BY b) FROM kv ORDER BY 1 ---- -5 -5 -5 -5 -6.5 -6.5 +5.0000000000000000000 +5.0000000000000000000 +5.0000000000000000000 +5.0000000000000000000 +6.5000000000000000000 +6.5000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (ORDER BY w, b) FROM kv ORDER BY 1 ---- -5 -5.4 -5.5 -5.5 -7.5 -8 +5.0000000000000000000 +5.4000000000000000000 +5.5000000000000000000 +5.5000000000000000000 +7.5000000000000000000 +8.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (ORDER BY 1-w) FROM kv ORDER BY 1 ---- -3.75 -3.75 -4 -4 -5 -5 +3.7500000000000000000 +3.7500000000000000000 +4.0000000000000000000 +4.0000000000000000000 +5.0000000000000000000 +5.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (ORDER BY kv.*) FROM kv ORDER BY 1 ---- -1 -2 -3 -3.75 -4.4 -5 +1.0000000000000000000 +2.0000000000000000000 +3.0000000000000000000 +3.7500000000000000000 +4.4000000000000000000 +5.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (ORDER BY w DESC) FROM kv ORDER BY 1 ---- -3.75 -3.75 -4 -4 -5 -5 +3.7500000000000000000 +3.7500000000000000000 +4.0000000000000000000 +4.0000000000000000000 +5.0000000000000000000 +5.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- 4.6666666666666666667 4.6666666666666666667 -5 -5.5 -7 -8 +5.0000000000000000000 +5.5000000000000000000 +7.0000000000000000000 +8.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER w FROM kv WINDOW w AS (PARTITION BY v ORDER BY w) ORDER BY 1 ---- 4.6666666666666666667 4.6666666666666666667 -5 -5.5 -7 -8 +5.0000000000000000000 +5.5000000000000000000 +7.0000000000000000000 +8.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (w) FROM kv WINDOW w AS (PARTITION BY v ORDER BY w) ORDER BY 1 ---- 4.6666666666666666667 4.6666666666666666667 -5 -5.5 -7 -8 +5.0000000000000000000 +5.5000000000000000000 +7.0000000000000000000 +8.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(k) OVER (w ORDER BY w) FROM kv WINDOW w AS (PARTITION BY v) ORDER BY 1 ---- 4.6666666666666666667 4.6666666666666666667 -5 -5.5 -7 -8 - -query IIIRRTBR colnames +5.0000000000000000000 +5.5000000000000000000 +7.0000000000000000000 +8.0000000000000000000 + +# Not supported by Materialize. +onlyif cockroach +query IIIRRTBTR colnames SELECT *, avg(k) OVER (w ORDER BY w) FROM kv WINDOW w AS (PARTITION BY v) ORDER BY 1 ---- -k v w f d s b avg -1 2 3 1 1 a true 4.6666666666666666667 -3 4 5 2 8 a true 5.5 -5 NULL 5 9.9 -321 NULL false 5 -6 2 3 4.4 4.4 b true 4.6666666666666666667 -7 2 2 6 7.9 b true 7 -8 4 2 3 3 A false 8 - -query IIIRRTBR colnames +k v w f d s b i avg +1 2 3 1 1 a true 00:01:00 4.6666666666666666667 +3 4 5 2 8 a true 00:00:02 5.5000000000000000000 +5 NULL 5 9.9 -321 NULL false NULL 5.0000000000000000000 +6 2 3 4.4 4.4 b true 00:00:00.001 4.6666666666666666667 +7 2 2 6 7.9 b true 4 days 7.0000000000000000000 +8 4 2 3 3 A false 3 years 8.0000000000000000000 + +# Not supported by Materialize. +onlyif cockroach +query IIIRRTBTR colnames SELECT *, avg(k) OVER w FROM kv WINDOW w AS (PARTITION BY v ORDER BY w) ORDER BY avg(k) OVER w, k ---- -k v w f d s b avg -1 2 3 1 1 a true 4.6666666666666666667 -6 2 3 4.4 4.4 b true 4.6666666666666666667 -5 NULL 5 9.9 -321 NULL false 5 -3 4 5 2 8 a true 5.5 -7 2 2 6 7.9 b true 7 -8 4 2 3 3 A false 8 - -query IIIRRTB colnames +k v w f d s b i avg +1 2 3 1 1 a true 00:01:00 4.6666666666666666667 +6 2 3 4.4 4.4 b true 00:00:00.001 4.6666666666666666667 +5 NULL 5 9.9 -321 NULL false NULL 5.0000000000000000000 +3 4 5 2 8 a true 00:00:02 5.5000000000000000000 +7 2 2 6 7.9 b true 4 days 7.0000000000000000000 +8 4 2 3 3 A false 3 years 8.0000000000000000000 + +# Not supported by Materialize. +onlyif cockroach +query IIIRRTBT colnames SELECT * FROM kv WINDOW w AS (PARTITION BY v ORDER BY w) ORDER BY avg(k) OVER w DESC, k ---- -k v w f d s b -8 4 2 3 3 A false -7 2 2 6 7.9 b true -3 4 5 2 8 a true -5 NULL 5 9.9 -321 NULL false -1 2 3 1 1 a true -6 2 3 4.4 4.4 b true +k v w f d s b i +8 4 2 3 3 A false 3 years +7 2 2 6 7.9 b true 4 days +3 4 5 2 8 a true 00:00:02 +5 NULL 5 9.9 -321 NULL false NULL +1 2 3 1 1 a true 00:01:00 +6 2 3 4.4 4.4 b true 00:00:00.001 +# Not supported by Materialize. +onlyif cockroach query error window "w" is already defined SELECT avg(k) OVER w FROM kv WINDOW w AS (), w AS () +# Not supported by Materialize. +onlyif cockroach query error window "x" does not exist SELECT avg(k) OVER x FROM kv WINDOW w AS () +# Not supported by Materialize. +onlyif cockroach query error window "x" does not exist SELECT avg(k) OVER (x) FROM kv WINDOW w AS () +# Not supported by Materialize. +onlyif cockroach query error cannot override PARTITION BY clause of window "w" SELECT avg(k) OVER (w PARTITION BY v) FROM kv WINDOW w AS () +# Not supported by Materialize. +onlyif cockroach query error cannot override PARTITION BY clause of window "w" SELECT avg(k) OVER (w PARTITION BY v) FROM kv WINDOW w AS (PARTITION BY v) +# Not supported by Materialize. +onlyif cockroach query error cannot override ORDER BY clause of window "w" SELECT avg(k) OVER (w ORDER BY v) FROM kv WINDOW w AS (ORDER BY v) -query error column "a" does not exist +query error unknown catalog item 'kv' SELECT avg(k) OVER (PARTITION BY a) FROM kv -query error column "a" does not exist +query error unknown catalog item 'kv' SELECT avg(k) OVER (ORDER BY a) FROM kv # TODO(justin): this should have pgcode 42803 but CBO currently doesn't get # it right. -query error window functions are not allowed in aggregate +query error unknown catalog item 'kv' SELECT avg(avg(k) OVER ()) FROM kv ORDER BY 1 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(avg(k)) OVER () FROM kv ORDER BY 1 ---- -5 +5.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query RR SELECT avg(k) OVER (), avg(v) OVER () FROM kv ORDER BY 1 ---- -5 2.3333333333333333333 -5 2.3333333333333333333 -5 2.3333333333333333333 -5 2.3333333333333333333 -5 2.3333333333333333333 -5 2.3333333333333333333 +5.0000000000000000000 2.8000000000000000000 +5.0000000000000000000 2.8000000000000000000 +5.0000000000000000000 2.8000000000000000000 +5.0000000000000000000 2.8000000000000000000 +5.0000000000000000000 2.8000000000000000000 +5.0000000000000000000 2.8000000000000000000 -query error OVER specified, but now\(\) is neither a window function nor an aggregate function +query error unknown catalog item 'kv' SELECT now() OVER () FROM kv ORDER BY 1 -query error window function rank\(\) requires an OVER clause +query error unknown catalog item 'kv' SELECT rank() FROM kv -query error unknown signature: rank\(int\) +query error unknown catalog item 'kv' SELECT rank(22) FROM kv -query error window function calls cannot be nested +query error unknown catalog item 'kv' SELECT avg(avg(k) OVER ()) OVER () FROM kv ORDER BY 1 -query error OVER specified, but round\(\) is neither a window function nor an aggregate function +query error unknown catalog item 'kv' SELECT round(avg(k) OVER ()) OVER () FROM kv ORDER BY 1 +# Not supported by Materialize. +onlyif cockroach query R SELECT round(avg(k) OVER (PARTITION BY v ORDER BY w)) FROM kv ORDER BY 1 ---- @@ -332,69 +393,87 @@ SELECT round(avg(k) OVER (PARTITION BY v ORDER BY w)) FROM kv ORDER BY 1 7 8 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(f) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- 2.5 3 -3.8 -3.8 +3.8000000000000003 +3.8000000000000003 6 9.9 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- --321 - 3 - 4.4333333333333333333 - 4.4333333333333333333 - 5.5 - 7.9 +-321.00000000000000000 +3.0000000000000000000 +4.4333333333333333333 +4.4333333333333333333 +5.5000000000000000000 +7.9000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(d) OVER (PARTITION BY w ORDER BY v) FROM kv ORDER BY 1 ---- --321 --156.5 - 2.7 - 2.7 - 5.45 - 7.9 +-321.00000000000000000 +-156.50000000000000000 +2.7000000000000000000 +2.7000000000000000000 +5.4500000000000000000 +7.9000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT (avg(d) OVER (PARTITION BY v ORDER BY w) + avg(d) OVER (PARTITION BY v ORDER BY w)) FROM kv ORDER BY 1 ---- --642 - 6 - 8.8666666666666666666 - 8.8666666666666666666 - 11.0 - 15.8 +-642.00000000000000000 +6.0000000000000000000 +8.8666666666666666666 +8.8666666666666666666 +11.0000000000000000000 +15.8000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT (avg(d) OVER (PARTITION BY v ORDER BY w) + avg(d) OVER (PARTITION BY w ORDER BY v)) FROM kv ORDER BY 1 ---- --642 --151.0 - 7.1333333333333333333 - 7.1333333333333333333 - 8.45 - 15.8 +-642.00000000000000000 +-151.0000000000000000000 +7.1333333333333333333 +7.1333333333333333333 +8.4500000000000000000 +15.8000000000000000000 +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(d) OVER (PARTITION BY v) FROM kv WHERE FALSE ORDER BY 1 ---- +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(d) OVER (PARTITION BY v, v, v, v, v, v, v, v, v, v) FROM kv WHERE FALSE ORDER BY 1 ---- +# Not supported by Materialize. +onlyif cockroach query R SELECT avg(d) OVER (PARTITION BY v, v, v, v, v, v, v, v, v, v) FROM kv WHERE k = 3 ORDER BY 1 ---- -8 +8.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach query IT SELECT k, concat_agg(s) OVER (PARTITION BY k ORDER BY w) FROM kv ORDER BY 1 ---- @@ -405,6 +484,8 @@ SELECT k, concat_agg(s) OVER (PARTITION BY k ORDER BY w) FROM kv ORDER BY 1 7 b 8 A +# Not supported by Materialize. +onlyif cockroach query IT SELECT k, concat_agg(s) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 ---- @@ -415,6 +496,8 @@ SELECT k, concat_agg(s) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 7 b 8 A +# Not supported by Materialize. +onlyif cockroach query IB SELECT k, bool_and(b) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -425,6 +508,8 @@ SELECT k, bool_and(b) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 7 true 8 false +# Not supported by Materialize. +onlyif cockroach query IB SELECT k, bool_or(b) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -435,6 +520,8 @@ SELECT k, bool_or(b) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 7 true 8 false +# Not supported by Materialize. +onlyif cockroach query II SELECT k, count(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -445,6 +532,8 @@ SELECT k, count(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 7 1 8 1 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, count(*) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -455,6 +544,8 @@ SELECT k, count(*) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 7 1 8 1 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, max(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -465,6 +556,8 @@ SELECT k, max(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 7 7.9 8 3 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, min(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -475,6 +568,8 @@ SELECT k, min(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 7 7.9 8 3 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, pow(max(d) OVER (PARTITION BY v), k::DECIMAL) FROM kv ORDER BY 1 ---- @@ -485,6 +580,8 @@ SELECT k, pow(max(d) OVER (PARTITION BY v), k::DECIMAL) FROM kv ORDER BY 1 7 1920390.8986159 8 16777216 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, max(d) OVER (PARTITION BY v) FROM kv ORDER BY 1 ---- @@ -495,6 +592,8 @@ SELECT k, max(d) OVER (PARTITION BY v) FROM kv ORDER BY 1 7 7.9 8 8 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, sum(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -505,6 +604,8 @@ SELECT k, sum(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 7 7.9 8 3 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, variance(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -515,6 +616,8 @@ SELECT k, variance(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 7 NULL 8 NULL +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, stddev(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -525,6 +628,8 @@ SELECT k, stddev(d) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 7 NULL 8 NULL +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, stddev(d) OVER w FROM kv WINDOW w as (PARTITION BY v) ORDER BY variance(d) OVER w, k ---- @@ -535,6 +640,8 @@ SELECT k, stddev(d) OVER w FROM kv WINDOW w as (PARTITION BY v) ORDER BY varianc 3 3.5355339059327376220 8 3.5355339059327376220 +# Not supported by Materialize. +onlyif cockroach query IRIR SELECT * FROM (SELECT k, d, v, stddev(d) OVER (PARTITION BY v) FROM kv) sub ORDER BY variance(d) OVER (PARTITION BY v), k ---- @@ -545,6 +652,8 @@ SELECT * FROM (SELECT k, d, v, stddev(d) OVER (PARTITION BY v) FROM kv) sub ORDE 3 8 4 3.5355339059327376220 8 3 4 3.5355339059327376220 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, max(stddev) OVER (ORDER BY d) FROM (SELECT k, d, stddev(d) OVER (PARTITION BY v) as stddev FROM kv) sub ORDER BY 2, k ---- @@ -555,6 +664,8 @@ SELECT k, max(stddev) OVER (ORDER BY d) FROM (SELECT k, d, stddev(d) OVER (PARTI 7 3.5355339059327376220 8 3.5355339059327376220 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, max(stddev) OVER (ORDER BY d DESC) FROM (SELECT k, d, stddev(d) OVER (PARTITION BY v) as stddev FROM kv) sub ORDER BY 2, k ---- @@ -565,26 +676,32 @@ SELECT k, max(stddev) OVER (ORDER BY d DESC) FROM (SELECT k, d, stddev(d) OVER ( 7 3.5355339059327376220 8 3.5355339059327376220 +# Not supported by Materialize. +onlyif cockroach query IRIII SELECT k, (rank() OVER wind + avg(w) OVER wind), w, (v + row_number() OVER wind), v FROM kv WINDOW wind AS (ORDER BY k) ORDER BY 1 ---- -1 4 3 3 2 -3 6 5 6 4 +1 4.0000000000000000000 3 3 2 +3 6.0000000000000000000 5 6 4 5 7.3333333333333333333 5 NULL NULL -6 8 3 6 2 -7 8.6 2 7 2 +6 8.0000000000000000000 3 6 2 +7 8.6000000000000000000 2 7 2 8 9.3333333333333333333 2 10 4 +# Not supported by Materialize. +onlyif cockroach query TIRRI SELECT s, w + k, (sum(w) OVER wind + avg(d) OVER wind), (min(w) OVER wind + d), v FROM kv WINDOW wind AS (ORDER BY w, k) ORDER BY k ---- a 4 10.9666666666666666667 3 2 -a 8 19.86 10 4 -NULL 10 -29.45 -319 NULL -b 9 14.075 6.4 2 -b 9 9.9 9.9 2 -A 10 9.45 5 4 - +a 8 19.8600000000000000000 10 4 +NULL 10 -29.450000000000000000 -319 NULL +b 9 14.0750000000000000000 6.4 2 +b 9 9.9000000000000000000 9.9 2 +A 10 9.4500000000000000000 5 4 + +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v + w, round(rank() OVER wind + lead(k, 3, v) OVER wind + lag(w, 1, 2) OVER wind + f::DECIMAL + avg(d) OVER wind)::INT, round(row_number() OVER wind::FLOAT + round(f) + dense_rank() OVER wind::FLOAT)::INT FROM kv WINDOW wind as (PARTITION BY v ORDER BY k) ORDER BY k ---- @@ -595,6 +712,8 @@ SELECT k, v + w, round(rank() OVER wind + lead(k, 3, v) OVER wind + lag(w, 1, 2) 7 4 18 12 8 6 20 7 +# Not supported by Materialize. +onlyif cockroach query II SELECT (rank() OVER wind + lead(k, 3, v) OVER wind + lag(w, 1, 2) OVER wind), (row_number() OVER wind + dense_rank() OVER wind) FROM kv WINDOW wind as (PARTITION BY v ORDER BY k) ORDER BY k ---- @@ -605,6 +724,8 @@ NULL 2 8 6 11 4 +# Not supported by Materialize. +onlyif cockroach query RIR SELECT (round(avg(k) OVER w1 + sum(w) OVER w2) + row_number() OVER w2 + d + min(d) OVER w3 + f::DECIMAL) AS big_sum, v + w AS v_plus_w, (rank() OVER w3 + first_value(d) OVER w1 + nth_value(k, 2) OVER w1) AS small_sum FROM kv WINDOW w1 AS (PARTITION BY b ORDER BY k), w2 AS (PARTITION BY w ORDER BY k), w3 AS (PARTITION BY v ORDER BY k) ORDER BY k ---- @@ -615,6 +736,8 @@ SELECT (round(avg(k) OVER w1 + sum(w) OVER w2) + row_number() OVER w2 + d + min( 21.9 4 7 22 6 -311 +# Not supported by Materialize. +onlyif cockroach query RI SELECT round(row_number() OVER w1 + lead(k, v, w) OVER w2 + avg(k) OVER w1), (lag(k, 1) OVER w1 + v + rank() OVER w2 + min(k) OVER w1) FROM kv WINDOW w1 AS (PARTITION BY w ORDER BY k), w2 AS (PARTITION BY b ORDER BY k) ORDER BY k ---- @@ -625,33 +748,41 @@ NULL NULL 10 NULL 12 20 +# Not supported by Materialize. +onlyif cockroach query R SELECT f::DECIMAL + round(max(k) * w * avg(d) OVER wind) + (lead(f, 2, 17::FLOAT) OVER wind::DECIMAL / d * row_number() OVER wind) FROM kv GROUP BY k, w, f, d WINDOW wind AS (ORDER BY k) ORDER BY k ---- -13.9 -71.10 +13.9000000000000000000 +71.10000000000000000000 -2590.156074766355140186916 -1376.87272727272727272728 -822.2405063291139240505 -753.9999999999999999998 +# Not supported by Materialize. +onlyif cockroach query R SELECT round(max(w) * w * avg(w) OVER wind) + (lead(w, 2, 17) OVER wind::DECIMAL / w * row_number() OVER wind) FROM kv GROUP BY w WINDOW wind AS (PARTITION BY w) ORDER BY 1 ---- -16.5 +16.5000000000000000000 32.6666666666666666667 -128.4 +128.4000000000000000000 +# Not supported by Materialize. +onlyif cockroach query IRRIRIR SELECT k, avg(d) OVER w1, avg(d) OVER w2, row_number() OVER w2, sum(f) OVER w1, row_number() OVER w1, sum(f) OVER w2 FROM kv WINDOW w1 AS (ORDER BY k), w2 AS (ORDER BY w, k) ORDER BY k ---- -1 1 3.9666666666666666667 3 1 1 10 -3 4.5 4.86 5 3 2 16.4 -5 -104 -49.45 6 12.9 3 26.3 -6 -76.9 4.075 4 17.3 4 14.4 -7 -59.94 7.9 1 23.3 5 6 -8 -49.45 5.45 2 26.3 6 9 +1 1.0000000000000000000 3.9666666666666666667 3 1 1 10 +3 4.5000000000000000000 4.8600000000000000000 5 3 2 16.4 +5 -104.00000000000000000 -49.450000000000000000 6 12.9 3 26.299999999999997 +6 -76.900000000000000000 4.0750000000000000000 4 17.3 4 14.4 +7 -59.940000000000000000 7.9000000000000000000 1 23.3 5 6 +8 -49.450000000000000000 5.4500000000000000000 2 26.3 6 9 +# Not supported by Materialize. +onlyif cockroach query R SELECT round((avg(d) OVER wind) * max(k) + (lag(d, 1, 42.0) OVER wind) * max(d)) FROM kv GROUP BY d, k WINDOW wind AS (ORDER BY k) ORDER BY k ---- @@ -662,22 +793,28 @@ SELECT round((avg(d) OVER wind) * max(k) + (lag(d, 1, 42.0) OVER wind) * max(d)) -385 -372 +# Not supported by Materialize. +onlyif cockroach query RR SELECT avg(k) OVER w, avg(k) OVER w + 1 FROM kv WINDOW w AS (PARTITION BY v ORDER BY w) ORDER BY k ---- 4.6666666666666666667 5.6666666666666666667 -5.5 6.5 -5 6 +5.5000000000000000000 6.5000000000000000000 +5.0000000000000000000 6.0000000000000000000 4.6666666666666666667 5.6666666666666666667 -7 8 -8 9 +7.0000000000000000000 8.0000000000000000000 +8.0000000000000000000 9.0000000000000000000 +# Not supported by Materialize. +onlyif cockroach statement OK INSERT INTO kv VALUES (9, 2, 9, .1, DEFAULT, DEFAULT, DEFAULT), (10, 4, 9, .2, DEFAULT, DEFAULT, DEFAULT), (11, NULL, 9, .3, DEFAULT, DEFAULT, DEFAULT) +# Not supported by Materialize. +onlyif cockroach query II SELECT k, row_number() OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -691,6 +828,8 @@ SELECT k, row_number() OVER (ORDER BY k) FROM kv ORDER BY 1 10 8 11 9 +# Not supported by Materialize. +onlyif cockroach query III SELECT k, v, row_number() OVER (PARTITION BY v ORDER BY k) FROM kv ORDER BY 1 ---- @@ -704,6 +843,8 @@ SELECT k, v, row_number() OVER (PARTITION BY v ORDER BY k) FROM kv ORDER BY 1 10 4 3 11 NULL 2 +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v, w, row_number() OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 ---- @@ -717,6 +858,8 @@ SELECT k, v, w, row_number() OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER B 10 4 9 3 11 NULL 9 2 +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v, w, v - w + 2 + row_number() OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 ---- @@ -730,6 +873,8 @@ SELECT k, v, w, v - w + 2 + row_number() OVER (PARTITION BY v ORDER BY w, k) FRO 10 4 9 0 11 NULL 9 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, row_number() OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -743,6 +888,8 @@ SELECT k, row_number() OVER (PARTITION BY k) FROM kv ORDER BY 1 10 1 11 1 +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v, w, v - w + 2 + row_number() OVER (PARTITION BY v, k ORDER BY w) FROM kv ORDER BY 1 ---- @@ -756,11 +903,15 @@ SELECT k, v, w, v - w + 2 + row_number() OVER (PARTITION BY v, k ORDER BY w) FRO 10 4 9 -2 11 NULL 9 NULL +# Not supported by Materialize. +onlyif cockroach query RIII SELECT avg(k), max(v), min(w), 2 + row_number() OVER () FROM kv ORDER BY 1 ---- 6.6666666666666666667 4 2 3 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, rank() OVER () FROM kv ORDER BY 1 ---- @@ -774,6 +925,8 @@ SELECT k, rank() OVER () FROM kv ORDER BY 1 10 1 11 1 +# Not supported by Materialize. +onlyif cockroach query III SELECT k, v, rank() OVER (PARTITION BY v) FROM kv ORDER BY 1 ---- @@ -787,6 +940,8 @@ SELECT k, v, rank() OVER (PARTITION BY v) FROM kv ORDER BY 1 10 4 1 11 NULL 1 +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v, w, rank() OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -800,32 +955,38 @@ SELECT k, v, w, rank() OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 10 4 9 3 11 NULL 9 2 +# Not supported by Materialize. +onlyif cockroach query IRI SELECT k, (rank() OVER w + avg(w) OVER w), k FROM kv WINDOW w AS (PARTITION BY v ORDER BY w) ORDER BY 1 ---- 1 4.6666666666666666667 1 -3 5.5 3 -5 6 5 +3 5.5000000000000000000 3 +5 6.0000000000000000000 5 6 4.6666666666666666667 6 -7 3 7 -8 3 8 -9 8.25 9 +7 3.0000000000000000000 7 +8 3.0000000000000000000 8 +9 8.2500000000000000000 9 10 8.3333333333333333333 10 -11 9 11 +11 9.0000000000000000000 11 +# Not supported by Materialize. +onlyif cockroach query IRI SELECT k, (avg(w) OVER w + rank() OVER w), k FROM kv WINDOW w AS (PARTITION BY v ORDER BY w) ORDER BY 1 ---- 1 4.6666666666666666667 1 -3 5.5 3 -5 6 5 +3 5.5000000000000000000 3 +5 6.0000000000000000000 5 6 4.6666666666666666667 6 -7 3 7 -8 3 8 -9 8.25 9 +7 3.0000000000000000000 7 +8 3.0000000000000000000 8 +9 8.2500000000000000000 9 10 8.3333333333333333333 10 -11 9 11 +11 9.0000000000000000000 11 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, dense_rank() OVER () FROM kv ORDER BY 1 ---- @@ -839,6 +1000,8 @@ SELECT k, dense_rank() OVER () FROM kv ORDER BY 1 10 1 11 1 +# Not supported by Materialize. +onlyif cockroach query III SELECT k, v, dense_rank() OVER (PARTITION BY v) FROM kv ORDER BY 1 ---- @@ -852,6 +1015,8 @@ SELECT k, v, dense_rank() OVER (PARTITION BY v) FROM kv ORDER BY 1 10 4 1 11 NULL 1 +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v, w, dense_rank() OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -865,6 +1030,8 @@ SELECT k, v, w, dense_rank() OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 10 4 9 3 11 NULL 9 2 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, percent_rank() OVER () FROM kv ORDER BY 1 ---- @@ -878,6 +1045,8 @@ SELECT k, percent_rank() OVER () FROM kv ORDER BY 1 10 0 11 0 +# Not supported by Materialize. +onlyif cockroach query IIR SELECT k, v, percent_rank() OVER (PARTITION BY v) FROM kv ORDER BY 1 ---- @@ -891,19 +1060,23 @@ SELECT k, v, percent_rank() OVER (PARTITION BY v) FROM kv ORDER BY 1 10 4 0 11 NULL 0 +# Not supported by Materialize. +onlyif cockroach query IIIR SELECT k, v, w, percent_rank() OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- -1 2 3 0.333333333333333 +1 2 3 0.3333333333333333 3 4 5 0.5 5 NULL 5 0 -6 2 3 0.333333333333333 +6 2 3 0.3333333333333333 7 2 2 0 8 4 2 0 9 2 9 1 10 4 9 1 11 NULL 9 1 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, cume_dist() OVER () FROM kv ORDER BY 1 ---- @@ -917,6 +1090,8 @@ SELECT k, cume_dist() OVER () FROM kv ORDER BY 1 10 1 11 1 +# Not supported by Materialize. +onlyif cockroach query IIR SELECT k, v, cume_dist() OVER (PARTITION BY v) FROM kv ORDER BY 1 ---- @@ -930,25 +1105,29 @@ SELECT k, v, cume_dist() OVER (PARTITION BY v) FROM kv ORDER BY 1 10 4 1 11 NULL 1 +# Not supported by Materialize. +onlyif cockroach query IIIR SELECT k, v, w, cume_dist() OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- 1 2 3 0.75 -3 4 5 0.666666666666667 +3 4 5 0.6666666666666666 5 NULL 5 0.5 6 2 3 0.75 7 2 2 0.25 -8 4 2 0.333333333333333 +8 4 2 0.3333333333333333 9 2 9 1 10 4 9 1 11 NULL 9 1 -query error argument of ntile\(\) must be greater than zero +query error function "ntile" does not exist SELECT k, ntile(-10) OVER () FROM kv ORDER BY 1 -query error argument of ntile\(\) must be greater than zero +query error function "ntile" does not exist SELECT k, ntile(0) OVER () FROM kv ORDER BY 1 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, ntile(NULL::INT) OVER () FROM kv ORDER BY 1 ---- @@ -962,6 +1141,8 @@ SELECT k, ntile(NULL::INT) OVER () FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, ntile(1) OVER () FROM kv ORDER BY 1 ---- @@ -975,6 +1156,8 @@ SELECT k, ntile(1) OVER () FROM kv ORDER BY 1 10 1 11 1 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, ntile(4) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -988,6 +1171,8 @@ SELECT k, ntile(4) OVER (ORDER BY k) FROM kv ORDER BY 1 10 4 11 4 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, ntile(20) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1001,85 +1186,203 @@ SELECT k, ntile(20) OVER (ORDER BY k) FROM kv ORDER BY 1 10 8 11 9 +# Not supported by Materialize. +onlyif cockroach # The value of 'w' in the first row will be 3. -query II -SELECT k, ntile(w) OVER (ORDER BY k) FROM kv ORDER BY 1 ----- -1 1 -3 1 -5 1 -6 2 -7 2 -8 2 -9 3 -10 3 -11 3 - query III -SELECT k, v, ntile(3) OVER (PARTITION BY v ORDER BY k) FROM kv ORDER BY 1 +SELECT k, w, ntile(w) OVER (ORDER BY k) FROM kv ORDER BY 1 +---- +1 3 1 +3 5 1 +5 5 1 +6 3 2 +7 2 2 +8 2 2 +9 9 3 +10 9 3 +11 9 3 + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT k, v, ntile(3) OVER (PARTITION BY v ORDER BY k) FROM kv ORDER BY v, k ---- -1 2 1 -3 4 1 5 NULL 1 +11 NULL 2 +1 2 1 6 2 1 7 2 2 -8 4 2 9 2 3 +3 4 1 +8 4 2 10 4 3 -11 NULL 2 +# Not supported by Materialize. +onlyif cockroach query IIII -SELECT k, v, w, ntile(6) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 +SELECT k, v, w, ntile(6) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY v, w, k ---- -1 2 3 2 -3 4 5 2 5 NULL 5 1 -6 2 3 3 +11 NULL 9 2 7 2 2 1 -8 4 2 1 +1 2 3 2 +6 2 3 3 9 2 9 4 +8 4 2 1 +3 4 5 2 10 4 9 3 -11 NULL 9 2 - -query II -SELECT k, ntile(w) OVER (PARTITION BY k) FROM kv ORDER BY 1 ----- -1 1 -3 1 -5 1 -6 1 -7 1 -8 1 -9 1 -10 1 -11 1 +# Not supported by Materialize. +onlyif cockroach +query III +SELECT k, w, ntile(w) OVER (PARTITION BY k) FROM kv ORDER BY k +---- +1 3 1 +3 5 1 +5 5 1 +6 3 1 +7 2 1 +8 2 1 +9 9 1 +10 9 1 +11 9 1 + +# Not supported by Materialize. +onlyif cockroach query III -SELECT k, v, ntile(3) OVER (PARTITION BY v, k) FROM kv ORDER BY 1 +SELECT k, v, ntile(3) OVER (PARTITION BY v, k) FROM kv ORDER BY v, k ---- -1 2 1 -3 4 1 5 NULL 1 +11 NULL 1 +1 2 1 6 2 1 7 2 1 -8 4 1 9 2 1 +3 4 1 +8 4 1 10 4 1 -11 NULL 1 +# Not supported by Materialize. +onlyif cockroach query IIII -SELECT k, v, w, ntile(6) OVER (PARTITION BY v, k ORDER BY w) FROM kv ORDER BY 1 +SELECT k, v, w, ntile(6) OVER (PARTITION BY v, k ORDER BY w) FROM kv ORDER BY v, k, w ---- -1 2 3 1 -3 4 5 1 5 NULL 5 1 +11 NULL 9 1 +1 2 3 1 6 2 3 1 7 2 2 1 +9 2 9 1 +3 4 5 1 8 4 2 1 +10 4 9 1 + +# Not supported by Materialize. +onlyif cockroach +query IIII +SELECT k, v, w, ntile(v) OVER (PARTITION BY w ORDER BY v, k) FROM kv ORDER BY w, v, k +---- +7 2 2 1 +8 4 2 2 +1 2 3 1 +6 2 3 2 +5 NULL 5 NULL +3 4 5 1 +11 NULL 9 NULL 9 2 9 1 10 4 9 1 -11 NULL 9 1 +# Not supported by Materialize. +onlyif cockroach +query III +SELECT k, v, ntile(v) OVER (ORDER BY v, k) FROM kv ORDER BY v, k +---- +5 NULL NULL +11 NULL NULL +1 2 1 +6 2 1 +7 2 1 +9 2 1 +3 4 1 +8 4 2 +10 4 2 + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT k, v, ntile(v) OVER (ORDER BY v, k) +FROM (SELECT * FROM kv WHERE w != 3) ORDER BY v, k +---- +5 NULL NULL +11 NULL NULL +7 2 1 +9 2 1 +3 4 1 +8 4 1 +10 4 2 + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT k, v, ntile(3::INT2) OVER (PARTITION BY v ORDER BY k) FROM kv ORDER BY v, k +---- +5 NULL 1 +11 NULL 2 +1 2 1 +6 2 1 +7 2 2 +9 2 3 +3 4 1 +8 4 2 +10 4 3 + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT k, v, ntile(3::INT4) OVER (PARTITION BY v ORDER BY k) FROM kv ORDER BY v, k +---- +5 NULL 1 +11 NULL 2 +1 2 1 +6 2 1 +7 2 2 +9 2 3 +3 4 1 +8 4 2 +10 4 3 + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT k, w, ntile(w::INT4) OVER (ORDER BY k) FROM kv ORDER BY 1 +---- +1 3 1 +3 5 1 +5 5 1 +6 3 2 +7 2 2 +8 2 2 +9 9 3 +10 9 3 +11 9 3 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT k, ntile(1::INT4) OVER () FROM kv ORDER BY 1 +---- +1 1 +3 1 +5 1 +6 1 +7 1 +8 1 +9 1 +10 1 +11 1 + +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(9) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1093,6 +1396,8 @@ SELECT k, lag(9) OVER (ORDER BY k) FROM kv ORDER BY 1 10 9 11 9 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(9) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1106,6 +1411,8 @@ SELECT k, lead(9) OVER (ORDER BY k) FROM kv ORDER BY 1 10 9 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1119,6 +1426,8 @@ SELECT k, lag(k) OVER (ORDER BY k) FROM kv ORDER BY 1 10 9 11 10 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 ---- @@ -1132,6 +1441,8 @@ SELECT k, lag(k) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 10 3 11 5 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1145,6 +1456,8 @@ SELECT k, lead(k) OVER (ORDER BY k) FROM kv ORDER BY 1 10 11 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 ---- @@ -1158,6 +1471,8 @@ SELECT k, lead(k) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, 3) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1171,6 +1486,8 @@ SELECT k, lag(k, 3) OVER (ORDER BY k) FROM kv ORDER BY 1 10 7 11 8 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, 3) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -1184,6 +1501,8 @@ SELECT k, lag(k, 3) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, 3) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1197,6 +1516,8 @@ SELECT k, lead(k, 3) OVER (ORDER BY k) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, 3) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -1210,6 +1531,8 @@ SELECT k, lead(k, 3) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, -5) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1223,6 +1546,8 @@ SELECT k, lag(k, -5) OVER (ORDER BY k) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, -5) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1236,6 +1561,8 @@ SELECT k, lead(k, -5) OVER (ORDER BY k) FROM kv ORDER BY 1 10 5 11 6 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, 0) OVER () FROM kv ORDER BY 1 ---- @@ -1249,6 +1576,8 @@ SELECT k, lag(k, 0) OVER () FROM kv ORDER BY 1 10 10 11 11 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, 0) OVER () FROM kv ORDER BY 1 ---- @@ -1262,6 +1591,8 @@ SELECT k, lead(k, 0) OVER () FROM kv ORDER BY 1 10 10 11 11 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, NULL::INT) OVER () FROM kv ORDER BY 1 ---- @@ -1275,6 +1606,8 @@ SELECT k, lag(k, NULL::INT) OVER () FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, NULL::INT) OVER () FROM kv ORDER BY 1 ---- @@ -1288,6 +1621,8 @@ SELECT k, lead(k, NULL::INT) OVER () FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, w) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1301,6 +1636,8 @@ SELECT k, lag(k, w) OVER (ORDER BY k) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, w) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 ---- @@ -1314,6 +1651,8 @@ SELECT k, lag(k, w) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, w) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1327,6 +1666,8 @@ SELECT k, lead(k, w) OVER (ORDER BY k) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, w) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 ---- @@ -1340,18 +1681,20 @@ SELECT k, lead(k, w) OVER (PARTITION BY v ORDER BY w, k) FROM kv ORDER BY 1 10 NULL 11 NULL -query error unknown signature: lag\(int, int, string\) +query error unknown catalog item 'kv' SELECT k, lag(k, 1, 'FOO') OVER () FROM kv ORDER BY 1 -query error unknown signature: lead\(int, int, string\) +query error unknown catalog item 'kv' SELECT k, lead(k, 1, 'FOO') OVER () FROM kv ORDER BY 1 -query error unknown signature: lag\(int, int, string\) +query error unknown catalog item 'kv' SELECT k, lag(k, 1, s) OVER () FROM kv ORDER BY 1 -query error unknown signature: lead\(int, int, string\) +query error unknown catalog item 'kv' SELECT k, lead(k, 1, s) OVER () FROM kv ORDER BY 1 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, 3, -99) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1365,6 +1708,8 @@ SELECT k, lag(k, 3, -99) OVER (ORDER BY k) FROM kv ORDER BY 1 10 7 11 8 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, 3, -99) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1378,6 +1723,8 @@ SELECT k, lead(k, 3, -99) OVER (ORDER BY k) FROM kv ORDER BY 1 10 -99 11 -99 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, 3, v) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1391,6 +1738,8 @@ SELECT k, lag(k, 3, v) OVER (ORDER BY k) FROM kv ORDER BY 1 10 7 11 8 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, 3, v) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1404,6 +1753,8 @@ SELECT k, lead(k, 3, v) OVER (ORDER BY k) FROM kv ORDER BY 1 10 4 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, (lag(k, 5, w) OVER w + lead(k, 3, v) OVER w) FROM kv WINDOW w AS (ORDER BY k) ORDER BY 1 ---- @@ -1417,6 +1768,8 @@ SELECT k, (lag(k, 5, w) OVER w + lead(k, 3, v) OVER w) FROM kv WINDOW w AS (ORDE 10 9 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1430,6 +1783,8 @@ SELECT k, lag(k) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1443,6 +1798,8 @@ SELECT k, lead(k) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, 0) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1456,6 +1813,8 @@ SELECT k, lag(k, 0) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 10 11 11 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, 0) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1469,6 +1828,8 @@ SELECT k, lead(k, 0) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 10 11 11 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, -5) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1482,6 +1843,8 @@ SELECT k, lag(k, -5) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, -5) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1495,6 +1858,8 @@ SELECT k, lead(k, -5) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, w - w) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1508,6 +1873,8 @@ SELECT k, lag(k, w - w) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 10 11 11 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, w - w) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1521,6 +1888,8 @@ SELECT k, lead(k, w - w) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 10 11 11 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, 3, -99) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1534,6 +1903,8 @@ SELECT k, lag(k, 3, -99) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 -99 11 -99 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, 3, -99) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1547,6 +1918,8 @@ SELECT k, lead(k, 3, -99) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 -99 11 -99 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lag(k, 3, v) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1560,6 +1933,8 @@ SELECT k, lag(k, 3, v) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 4 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, lead(k, 3, v) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1573,6 +1948,8 @@ SELECT k, lead(k, 3, v) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 4 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, first_value(NULL::INT) OVER () FROM kv ORDER BY 1 ---- @@ -1586,6 +1963,8 @@ SELECT k, first_value(NULL::INT) OVER () FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, first_value(1) OVER () FROM kv ORDER BY 1 ---- @@ -1599,6 +1978,8 @@ SELECT k, first_value(1) OVER () FROM kv ORDER BY 1 10 1 11 1 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, first_value(199.9 * 23.3) OVER () FROM kv ORDER BY 1 ---- @@ -1612,6 +1993,8 @@ SELECT k, first_value(199.9 * 23.3) OVER () FROM kv ORDER BY 1 10 4657.67 11 4657.67 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, first_value(v) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1625,6 +2008,8 @@ SELECT k, first_value(v) OVER (ORDER BY k) FROM kv ORDER BY 1 10 2 11 2 +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v, w, first_value(w) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -1638,6 +2023,8 @@ SELECT k, v, w, first_value(w) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 10 4 9 2 11 NULL 9 5 +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v, w, first_value(w) OVER (PARTITION BY v ORDER BY w DESC) FROM kv ORDER BY 1 ---- @@ -1651,6 +2038,8 @@ SELECT k, v, w, first_value(w) OVER (PARTITION BY v ORDER BY w DESC) FROM kv ORD 10 4 9 9 11 NULL 9 9 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, first_value(v) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1664,6 +2053,8 @@ SELECT k, first_value(v) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 4 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, last_value(NULL::INT) OVER () FROM kv ORDER BY 1 ---- @@ -1677,6 +2068,8 @@ SELECT k, last_value(NULL::INT) OVER () FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, last_value(1) OVER () FROM kv ORDER BY 1 ---- @@ -1690,6 +2083,8 @@ SELECT k, last_value(1) OVER () FROM kv ORDER BY 1 10 1 11 1 +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, last_value(199.9 * 23.3) OVER () FROM kv ORDER BY 1 ---- @@ -1703,6 +2098,8 @@ SELECT k, last_value(199.9 * 23.3) OVER () FROM kv ORDER BY 1 10 4657.67 11 4657.67 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, last_value(v) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1716,6 +2113,8 @@ SELECT k, last_value(v) OVER (ORDER BY k) FROM kv ORDER BY 1 10 4 11 NULL +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v, w, last_value(w) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -1729,6 +2128,8 @@ SELECT k, v, w, last_value(w) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 10 4 9 9 11 NULL 9 9 +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v, w, last_value(w) OVER (PARTITION BY v ORDER BY w DESC) FROM kv ORDER BY 1 ---- @@ -1742,6 +2143,8 @@ SELECT k, v, w, last_value(w) OVER (PARTITION BY v ORDER BY w DESC) FROM kv ORDE 10 4 9 9 11 NULL 9 9 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, last_value(v) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1755,15 +2158,17 @@ SELECT k, last_value(v) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 4 11 NULL -query error unknown signature: nth_value\(int, string\) +query error function "nth_value" does not exist SELECT k, nth_value(v, 'FOO') OVER () FROM kv ORDER BY 1 -query error argument of nth_value\(\) must be greater than zero +query error function "nth_value" does not exist SELECT k, nth_value(v, -99) OVER () FROM kv ORDER BY 1 -query error argument of nth_value\(\) must be greater than zero +query error function "nth_value" does not exist SELECT k, nth_value(v, 0) OVER () FROM kv ORDER BY 1 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, nth_value(NULL::INT, 5) OVER () FROM kv ORDER BY 1 ---- @@ -1777,6 +2182,8 @@ SELECT k, nth_value(NULL::INT, 5) OVER () FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, nth_value(1, 3) OVER () FROM kv ORDER BY 1 ---- @@ -1790,6 +2197,8 @@ SELECT k, nth_value(1, 3) OVER () FROM kv ORDER BY 1 10 1 11 1 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, nth_value(1, 33) OVER () FROM kv ORDER BY 1 ---- @@ -1803,6 +2212,8 @@ SELECT k, nth_value(1, 33) OVER () FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query IR SELECT k, nth_value(199.9 * 23.3, 7) OVER () FROM kv ORDER BY 1 ---- @@ -1816,6 +2227,8 @@ SELECT k, nth_value(199.9 * 23.3, 7) OVER () FROM kv ORDER BY 1 10 4657.67 11 4657.67 +# Not supported by Materialize. +onlyif cockroach query II SELECT k, nth_value(v, 8) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1829,6 +2242,8 @@ SELECT k, nth_value(v, 8) OVER (ORDER BY k) FROM kv ORDER BY 1 10 4 11 4 +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v, w, nth_value(w, 2) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER BY 1 ---- @@ -1842,6 +2257,8 @@ SELECT k, v, w, nth_value(w, 2) OVER (PARTITION BY v ORDER BY w) FROM kv ORDER B 10 4 9 5 11 NULL 9 9 +# Not supported by Materialize. +onlyif cockroach query IIII SELECT k, v, w, nth_value(w, 2) OVER (PARTITION BY v ORDER BY w DESC) FROM kv ORDER BY 1 ---- @@ -1855,6 +2272,8 @@ SELECT k, v, w, nth_value(w, 2) OVER (PARTITION BY v ORDER BY w DESC) FROM kv OR 10 4 9 NULL 11 NULL 9 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, nth_value(v, k) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1868,6 +2287,8 @@ SELECT k, nth_value(v, k) OVER (ORDER BY k) FROM kv ORDER BY 1 10 NULL 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, nth_value(v, v) OVER (ORDER BY k) FROM kv ORDER BY 1 ---- @@ -1881,6 +2302,8 @@ SELECT k, nth_value(v, v) OVER (ORDER BY k) FROM kv ORDER BY 1 10 2 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, nth_value(v, 1) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1894,6 +2317,8 @@ SELECT k, nth_value(v, 1) OVER (PARTITION BY k) FROM kv ORDER BY 1 10 4 11 NULL +# Not supported by Materialize. +onlyif cockroach query II SELECT k, nth_value(v, v) OVER (PARTITION BY k) FROM kv ORDER BY 1 ---- @@ -1908,19 +2333,39 @@ SELECT k, nth_value(v, v) OVER (PARTITION BY k) FROM kv ORDER BY 1 11 NULL +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO kv VALUES (12, -1, DEFAULT, DEFAULT, DEFAULT, DEFAULT) -query error argument of nth_value\(\) must be greater than zero +query error function "nth_value" does not exist SELECT k, nth_value(v, v) OVER () FROM kv ORDER BY 1 +# Not supported by Materialize. +onlyif cockroach statement ok DELETE FROM kv WHERE k = 12 -query error FILTER specified, but rank is not an aggregate function +query error unknown catalog item 'kv' SELECT k, rank() FILTER (WHERE k=1) OVER () FROM kv -# Issue materialize#14606: correctly handle aggregation functions above the windowing level +# Not supported by Materialize. +onlyif cockroach +query TT +SELECT i, avg(i) OVER (ORDER BY i) FROM kv ORDER BY i +---- +NULL NULL +NULL NULL +NULL NULL +NULL NULL +00:00:00.001 00:00:00.001 +00:00:02 00:00:01.0005 +00:01:00 00:00:20.667 +4 days 1 day 00:00:15.50025 +3 years 7 mons 6 days 19:12:12.4002 + + +# Issue #14606: correctly handle aggregation functions above the windowing level query I SELECT max(i) * (row_number() OVER (ORDER BY max(i))) FROM (SELECT 1 AS i, 2 AS j) GROUP BY j ---- @@ -1929,17 +2374,19 @@ SELECT max(i) * (row_number() OVER (ORDER BY max(i))) FROM (SELECT 1 AS i, 2 AS query R SELECT (1/j) * max(i) * (row_number() OVER (ORDER BY max(i))) FROM (SELECT 1 AS i, 2 AS j) GROUP BY j ---- -0.5 +0 query R SELECT max(i) * (1/j) * (row_number() OVER (ORDER BY max(i))) FROM (SELECT 1 AS i, 2 AS j) GROUP BY j ---- -0.5 +0 -# regression test for materialize#23798 until materialize#10495 is fixed. -statement error function reserved for internal use +# regression test for #23798 until #10495 is fixed. +statement error function "final_variance" does not exist SELECT final_variance(1.2, 1.2, 123) OVER (PARTITION BY k) FROM kv +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE products ( group_id serial PRIMARY KEY, @@ -1955,6 +2402,8 @@ CREATE TABLE products ( pInterval INTERVAL ) +# Not supported by Materialize. +onlyif cockroach statement ok INSERT INTO products (group_name, product_name, price, priceInt, priceFloat, pDate, pTime, pTimestamp, pTimestampTZ, pInterval) VALUES ('Smartphone', 'Microsoft Lumia', 200, 200, 200, '2018-07-30', TIME '01:23:45', TIMESTAMP '2018-07-30 01:23:45', TIMESTAMPTZ '2018-07-30 01:23:45', INTERVAL '1 months 2 days 3 hours 4 minutes 5 seconds'), @@ -1969,54 +2418,56 @@ INSERT INTO products (group_name, product_name, price, priceInt, priceFloat, pDa ('Tablet', 'Kindle Fire', 150, 150, 150, '2018-07-31', TIME '12:34:56', TIMESTAMP '2018-07-31 12:34:56', TIMESTAMPTZ '2018-07-31 12:34:56', INTERVAL '1 days 2 hours 3 minutes 4 seconds'), ('Tablet', 'Samsung', 200, 200, 200, '2018-07-30', TIME '11:23:45', TIMESTAMP '2018-07-30 11:23:45', TIMESTAMPTZ '2018-07-30 11:23:45', INTERVAL '1 hours 2 minutes 3 seconds') -statement error cannot copy window "w" because it has a frame clause +statement error Expected one of ROWS or RANGE or GROUPS, found identifier "w" SELECT avg(price) OVER (w) FROM products WINDOW w AS (ROWS 1 PRECEDING) -statement error cannot copy window "w" because it has a frame clause +statement error Expected one of ROWS or RANGE or GROUPS, found identifier "w" SELECT avg(price) OVER (w ORDER BY price) FROM products WINDOW w AS (ROWS 1 PRECEDING) -statement error frame starting offset must not be null +statement error Expected literal unsigned integer, found NULL SELECT avg(price) OVER (ROWS NULL PRECEDING) FROM products -statement error frame starting offset must not be null +statement error Expected literal unsigned integer, found NULL SELECT avg(price) OVER (ROWS BETWEEN NULL PRECEDING AND 1 FOLLOWING) FROM products -statement error frame starting offset must not be negative +statement error Expected literal unsigned integer, found operator "\-" SELECT price, avg(price) OVER (PARTITION BY price ROWS -1 PRECEDING) AS avg_price FROM products -statement error frame starting offset must not be negative +statement error Expected left parenthesis, found identifier "w" SELECT price, avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY price ROWS -1 PRECEDING) -statement error frame ending offset must not be null +statement error Expected literal unsigned integer, found NULL SELECT avg(price) OVER (ROWS BETWEEN 1 PRECEDING AND NULL FOLLOWING) FROM products -statement error frame ending offset must not be negative +statement error Expected literal unsigned integer, found operator "\-" SELECT price, avg(price) OVER (PARTITION BY price ROWS BETWEEN 1 FOLLOWING AND -1 FOLLOWING) AS avg_price FROM products -statement error frame ending offset must not be negative +statement error Expected left parenthesis, found identifier "w" SELECT price, avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY price ROWS BETWEEN 1 FOLLOWING AND -1 FOLLOWING) -statement error frame ending offset must not be negative +statement error Expected literal unsigned integer, found operator "\-" SELECT product_name, price, min(price) OVER (PARTITION BY group_name ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS min_over_three, max(price) OVER (PARTITION BY group_name ROWS BETWEEN UNBOUNDED PRECEDING AND -1 FOLLOWING) AS max_over_partition FROM products ORDER BY group_id -statement error incompatible window frame start type: decimal +statement error Could not parse '1\.5' as u64: invalid digit found in string SELECT avg(price) OVER (PARTITION BY group_name ROWS 1.5 PRECEDING) AS avg_price FROM products -statement error incompatible window frame start type: decimal +statement error Expected left parenthesis, found identifier "w" SELECT avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY group_name ROWS 1.5 PRECEDING) -statement error incompatible window frame start type: decimal +statement error Could not parse '1\.5' as u64: invalid digit found in string SELECT avg(price) OVER (PARTITION BY group_name ROWS BETWEEN 1.5 PRECEDING AND UNBOUNDED FOLLOWING) AS avg_price FROM products -statement error incompatible window frame start type: decimal +statement error Expected left parenthesis, found identifier "w" SELECT avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY group_name ROWS BETWEEN 1.5 PRECEDING AND UNBOUNDED FOLLOWING) -statement error incompatible window frame end type: decimal +statement error Could not parse '1\.5' as u64: invalid digit found in string SELECT avg(price) OVER (PARTITION BY group_name ROWS BETWEEN UNBOUNDED PRECEDING AND 1.5 FOLLOWING) AS avg_price FROM products -statement error incompatible window frame end type: decimal +statement error Expected left parenthesis, found identifier "w" SELECT avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY group_name ROWS BETWEEN UNBOUNDED PRECEDING AND 1.5 FOLLOWING) +# Not supported by Materialize. +onlyif cockroach query TRT SELECT product_name, price, first_value(product_name) OVER w AS first FROM products WHERE price = 200 OR price = 700 WINDOW w as (PARTITION BY price ORDER BY product_name RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) ORDER BY price, product_name ---- @@ -2026,6 +2477,8 @@ Lenovo Thinkpad 700.00 Lenovo Thinkpad Sony VAIO 700.00 Lenovo Thinkpad iPad 700.00 Lenovo Thinkpad +# Not supported by Materialize. +onlyif cockroach query TRT SELECT product_name, price, last_value(product_name) OVER w AS last FROM products WHERE price = 200 OR price = 700 WINDOW w as (PARTITION BY price ORDER BY product_name RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) ORDER BY price, product_name ---- @@ -2035,6 +2488,8 @@ Lenovo Thinkpad 700.00 iPad Sony VAIO 700.00 iPad iPad 700.00 iPad +# Not supported by Materialize. +onlyif cockroach query TRT SELECT product_name, price, nth_value(product_name, 2) OVER w AS second FROM products WHERE price = 200 OR price = 700 WINDOW w as (PARTITION BY price ORDER BY product_name RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) ORDER BY price, product_name ---- @@ -2044,66 +2499,76 @@ Lenovo Thinkpad 700.00 Sony VAIO Sony VAIO 700.00 iPad iPad 700.00 NULL +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT product_name, group_name, price, avg(price) OVER (PARTITION BY group_name ORDER BY price, product_name ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS avg_of_three FROM products ORDER BY group_name, price, product_name ---- -Lenovo Thinkpad Laptop 700.00 700.00 -Sony VAIO Laptop 700.00 733.33333333333333333 -Dell Laptop 800.00 900.00 -HP Elite Laptop 1200.00 1000.00 -Microsoft Lumia Smartphone 200.00 300.00 -HTC One Smartphone 400.00 366.66666666666666667 -Nexus Smartphone 500.00 600.00 -iPhone Smartphone 900.00 700.00 -Kindle Fire Tablet 150.00 175.00 -Samsung Tablet 200.00 350.00 -iPad Tablet 700.00 450.00 - +Lenovo Thinkpad Laptop 700.00 700.00000000000000000 +Sony VAIO Laptop 700.00 733.33333333333333333 +Dell Laptop 800.00 900.00000000000000000 +HP Elite Laptop 1200.00 1000.0000000000000000 +Microsoft Lumia Smartphone 200.00 300.00000000000000000 +HTC One Smartphone 400.00 366.66666666666666667 +Nexus Smartphone 500.00 600.00000000000000000 +iPhone Smartphone 900.00 700.00000000000000000 +Kindle Fire Tablet 150.00 175.00000000000000000 +Samsung Tablet 200.00 350.00000000000000000 +iPad Tablet 700.00 450.00000000000000000 + +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT product_name, group_name, price, avg(priceFloat) OVER (PARTITION BY group_name ORDER BY price, product_name ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS avg_of_three_floats FROM products ORDER BY group_name, price, product_name ---- Lenovo Thinkpad Laptop 700.00 700 -Sony VAIO Laptop 700.00 733.333333333333 +Sony VAIO Laptop 700.00 733.3333333333334 Dell Laptop 800.00 900 HP Elite Laptop 1200.00 1000 Microsoft Lumia Smartphone 200.00 300 -HTC One Smartphone 400.00 366.666666666667 +HTC One Smartphone 400.00 366.6666666666667 Nexus Smartphone 500.00 600 iPhone Smartphone 900.00 700 Kindle Fire Tablet 150.00 175 Samsung Tablet 200.00 350 iPad Tablet 700.00 450 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT product_name, group_name, price, avg(priceInt) OVER (PARTITION BY group_name ORDER BY price, product_name ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS avg_of_three_ints FROM products ORDER BY group_name, price, product_name ---- -Lenovo Thinkpad Laptop 700.00 700 +Lenovo Thinkpad Laptop 700.00 700.00000000000000000 Sony VAIO Laptop 700.00 733.33333333333333333 -Dell Laptop 800.00 900 -HP Elite Laptop 1200.00 1000 -Microsoft Lumia Smartphone 200.00 300 +Dell Laptop 800.00 900.00000000000000000 +HP Elite Laptop 1200.00 1000.0000000000000000 +Microsoft Lumia Smartphone 200.00 300.00000000000000000 HTC One Smartphone 400.00 366.66666666666666667 -Nexus Smartphone 500.00 600 -iPhone Smartphone 900.00 700 -Kindle Fire Tablet 150.00 175 -Samsung Tablet 200.00 350 -iPad Tablet 700.00 450 - +Nexus Smartphone 500.00 600.00000000000000000 +iPhone Smartphone 900.00 700.00000000000000000 +Kindle Fire Tablet 150.00 175.00000000000000000 +Samsung Tablet 200.00 350.00000000000000000 +iPad Tablet 700.00 450.00000000000000000 + +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, avg(price) OVER (PARTITION BY group_name ORDER BY group_id ROWS (SELECT count(*) FROM PRODUCTS WHERE price = 200) PRECEDING) AS running_avg_of_three FROM products ORDER BY group_id ---- -Smartphone Microsoft Lumia 200.00 200.00 -Smartphone HTC One 400.00 300.00 +Smartphone Microsoft Lumia 200.00 200.00000000000000000 +Smartphone HTC One 400.00 300.00000000000000000 Smartphone Nexus 500.00 366.66666666666666667 -Smartphone iPhone 900.00 600.00 -Laptop HP Elite 1200.00 1200.00 -Laptop Lenovo Thinkpad 700.00 950.00 +Smartphone iPhone 900.00 600.00000000000000000 +Laptop HP Elite 1200.00 1200.0000000000000000 +Laptop Lenovo Thinkpad 700.00 950.00000000000000000 Laptop Sony VAIO 700.00 866.66666666666666667 Laptop Dell 800.00 733.33333333333333333 -Tablet iPad 700.00 700.00 -Tablet Kindle Fire 150.00 425.00 -Tablet Samsung 200.00 350.00 +Tablet iPad 700.00 700.00000000000000000 +Tablet Kindle Fire 150.00 425.00000000000000000 +Tablet Samsung 200.00 350.00000000000000000 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(price) OVER (PARTITION BY group_name ORDER BY group_id ROWS 2 PRECEDING) AS running_sum FROM products ORDER BY group_id ---- @@ -2119,6 +2584,8 @@ Tablet iPad 700.00 700.00 Tablet Kindle Fire 150.00 850.00 Tablet Samsung 200.00 1050.00 +# Not supported by Materialize. +onlyif cockroach query TTRT SELECT group_name, product_name, price, array_agg(price) OVER (PARTITION BY group_name ORDER BY group_id ROWS BETWEEN 1 PRECEDING AND 2 FOLLOWING) AS array_agg_price FROM products ORDER BY group_id ---- @@ -2134,21 +2601,42 @@ Tablet iPad 700.00 {700.00,150.00,200.00} Tablet Kindle Fire 150.00 {700.00,150.00,200.00} Tablet Samsung 200.00 {150.00,200.00} +# Not supported by Materialize. +onlyif cockroach +query TTRTTTT +SELECT group_name, product_name, price, array_agg(price) OVER (w ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING), array_agg(price) OVER (w ROWS BETWEEN UNBOUNDED PRECEDING AND 3 FOLLOWING), array_agg(price) OVER (w GROUPS BETWEEN 3 PRECEDING AND UNBOUNDED FOLLOWING), array_agg(price) OVER (w RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM products WINDOW w AS (PARTITION BY group_name ORDER BY group_id DESC) ORDER BY group_id +---- +Smartphone Microsoft Lumia 200.00 {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} +Smartphone HTC One 400.00 {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} +Smartphone Nexus 500.00 {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} +Smartphone iPhone 900.00 {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} {900.00,500.00,400.00,200.00} +Laptop HP Elite 1200.00 {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} +Laptop Lenovo Thinkpad 700.00 {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} +Laptop Sony VAIO 700.00 {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} +Laptop Dell 800.00 {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} {800.00,700.00,700.00,1200.00} +Tablet iPad 700.00 {200.00,150.00,700.00} {200.00,150.00,700.00} {200.00,150.00,700.00} {200.00,150.00,700.00} +Tablet Kindle Fire 150.00 {200.00,150.00,700.00} {200.00,150.00,700.00} {200.00,150.00,700.00} {200.00,150.00,700.00} +Tablet Samsung 200.00 {200.00,150.00,700.00} {200.00,150.00,700.00} {200.00,150.00,700.00} {200.00,150.00,700.00} + +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, avg(price) OVER (PARTITION BY group_name RANGE UNBOUNDED PRECEDING) AS avg_price FROM products ORDER BY group_id ---- -Smartphone Microsoft Lumia 200.00 500.00 -Smartphone HTC One 400.00 500.00 -Smartphone Nexus 500.00 500.00 -Smartphone iPhone 900.00 500.00 -Laptop HP Elite 1200.00 850.00 -Laptop Lenovo Thinkpad 700.00 850.00 -Laptop Sony VAIO 700.00 850.00 -Laptop Dell 800.00 850.00 -Tablet iPad 700.00 350.00 -Tablet Kindle Fire 150.00 350.00 -Tablet Samsung 200.00 350.00 - +Smartphone Microsoft Lumia 200.00 500.00000000000000000 +Smartphone HTC One 400.00 500.00000000000000000 +Smartphone Nexus 500.00 500.00000000000000000 +Smartphone iPhone 900.00 500.00000000000000000 +Laptop HP Elite 1200.00 850.00000000000000000 +Laptop Lenovo Thinkpad 700.00 850.00000000000000000 +Laptop Sony VAIO 700.00 850.00000000000000000 +Laptop Dell 800.00 850.00000000000000000 +Tablet iPad 700.00 350.00000000000000000 +Tablet Kindle Fire 150.00 350.00000000000000000 +Tablet Samsung 200.00 350.00000000000000000 + +# Not supported by Materialize. +onlyif cockroach query TTRT SELECT group_name, product_name, price, min(price) OVER (PARTITION BY group_name ROWS BETWEEN 1 PRECEDING AND 2 PRECEDING) AS min_over_empty_frame FROM products ORDER BY group_id ---- @@ -2164,6 +2652,8 @@ Tablet iPad 700.00 NULL Tablet Kindle Fire 150.00 NULL Tablet Samsung 200.00 NULL +# Not supported by Materialize. +onlyif cockroach query TRRR SELECT product_name, price, min(price) OVER (PARTITION BY group_name ORDER BY group_id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS min_over_three, max(price) OVER (PARTITION BY group_name ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS max_over_partition FROM products ORDER BY group_id ---- @@ -2179,6 +2669,8 @@ iPad 700.00 150.00 700.00 Kindle Fire 150.00 150.00 700.00 Samsung 200.00 150.00 700.00 +# Not supported by Materialize. +onlyif cockroach query TTRT SELECT group_name, product_name, price, min(price) OVER (PARTITION BY group_name ROWS CURRENT ROW) AS min_over_single_row FROM products ORDER BY group_id ---- @@ -2194,51 +2686,59 @@ Tablet iPad 700.00 700.00 Tablet Kindle Fire 150.00 150.00 Tablet Samsung 200.00 200.00 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, avg(price) OVER (PARTITION BY group_name ORDER BY group_id ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING) AS running_avg FROM products ORDER BY group_id ---- -Smartphone Microsoft Lumia 200.00 600.00 -Smartphone HTC One 400.00 700.00 -Smartphone Nexus 500.00 900.00 -Smartphone iPhone 900.00 NULL +Smartphone Microsoft Lumia 200.00 600.00000000000000000 +Smartphone HTC One 400.00 700.00000000000000000 +Smartphone Nexus 500.00 900.00000000000000000 +Smartphone iPhone 900.00 NULL Laptop HP Elite 1200.00 733.33333333333333333 -Laptop Lenovo Thinkpad 700.00 750.00 -Laptop Sony VAIO 700.00 800.00 -Laptop Dell 800.00 NULL -Tablet iPad 700.00 175.00 -Tablet Kindle Fire 150.00 200.00 -Tablet Samsung 200.00 NULL +Laptop Lenovo Thinkpad 700.00 750.00000000000000000 +Laptop Sony VAIO 700.00 800.00000000000000000 +Laptop Dell 800.00 NULL +Tablet iPad 700.00 175.00000000000000000 +Tablet Kindle Fire 150.00 200.00000000000000000 +Tablet Samsung 200.00 NULL +# Not supported by Materialize. +onlyif cockroach query TRRRRR SELECT product_name, price, min(price) OVER (PARTITION BY group_name ORDER BY group_id ROWS UNBOUNDED PRECEDING), max(price) OVER (PARTITION BY group_name ORDER BY group_id ROWS BETWEEN UNBOUNDED PRECEDING AND 1 FOLLOWING), sum(price) OVER (PARTITION BY group_name ORDER BY group_id ROWS BETWEEN 1 PRECEDING AND UNBOUNDED FOLLOWING), avg(price) OVER (PARTITION BY group_name ROWS CURRENT ROW) FROM products ORDER BY group_id ---- -Microsoft Lumia 200.00 200.00 400.00 2000.00 200.00 -HTC One 400.00 200.00 500.00 2000.00 400.00 -Nexus 500.00 200.00 900.00 1800.00 500.00 -iPhone 900.00 200.00 900.00 1400.00 900.00 -HP Elite 1200.00 1200.00 1200.00 3400.00 1200.00 -Lenovo Thinkpad 700.00 700.00 1200.00 3400.00 700.00 -Sony VAIO 700.00 700.00 1200.00 2200.00 700.00 -Dell 800.00 700.00 1200.00 1500.00 800.00 -iPad 700.00 700.00 700.00 1050.00 700.00 -Kindle Fire 150.00 150.00 700.00 1050.00 150.00 -Samsung 200.00 150.00 700.00 350.00 200.00 - +Microsoft Lumia 200.00 200.00 400.00 2000.00 200.00000000000000000 +HTC One 400.00 200.00 500.00 2000.00 400.00000000000000000 +Nexus 500.00 200.00 900.00 1800.00 500.00000000000000000 +iPhone 900.00 200.00 900.00 1400.00 900.00000000000000000 +HP Elite 1200.00 1200.00 1200.00 3400.00 1200.0000000000000000 +Lenovo Thinkpad 700.00 700.00 1200.00 3400.00 700.00000000000000000 +Sony VAIO 700.00 700.00 1200.00 2200.00 700.00000000000000000 +Dell 800.00 700.00 1200.00 1500.00 800.00000000000000000 +iPad 700.00 700.00 700.00 1050.00 700.00000000000000000 +Kindle Fire 150.00 150.00 700.00 1050.00 150.00000000000000000 +Samsung 200.00 150.00 700.00 350.00 200.00000000000000000 + +# Not supported by Materialize. +onlyif cockroach query RRR SELECT avg(price) OVER w1, avg(price) OVER w2, avg(price) OVER w1 FROM products WINDOW w1 AS (PARTITION BY group_name ORDER BY group_id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING), w2 AS (ORDER BY group_id ROWS 1 PRECEDING) ORDER BY group_id ---- -300.00 200.00 300.00 -366.66666666666666667 300.00 366.66666666666666667 -600.00 450.00 600.00 -700.00 700.00 700.00 -950.00 1050.00 950.00 -866.66666666666666667 950.00 866.66666666666666667 -733.33333333333333333 700.00 733.33333333333333333 -750.00 750.00 750.00 -425.00 750.00 425.00 -350.00 425.00 350.00 -175.00 175.00 175.00 - +300.00000000000000000 200.00000000000000000 300.00000000000000000 +366.66666666666666667 300.00000000000000000 366.66666666666666667 +600.00000000000000000 450.00000000000000000 600.00000000000000000 +700.00000000000000000 700.00000000000000000 700.00000000000000000 +950.00000000000000000 1050.0000000000000000 950.00000000000000000 +866.66666666666666667 950.00000000000000000 866.66666666666666667 +733.33333333333333333 700.00000000000000000 733.33333333333333333 +750.00000000000000000 750.00000000000000000 750.00000000000000000 +425.00000000000000000 750.00000000000000000 425.00000000000000000 +350.00000000000000000 425.00000000000000000 350.00000000000000000 +175.00000000000000000 175.00000000000000000 175.00000000000000000 + +# Not supported by Materialize. +onlyif cockroach # In the following 4 tests, since ORDER BY is omitted, all rows are peers, so frame includes all the rows for every row. query TTRR SELECT group_name, product_name, price, sum(price) OVER (RANGE CURRENT ROW) FROM products ORDER BY group_id @@ -2255,6 +2755,8 @@ Tablet iPad 700.00 6450.00 Tablet Kindle Fire 150.00 6450.00 Tablet Samsung 200.00 6450.00 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(price) OVER (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM products ORDER BY group_id ---- @@ -2270,6 +2772,8 @@ Tablet iPad 700.00 6450.00 Tablet Kindle Fire 150.00 6450.00 Tablet Samsung 200.00 6450.00 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(price) OVER (RANGE BETWEEN CURRENT ROW AND CURRENT ROW) FROM products ORDER BY group_id ---- @@ -2285,6 +2789,8 @@ Tablet iPad 700.00 6450.00 Tablet Kindle Fire 150.00 6450.00 Tablet Samsung 200.00 6450.00 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(price) OVER (RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM products ORDER BY group_id ---- @@ -2300,18 +2806,20 @@ Tablet iPad 700.00 6450.00 Tablet Kindle Fire 150.00 6450.00 Tablet Samsung 200.00 6450.00 -statement error aggregate functions are not allowed in FILTER +statement error unknown catalog item 'products' SELECT count(*) FILTER (WHERE count(*) > 5) OVER () FROM products -statement error window functions are not allowed in FILTER +statement error unknown catalog item 'products' SELECT count(*) FILTER (WHERE count(*) OVER () > 5) OVER () FROM products -statement error incompatible FILTER expression type: int +statement error unknown catalog item 'products' SELECT count(*) FILTER (WHERE 1) OVER () FROM products -statement error syntax error at or near "filter" +statement error Expected end of statement, found left parenthesis SELECT price FILTER (WHERE price=1) OVER () FROM products +# Not supported by Materialize. +onlyif cockroach query II SELECT count(*) FILTER (WHERE true) OVER (), count(*) FILTER (WHERE false) OVER () FROM products ---- @@ -2327,48 +2835,55 @@ SELECT count(*) FILTER (WHERE true) OVER (), count(*) FILTER (WHERE false) OVER 11 0 11 0 +# Not supported by Materialize. +onlyif cockroach query RRRR SELECT avg(price) FILTER (WHERE price > 300) OVER w1, sum(price) FILTER (WHERE group_name = 'Smartphone') OVER w2, avg(price) FILTER (WHERE price = 200 OR price = 700) OVER w1, avg(price) FILTER (WHERE price < 900) OVER w2 FROM products WINDOW w1 AS (ORDER BY group_id), w2 AS (PARTITION BY group_name ORDER BY price, group_id) ORDER BY group_id ---- -NULL 200.00 200.00 200.00 -400.00 600.00 200.00 300.00 -450.00 1100.00 200.00 366.66666666666666667 -600.00 2000.00 200.00 366.66666666666666667 -750.00 NULL 200.00 733.33333333333333333 -740.00 NULL 450.00 700.00 -733.33333333333333333 NULL 533.33333333333333333 700.00 +NULL 200.00 200.00000000000000000 200.00000000000000000 +400.00000000000000000 600.00 200.00000000000000000 300.00000000000000000 +450.00000000000000000 1100.00 200.00000000000000000 366.66666666666666667 +600.00000000000000000 2000.00 200.00000000000000000 366.66666666666666667 +750.00000000000000000 NULL 200.00000000000000000 733.33333333333333333 +740.00000000000000000 NULL 450.00000000000000000 700.00000000000000000 +733.33333333333333333 NULL 533.33333333333333333 700.00000000000000000 742.85714285714285714 NULL 533.33333333333333333 733.33333333333333333 -737.50 NULL 575.00 350.00 -737.50 NULL 575.00 150.00 -737.50 NULL 500.00 175.00 +737.50000000000000000 NULL 575.00000000000000000 350.00000000000000000 +737.50000000000000000 NULL 575.00000000000000000 150.00000000000000000 +737.50000000000000000 NULL 500.00000000000000000 175.00000000000000000 + +statement error unknown catalog item 'products' +SELECT count(DISTINCT group_name) OVER (), count(DISTINCT product_name) OVER () FROM products -statement error RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column +statement error unknown catalog item 'products' SELECT sum(price) OVER (RANGE 100 PRECEDING) FROM products -statement error RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column +statement error unknown catalog item 'products' SELECT sum(price) OVER (ORDER BY price, priceint RANGE 100 PRECEDING) FROM products -statement error invalid preceding or following size in window function +statement error Expected literal unsigned integer, found string literal "\-1 days" SELECT sum(price) OVER (ORDER BY pdate RANGE '-1 days' PRECEDING) FROM products -statement error invalid preceding or following size in window function +statement error Expected literal unsigned integer, found string literal "\-1 hours" SELECT sum(price) OVER (ORDER BY ptime RANGE BETWEEN '-1 hours' PRECEDING AND '1 hours' FOLLOWING) FROM products -statement error invalid preceding or following size in window function +statement error Expected literal unsigned integer, found string literal "1 hours" SELECT sum(price) OVER (ORDER BY ptime RANGE BETWEEN '1 hours' PRECEDING AND '-1 hours' FOLLOWING) FROM products -statement error incompatible window frame start type: decimal +statement error Could not parse '123\.4' as u64: invalid digit found in string SELECT sum(price) OVER (ORDER BY ptimestamp RANGE 123.4 PRECEDING) FROM products -statement error incompatible window frame start type: int +statement error unknown catalog item 'products' SELECT sum(price) OVER (ORDER BY ptimestamptz RANGE BETWEEN 123 PRECEDING AND CURRENT ROW) FROM products -statement error could not parse "1 days" as type decimal +statement error Could not parse '123\.4' as u64: invalid digit found in string SELECT sum(price) OVER (ORDER BY price RANGE BETWEEN 123.4 PRECEDING AND '1 days' FOLLOWING) FROM products -statement error RANGE with offset PRECEDING/FOLLOWING is not supported for column type varchar +statement error Expected literal unsigned integer, found string literal "foo" SELECT sum(price) OVER (ORDER BY product_name RANGE 'foo' PRECEDING) FROM products +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(priceint) OVER (PARTITION BY group_name ORDER BY priceint RANGE 200 PRECEDING) FROM products ORDER BY group_name, priceint, group_id ---- @@ -2384,6 +2899,8 @@ Tablet Kindle Fire 150.00 150 Tablet Samsung 200.00 350 Tablet iPad 700.00 700 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(price) OVER (PARTITION BY group_name ORDER BY price RANGE 200.002 PRECEDING) FROM products ORDER BY group_name, price, group_id ---- @@ -2399,6 +2916,8 @@ Tablet Kindle Fire 150.00 150.00 Tablet Samsung 200.00 350.00 Tablet iPad 700.00 700.00 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(pricefloat) OVER (PARTITION BY group_name ORDER BY pricefloat RANGE BETWEEN 200.01 PRECEDING AND 99.99 FOLLOWING) FROM products ORDER BY group_name, priceint, group_id ---- @@ -2414,6 +2933,8 @@ Tablet Kindle Fire 150.00 350 Tablet Samsung 200.00 350 Tablet iPad 700.00 700 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(price) OVER (PARTITION BY group_name ORDER BY price RANGE BETWEEN 99.99 PRECEDING AND 100.00 PRECEDING) FROM products ORDER BY group_name, priceint, group_id ---- @@ -2429,6 +2950,8 @@ Tablet Kindle Fire 150.00 NULL Tablet Samsung 200.00 NULL Tablet iPad 700.00 NULL +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(priceint) OVER (PARTITION BY group_name ORDER BY priceint RANGE BETWEEN 300 PRECEDING AND 50 PRECEDING) FROM products ORDER BY group_name, priceint, group_id ---- @@ -2444,6 +2967,8 @@ Tablet Kindle Fire 150.00 NULL Tablet Samsung 200.00 150 Tablet iPad 700.00 NULL +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(priceint) OVER (PARTITION BY group_name ORDER BY priceint RANGE BETWEEN 50 FOLLOWING AND 300 FOLLOWING) FROM products ORDER BY group_name, priceint, group_id ---- @@ -2459,6 +2984,8 @@ Tablet Kindle Fire 150.00 200 Tablet Samsung 200.00 NULL Tablet iPad 700.00 NULL +# Not supported by Materialize. +onlyif cockroach query TRR SELECT group_name, price, sum(price) OVER (PARTITION BY group_name ORDER BY price RANGE BETWEEN 49.999 FOLLOWING AND 300.001 FOLLOWING) FROM products ORDER BY group_name, price, group_id ---- @@ -2474,6 +3001,8 @@ Tablet 150.00 200.00 Tablet 200.00 NULL Tablet 700.00 NULL +# Not supported by Materialize. +onlyif cockroach query TRR SELECT group_name, price, sum(pricefloat) OVER (PARTITION BY group_name ORDER BY pricefloat RANGE BETWEEN 50 FOLLOWING AND 300 FOLLOWING) FROM products ORDER BY group_name, price, group_id ---- @@ -2489,6 +3018,8 @@ Tablet 150.00 200 Tablet 200.00 NULL Tablet 700.00 NULL +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, nth_value(pricefloat, 2) OVER (PARTITION BY group_name ORDER BY pricefloat RANGE BETWEEN 1.23 FOLLOWING AND 500.23 FOLLOWING) FROM products ORDER BY group_name, pricefloat, group_id ---- @@ -2504,6 +3035,8 @@ Tablet Kindle Fire 150.00 NULL Tablet Samsung 200.00 NULL Tablet iPad 700.00 NULL +# Not supported by Materialize. +onlyif cockroach query TTTRR SELECT group_name, product_name, pdate, price, sum(price) OVER (ORDER BY pdate RANGE '1 days' PRECEDING) FROM products ORDER BY pdate, group_id ---- @@ -2519,14 +3052,16 @@ Laptop Lenovo Thinkpad 2018-07-31 00:00:00 +0000 +0000 700.00 6450.00 Laptop Dell 2018-07-31 00:00:00 +0000 +0000 800.00 6450.00 Tablet Kindle Fire 2018-07-31 00:00:00 +0000 +0000 150.00 6450.00 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT product_name, ptime, price, avg(price) OVER (ORDER BY ptime RANGE BETWEEN '1 hours 15 minutes' PRECEDING AND '1 hours 15 minutes' FOLLOWING) FROM products ORDER BY ptime, group_id ---- -Microsoft Lumia 0000-01-01 01:23:45 +0000 UTC 200.00 700.00 -HP Elite 0000-01-01 01:23:45 +0000 UTC 1200.00 700.00 -iPad 0000-01-01 01:23:45 +0000 UTC 700.00 700.00 -iPhone 0000-01-01 07:34:56 +0000 UTC 900.00 850.00 -Dell 0000-01-01 07:34:56 +0000 UTC 800.00 850.00 +Microsoft Lumia 0000-01-01 01:23:45 +0000 UTC 200.00 700.00000000000000000 +HP Elite 0000-01-01 01:23:45 +0000 UTC 1200.00 700.00000000000000000 +iPad 0000-01-01 01:23:45 +0000 UTC 700.00 700.00000000000000000 +iPhone 0000-01-01 07:34:56 +0000 UTC 900.00 850.00000000000000000 +Dell 0000-01-01 07:34:56 +0000 UTC 800.00 850.00000000000000000 Nexus 0000-01-01 11:23:45 +0000 UTC 500.00 441.66666666666666667 Sony VAIO 0000-01-01 11:23:45 +0000 UTC 700.00 441.66666666666666667 Samsung 0000-01-01 11:23:45 +0000 UTC 200.00 441.66666666666666667 @@ -2534,6 +3069,8 @@ HTC One 0000-01-01 12:34:56 +0000 UTC 400.00 441.66666666666666667 Lenovo Thinkpad 0000-01-01 12:34:56 +0000 UTC 700.00 441.66666666666666667 Kindle Fire 0000-01-01 12:34:56 +0000 UTC 150.00 441.66666666666666667 +# Not supported by Materialize. +onlyif cockroach query TTTRR SELECT group_name, product_name, ptime, price, min(price) OVER (PARTITION BY group_name ORDER BY ptime RANGE BETWEEN '1 hours' FOLLOWING AND UNBOUNDED FOLLOWING) FROM products ORDER BY group_name, ptime ---- @@ -2549,6 +3086,8 @@ Tablet iPad 0000-01-01 01:23:45 +0000 UTC 700.00 150.00 Tablet Samsung 0000-01-01 11:23:45 +0000 UTC 200.00 150.00 Tablet Kindle Fire 0000-01-01 12:34:56 +0000 UTC 150.00 NULL +# Not supported by Materialize. +onlyif cockroach query TTTRR SELECT group_name, product_name, ptimestamp, price, first_value(price) OVER (PARTITION BY group_name ORDER BY ptimestamp RANGE BETWEEN '12 hours' PRECEDING AND '6 hours' FOLLOWING) FROM products ORDER BY group_name, ptimestamp ---- @@ -2564,21 +3103,25 @@ Tablet iPad 2018-07-30 01:23:45 +0000 +0000 700.00 700.00 Tablet Samsung 2018-07-30 11:23:45 +0000 +0000 200.00 700.00 Tablet Kindle Fire 2018-07-31 12:34:56 +0000 +0000 150.00 150.00 +# Not supported by Materialize. +onlyif cockroach query TTTRR SELECT group_name, product_name, ptimestamptz, price, avg(price) OVER (PARTITION BY group_name ORDER BY ptimestamptz RANGE BETWEEN '1 days 12 hours' PRECEDING AND CURRENT ROW) FROM products ORDER BY group_name, ptimestamptz ---- -Laptop HP Elite 2018-07-30 01:23:45 +0000 UTC 1200.00 1200.00 -Laptop Sony VAIO 2018-07-30 11:23:45 +0000 UTC 700.00 950.00 -Laptop Dell 2018-07-31 07:34:56 +0000 UTC 800.00 900.00 -Laptop Lenovo Thinkpad 2018-07-31 12:34:56 +0000 UTC 700.00 850.00 -Smartphone Microsoft Lumia 2018-07-30 01:23:45 +0000 UTC 200.00 200.00 -Smartphone Nexus 2018-07-30 11:23:45 +0000 UTC 500.00 350.00 +Laptop HP Elite 2018-07-30 01:23:45 +0000 UTC 1200.00 1200.0000000000000000 +Laptop Sony VAIO 2018-07-30 11:23:45 +0000 UTC 700.00 950.00000000000000000 +Laptop Dell 2018-07-31 07:34:56 +0000 UTC 800.00 900.00000000000000000 +Laptop Lenovo Thinkpad 2018-07-31 12:34:56 +0000 UTC 700.00 850.00000000000000000 +Smartphone Microsoft Lumia 2018-07-30 01:23:45 +0000 UTC 200.00 200.00000000000000000 +Smartphone Nexus 2018-07-30 11:23:45 +0000 UTC 500.00 350.00000000000000000 Smartphone iPhone 2018-07-31 07:34:56 +0000 UTC 900.00 533.33333333333333333 -Smartphone HTC One 2018-07-31 12:34:56 +0000 UTC 400.00 500.00 -Tablet iPad 2018-07-30 01:23:45 +0000 UTC 700.00 700.00 -Tablet Samsung 2018-07-30 11:23:45 +0000 UTC 200.00 450.00 -Tablet Kindle Fire 2018-07-31 12:34:56 +0000 UTC 150.00 350.00 +Smartphone HTC One 2018-07-31 12:34:56 +0000 UTC 400.00 500.00000000000000000 +Tablet iPad 2018-07-30 01:23:45 +0000 UTC 700.00 700.00000000000000000 +Tablet Samsung 2018-07-30 11:23:45 +0000 UTC 200.00 450.00000000000000000 +Tablet Kindle Fire 2018-07-31 12:34:56 +0000 UTC 150.00 350.00000000000000000 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT product_name, pinterval, price, avg(price) OVER (ORDER BY pinterval RANGE BETWEEN '2 hours 34 minutes 56 seconds' PRECEDING AND '3 months' FOLLOWING) FROM products ORDER BY pinterval, group_id ---- @@ -2590,10 +3133,12 @@ Samsung 01:02:03 200.00 586.36363636363636364 HTC One 1 day 02:03:04 400.00 558.33333333333333333 Lenovo Thinkpad 1 day 02:03:04 700.00 558.33333333333333333 Kindle Fire 1 day 02:03:04 150.00 558.33333333333333333 -Microsoft Lumia 1 mon 2 days 03:04:05 200.00 700.00 -HP Elite 1 mon 2 days 03:04:05 1200.00 700.00 -iPad 1 mon 2 days 03:04:05 700.00 700.00 +Microsoft Lumia 1 mon 2 days 03:04:05 200.00 700.00000000000000000 +HP Elite 1 mon 2 days 03:04:05 1200.00 700.00000000000000000 +iPad 1 mon 2 days 03:04:05 700.00 700.00000000000000000 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(priceint) OVER (PARTITION BY group_name ORDER BY priceint DESC RANGE 200 PRECEDING) FROM products ORDER BY group_name, priceint DESC, group_id ---- @@ -2609,6 +3154,8 @@ Tablet iPad 700.00 700 Tablet Samsung 200.00 200 Tablet Kindle Fire 150.00 350 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(price) OVER (PARTITION BY group_name ORDER BY price DESC RANGE 200.002 PRECEDING) FROM products ORDER BY group_name, price DESC, group_id ---- @@ -2624,6 +3171,8 @@ Tablet iPad 700.00 700.00 Tablet Samsung 200.00 200.00 Tablet Kindle Fire 150.00 350.00 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(pricefloat) OVER (PARTITION BY group_name ORDER BY pricefloat DESC RANGE BETWEEN 200.01 PRECEDING AND 99.99 FOLLOWING) FROM products ORDER BY group_name, priceint DESC, group_id ---- @@ -2639,6 +3188,8 @@ Tablet iPad 700.00 700 Tablet Samsung 200.00 350 Tablet Kindle Fire 150.00 350 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(price) OVER (PARTITION BY group_name ORDER BY price DESC RANGE BETWEEN 99.99 PRECEDING AND 100.00 PRECEDING) FROM products ORDER BY group_name, priceint DESC, group_id ---- @@ -2654,6 +3205,8 @@ Tablet iPad 700.00 NULL Tablet Samsung 200.00 NULL Tablet Kindle Fire 150.00 NULL +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(priceint) OVER (PARTITION BY group_name ORDER BY priceint DESC RANGE BETWEEN 300 PRECEDING AND 50 PRECEDING) FROM products ORDER BY group_name, priceint DESC, group_id ---- @@ -2669,6 +3222,8 @@ Tablet iPad 700.00 NULL Tablet Samsung 200.00 NULL Tablet Kindle Fire 150.00 200 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, sum(priceint) OVER (PARTITION BY group_name ORDER BY priceint DESC RANGE BETWEEN 50 FOLLOWING AND 300 FOLLOWING) FROM products ORDER BY group_name, priceint DESC, group_id ---- @@ -2684,6 +3239,8 @@ Tablet iPad 700.00 NULL Tablet Samsung 200.00 150 Tablet Kindle Fire 150.00 NULL +# Not supported by Materialize. +onlyif cockroach query TRR SELECT group_name, price, sum(price) OVER (PARTITION BY group_name ORDER BY price DESC RANGE BETWEEN 49.999 FOLLOWING AND 300.001 FOLLOWING) FROM products ORDER BY group_name, price DESC, group_id ---- @@ -2699,6 +3256,8 @@ Tablet 700.00 NULL Tablet 200.00 150.00 Tablet 150.00 NULL +# Not supported by Materialize. +onlyif cockroach query TRR SELECT group_name, price, sum(pricefloat) OVER (PARTITION BY group_name ORDER BY pricefloat DESC RANGE BETWEEN 50 FOLLOWING AND 300 FOLLOWING) FROM products ORDER BY group_name, price DESC, group_id ---- @@ -2714,6 +3273,8 @@ Tablet 700.00 NULL Tablet 200.00 150 Tablet 150.00 NULL +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT group_name, product_name, price, nth_value(pricefloat, 2) OVER (PARTITION BY group_name ORDER BY pricefloat DESC RANGE BETWEEN 1.23 FOLLOWING AND 500.23 FOLLOWING) FROM products ORDER BY group_name, pricefloat DESC, group_id ---- @@ -2729,6 +3290,8 @@ Tablet iPad 700.00 NULL Tablet Samsung 200.00 NULL Tablet Kindle Fire 150.00 NULL +# Not supported by Materialize. +onlyif cockroach query TTTRR SELECT group_name, product_name, pdate, price, sum(price) OVER (ORDER BY pdate DESC RANGE '1 days' PRECEDING) FROM products ORDER BY pdate DESC, group_id ---- @@ -2744,6 +3307,8 @@ Laptop Sony VAIO 2018-07-30 00:00:00 +0000 +0000 700.00 6450.00 Tablet iPad 2018-07-30 00:00:00 +0000 +0000 700.00 6450.00 Tablet Samsung 2018-07-30 00:00:00 +0000 +0000 200.00 6450.00 +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT product_name, ptime, price, avg(price) OVER (ORDER BY ptime DESC RANGE BETWEEN '1 hours 15 minutes' PRECEDING AND '1 hours 15 minutes' FOLLOWING) FROM products ORDER BY ptime DESC, group_id ---- @@ -2753,12 +3318,14 @@ Kindle Fire 0000-01-01 12:34:56 +0000 UTC 150.00 441.66666666666666667 Nexus 0000-01-01 11:23:45 +0000 UTC 500.00 441.66666666666666667 Sony VAIO 0000-01-01 11:23:45 +0000 UTC 700.00 441.66666666666666667 Samsung 0000-01-01 11:23:45 +0000 UTC 200.00 441.66666666666666667 -iPhone 0000-01-01 07:34:56 +0000 UTC 900.00 850.00 -Dell 0000-01-01 07:34:56 +0000 UTC 800.00 850.00 -Microsoft Lumia 0000-01-01 01:23:45 +0000 UTC 200.00 700.00 -HP Elite 0000-01-01 01:23:45 +0000 UTC 1200.00 700.00 -iPad 0000-01-01 01:23:45 +0000 UTC 700.00 700.00 - +iPhone 0000-01-01 07:34:56 +0000 UTC 900.00 850.00000000000000000 +Dell 0000-01-01 07:34:56 +0000 UTC 800.00 850.00000000000000000 +Microsoft Lumia 0000-01-01 01:23:45 +0000 UTC 200.00 700.00000000000000000 +HP Elite 0000-01-01 01:23:45 +0000 UTC 1200.00 700.00000000000000000 +iPad 0000-01-01 01:23:45 +0000 UTC 700.00 700.00000000000000000 + +# Not supported by Materialize. +onlyif cockroach query TTTRR SELECT group_name, product_name, ptime, price, min(price) OVER (PARTITION BY group_name ORDER BY ptime DESC RANGE BETWEEN '1 hours' FOLLOWING AND UNBOUNDED FOLLOWING) FROM products ORDER BY group_name, ptime DESC ---- @@ -2774,6 +3341,8 @@ Tablet Kindle Fire 0000-01-01 12:34:56 +0000 UTC 150.00 200.00 Tablet Samsung 0000-01-01 11:23:45 +0000 UTC 200.00 700.00 Tablet iPad 0000-01-01 01:23:45 +0000 UTC 700.00 NULL +# Not supported by Materialize. +onlyif cockroach query TTTRR SELECT group_name, product_name, ptimestamp, price, first_value(price) OVER (PARTITION BY group_name ORDER BY ptimestamp DESC RANGE BETWEEN '12 hours' PRECEDING AND '6 hours' FOLLOWING) FROM products ORDER BY group_name, ptimestamp DESC ---- @@ -2789,36 +3358,42 @@ Tablet Kindle Fire 2018-07-31 12:34:56 +0000 +0000 150.00 150.00 Tablet Samsung 2018-07-30 11:23:45 +0000 +0000 200.00 200.00 Tablet iPad 2018-07-30 01:23:45 +0000 +0000 700.00 200.00 +# Not supported by Materialize. +onlyif cockroach query TTTRR SELECT group_name, product_name, ptimestamptz, price, avg(price) OVER (PARTITION BY group_name ORDER BY ptimestamptz DESC RANGE BETWEEN '1 days 12 hours' PRECEDING AND CURRENT ROW) FROM products ORDER BY group_name, ptimestamptz DESC ---- -Laptop Lenovo Thinkpad 2018-07-31 12:34:56 +0000 UTC 700.00 700.00 -Laptop Dell 2018-07-31 07:34:56 +0000 UTC 800.00 750.00 +Laptop Lenovo Thinkpad 2018-07-31 12:34:56 +0000 UTC 700.00 700.00000000000000000 +Laptop Dell 2018-07-31 07:34:56 +0000 UTC 800.00 750.00000000000000000 Laptop Sony VAIO 2018-07-30 11:23:45 +0000 UTC 700.00 733.33333333333333333 -Laptop HP Elite 2018-07-30 01:23:45 +0000 UTC 1200.00 850.00 -Smartphone HTC One 2018-07-31 12:34:56 +0000 UTC 400.00 400.00 -Smartphone iPhone 2018-07-31 07:34:56 +0000 UTC 900.00 650.00 -Smartphone Nexus 2018-07-30 11:23:45 +0000 UTC 500.00 600.00 -Smartphone Microsoft Lumia 2018-07-30 01:23:45 +0000 UTC 200.00 500.00 -Tablet Kindle Fire 2018-07-31 12:34:56 +0000 UTC 150.00 150.00 -Tablet Samsung 2018-07-30 11:23:45 +0000 UTC 200.00 175.00 -Tablet iPad 2018-07-30 01:23:45 +0000 UTC 700.00 350.00 - +Laptop HP Elite 2018-07-30 01:23:45 +0000 UTC 1200.00 850.00000000000000000 +Smartphone HTC One 2018-07-31 12:34:56 +0000 UTC 400.00 400.00000000000000000 +Smartphone iPhone 2018-07-31 07:34:56 +0000 UTC 900.00 650.00000000000000000 +Smartphone Nexus 2018-07-30 11:23:45 +0000 UTC 500.00 600.00000000000000000 +Smartphone Microsoft Lumia 2018-07-30 01:23:45 +0000 UTC 200.00 500.00000000000000000 +Tablet Kindle Fire 2018-07-31 12:34:56 +0000 UTC 150.00 150.00000000000000000 +Tablet Samsung 2018-07-30 11:23:45 +0000 UTC 200.00 175.00000000000000000 +Tablet iPad 2018-07-30 01:23:45 +0000 UTC 700.00 350.00000000000000000 + +# Not supported by Materialize. +onlyif cockroach query TTRR SELECT product_name, pinterval, price, avg(price) OVER (ORDER BY pinterval DESC RANGE BETWEEN '2 hours 34 minutes 56 seconds' PRECEDING AND '3 months' FOLLOWING) FROM products ORDER BY pinterval DESC, group_id ---- Microsoft Lumia 1 mon 2 days 03:04:05 200.00 586.36363636363636364 HP Elite 1 mon 2 days 03:04:05 1200.00 586.36363636363636364 iPad 1 mon 2 days 03:04:05 700.00 586.36363636363636364 -HTC One 1 day 02:03:04 400.00 543.75 -Lenovo Thinkpad 1 day 02:03:04 700.00 543.75 -Kindle Fire 1 day 02:03:04 150.00 543.75 -Nexus 01:02:03 500.00 620.00 -Sony VAIO 01:02:03 700.00 620.00 -Samsung 01:02:03 200.00 620.00 -iPhone 00:01:02 900.00 620.00 -Dell 00:01:02 800.00 620.00 - +HTC One 1 day 02:03:04 400.00 543.75000000000000000 +Lenovo Thinkpad 1 day 02:03:04 700.00 543.75000000000000000 +Kindle Fire 1 day 02:03:04 150.00 543.75000000000000000 +Nexus 01:02:03 500.00 620.00000000000000000 +Sony VAIO 01:02:03 700.00 620.00000000000000000 +Samsung 01:02:03 200.00 620.00000000000000000 +iPhone 00:01:02 900.00 620.00000000000000000 +Dell 00:01:02 800.00 620.00000000000000000 + +# Not supported by Materialize. +onlyif cockroach query TRTT SELECT group_name, price, product_name, array_agg(product_name) OVER (PARTITION BY group_name ORDER BY price, group_id) FROM products ORDER BY group_id ---- @@ -2834,6 +3409,8 @@ Tablet 700.00 iPad {"Kindle Fire",Samsung,iPad} Tablet 150.00 Kindle Fire {"Kindle Fire"} Tablet 200.00 Samsung {"Kindle Fire",Samsung} +# Not supported by Materialize. +onlyif cockroach query TT SELECT product_name, array_agg(product_name) OVER (ORDER BY group_id) FROM products ORDER BY group_id ---- @@ -2849,48 +3426,56 @@ iPad {"Microsoft Lumia","HTC One",Nexus,iPhone,"HP Elite","Lenovo Th Kindle Fire {"Microsoft Lumia","HTC One",Nexus,iPhone,"HP Elite","Lenovo Thinkpad","Sony VAIO",Dell,iPad,"Kindle Fire"} Samsung {"Microsoft Lumia","HTC One",Nexus,iPhone,"HP Elite","Lenovo Thinkpad","Sony VAIO",Dell,iPad,"Kindle Fire",Samsung} -statement error frame starting offset must not be null -SELECT avg(price) OVER (GROUPS NULL PRECEDING) FROM products +statement error Expected literal unsigned integer, found identifier "group_id" +SELECT avg(price) OVER (GROUPS group_id PRECEDING) FROM products + +statement error unknown catalog item 'products' +SELECT avg(price) OVER (GROUPS 1 PRECEDING) FROM products + +statement error Expected literal unsigned integer, found NULL +SELECT avg(price) OVER (ORDER BY group_id GROUPS NULL PRECEDING) FROM products -statement error frame starting offset must not be null -SELECT avg(price) OVER (GROUPS BETWEEN NULL PRECEDING AND 1 FOLLOWING) FROM products +statement error Expected literal unsigned integer, found NULL +SELECT avg(price) OVER (ORDER BY group_id GROUPS BETWEEN NULL PRECEDING AND 1 FOLLOWING) FROM products -statement error frame starting offset must not be negative -SELECT price, avg(price) OVER (PARTITION BY price GROUPS -1 PRECEDING) AS avg_price FROM products +statement error Expected literal unsigned integer, found operator "\-" +SELECT price, avg(price) OVER (PARTITION BY price ORDER BY group_id GROUPS -1 PRECEDING) AS avg_price FROM products -statement error frame starting offset must not be negative -SELECT price, avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY price GROUPS -1 PRECEDING) +statement error Expected left parenthesis, found identifier "w" +SELECT price, avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY price ORDER BY group_id GROUPS -1 PRECEDING) -statement error frame ending offset must not be null -SELECT avg(price) OVER (GROUPS BETWEEN 1 PRECEDING AND NULL FOLLOWING) FROM products +statement error Expected literal unsigned integer, found NULL +SELECT avg(price) OVER (ORDER BY group_id GROUPS BETWEEN 1 PRECEDING AND NULL FOLLOWING) FROM products -statement error frame ending offset must not be negative -SELECT price, avg(price) OVER (PARTITION BY price GROUPS BETWEEN 1 FOLLOWING AND -1 FOLLOWING) AS avg_price FROM products +statement error Expected literal unsigned integer, found operator "\-" +SELECT price, avg(price) OVER (PARTITION BY price ORDER BY group_id GROUPS BETWEEN 1 FOLLOWING AND -1 FOLLOWING) AS avg_price FROM products -statement error frame ending offset must not be negative -SELECT price, avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY price GROUPS BETWEEN 1 FOLLOWING AND -1 FOLLOWING) +statement error Expected left parenthesis, found identifier "w" +SELECT price, avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY price ORDER BY group_id GROUPS BETWEEN 1 FOLLOWING AND -1 FOLLOWING) -statement error frame ending offset must not be negative -SELECT product_name, price, min(price) OVER (PARTITION BY group_name GROUPS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS min_over_three, max(price) OVER (PARTITION BY group_name GROUPS BETWEEN UNBOUNDED PRECEDING AND -1 FOLLOWING) AS max_over_partition FROM products ORDER BY group_id +statement error Expected literal unsigned integer, found operator "\-" +SELECT product_name, price, min(price) OVER (PARTITION BY group_name ORDER BY group_id GROUPS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS min_over_three, max(price) OVER (PARTITION BY group_name ORDER BY group_id GROUPS BETWEEN UNBOUNDED PRECEDING AND -1 FOLLOWING) AS max_over_partition FROM products ORDER BY group_id -statement error incompatible window frame start type: decimal -SELECT avg(price) OVER (PARTITION BY group_name GROUPS 1.5 PRECEDING) AS avg_price FROM products +statement error Could not parse '1\.5' as u64: invalid digit found in string +SELECT avg(price) OVER (PARTITION BY group_name ORDER BY group_id GROUPS 1.5 PRECEDING) AS avg_price FROM products -statement error incompatible window frame start type: decimal -SELECT avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY group_name GROUPS 1.5 PRECEDING) +statement error Expected left parenthesis, found identifier "w" +SELECT avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY group_name ORDER BY group_id GROUPS 1.5 PRECEDING) -statement error incompatible window frame start type: decimal -SELECT avg(price) OVER (PARTITION BY group_name GROUPS BETWEEN 1.5 PRECEDING AND UNBOUNDED FOLLOWING) AS avg_price FROM products +statement error Could not parse '1\.5' as u64: invalid digit found in string +SELECT avg(price) OVER (PARTITION BY group_name ORDER BY group_id GROUPS BETWEEN 1.5 PRECEDING AND UNBOUNDED FOLLOWING) AS avg_price FROM products -statement error incompatible window frame start type: decimal -SELECT avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY group_name GROUPS BETWEEN 1.5 PRECEDING AND UNBOUNDED FOLLOWING) +statement error Expected left parenthesis, found identifier "w" +SELECT avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY group_name ORDER BY group_id GROUPS BETWEEN 1.5 PRECEDING AND UNBOUNDED FOLLOWING) -statement error incompatible window frame end type: decimal -SELECT avg(price) OVER (PARTITION BY group_name GROUPS BETWEEN UNBOUNDED PRECEDING AND 1.5 FOLLOWING) AS avg_price FROM products +statement error Could not parse '1\.5' as u64: invalid digit found in string +SELECT avg(price) OVER (PARTITION BY group_name ORDER BY group_id GROUPS BETWEEN UNBOUNDED PRECEDING AND 1.5 FOLLOWING) AS avg_price FROM products -statement error incompatible window frame end type: decimal -SELECT avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY group_name GROUPS BETWEEN UNBOUNDED PRECEDING AND 1.5 FOLLOWING) +statement error Expected left parenthesis, found identifier "w" +SELECT avg(price) OVER w AS avg_price FROM products WINDOW w AS (PARTITION BY group_name ORDER BY group_id GROUPS BETWEEN UNBOUNDED PRECEDING AND 1.5 FOLLOWING) +# Not supported by Materialize. +onlyif cockroach query RRRRR SELECT price, sum(price) OVER (ORDER BY price GROUPS UNBOUNDED PRECEDING), sum(price) OVER (ORDER BY price GROUPS 100 PRECEDING), sum(price) OVER (ORDER BY price GROUPS 1 PRECEDING), sum(price) OVER (ORDER BY group_name GROUPS CURRENT ROW) FROM products ORDER BY price, group_id ---- @@ -2906,97 +3491,330 @@ SELECT price, sum(price) OVER (ORDER BY price GROUPS UNBOUNDED PRECEDING), sum(p 900.00 5250.00 5250.00 1700.00 2000.00 1200.00 6450.00 6450.00 2100.00 3400.00 +# Not supported by Materialize. +onlyif cockroach query RIRRRRRR SELECT price, dense_rank() OVER w, avg(price) OVER (w GROUPS BETWEEN UNBOUNDED PRECEDING AND 100 PRECEDING), avg(price) OVER (w GROUPS BETWEEN UNBOUNDED PRECEDING AND 2 PRECEDING), avg(price) OVER (w GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW), avg(price) OVER (w GROUPS BETWEEN UNBOUNDED PRECEDING AND 2 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN UNBOUNDED PRECEDING AND 100 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM products WINDOW w AS (ORDER BY price) ORDER BY price ---- -150.00 1 NULL NULL 150.00 237.50 586.36363636363636364 586.36363636363636364 -200.00 2 NULL NULL 183.33333333333333333 290.00 586.36363636363636364 586.36363636363636364 -200.00 2 NULL NULL 183.33333333333333333 290.00 586.36363636363636364 586.36363636363636364 -400.00 3 NULL 150.00 237.50 443.75 586.36363636363636364 586.36363636363636364 -500.00 4 NULL 183.33333333333333333 290.00 483.33333333333333333 586.36363636363636364 586.36363636363636364 -700.00 5 NULL 237.50 443.75 525.00 586.36363636363636364 586.36363636363636364 -700.00 5 NULL 237.50 443.75 525.00 586.36363636363636364 586.36363636363636364 -700.00 5 NULL 237.50 443.75 525.00 586.36363636363636364 586.36363636363636364 -800.00 6 NULL 290.00 483.33333333333333333 586.36363636363636364 586.36363636363636364 586.36363636363636364 -900.00 7 NULL 443.75 525.00 586.36363636363636364 586.36363636363636364 586.36363636363636364 +150.00 1 NULL NULL 150.00000000000000000 237.50000000000000000 586.36363636363636364 586.36363636363636364 +200.00 2 NULL NULL 183.33333333333333333 290.00000000000000000 586.36363636363636364 586.36363636363636364 +200.00 2 NULL NULL 183.33333333333333333 290.00000000000000000 586.36363636363636364 586.36363636363636364 +400.00 3 NULL 150.00000000000000000 237.50000000000000000 443.75000000000000000 586.36363636363636364 586.36363636363636364 +500.00 4 NULL 183.33333333333333333 290.00000000000000000 483.33333333333333333 586.36363636363636364 586.36363636363636364 +700.00 5 NULL 237.50000000000000000 443.75000000000000000 525.00000000000000000 586.36363636363636364 586.36363636363636364 +700.00 5 NULL 237.50000000000000000 443.75000000000000000 525.00000000000000000 586.36363636363636364 586.36363636363636364 +700.00 5 NULL 237.50000000000000000 443.75000000000000000 525.00000000000000000 586.36363636363636364 586.36363636363636364 +800.00 6 NULL 290.00000000000000000 483.33333333333333333 586.36363636363636364 586.36363636363636364 586.36363636363636364 +900.00 7 NULL 443.75000000000000000 525.00000000000000000 586.36363636363636364 586.36363636363636364 586.36363636363636364 1200.00 8 NULL 483.33333333333333333 586.36363636363636364 586.36363636363636364 586.36363636363636364 586.36363636363636364 +# Not supported by Materialize. +onlyif cockroach query RIRRRRRR SELECT price, dense_rank() OVER w, avg(price) OVER (w GROUPS BETWEEN 4 PRECEDING AND 100 PRECEDING), avg(price) OVER (w GROUPS BETWEEN 3 PRECEDING AND 2 PRECEDING), avg(price) OVER (w GROUPS BETWEEN 2 PRECEDING AND CURRENT ROW), avg(price) OVER (w GROUPS BETWEEN 1 PRECEDING AND 2 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN 1 PRECEDING AND 100 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN 1 PRECEDING AND UNBOUNDED FOLLOWING) FROM products WINDOW w AS (ORDER BY price) ORDER BY price ---- -150.00 1 NULL NULL 150.00 237.50 586.36363636363636364 586.36363636363636364 -200.00 2 NULL NULL 183.33333333333333333 290.00 586.36363636363636364 586.36363636363636364 -200.00 2 NULL NULL 183.33333333333333333 290.00 586.36363636363636364 586.36363636363636364 -400.00 3 NULL 150.00 237.50 485.71428571428571429 630.00 630.00 -500.00 4 NULL 183.33333333333333333 325.00 633.33333333333333333 737.50 737.50 -700.00 5 NULL 266.66666666666666667 600.00 716.66666666666666667 785.71428571428571429 785.71428571428571429 -700.00 5 NULL 266.66666666666666667 600.00 716.66666666666666667 785.71428571428571429 785.71428571428571429 -700.00 5 NULL 266.66666666666666667 600.00 716.66666666666666667 785.71428571428571429 785.71428571428571429 -800.00 6 NULL 450.00 680.00 833.33333333333333333 833.33333333333333333 833.33333333333333333 -900.00 7 NULL 650.00 760.00 966.66666666666666667 966.66666666666666667 966.66666666666666667 -1200.00 8 NULL 725.00 966.66666666666666667 1050.00 1050.00 1050.00 - +150.00 1 NULL NULL 150.00000000000000000 237.50000000000000000 586.36363636363636364 586.36363636363636364 +200.00 2 NULL NULL 183.33333333333333333 290.00000000000000000 586.36363636363636364 586.36363636363636364 +200.00 2 NULL NULL 183.33333333333333333 290.00000000000000000 586.36363636363636364 586.36363636363636364 +400.00 3 NULL 150.00000000000000000 237.50000000000000000 485.71428571428571429 630.00000000000000000 630.00000000000000000 +500.00 4 NULL 183.33333333333333333 325.00000000000000000 633.33333333333333333 737.50000000000000000 737.50000000000000000 +700.00 5 NULL 266.66666666666666667 600.00000000000000000 716.66666666666666667 785.71428571428571429 785.71428571428571429 +700.00 5 NULL 266.66666666666666667 600.00000000000000000 716.66666666666666667 785.71428571428571429 785.71428571428571429 +700.00 5 NULL 266.66666666666666667 600.00000000000000000 716.66666666666666667 785.71428571428571429 785.71428571428571429 +800.00 6 NULL 450.00000000000000000 680.00000000000000000 833.33333333333333333 833.33333333333333333 833.33333333333333333 +900.00 7 NULL 650.00000000000000000 760.00000000000000000 966.66666666666666667 966.66666666666666667 966.66666666666666667 +1200.00 8 NULL 725.00000000000000000 966.66666666666666667 1050.0000000000000000 1050.0000000000000000 1050.0000000000000000 + +# Not supported by Materialize. +onlyif cockroach query RIRRRRRRR SELECT price, dense_rank() OVER w, avg(price) OVER (w GROUPS BETWEEN 0 PRECEDING AND 0 PRECEDING), avg(price) OVER (w GROUPS BETWEEN 0 PRECEDING AND CURRENT ROW), avg(price) OVER (w GROUPS BETWEEN 0 PRECEDING AND 0 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN CURRENT ROW AND CURRENT ROW), avg(price) OVER (w GROUPS BETWEEN CURRENT ROW AND 2 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN CURRENT ROW AND 100 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM products WINDOW w AS (ORDER BY price) ORDER BY price ---- -150.00 1 150.00 150.00 150.00 150.00 237.50 586.36363636363636364 586.36363636363636364 -200.00 2 200.00 200.00 200.00 200.00 325.00 630.00 630.00 -200.00 2 200.00 200.00 200.00 200.00 325.00 630.00 630.00 -400.00 3 400.00 400.00 400.00 400.00 600.00 737.50 737.50 -500.00 4 500.00 500.00 500.00 500.00 680.00 785.71428571428571429 785.71428571428571429 -700.00 5 700.00 700.00 700.00 700.00 760.00 833.33333333333333333 833.33333333333333333 -700.00 5 700.00 700.00 700.00 700.00 760.00 833.33333333333333333 833.33333333333333333 -700.00 5 700.00 700.00 700.00 700.00 760.00 833.33333333333333333 833.33333333333333333 -800.00 6 800.00 800.00 800.00 800.00 966.66666666666666667 966.66666666666666667 966.66666666666666667 -900.00 7 900.00 900.00 900.00 900.00 1050.00 1050.00 1050.00 -1200.00 8 1200.00 1200.00 1200.00 1200.00 1200.00 1200.00 1200.00 - +150.00 1 150.00000000000000000 150.00000000000000000 150.00000000000000000 150.00000000000000000 237.50000000000000000 586.36363636363636364 586.36363636363636364 +200.00 2 200.00000000000000000 200.00000000000000000 200.00000000000000000 200.00000000000000000 325.00000000000000000 630.00000000000000000 630.00000000000000000 +200.00 2 200.00000000000000000 200.00000000000000000 200.00000000000000000 200.00000000000000000 325.00000000000000000 630.00000000000000000 630.00000000000000000 +400.00 3 400.00000000000000000 400.00000000000000000 400.00000000000000000 400.00000000000000000 600.00000000000000000 737.50000000000000000 737.50000000000000000 +500.00 4 500.00000000000000000 500.00000000000000000 500.00000000000000000 500.00000000000000000 680.00000000000000000 785.71428571428571429 785.71428571428571429 +700.00 5 700.00000000000000000 700.00000000000000000 700.00000000000000000 700.00000000000000000 760.00000000000000000 833.33333333333333333 833.33333333333333333 +700.00 5 700.00000000000000000 700.00000000000000000 700.00000000000000000 700.00000000000000000 760.00000000000000000 833.33333333333333333 833.33333333333333333 +700.00 5 700.00000000000000000 700.00000000000000000 700.00000000000000000 700.00000000000000000 760.00000000000000000 833.33333333333333333 833.33333333333333333 +800.00 6 800.00000000000000000 800.00000000000000000 800.00000000000000000 800.00000000000000000 966.66666666666666667 966.66666666666666667 966.66666666666666667 +900.00 7 900.00000000000000000 900.00000000000000000 900.00000000000000000 900.00000000000000000 1050.0000000000000000 1050.0000000000000000 1050.0000000000000000 +1200.00 8 1200.0000000000000000 1200.0000000000000000 1200.0000000000000000 1200.0000000000000000 1200.0000000000000000 1200.0000000000000000 1200.0000000000000000 + +# Not supported by Materialize. +onlyif cockroach query RIRRRRRR SELECT price, dense_rank() OVER w, avg(price) OVER (w GROUPS BETWEEN 3 FOLLOWING AND 100 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN 3 FOLLOWING AND 1 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN 2 FOLLOWING AND 6 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN 3 FOLLOWING AND 3 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN 0 FOLLOWING AND 4 FOLLOWING), avg(price) OVER (w GROUPS BETWEEN 5 FOLLOWING AND UNBOUNDED FOLLOWING) FROM products WINDOW w AS (ORDER BY price) ORDER BY price ---- -150.00 1 785.71428571428571429 NULL 671.42857142857142857 500.00 443.75 966.66666666666666667 -200.00 2 833.33333333333333333 NULL 785.71428571428571429 700.00 525.00 1050.00 -200.00 2 833.33333333333333333 NULL 785.71428571428571429 700.00 525.00 1050.00 -400.00 3 966.66666666666666667 NULL 833.33333333333333333 800.00 671.42857142857142857 1200.00 -500.00 4 1050.00 NULL 966.66666666666666667 900.00 785.71428571428571429 NULL -700.00 5 1200.00 NULL 1050.00 1200.00 833.33333333333333333 NULL -700.00 5 1200.00 NULL 1050.00 1200.00 833.33333333333333333 NULL -700.00 5 1200.00 NULL 1050.00 1200.00 833.33333333333333333 NULL -800.00 6 NULL NULL 1200.00 NULL 966.66666666666666667 NULL -900.00 7 NULL NULL NULL NULL 1050.00 NULL -1200.00 8 NULL NULL NULL NULL 1200.00 NULL - +150.00 1 785.71428571428571429 NULL 671.42857142857142857 500.00000000000000000 443.75000000000000000 966.66666666666666667 +200.00 2 833.33333333333333333 NULL 785.71428571428571429 700.00000000000000000 525.00000000000000000 1050.0000000000000000 +200.00 2 833.33333333333333333 NULL 785.71428571428571429 700.00000000000000000 525.00000000000000000 1050.0000000000000000 +400.00 3 966.66666666666666667 NULL 833.33333333333333333 800.00000000000000000 671.42857142857142857 1200.0000000000000000 +500.00 4 1050.0000000000000000 NULL 966.66666666666666667 900.00000000000000000 785.71428571428571429 NULL +700.00 5 1200.0000000000000000 NULL 1050.0000000000000000 1200.0000000000000000 833.33333333333333333 NULL +700.00 5 1200.0000000000000000 NULL 1050.0000000000000000 1200.0000000000000000 833.33333333333333333 NULL +700.00 5 1200.0000000000000000 NULL 1050.0000000000000000 1200.0000000000000000 833.33333333333333333 NULL +800.00 6 NULL NULL 1200.0000000000000000 NULL 966.66666666666666667 NULL +900.00 7 NULL NULL NULL NULL 1050.0000000000000000 NULL +1200.00 8 NULL NULL NULL NULL 1200.0000000000000000 NULL + +# Not supported by Materialize. +onlyif cockroach query TTRRR SELECT group_name, product_name, price, avg(price) OVER (PARTITION BY group_name ORDER BY price GROUPS BETWEEN CURRENT ROW AND 3 FOLLOWING), avg(price) OVER (ORDER BY price GROUPS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM products ORDER BY group_id ---- -Smartphone Microsoft Lumia 200.00 500.00 586.36363636363636364 -Smartphone HTC One 400.00 600.00 586.36363636363636364 -Smartphone Nexus 500.00 700.00 586.36363636363636364 -Smartphone iPhone 900.00 900.00 586.36363636363636364 -Laptop HP Elite 1200.00 1200.00 586.36363636363636364 -Laptop Lenovo Thinkpad 700.00 850.00 586.36363636363636364 -Laptop Sony VAIO 700.00 850.00 586.36363636363636364 -Laptop Dell 800.00 1000.00 586.36363636363636364 -Tablet iPad 700.00 700.00 586.36363636363636364 -Tablet Kindle Fire 150.00 350.00 586.36363636363636364 -Tablet Samsung 200.00 450.00 586.36363636363636364 - +Smartphone Microsoft Lumia 200.00 500.00000000000000000 586.36363636363636364 +Smartphone HTC One 400.00 600.00000000000000000 586.36363636363636364 +Smartphone Nexus 500.00 700.00000000000000000 586.36363636363636364 +Smartphone iPhone 900.00 900.00000000000000000 586.36363636363636364 +Laptop HP Elite 1200.00 1200.0000000000000000 586.36363636363636364 +Laptop Lenovo Thinkpad 700.00 850.00000000000000000 586.36363636363636364 +Laptop Sony VAIO 700.00 850.00000000000000000 586.36363636363636364 +Laptop Dell 800.00 1000.0000000000000000 586.36363636363636364 +Tablet iPad 700.00 700.00000000000000000 586.36363636363636364 +Tablet Kindle Fire 150.00 350.00000000000000000 586.36363636363636364 +Tablet Samsung 200.00 450.00000000000000000 586.36363636363636364 + +# Not supported by Materialize. +onlyif cockroach query TTRRR -SELECT group_name, product_name, price, avg(price) OVER (GROUPS BETWEEN 1 PRECEDING AND 2 PRECEDING), avg(price) OVER (ORDER BY price GROUPS BETWEEN CURRENT ROW AND CURRENT ROW) FROM products ORDER BY group_id ----- -Smartphone Microsoft Lumia 200.00 NULL 200.00 -Smartphone HTC One 400.00 NULL 400.00 -Smartphone Nexus 500.00 NULL 500.00 -Smartphone iPhone 900.00 NULL 900.00 -Laptop HP Elite 1200.00 NULL 1200.00 -Laptop Lenovo Thinkpad 700.00 NULL 700.00 -Laptop Sony VAIO 700.00 NULL 700.00 -Laptop Dell 800.00 NULL 800.00 -Tablet iPad 700.00 NULL 700.00 -Tablet Kindle Fire 150.00 NULL 150.00 -Tablet Samsung 200.00 NULL 200.00 - -# Test for cockroach#32702 +SELECT group_name, product_name, price, avg(price) OVER (ORDER BY group_id GROUPS BETWEEN 1 PRECEDING AND 2 PRECEDING), avg(price) OVER (ORDER BY price GROUPS BETWEEN CURRENT ROW AND CURRENT ROW) FROM products ORDER BY group_id +---- +Smartphone Microsoft Lumia 200.00 NULL 200.00000000000000000 +Smartphone HTC One 400.00 NULL 400.00000000000000000 +Smartphone Nexus 500.00 NULL 500.00000000000000000 +Smartphone iPhone 900.00 NULL 900.00000000000000000 +Laptop HP Elite 1200.00 NULL 1200.0000000000000000 +Laptop Lenovo Thinkpad 700.00 NULL 700.00000000000000000 +Laptop Sony VAIO 700.00 NULL 700.00000000000000000 +Laptop Dell 800.00 NULL 800.00000000000000000 +Tablet iPad 700.00 NULL 700.00000000000000000 +Tablet Kindle Fire 150.00 NULL 150.00000000000000000 +Tablet Samsung 200.00 NULL 200.00000000000000000 + +# Not supported by Materialize. +onlyif cockroach +query RTR +SELECT + price, array_agg(price) OVER w, sum(price) OVER w +FROM + products +WINDOW + w AS ( + ORDER BY + price + RANGE + UNBOUNDED PRECEDING EXCLUDE CURRENT ROW + ) +ORDER BY + price +---- +150.00 NULL NULL +200.00 {150.00,200.00} 350.00 +200.00 {150.00,200.00} 350.00 +400.00 {150.00,200.00,200.00} 550.00 +500.00 {150.00,200.00,200.00,400.00} 950.00 +700.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00} 2850.00 +700.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00} 2850.00 +700.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00} 2850.00 +800.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00} 3550.00 +900.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00,800.00} 4350.00 +1200.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00,800.00,900.00} 5250.00 + +# Not supported by Materialize. +onlyif cockroach +query RTR +SELECT + price, array_agg(price) OVER w, max(price) OVER w +FROM + products +WINDOW + w AS ( + ORDER BY + price + RANGE + UNBOUNDED PRECEDING EXCLUDE GROUP + ) +ORDER BY + price +---- +150.00 NULL NULL +200.00 {150.00} 150.00 +200.00 {150.00} 150.00 +400.00 {150.00,200.00,200.00} 200.00 +500.00 {150.00,200.00,200.00,400.00} 400.00 +700.00 {150.00,200.00,200.00,400.00,500.00} 500.00 +700.00 {150.00,200.00,200.00,400.00,500.00} 500.00 +700.00 {150.00,200.00,200.00,400.00,500.00} 500.00 +800.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00} 700.00 +900.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00,800.00} 800.00 +1200.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00,800.00,900.00} 900.00 + +# Not supported by Materialize. +onlyif cockroach +query RTR +SELECT + price, array_agg(price) OVER w, avg(price) OVER w +FROM + products +WINDOW + w AS ( + ORDER BY + price + RANGE + UNBOUNDED PRECEDING EXCLUDE TIES + ) +ORDER BY + price +---- +150.00 {150.00} 150.00000000000000000 +200.00 {150.00,200.00} 175.00000000000000000 +200.00 {150.00,200.00} 175.00000000000000000 +400.00 {150.00,200.00,200.00,400.00} 237.50000000000000000 +500.00 {150.00,200.00,200.00,400.00,500.00} 290.00000000000000000 +700.00 {150.00,200.00,200.00,400.00,500.00,700.00} 358.33333333333333333 +700.00 {150.00,200.00,200.00,400.00,500.00,700.00} 358.33333333333333333 +700.00 {150.00,200.00,200.00,400.00,500.00,700.00} 358.33333333333333333 +800.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00,800.00} 483.33333333333333333 +900.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00,800.00,900.00} 525.00000000000000000 +1200.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00,800.00,900.00,1200.00} 586.36363636363636364 + +# Not supported by Materialize. +onlyif cockroach +query RTR +SELECT + price, array_agg(price) OVER w, avg(price) OVER w +FROM + products +WINDOW + w AS ( + ORDER BY + price + RANGE + UNBOUNDED PRECEDING EXCLUDE NO OTHERS + ) +ORDER BY + price +---- +150.00 {150.00} 150.00000000000000000 +200.00 {150.00,200.00,200.00} 183.33333333333333333 +200.00 {150.00,200.00,200.00} 183.33333333333333333 +400.00 {150.00,200.00,200.00,400.00} 237.50000000000000000 +500.00 {150.00,200.00,200.00,400.00,500.00} 290.00000000000000000 +700.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00} 443.75000000000000000 +700.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00} 443.75000000000000000 +700.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00} 443.75000000000000000 +800.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00,800.00} 483.33333333333333333 +900.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00,800.00,900.00} 525.00000000000000000 +1200.00 {150.00,200.00,200.00,400.00,500.00,700.00,700.00,700.00,800.00,900.00,1200.00} 586.36363636363636364 + +# Not supported by Materialize. +onlyif cockroach +query TTTT +SELECT + first_value(product_name) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE CURRENT ROW + ), + first_value(product_name) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE GROUP + ), + first_value(product_name) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE TIES + ), + first_value(product_name) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE NO OTHERS + ) +FROM + products +WINDOW + w AS (ORDER BY group_id) +ORDER BY + group_id +---- +NULL NULL Microsoft Lumia Microsoft Lumia +Microsoft Lumia Microsoft Lumia Microsoft Lumia Microsoft Lumia +Microsoft Lumia Microsoft Lumia Microsoft Lumia Microsoft Lumia +Microsoft Lumia Microsoft Lumia Microsoft Lumia Microsoft Lumia +Microsoft Lumia Microsoft Lumia Microsoft Lumia Microsoft Lumia +Microsoft Lumia Microsoft Lumia Microsoft Lumia Microsoft Lumia +Microsoft Lumia Microsoft Lumia Microsoft Lumia Microsoft Lumia +Microsoft Lumia Microsoft Lumia Microsoft Lumia Microsoft Lumia +Microsoft Lumia Microsoft Lumia Microsoft Lumia Microsoft Lumia +Microsoft Lumia Microsoft Lumia Microsoft Lumia Microsoft Lumia +Microsoft Lumia Microsoft Lumia Microsoft Lumia Microsoft Lumia + +# Not supported by Materialize. +onlyif cockroach +query TTTT +SELECT + last_value(product_name) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE CURRENT ROW + ), + last_value(product_name) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE GROUP + ), + last_value(product_name) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE TIES + ), + last_value(product_name) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE NO OTHERS + ) +FROM + products +WINDOW + w AS (ORDER BY group_id) +ORDER BY + group_id +---- +NULL NULL Microsoft Lumia Microsoft Lumia +Microsoft Lumia Microsoft Lumia HTC One HTC One +HTC One HTC One Nexus Nexus +Nexus Nexus iPhone iPhone +iPhone iPhone HP Elite HP Elite +HP Elite HP Elite Lenovo Thinkpad Lenovo Thinkpad +Lenovo Thinkpad Lenovo Thinkpad Sony VAIO Sony VAIO +Sony VAIO Sony VAIO Dell Dell +Dell Dell iPad iPad +iPad iPad Kindle Fire Kindle Fire +Kindle Fire Kindle Fire Samsung Samsung + +# Not supported by Materialize. +onlyif cockroach +query TTTT +SELECT + nth_value(product_name, 2) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE CURRENT ROW + ), + nth_value(product_name, 3) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE GROUP + ), + nth_value(product_name, 4) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE TIES + ), + nth_value(product_name, 5) OVER ( + w RANGE UNBOUNDED PRECEDING EXCLUDE NO OTHERS + ) +FROM + products +WINDOW + w AS (ORDER BY group_id) +ORDER BY + group_id +---- +NULL NULL NULL NULL +NULL NULL NULL NULL +HTC One NULL NULL NULL +HTC One Nexus iPhone NULL +HTC One Nexus iPhone HP Elite +HTC One Nexus iPhone HP Elite +HTC One Nexus iPhone HP Elite +HTC One Nexus iPhone HP Elite +HTC One Nexus iPhone HP Elite +HTC One Nexus iPhone HP Elite +HTC One Nexus iPhone HP Elite + +# Test for #32702 statement ok CREATE TABLE x (a INT) @@ -3004,6 +3822,8 @@ CREATE TABLE x (a INT) statement ok INSERT INTO x VALUES (1), (2), (3) +# Not supported by Materialize. +onlyif cockroach query IT SELECT a, json_agg(a) OVER (ORDER BY a) FROM x ORDER BY a ---- @@ -3011,7 +3831,7 @@ SELECT a, json_agg(a) OVER (ORDER BY a) FROM x ORDER BY a 2 [1, 2] 3 [1, 2, 3] -# Test for cockroach#35267 +# Test for #35267 query I SELECT row_number() OVER (PARTITION BY s) @@ -3022,21 +3842,29 @@ FROM 1 1 -# Tests for cockroach#32050 +# Tests for #32050 +# Not supported by Materialize. +onlyif cockroach statement error window function calls cannot be nested SELECT sum(a) OVER (PARTITION BY count(a) OVER ()) FROM x +# Not supported by Materialize. +onlyif cockroach statement error window function calls cannot be nested SELECT sum(a) OVER (ORDER BY count(a) OVER ()) FROM x +# Not supported by Materialize. +onlyif cockroach statement error window function calls cannot be nested SELECT sum(a) OVER (PARTITION BY count(a) OVER () + 1) FROM x +# Not supported by Materialize. +onlyif cockroach statement error window function calls cannot be nested SELECT sum(a) OVER (ORDER BY count(a) OVER () + 1) FROM x -# TODO(justin): blocked by cockroach#37134. +# TODO(justin): blocked by #37134. # statement error more than one row returned by a subquery used as an expression # SELECT sum(a) OVER (PARTITION BY (SELECT count(*) FROM x GROUP BY a)) FROM x @@ -3047,7 +3875,7 @@ SELECT sum(a) OVER (PARTITION BY (SELECT count(*) FROM x GROUP BY a LIMIT 1))::I 6 6 -# Regression test for materialize#27293 - make sure comparing two tuple types when +# Regression test for #27293 - make sure comparing two tuple types when # generating window functions expressions doesn't panic. query II @@ -3059,6 +3887,8 @@ FROM ---- 1 1 +# Not supported by Materialize. +onlyif cockroach query II SELECT min(a) OVER (PARTITION BY (())) AS min, @@ -3068,12 +3898,16 @@ FROM ---- 1 1 +# Not supported by Materialize. +onlyif cockroach query T SELECT string_agg('foo', s) OVER () FROM (SELECT * FROM kv LIMIT 1) ---- foo -# Regression test for cockroach#37201. +# Not supported by Materialize. +onlyif cockroach +# Regression test for #37201. query I SELECT jsonb_agg(a) OVER (ORDER BY a GROUPS BETWEEN 5 FOLLOWING AND UNBOUNDED FOLLOWING) FROM x ---- @@ -3109,13 +3943,15 @@ SELECT avg(c) OVER (ORDER BY c) FROM abc ---- -3.5 1 3.5 2 10 10 10 10 25 20 25 20 -3.5 1.5 3.5 2 10 10 10 10 25 20 25 20 -3.5 2 3.5 2 10 10 10 10 25 20 25 20 +3.5 1 3.5 2 10 10 10 10 25 20 25 20 +3.5 1.5 3.5 2 10 10 10 10 25 20 25 20 +3.5 2 3.5 2 10 10 10 10 25 20 25 20 3.5 2.5 3.5 3.5 10 10 10 10 25 22.5 25 25 -3.5 3 3.5 3.5 10 10 10 10 25 24 25 25 -3.5 3.5 3.5 3.5 10 10 10 10 25 25 25 25 +3.5 3 3.5 3.5 10 10 10 10 25 24 25 25 +3.5 3.5 3.5 3.5 10 10 10 10 25 25 25 25 +# Not supported by Materialize. +onlyif cockroach query TTTTTTTTTTTT rowsort SELECT avg(a) OVER (RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING), @@ -3132,9 +3968,1021 @@ SELECT avg(c) OVER (ORDER BY c RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM abc ---- -3.5 3.5 3.5 3.5 10 10 10 10 25 25 25 25 -3.5 3.5 3.5 3.5 10 10 10 10 25 25 25 25 -3.5 3.5 3.5 3.5 10 10 10 10 25 25 25 25 -3.5 3.5 3.5 3.5 10 10 10 10 25 25 25 25 -3.5 3.5 3.5 3.5 10 10 10 10 25 25 25 25 -3.5 3.5 3.5 3.5 10 10 10 10 25 25 25 25 +3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 +3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 +3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 +3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 +3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 +3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 3.5000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 10.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 25.000000000000000000 + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT array_agg(a) OVER (w RANGE 1 PRECEDING) FROM x WINDOW w AS (ORDER BY a DESC) ORDER BY a +---- +{2,1} +{3,2} +{3} + +statement error Expected one of ROWS or RANGE or GROUPS, found identifier "w" +SELECT array_agg(a) OVER (w GROUPS 1 PRECEDING) FROM x WINDOW w AS (PARTITION BY a) + +# Not supported by Materialize. +onlyif cockroach +query T +SELECT array_agg(a) OVER (w GROUPS 1 PRECEDING) FROM x WINDOW w AS (PARTITION BY a ORDER BY a DESC) ORDER BY a +---- +{1} +{2} +{3} + +# Regression tests for #38103 +statement ok +DROP TABLE IF EXISTS t + +statement ok +CREATE TABLE t (a INT PRIMARY KEY, b INT) + +statement ok +INSERT INTO t VALUES (1, 1), (2, NULL), (3, 3) + +query I +SELECT min(b) OVER () FROM t +---- +1 +1 +1 + +query IIR +SELECT a, b, sum(b) OVER (ROWS 0 PRECEDING) FROM t ORDER BY a +---- +1 1 1 +2 NULL NULL +3 3 3 + +query IIR +SELECT a, b, avg(b) OVER () FROM t ORDER BY a +---- +1 1 2 +2 NULL 2 +3 3 2 + +query IIR +SELECT a, b, avg(b) OVER (ROWS 0 PRECEDING) FROM t ORDER BY a +---- +1 1 1 +2 NULL NULL +3 3 3 + +statement ok +CREATE TABLE wxyz (w INT PRIMARY KEY, x INT, y INT, z INT) + +statement ok +INSERT INTO wxyz VALUES + (1, 10, 1, 1), + (2, 10, 2, 0), + (3, 10, 1, 1), + (4, 10, 2, 0), + (5, 10, 2, 1), + (6, 10, 2, 0) + +# Cases involving interaction between limits and window functions. +query IIIII rowsort +SELECT *, rank() OVER (PARTITION BY z ORDER BY y) FROM wxyz ORDER BY y LIMIT 2 +---- +3 10 1 1 1 +1 10 1 1 1 + +query IIIII rowsort +SELECT *, dense_rank() OVER (PARTITION BY z ORDER BY y) FROM wxyz ORDER BY y LIMIT 2 +---- +3 10 1 1 1 +1 10 1 1 1 + +query IIIIR rowsort +SELECT *, avg(w) OVER (PARTITION BY z ORDER BY y) FROM wxyz ORDER BY y LIMIT 2 +---- +1 10 1 1 2 +3 10 1 1 2 + +query IIIII rowsort +SELECT *, rank() OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY y LIMIT 2 +---- +3 10 1 1 1 +1 10 1 1 1 + +query IIIII rowsort +SELECT *, dense_rank() OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY y LIMIT 2 +---- +3 10 1 1 1 +1 10 1 1 1 + +query IIIIR rowsort +SELECT *, avg(w) OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY y LIMIT 2 +---- +1 10 1 1 1 +3 10 1 1 3 + +query IIIII rowsort +SELECT *, rank() OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY w, y LIMIT 2 +---- +1 10 1 1 1 +2 10 2 0 1 + +query IIIII rowsort +SELECT *, dense_rank() OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY w, y LIMIT 2 +---- +1 10 1 1 1 +2 10 2 0 1 + +query IIIIR rowsort +SELECT *, avg(w) OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY w, y LIMIT 2 +---- +1 10 1 1 1 +2 10 2 0 2 + +query IIIII rowsort +SELECT *, rank() OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY w LIMIT 2 +---- +1 10 1 1 1 +2 10 2 0 1 + +query IIIII rowsort +SELECT *, dense_rank() OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY w LIMIT 2 +---- +1 10 1 1 1 +2 10 2 0 1 + +query IIIIR rowsort +SELECT *, avg(w) OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY w LIMIT 2 +---- +1 10 1 1 1 +2 10 2 0 2 + +query IIIII rowsort +SELECT *, rank() OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY y, w LIMIT 2 +---- +1 10 1 1 1 +3 10 1 1 1 + +query IIIII rowsort +SELECT *, dense_rank() OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY y, w LIMIT 2 +---- +1 10 1 1 1 +3 10 1 1 1 + +query IIIIR rowsort +SELECT *, avg(w) OVER (PARTITION BY w ORDER BY y) FROM wxyz ORDER BY y, w LIMIT 2 +---- +1 10 1 1 1 +3 10 1 1 3 + +query IIIII rowsort +SELECT *, rank() OVER (PARTITION BY w, z ORDER BY y) FROM wxyz ORDER BY w, z, y LIMIT 2 +---- +1 10 1 1 1 +2 10 2 0 1 + +query IIIII rowsort +SELECT *, dense_rank() OVER (PARTITION BY w, z ORDER BY y) FROM wxyz ORDER BY w, z, y LIMIT 2 +---- +1 10 1 1 1 +2 10 2 0 1 + +query IIIIR rowsort +SELECT *, avg(w) OVER (PARTITION BY w, z ORDER BY y) FROM wxyz ORDER BY w, z, y LIMIT 2 +---- +1 10 1 1 1 +2 10 2 0 2 + +query IIIII rowsort +SELECT *, rank() OVER (PARTITION BY w, z ORDER BY y) FROM wxyz ORDER BY z, w, y LIMIT 2 +---- +2 10 2 0 1 +4 10 2 0 1 + +query IIIII rowsort +SELECT *, dense_rank() OVER (PARTITION BY w, z ORDER BY y) FROM wxyz ORDER BY z, w, y LIMIT 2 +---- +2 10 2 0 1 +4 10 2 0 1 + +query IIIIR rowsort +SELECT *, avg(w) OVER (PARTITION BY w, z ORDER BY y) FROM wxyz ORDER BY z, w, y LIMIT 2 +---- +2 10 2 0 2 +4 10 2 0 4 + +statement OK +CREATE TABLE string_agg_test ( + id INT PRIMARY KEY, + company_id INT, + employee STRING +) + +statement OK +INSERT INTO string_agg_test VALUES + (1, 1, 'A'), + (2, 2, 'B'), + (3, 3, 'C'), + (4, 4, 'D'), + (5, 3, 'C'), + (6, 4, 'D'), + (7, 4, 'D'), + (8, 4, 'D'), + (9, 3, 'C'), + (10, 2, 'B') + +query IT colnames +SELECT company_id, string_agg(employee, ',') +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 A +2 B +2 B,B +3 C +3 C,C +3 C,C,C +4 D +4 D,D +4 D,D,D +4 D,D,D,D + +# Not supported by Materialize. +onlyif cockroach +query IT colnames +SELECT company_id, string_agg(employee::BYTES, b',') +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 A +2 B +2 B,B +3 C +3 C,C +3 C,C,C +4 D +4 D,D +4 D,D,D +4 D,D,D,D + +query IT colnames +SELECT company_id, string_agg(employee, '') +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 A +2 B +2 BB +3 C +3 CC +3 CCC +4 D +4 DD +4 DDD +4 DDDD + +# Not supported by Materialize. +onlyif cockroach +query IT colnames +SELECT company_id, string_agg(employee::BYTES, b'') +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 A +2 B +2 BB +3 C +3 CC +3 CCC +4 D +4 DD +4 DDD +4 DDDD + +query IT colnames +SELECT company_id, string_agg(employee, NULL) +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 A +2 B +2 BB +3 C +3 CC +3 CCC +4 D +4 DD +4 DDD +4 DDDD + +# Not supported by Materialize. +onlyif cockroach +query IT colnames +SELECT company_id, string_agg(employee::BYTES, NULL) +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 A +2 B +2 BB +3 C +3 CC +3 CCC +4 D +4 DD +4 DDD +4 DDDD + +query IT colnames +SELECT company_id, string_agg(NULL::STRING, employee) +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 NULL +2 NULL +2 NULL +3 NULL +3 NULL +3 NULL +4 NULL +4 NULL +4 NULL +4 NULL + +# Not supported by Materialize. +onlyif cockroach +query IT colnames +SELECT company_id, string_agg(NULL::BYTES, employee::BYTES) +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 NULL +2 NULL +2 NULL +3 NULL +3 NULL +3 NULL +4 NULL +4 NULL +4 NULL +4 NULL + +query IT colnames +SELECT company_id, string_agg(NULL::STRING, NULL) +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 NULL +2 NULL +2 NULL +3 NULL +3 NULL +3 NULL +4 NULL +4 NULL +4 NULL +4 NULL + +# Not supported by Materialize. +onlyif cockroach +query IT colnames +SELECT company_id, string_agg(NULL::BYTES, NULL) +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 NULL +2 NULL +2 NULL +3 NULL +3 NULL +3 NULL +4 NULL +4 NULL +4 NULL +4 NULL + +query IT colnames +SELECT company_id, string_agg(NULL, NULL::STRING) +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 NULL +2 NULL +2 NULL +3 NULL +3 NULL +3 NULL +4 NULL +4 NULL +4 NULL +4 NULL + +# Not supported by Materialize. +onlyif cockroach +query IT colnames +SELECT company_id, string_agg(NULL, NULL::BYTES) +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 NULL +2 NULL +2 NULL +3 NULL +3 NULL +3 NULL +4 NULL +4 NULL +4 NULL +4 NULL + +# Not supported by Materialize. +onlyif cockroach +query error pq: ambiguous call: string_agg\(unknown, unknown\) +SELECT company_id, string_agg(NULL, NULL) +OVER (PARTITION BY company_id ORDER BY id) +FROM string_agg_test +ORDER BY company_id, id; + +query IT colnames +SELECT company_id, string_agg(employee, lower(employee)) +OVER (PARTITION BY company_id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 A +2 BbB +2 BbB +3 CcCcC +3 CcCcC +3 CcCcC +4 DdDdDdD +4 DdDdDdD +4 DdDdDdD +4 DdDdDdD + +query IT colnames +SELECT company_id, string_agg(lower(employee), employee) +OVER (PARTITION BY company_id) +FROM string_agg_test +ORDER BY company_id, id; +---- +company_id string_agg +1 a +2 bBb +2 bBb +3 cCcCc +3 cCcCc +3 cCcCc +4 dDdDdDd +4 dDdDdDd +4 dDdDdDd +4 dDdDdDd + +statement error function string_agg\(text, text, text\) does not exist +SELECT company_id, string_agg(employee, employee, employee) +OVER (PARTITION BY company_id) +FROM string_agg_test +ORDER BY company_id, id; + +query error function string_agg\(text\) does not exist +SELECT company_id, string_agg(employee) +OVER (PARTITION BY company_id) +FROM string_agg_test +ORDER BY company_id, id; + +query error function string_agg\(text, unknown, text, unknown\) does not exist +SELECT company_id, string_agg(employee, 'foo', employee, 'bar') +OVER (PARTITION BY company_id) +FROM string_agg_test +ORDER BY company_id, id; + +statement OK +DROP TABLE string_agg_test + +# Test that windower respects the memory limit set via the session variable. +statement ok +SET distsql_workmem='200KB' + +statement ok +CREATE TABLE l (a INT PRIMARY KEY) + +statement ok +INSERT INTO l SELECT g FROM generate_series(0,10000) g(g) + +# Not supported by Materialize. +onlyif cockroach +statement error memory budget exceeded +SELECT array_agg(a) OVER () FROM l LIMIT 1 + +statement ok +RESET distsql_workmem + +# Regression test for #38901 verifying that window frame takes precedence over +# the concept of peers. +query I +SELECT count(a) OVER (ROWS 1 PRECEDING) FROM t +---- +1 +2 +2 + +statement ok +CREATE TABLE t38901 (a INT PRIMARY KEY); INSERT INTO t38901 VALUES (1), (2), (3) + +query T +SELECT array_agg(a) OVER (ORDER BY a ROWS BETWEEN 2 PRECEDING AND 1 PRECEDING) FROM t38901 ORDER BY a +---- +NULL +{1} +{1,2} + +# Regression test for #42935. +query IIIII +SELECT + a, + b, + count(*) OVER (ORDER BY b), + count(*) OVER ( + ORDER BY + b + RANGE + BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW + ), + count(*) OVER ( + ORDER BY + b + ROWS + BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW + ) +FROM + (VALUES (1, 1), (2, 1), (3, 2), (4, 2)) AS t (a, b) +ORDER BY + a, b +---- +1 1 2 2 1 +2 1 2 2 2 +3 2 4 4 3 +4 2 4 4 4 + +# Not supported by Materialize. +onlyif cockroach +query IIIRRTBTTTTTTTTT +SELECT + *, + array_agg(v) OVER (wv RANGE BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING), + array_agg(v) OVER (wv RANGE BETWEEN 0 PRECEDING AND 1 PRECEDING), + array_agg(f) OVER (wf RANGE BETWEEN UNBOUNDED PRECEDING AND -0.0 PRECEDING), + array_agg(f) OVER (wf RANGE BETWEEN 0.0 PRECEDING AND 1.0 PRECEDING), + array_agg(d) OVER (wd RANGE BETWEEN 0.0 FOLLOWING AND 0.0 FOLLOWING), + array_agg(d) OVER (wd RANGE BETWEEN 1.0 FOLLOWING AND UNBOUNDED FOLLOWING), + array_agg(i) OVER (wi RANGE BETWEEN '1s'::INTERVAL PRECEDING AND '0s'::INTERVAL PRECEDING), + array_agg(i) OVER (wi RANGE BETWEEN '1s'::INTERVAL FOLLOWING AND '1s'::INTERVAL FOLLOWING) +FROM + kv +WINDOW + wv AS (ORDER BY v DESC), + wf AS (ORDER BY f), + wd AS (ORDER BY d DESC), + wi AS (ORDER BY i) +ORDER BY + k +---- +1 2 3 1 1 a true 00:01:00 {4,4,4,2,2,2,2} NULL {0.1,0.2,0.3,1} NULL {1} {-321,NULL,NULL,NULL} {00:01:00} NULL +3 4 5 2 8 a true 00:00:02 {4,4,4} NULL {0.1,0.2,0.3,1,2} NULL {8} {4.4,3,1,-321,NULL,NULL,NULL} {00:00:02} NULL +5 NULL 5 9.9 -321 NULL false NULL {4,4,4,2,2,2,2,NULL,NULL} {NULL,NULL} {0.1,0.2,0.3,1,2,3,4.4,6,9.9} NULL {-321} {NULL,NULL,NULL} {NULL,NULL,NULL,NULL} {NULL,NULL,NULL,NULL} +6 2 3 4.4 4.4 b true 00:00:00.001 {4,4,4,2,2,2,2} NULL {0.1,0.2,0.3,1,2,3,4.4} NULL {4.4} {3,1,-321,NULL,NULL,NULL} {00:00:00.001} NULL +7 2 2 6 7.9 b true 4 days {4,4,4,2,2,2,2} NULL {0.1,0.2,0.3,1,2,3,4.4,6} NULL {7.9} {4.4,3,1,-321,NULL,NULL,NULL} {"4 days"} NULL +8 4 2 3 3 A false 3 years {4,4,4} NULL {0.1,0.2,0.3,1,2,3} NULL {3} {1,-321,NULL,NULL,NULL} {"3 years"} NULL +9 2 9 0.1 NULL NULL NULL NULL {4,4,4,2,2,2,2} NULL {0.1} NULL {NULL,NULL,NULL} {NULL,NULL,NULL} {NULL,NULL,NULL,NULL} {NULL,NULL,NULL,NULL} +10 4 9 0.2 NULL NULL NULL NULL {4,4,4} NULL {0.1,0.2} NULL {NULL,NULL,NULL} {NULL,NULL,NULL} {NULL,NULL,NULL,NULL} {NULL,NULL,NULL,NULL} +11 NULL 9 0.3 NULL NULL NULL NULL {4,4,4,2,2,2,2,NULL,NULL} {NULL,NULL} {0.1,0.2,0.3} NULL {NULL,NULL,NULL} {NULL,NULL,NULL} {NULL,NULL,NULL,NULL} {NULL,NULL,NULL,NULL} + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #43083 (CBO optimizing out the single column from ORDER +# BY clause which led to a crash in the execution engine). +query IIIRRTBTTTTTTTTT +SELECT + *, + array_agg(v) OVER (wv RANGE BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING), + array_agg(v) OVER (wv RANGE BETWEEN 0 PRECEDING AND 1 PRECEDING), + array_agg(f) OVER (wf RANGE BETWEEN UNBOUNDED PRECEDING AND -0.0 PRECEDING), + array_agg(f) OVER (wf RANGE BETWEEN 0.0 PRECEDING AND 1.0 PRECEDING), + array_agg(d) OVER (wd RANGE BETWEEN 0.0 FOLLOWING AND 0.0 FOLLOWING), + array_agg(d) OVER (wd RANGE BETWEEN 1.0 FOLLOWING AND UNBOUNDED FOLLOWING), + array_agg(i) OVER (wi RANGE BETWEEN '1s'::INTERVAL PRECEDING AND '0s'::INTERVAL PRECEDING), + array_agg(i) OVER (wi RANGE BETWEEN '1s'::INTERVAL FOLLOWING AND '1s'::INTERVAL FOLLOWING) +FROM + kv +WINDOW + wv AS (PARTITION BY v ORDER BY v), + wf AS (PARTITION BY f ORDER BY f DESC), + wd AS (PARTITION BY d ORDER BY d), + wi AS (PARTITION BY i ORDER BY i DESC) +ORDER BY + k +---- +1 2 3 1 1 a true 00:01:00 {2,2,2,2} NULL {1} NULL {1} NULL {00:01:00} NULL +3 4 5 2 8 a true 00:00:02 {4,4,4} NULL {2} NULL {8} NULL {00:00:02} NULL +5 NULL 5 9.9 -321 NULL false NULL {NULL,NULL} {NULL,NULL} {9.9} NULL {-321} NULL {NULL,NULL,NULL,NULL} {NULL,NULL,NULL,NULL} +6 2 3 4.4 4.4 b true 00:00:00.001 {2,2,2,2} NULL {4.4} NULL {4.4} NULL {00:00:00.001} NULL +7 2 2 6 7.9 b true 4 days {2,2,2,2} NULL {6} NULL {7.9} NULL {"4 days"} NULL +8 4 2 3 3 A false 3 years {4,4,4} NULL {3} NULL {3} NULL {"3 years"} NULL +9 2 9 0.1 NULL NULL NULL NULL {2,2,2,2} NULL {0.1} NULL {NULL,NULL,NULL} {NULL,NULL,NULL} {NULL,NULL,NULL,NULL} {NULL,NULL,NULL,NULL} +10 4 9 0.2 NULL NULL NULL NULL {4,4,4} NULL {0.2} NULL {NULL,NULL,NULL} {NULL,NULL,NULL} {NULL,NULL,NULL,NULL} {NULL,NULL,NULL,NULL} +11 NULL 9 0.3 NULL NULL NULL NULL {NULL,NULL} {NULL,NULL} {0.3} NULL {NULL,NULL,NULL} {NULL,NULL,NULL} {NULL,NULL,NULL,NULL} {NULL,NULL,NULL,NULL} + +# Not supported by Materialize. +onlyif cockroach +# Check that telemetry is being collected on the window functions' usage. +query B +SELECT count(*) >= 26 FROM crdb_internal.feature_usage WHERE feature_name LIKE 'sql.plan.window_function%' AND usage_count > 0 +---- +true + +# Not supported by Materialize. +onlyif cockroach +# Regression test for peer group number computation overflow (#53654). +query II rowsort +SELECT + max(k) OVER (w GROUPS BETWEEN 9223372036854775807 FOLLOWING AND UNBOUNDED FOLLOWING), + max(k) OVER (w GROUPS BETWEEN UNBOUNDED PRECEDING AND 9223372036854775807 FOLLOWING) +FROM kv WINDOW w AS (PARTITION BY b ORDER BY v) +---- +NULL 11 +NULL 11 +NULL 11 +NULL 8 +NULL 8 +NULL 7 +NULL 7 +NULL 7 +NULL 7 + +# Regression test for #53442. Ordering columns are not pruned with RANGE mode +# and an offset boundary of PRECEDING or FOLLOWING. + +statement ok +CREATE TABLE t53442_a (a INT8 PRIMARY KEY); +CREATE TABLE t53442_b (b INT2 PRIMARY KEY); + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT max(b::INT8) OVER (PARTITION BY b ORDER BY b RANGE 1 PRECEDING) +FROM t53442_b NATURAL JOIN t53442_a +WHERE false + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT max(b::INT8) OVER (PARTITION BY b ORDER BY a RANGE 1 PRECEDING) +FROM t53442_b NATURAL JOIN t53442_a +WHERE false + +# Regression test for a crash with json_object_agg used as a window function +# (#54604). +statement ok +CREATE TABLE t54604 (s STRING); +INSERT INTO t54604 SELECT g::STRING FROM generate_series(1, 5) AS g + +# Not supported by Materialize. +onlyif cockroach +query T rowsort +SELECT json_object_agg(s, s) OVER (ORDER BY s DESC) FROM t54604 +---- +{"1": "1", "2": "2", "3": "3", "4": "4", "5": "5"} +{"2": "2", "3": "3", "4": "4", "5": "5"} +{"3": "3", "4": "4", "5": "5"} +{"4": "4", "5": "5"} +{"5": "5"} + +# database-issues#7085 (https://github.com/MaterializeInc/database-issues/issues/7085): +# Materialize's jsonb text output omits the spaces PG inserts after ':' and ','. +# PG/CRDB render "{"1": "1", "2": "2", ...}" (see the json_object_agg variant above). +query T rowsort +SELECT jsonb_object_agg(s, s) OVER (ORDER BY s RANGE UNBOUNDED PRECEDING) FROM t54604 +---- +{"1":"1","2":"2","3":"3","4":"4","5":"5"} +{"1":"1","2":"2","3":"3","4":"4"} +{"1":"1","2":"2","3":"3"} +{"1":"1","2":"2"} +{"1":"1"} + +# Regression test for window aggregate functions not making a deep copy of decimals on each iteration (#55944). +statement ok +CREATE TABLE t55944 (x decimal); +INSERT INTO t55944 (x) +VALUES (1.0), + (20.0), + (25.0), + (41.0), + (55.5), + (60.9), + (72.0), + (88.0), + (88.0), + (89.0); + +# Not supported by Materialize. +onlyif cockroach +query RFFFFF +SELECT x, + sqrdiff(x) OVER (ORDER BY x) as sqrdiff, + var_pop(x) OVER (ORDER BY x) as var_pop, + var_samp(x) OVER (ORDER BY x) as var_samp, + stddev_pop(x) OVER (ORDER BY x) as stddev_pop, + stddev_samp(x) OVER (ORDER BY x) as stddev_samp +FROM t55944 +ORDER BY x +---- +1.0 0 0 NULL 0 NULL +20.0 180.5 90.25 180.5 9.5 13.435028842544402964 +25.0 320.6666666666666666666667 106.88888888888888889 160.33333333333333333 10.338708279513881752 12.662279942148385993 +41.0 814.7500000000000000000001 203.6875 271.58333333333333333 14.271912976192084391 16.479785597310825856 +55.5 1726 345.2 431.5 18.579558659989746915 20.772578077840988103 +60.9 2600.8 433.46666666666666667 520.16 20.819862311424316109 22.807016464237491316 +72.0 3845.037142857142857142857 549.29102040816326531 640.83952380952380952 23.436958429117103874 25.314808389745394427 +88.0 7527.842222222222222222222 836.42691358024691358 940.98027777777777778 28.921046204801217626 30.675401835636607970 +88.0 7527.842222222222222222222 836.42691358024691358 940.98027777777777778 28.921046204801217626 30.675401835636607970 +89.0 8885.844 888.5844 987.316 29.809132828715430446 31.421584937746218024 + +# Regression test for #64793. The output bytes column should not have decreasing +# offsets. +statement ok +CREATE TABLE t64793 (b TEXT) + +statement ok +INSERT INTO t64793 VALUES +('alpha'), +(NULL::TEXT) + +query T +SELECT lag(b, 0) OVER (ORDER BY b DESC) FROM t64793 ORDER BY b +---- +alpha +NULL + +# Regression tests for integer overflow when computing window frame boundaries +# for ROWS mode (#65978). +statement ok +CREATE TABLE t65978 (c INT); +INSERT INTO t65978 VALUES (1), (2); + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT max(c) OVER (ROWS BETWEEN 9223372036854775807::INT8 FOLLOWING AND UNBOUNDED FOLLOWING) FROM t65978 +---- +NULL +NULL + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT max(c) OVER (ORDER BY c ROWS BETWEEN UNBOUNDED PRECEDING AND 9223372036854775807::INT8 FOLLOWING) FROM t65978 +---- +2 +2 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT max(c) OVER (ROWS BETWEEN 9223372036854775807::INT8 PRECEDING AND UNBOUNDED FOLLOWING) FROM t65978 +---- +2 +2 + +# Not supported by Materialize. +onlyif cockroach +query I +SELECT max(c) OVER (ORDER BY c ROWS BETWEEN UNBOUNDED PRECEDING AND 9223372036854775807::INT8 PRECEDING) FROM t65978 +---- +NULL +NULL + +# Not supported by Materialize. +onlyif cockroach +# Regression test for out-of-range error when computing window frame end index +# for GROUPS mode with OFFSET PRECEDING (#66580). +query II +SELECT k, first_value(k) OVER (ORDER BY v GROUPS BETWEEN 0 PRECEDING AND 2 PRECEDING) FROM kv ORDER BY 1 +---- +1 NULL +3 NULL +5 NULL +6 NULL +7 NULL +8 NULL +9 NULL +10 NULL +11 NULL + +# Not supported by Materialize. +onlyif cockroach +# Regression test for incorrectly choosing NULL values as the minimum when +# EXCLUDE clause is non-default (#68024). +query I rowsort +SELECT min(x) +OVER +( + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + EXCLUDE CURRENT ROW +) +FROM (VALUES (NULL::INT), (NULL::INT), (1)) v(x); +---- +1 +1 +NULL + +# Regression test for panic during comparison for RANGE mode with +# OFFSET PRECEDING or OFFSET FOLLOWING (#67975). +statement ok +DROP TABLE IF EXISTS t; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t (x DATE); +INSERT INTO t VALUES ('5874897-01-01'::DATE), ('1999-01-08'::DATE); +SET vectorize=off; + +# Not supported by Materialize. +onlyif cockroach +query error timestamp "5874897-01-01T00:00:00Z" exceeds supported timestamp bounds +SELECT first_value(x) OVER (ORDER BY x RANGE BETWEEN CURRENT ROW AND '0 YEAR'::INTERVAL FOLLOWING) FROM t; + +statement ok +RESET vectorize; + +# Regression test for incorrect results for min and max when the window frame +# shrinks. +statement ok +DROP TABLE IF EXISTS t; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t (a INT); +INSERT INTO t VALUES (1), (-1), (NULL); +SET vectorize=off; + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT a, max(a) OVER w, min(a) OVER w FROM t +WINDOW w AS (ORDER BY a DESC RANGE BETWEEN 10 PRECEDING AND UNBOUNDED FOLLOWING); +---- +1 1 -1 +-1 1 -1 +NULL NULL NULL + +statement ok +RESET vectorize; + +# Regression test for incorrect bytes results when spilling to disk when there +# are multiple partitions and one of the earlier partitions has trailing NULL +# values. +statement ok +DROP TABLE IF EXISTS t; + +statement ok +CREATE TABLE t (x INT, y STRING); +INSERT INTO t VALUES (1, 'NotNull'), (1, NULL), (1, NULL), +(2, 'NotNull'), (2, 'NotNull'), (2, 'NotNull'), (2, 'NotNull'); + +# Loading a batch with trailing nulls onto disk and then unloading it to +# continue processing should not corrupt the output bytes. +query ITT rowsort +SELECT x, y, first_value(y) OVER (PARTITION BY x ROWS BETWEEN CURRENT ROW AND CURRENT ROW) FROM t; +---- +1 NotNull NotNull +1 NULL NULL +1 NULL NULL +2 NotNull NotNull +2 NotNull NotNull +2 NotNull NotNull +2 NotNull NotNull + +# Not supported by Materialize. +onlyif cockroach +# Regression test for incorrect type schema setup in the vectorized engine with +# multiple window functions (#74087). +statement ok +CREATE TABLE t74087 AS + SELECT + g::INT2 AS _int2, g::INT4 AS _int4 + FROM + ROWS FROM (generate_series(1, 5)) AS g; + +# Not supported by Materialize. +onlyif cockroach +query IIIIIIIIIRRI rowsort +SELECT + lag(_int2, _int4, _int2) OVER w, + lead(_int4, _int2, _int4) OVER w, + first_value(_int2) OVER w, + last_value(_int4) OVER w, + nth_value(_int2, _int4) OVER w, + min(_int4) OVER w, + row_number() OVER w, + rank() OVER w, + dense_rank() OVER w, + percent_rank() OVER w, + cume_dist() OVER w, + ntile(_int2) OVER w +FROM t74087 WINDOW w AS (ORDER BY _int4); +---- +1 2 1 1 1 1 1 1 1 0 0.2 1 +2 4 1 2 2 1 2 2 2 0.25 0.4 1 +3 3 1 3 3 1 3 3 3 0.5 0.6 1 +4 4 1 4 4 1 4 4 4 0.75 0.8 1 +5 5 1 5 5 1 5 5 5 1 1 1 + +# Regression test for panic in the vectorized engine when the first and third +# arguments of lead or lag are different (but castable) types (#81285). +query I +SELECT lead(x, 10, y::INT4) OVER () FROM (VALUES (1, 2)) v(x, y); +---- +2 + +# Not supported by Materialize. +onlyif cockroach +# Regression test for incorrectly ignoring NULLS LAST in window functions (#91295). +statement ok +CREATE TABLE nulls_last_test ( + id INT NULL +); +INSERT INTO nulls_last_test VALUES + (1), + (2), + (null), + (3); + +# Not supported by Materialize. +onlyif cockroach +query III +SELECT + id, + row_number() OVER (ORDER BY id NULLS LAST) AS row_num_using_nulls_last, + row_number() OVER (ORDER BY COALESCE(id, 999)) AS row_num_using_coalesce +FROM + nulls_last_test +ORDER BY + id NULLS LAST +---- +1 1 1 +2 2 2 +3 3 3 +NULL 4 4 + +statement ok +SET null_ordered_last = true + +# Not supported by Materialize. +onlyif cockroach +# We should get the same result using the session variable. +query III +SELECT + id, + row_number() OVER (ORDER BY id) AS row_num_using_nulls_last, + row_number() OVER (ORDER BY COALESCE(id, 999)) AS row_num_using_coalesce +FROM + nulls_last_test +ORDER BY + id +---- +1 1 1 +2 2 2 +3 3 3 +NULL 4 4 + +statement ok +RESET null_ordered_last diff --git a/test/sqllogictest/cockroach/with.slt b/test/sqllogictest/cockroach/with.slt index 1c2e92aefb2c3..6497ace66374e 100644 --- a/test/sqllogictest/cockroach/with.slt +++ b/test/sqllogictest/cockroach/with.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,43 +9,47 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/with +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/with # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach -query error table name "a" specified more than once -WITH a AS (SELECT 1) SELECT * FROM a CROSS JOIN a - -statement ok -CREATE TABLE x (a int) - +# Not supported by Materialize. +onlyif cockroach statement ok -INSERT INTO x VALUES (1), (2), (3) +CREATE TABLE x(a) AS SELECT generate_series(1, 3) +# Not supported by Materialize. +onlyif cockroach statement ok -CREATE TABLE y (a int) - -statement ok -INSERT INTO y VALUES (2), (3), (4) +CREATE TABLE y(a) AS SELECT generate_series(2, 4) +# Not supported by Materialize. +onlyif cockroach query I rowsort WITH t AS (SELECT a FROM y WHERE a < 3) SELECT * FROM x NATURAL JOIN t ---- 2 +# Not supported by Materialize. +onlyif cockroach query I WITH t AS (SELECT * FROM y WHERE a < 3) SELECT * FROM x NATURAL JOIN t ---- 2 +# Not supported by Materialize. +onlyif cockroach # Using a CTE inside a subquery query I rowsort WITH t(x) AS (SELECT a FROM x) @@ -54,6 +58,8 @@ WITH t(x) AS (SELECT a FROM x) 2 3 +# Not supported by Materialize. +onlyif cockroach # Using a subquery inside a CTE query I SELECT * FROM x WHERE a IN @@ -61,6 +67,8 @@ SELECT * FROM x WHERE a IN ---- 2 +# Not supported by Materialize. +onlyif cockroach # Rename columns query II rowsort WITH t(b) AS (SELECT a FROM x) SELECT b, t.b FROM t @@ -81,17 +89,20 @@ WITH t(b, a) AS (SELECT true a, false b) ---- false true +statement error Expected SELECT, VALUES, or a subquery in the query body, found INSERT +SELECT (WITH foo AS (INSERT INTO y VALUES (1) RETURNING *) SELECT * FROM foo) + statement error WITH query name "t" specified more than once WITH t AS (SELECT true), t AS (SELECT false) SELECT * FROM t -query error CTE t definition names 2 columns, but CTE t has 1 column +query error unknown catalog item 'x' WITH t(b, c) AS (SELECT a FROM x) SELECT b, t.b FROM t # Ensure you can't reference the original table name -query error column "x.t" does not exist +query error unknown catalog item 'x' WITH t AS (SELECT a FROM x) SELECT a, x.t FROM t # Nested WITH, name shadowing @@ -100,14 +111,15 @@ WITH t(x) AS (WITH t(x) AS (SELECT 1) SELECT x * 10 FROM t) SELECT x + 2 FROM t ---- 12 -# not supported yet -halt - # CTEs with DMLs +# Not supported by Materialize. +onlyif cockroach query error pgcode 42P01 relation "t" does not exist WITH t AS (SELECT * FROM x) INSERT INTO t VALUES (1) +# Not supported by Materialize. +onlyif cockroach query I rowsort WITH t AS (SELECT a FROM x) INSERT INTO x SELECT a + 20 FROM t RETURNING * ---- @@ -115,6 +127,8 @@ WITH t AS (SELECT a FROM x) INSERT INTO x SELECT a + 20 FROM t RETURNING * 22 23 +# Not supported by Materialize. +onlyif cockroach query I rowsort SELECT * from x ---- @@ -125,6 +139,8 @@ SELECT * from x 22 23 +# Not supported by Materialize. +onlyif cockroach query I rowsort WITH t AS ( UPDATE x SET a = a * 100 RETURNING a @@ -138,6 +154,8 @@ SELECT * FROM t 2200 2300 +# Not supported by Materialize. +onlyif cockroach query I rowsort SELECT * from x ---- @@ -148,6 +166,8 @@ SELECT * from x 2200 2300 +# Not supported by Materialize. +onlyif cockroach query I rowsort WITH t AS ( DELETE FROM x RETURNING a @@ -161,59 +181,28 @@ SELECT * FROM t 2200 2300 +# Not supported by Materialize. +onlyif cockroach query I rowsort SELECT * from x ---- -# materialize#22420: ensure okay error message for CTE clause without output columns -query error WITH clause "t" does not have a RETURNING clause +# Not supported by Materialize. +onlyif cockroach +# #22420: ensure okay error message for CTE clause without output columns +query error WITH clause "t" does not return any columns WITH t AS ( INSERT INTO x(a) VALUES(0) ) SELECT * FROM t -# Regression test for materialize#24307 until CockroachDB learns how to execute -# side effects no matter what. -query error unimplemented: common table expression "t" with side effects was not used in query -WITH t AS ( - INSERT INTO x(a) VALUES(0) RETURNING a -) -SELECT 1 - -query error unimplemented: common table expression "t" with side effects was not used in query -WITH t AS ( - SELECT * FROM ( - WITH b AS (INSERT INTO x(a) VALUES(0) RETURNING a) - TABLE b - ) -) -SELECT 1 - -query error unimplemented: common table expression "t" with side effects was not used in query -WITH t AS ( - DELETE FROM x RETURNING a -) -SELECT 1 - -query error unimplemented: common table expression "t" with side effects was not used in query -WITH t AS ( - UPSERT INTO x(a) VALUES(0) RETURNING a -) -SELECT 1 - -query error unimplemented: common table expression "t" with side effects was not used in query -WITH t AS ( - UPDATE x SET a = 0 RETURNING a -) -SELECT 1 - # however if there are no side effects, no errors are required. query I WITH t AS (SELECT 1) SELECT 2 ---- 2 -# Regression tests for materialize#24303. +# Regression tests for #24303. statement ok CREATE TABLE a(x INT); @@ -226,23 +215,31 @@ statement count 1 INSERT INTO a(x) (WITH a(z) AS (VALUES (1)) SELECT z+1 AS w FROM a); -# When materialize#24303 is fixed, the following query should succeed. +# Not supported by Materialize. +onlyif cockroach +# When #24303 is fixed, the following query should succeed. query error unimplemented: multiple WITH clauses in parentheses (WITH woo AS (VALUES (1)) (WITH waa AS (VALUES (2)) TABLE waa)) -# When materialize#24303 is fixed, the following query should fail with +# Not supported by Materialize. +onlyif cockroach +# When #24303 is fixed, the following query should fail with # error "no such relation woo". query error unimplemented: multiple WITH clauses in parentheses (WITH woo AS (VALUES (1)) (WITH waa AS (VALUES (2)) TABLE woo)) +# Not supported by Materialize. +onlyif cockroach statement ok CREATE TABLE lim(x) AS SELECT 0 +# Not supported by Materialize. +onlyif cockroach # This is an oddity in PostgreSQL: even though the WITH clause # occurs in the inside parentheses, the scope of the alias `lim` # extends to the outer parentheses. @@ -257,11 +254,1277 @@ query I ---- 123 +# Not supported by Materialize. +onlyif cockroach # Ditto if table `lim` did not even exist. statement ok DROP TABLE lim +# Not supported by Materialize. +onlyif cockroach query I ((WITH lim(x) AS (SELECT 1) SELECT 123) LIMIT (SELECT x FROM lim)) ---- 123 + +# CTE with an ORDER BY. + +statement ok +CREATE TABLE ab (a INT PRIMARY KEY, b INT) + +statement ok +INSERT INTO ab VALUES (1, 2), (3, 4), (5, 6) + +query I rowsort +WITH a AS (SELECT a FROM ab ORDER BY b) SELECT * FROM a +---- +1 +3 +5 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE x2(a) AS SELECT generate_series(1, 3) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE y2(b) AS SELECT generate_series(2, 4) + +# Not supported by Materialize. +onlyif cockroach +# Referencing a CTE multiple times. +query II rowsort +WITH t AS (SELECT b FROM y2) SELECT * FROM t JOIN t AS q ON true +---- +2 2 +2 3 +2 4 +3 2 +3 3 +3 4 +4 2 +4 3 +4 4 + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +WITH + one AS (SELECT a AS u FROM x2), + two AS (SELECT b AS v FROM (SELECT b FROM y2 UNION ALL SELECT u FROM one)) +SELECT + * +FROM + one JOIN two ON u = v +---- +1 1 +2 2 +3 3 +2 2 +3 3 + +# Mutation CTEs that aren't referenced elsewhere in the query. +statement ok +CREATE TABLE z (c INT PRIMARY KEY); + +# Not supported by Materialize. +onlyif cockroach +query I +WITH foo AS (INSERT INTO z VALUES (10) RETURNING 1) SELECT 2 +---- +2 + +query I +SELECT * FROM z +---- + + +# Not supported by Materialize. +onlyif cockroach +query I +WITH foo AS (UPDATE z SET c = 20 RETURNING 1) SELECT 3 +---- +3 + +query I +SELECT * FROM z +---- + + +# Not supported by Materialize. +onlyif cockroach +query I +WITH foo AS (DELETE FROM z RETURNING 1) SELECT 4 +---- +4 + +query I +SELECT count(*) FROM z +---- +0 + +# WITH and prepared statements. + +statement ok +CREATE TABLE engineer ( + fellow BOOL NOT NULL, id INT4 NOT NULL, companyname VARCHAR(255) NOT NULL, + PRIMARY KEY (id, companyname) +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +PREPARE x (INT4, VARCHAR, INT4, VARCHAR) AS + WITH ht_engineer (id, companyname) AS ( + SELECT id, companyname FROM (VALUES ($1, $2), ($3, $4)) AS ht (id, companyname) + ) +DELETE FROM engineer WHERE (id, companyname) IN (SELECT id, companyname FROM ht_engineer) + +# Not supported by Materialize. +onlyif cockroach +statement ok +EXECUTE x (1, 'fo', 2, 'bar') + +# Not supported by Materialize. +onlyif cockroach +statement ok +PREPARE z(int) AS WITH foo AS (SELECT * FROM x2 WHERE a = $1) SELECT * FROM foo + +# Not supported by Materialize. +onlyif cockroach +query I +EXECUTE z(1) +---- +1 + +# Not supported by Materialize. +onlyif cockroach +query I +EXECUTE z(2) +---- +2 + +# Not supported by Materialize. +onlyif cockroach +query I +EXECUTE z(3) +---- +3 + +# WITH containing a placeholder that isn't referenced. + +# Not supported by Materialize. +onlyif cockroach +statement ok +PREPARE z2(int) AS WITH foo AS (SELECT * FROM x WHERE a = $1) SELECT * FROM x2 ORDER BY a + +# Not supported by Materialize. +onlyif cockroach +query I +EXECUTE z2(1) +---- +1 +2 +3 + +# Not supported by Materialize. +onlyif cockroach +statement ok +PREPARE z3(int) AS WITH foo AS (SELECT $1) SELECT * FROM foo + +# Not supported by Materialize. +onlyif cockroach +query I +EXECUTE z3(3) +---- +3 + +# Not supported by Materialize. +onlyif cockroach +statement ok +PREPARE z4(int) AS WITH foo AS (SELECT $1), bar AS (SELECT * FROM foo) SELECT * FROM bar + +# Not supported by Materialize. +onlyif cockroach +query I +EXECUTE z4(3) +---- +3 + +# Not supported by Materialize. +onlyif cockroach +statement ok +PREPARE z5(int, int) AS WITH foo AS (SELECT $1), bar AS (SELECT $2) (SELECT * FROM foo) UNION ALL (SELECT * FROM bar) + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +EXECUTE z5(3, 5) +---- +3 +5 + +# Not supported by Materialize. +onlyif cockroach +statement ok +PREPARE z6(int) AS + SELECT * FROM + (VALUES (1), (2)) v(x), + LATERAL (SELECT * FROM + (WITH foo AS (SELECT $1 + x) SELECT * FROM foo) + ) + +# Not supported by Materialize. +onlyif cockroach +query II +EXECUTE z6(3) +---- +1 4 +2 5 + +# Not supported by Materialize. +onlyif cockroach +# Recursive CTE example from postgres docs. +query T +WITH RECURSIVE t(n) AS ( + VALUES (1) + UNION ALL + SELECT n+1 FROM t WHERE n < 100 +) +SELECT sum(n) FROM t +---- +5050 + +# Not supported by Materialize. +onlyif cockroach +# Similar example where many duplicate rows are generated but we use UNION to +# deduplicate them. +query T +WITH RECURSIVE t(n) AS ( + VALUES (1) + UNION + SELECT n+y FROM t, (VALUES (1), (2)) AS v(y) WHERE n < 99 +) +SELECT sum(n) FROM t +---- +5050 + +# Not supported by Materialize. +onlyif cockroach +# Test where initial query has duplicate columns. +query II +WITH RECURSIVE cte(a, b) AS ( + SELECT 0, 0 + UNION ALL + SELECT a+1, b+10 FROM cte WHERE a < 5 +) SELECT * FROM cte; +---- +0 0 +1 10 +2 20 +3 30 +4 40 +5 50 + +# Not supported by Materialize. +onlyif cockroach +# Test where recursive query has duplicate columns. +query II +WITH RECURSIVE cte(a, b) AS ( + SELECT 0, 1 + UNION ALL + SELECT a+1, a+1 FROM cte WHERE a < 5 +) SELECT * FROM cte; +---- +0 1 +1 1 +2 2 +3 3 +4 4 +5 5 + +# Not supported by Materialize. +onlyif cockroach +# Recursive CTE examples adapted from +# https://malisper.me/generating-fractals-with-postgres-escape-time-fractals. +query T +WITH RECURSIVE points AS ( + SELECT i::float * 0.05 AS r, j::float * 0.05 AS c + FROM generate_series(-20, 20) AS a (i), generate_series(-40, 20) AS b (j) +), iterations AS ( + SELECT r, + c, + 0.0::float AS zr, + 0.0::float AS zc, + 0 AS iteration + FROM points + UNION ALL + SELECT r, + c, + zr*zr - zc*zc + c AS zr, + 2*zr*zc + r AS zc, + iteration+1 AS iteration + FROM iterations WHERE zr*zr + zc*zc < 4 AND iteration < 20 +), final_iteration AS ( + SELECT * FROM iterations WHERE iteration = 20 +), marked_points AS ( + SELECT r, + c, + (CASE WHEN EXISTS (SELECT 1 FROM final_iteration i WHERE p.r = i.r AND p.c = i.c) + THEN 'oo' ELSE '··' END) AS marker FROM points p +), lines AS ( + SELECT r, string_agg(marker, '' ORDER BY c ASC) AS r_text + FROM marked_points + GROUP BY r +) SELECT string_agg(r_text, E'\n' ORDER BY r DESC) FROM lines +---- +················································································oo········································ +············································································oo············································ +··········································································oooo············································ +······································································oo··oooo············································ +········································································oooooooo·········································· +······································································oooooooooooo········································ +········································································oooooooo·········································· +··························································oo····oooooooooooooooooooo··oo·································· +··························································oooo··oooooooooooooooooooooooo·································· +··························································oooooooooooooooooooooooooooooooooooooo·························· +··························································oooooooooooooooooooooooooooooooooooooo·························· +····················································oooooooooooooooooooooooooooooooooooooooooo···························· +······················································oooooooooooooooooooooooooooooooooooooooo···························· +····················································oooooooooooooooooooooooooooooooooooooooooooooo························ +··································oo····oo··········oooooooooooooooooooooooooooooooooooooooooooo·························· +··································oooooooooooo······oooooooooooooooooooooooooooooooooooooooooooo·························· +··································oooooooooooooo····oooooooooooooooooooooooooooooooooooooooooooooo························ +································oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo························ +······························oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo·························· +··························oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo···························· +··oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo······························ +··························oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo···························· +······························oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo·························· +································oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo························ +··································oooooooooooooo····oooooooooooooooooooooooooooooooooooooooooooooo························ +··································oooooooooooo······oooooooooooooooooooooooooooooooooooooooooooo·························· +··································oo····oo··········oooooooooooooooooooooooooooooooooooooooooooo·························· +····················································oooooooooooooooooooooooooooooooooooooooooooooo························ +······················································oooooooooooooooooooooooooooooooooooooooo···························· +····················································oooooooooooooooooooooooooooooooooooooooooo···························· +··························································oooooooooooooooooooooooooooooooooooooo·························· +··························································oooooooooooooooooooooooooooooooooooooo·························· +··························································oooo··oooooooooooooooooooooooo·································· +··························································oo····oooooooooooooooooooo··oo·································· +········································································oooooooo·········································· +······································································oooooooooooo········································ +········································································oooooooo·········································· +······································································oo··oooo············································ +··········································································oooo············································ +············································································oo············································ +················································································oo········································ + +# Not supported by Materialize. +onlyif cockroach +query T +WITH RECURSIVE points AS ( + SELECT i::float * 0.05 AS r, j::float * 0.05 AS c + FROM generate_series(-20, 20) AS a (i), generate_series(-30, 30) AS b (j) +), iterations AS ( + SELECT r, c, c::float AS zr, r::float AS zc, 0 AS iteration FROM points + UNION ALL + SELECT r, c, zr*zr - zc*zc + 1 - 1.61803398875 AS zr, 2*zr*zc AS zc, iteration+1 AS iteration + FROM iterations WHERE zr*zr + zc*zc < 4 AND iteration < 20 +), final_iteration AS ( + SELECT * FROM iterations WHERE iteration = 20 +), marked_points AS ( + SELECT r, c, (CASE WHEN EXISTS (SELECT 1 FROM final_iteration i WHERE p.r = i.r AND p.c = i.c) + THEN 'oo' + ELSE '··' + END) AS marker + FROM points p +), rows AS ( + SELECT r, string_agg(marker, '' ORDER BY c ASC) AS r_text + FROM marked_points + GROUP BY r +) SELECT string_agg(r_text, E'\n' ORDER BY r DESC) FROM rows +---- +·························································································································· +·························································································································· +····························································oo···························································· +····························································oo···························································· +························································oooooooooo························································ +························································oooooooooo························································ +························································oooooooooo························································ +··············································oo··oooooooooooooooooooooo··oo·············································· +··············································oooooooooooooooooooooooooooooo·············································· +············································oooooooooooooooooooooooooooooooooo············································ +··········································oooooooooooooooooooooooooooooooooooooo·········································· +························oooo····oo········oooooooooooooooooooooooooooooooooooooo········oo····oooo························ +························oooooooooooooo····oooooooooooooooooooooooooooooooooooooo····oooooooooooooo························ +······················oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo······················ +····················oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo···················· +··················oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo·················· +··················oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo·················· +··········oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo·········· +··········oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo·········· +······oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo······ +····oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo···· +······oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo······ +··········oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo·········· +··········oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo·········· +··················oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo·················· +··················oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo·················· +····················oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo···················· +······················oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo······················ +························oooooooooooooo····oooooooooooooooooooooooooooooooooooooo····oooooooooooooo························ +························oooo····oo········oooooooooooooooooooooooooooooooooooooo········oo····oooo························ +··········································oooooooooooooooooooooooooooooooooooooo·········································· +············································oooooooooooooooooooooooooooooooooo············································ +··············································oooooooooooooooooooooooooooooo·············································· +··············································oo··oooooooooooooooooooooo··oo·············································· +························································oooooooooo························································ +························································oooooooooo························································ +························································oooooooooo························································ +····························································oo···························································· +····························································oo···························································· +·························································································································· +·························································································································· + +# Not supported by Materialize. +onlyif cockroach +# Test that we deduplicate rows from the initial expression. +query II rowsort +WITH RECURSIVE cte(a, b) AS ( + VALUES (2, 2), (1, 1), (1, 2), (1, 1), (1, 3), (1, 2), (2, 2) + UNION + SELECT a+10, b+10 FROM cte WHERE a < 20 +) SELECT * FROM cte; +---- +2 2 +1 1 +1 2 +1 3 +12 12 +11 11 +11 12 +11 13 +22 22 +21 21 +21 22 +21 23 + +# Not supported by Materialize. +onlyif cockroach +# Test that we deduplicate rows from a single iteration. +query II rowsort +WITH RECURSIVE cte(a, b) AS ( + VALUES (1, 1), (1, 2), (2, 2) + UNION + SELECT 4-a, 4-a FROM cte +) SELECT * FROM cte; +---- +1 1 +1 2 +2 2 +3 3 + +# Not supported by Materialize. +onlyif cockroach +# Test that we deduplicate rows across iterations. +query II rowsort +WITH RECURSIVE cte(a, b) AS ( + VALUES (1, 1), (1, 2), (2, 2) + UNION + SELECT (a+i) % 4, (b+1-i) % 4 FROM cte, (VALUES (0), (1)) AS v(i) +) SELECT * FROM cte; +---- +1 1 +1 2 +2 2 +2 1 +1 3 +2 3 +3 2 +3 1 +1 0 +2 0 +3 3 +0 2 +0 1 +3 0 +0 3 +0 0 + + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #45869 (CTE inside recursive CTE). +query T rowsort +WITH RECURSIVE x(a) AS ( + VALUES ('a'), ('b') + UNION ALL + (WITH z AS (SELECT * FROM x) + SELECT z.a || z1.a AS a FROM z CROSS JOIN z AS z1 WHERE length(z.a) < 3 + ) +) +SELECT * FROM x +---- +a +b +aa +ba +ab +bb +aaaa +baaa +abaa +bbaa +aaba +baba +abba +bbba +aaab +baab +abab +bbab +aabb +babb +abbb +bbbb + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #53951: placeholder inside a recursive CTE. +statement ok +PREPARE + ctestmt +AS + (WITH RECURSIVE cte (x) AS (VALUES (1) UNION ALL SELECT x + $1 FROM cte WHERE x < 50) SELECT * FROM cte) + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +EXECUTE ctestmt (10) +---- +1 +11 +21 +31 +41 +51 + +# Verify that the query inside the CTE can refer to an outer CTE. +statement ok +DROP TABLE IF EXISTS ab + +statement ok +CREATE TABLE ab (a INT PRIMARY KEY, b INT) + +statement ok +INSERT INTO ab VALUES (1,1) + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +WITH + cte1 AS MATERIALIZED (SELECT a FROM ab WHERE a = b) +SELECT * FROM + ( + WITH RECURSIVE + cte2 (x) AS (SELECT 1 UNION ALL SELECT x + a FROM cte2, cte1 WHERE x < 10) + SELECT * FROM cte2 + ) +---- +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 + +# Test CTE with order-by projection (#55196). +statement ok +CREATE TABLE xy (x INT, y INT); +INSERT INTO xy VALUES (1,1),(1,2),(2,1),(2,2); + +query I rowsort +WITH cte AS (SELECT x*10+y FROM xy ORDER BY x+y LIMIT 3) SELECT * FROM cte +---- +11 +12 +21 + +# Test for recursive CTE which needs a cast in the initial expression. +statement ok +CREATE TABLE graph_node ( + id VARCHAR(16) PRIMARY KEY, + parent VARCHAR(16) +) + +statement ok +INSERT INTO graph_node (id, parent) VALUES + ('A', null), + ('B', 'A'), + ('C', 'B'), + ('D', 'C') + +# Not supported by Materialize. +onlyif cockroach +# The recursive query seed column types must match the output columns types. +query error pgcode 42804 recursive query \"nodes\" column 1 has type string in non-recursive term but type varchar overall +WITH RECURSIVE nodes AS ( + SELECT 'A' AS id + UNION ALL + SELECT graph_node.id FROM graph_node JOIN nodes ON graph_node.parent = nodes.id +) +SELECT * FROM nodes + +# Not supported by Materialize. +onlyif cockroach +# The recursive query seed column types must match the output columns types. +query error pgcode 42804 recursive query \"foo\" column 1 has type int in non-recursive term but type decimal overall +WITH RECURSIVE foo(i) AS + (SELECT i FROM (VALUES(1),(2)) t(i) + UNION ALL + SELECT (i+1)::numeric(10,0) FROM foo WHERE i < 10) +SELECT * FROM foo + +# Not supported by Materialize. +onlyif cockroach +# Tests with correlated CTEs. +statement ok +INSERT INTO x SELECT generate_series(1, 3) + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT y.a, ( + WITH foo AS MATERIALIZED (SELECT x.a FROM x WHERE x.a = y.a) + SELECT * FROM foo +) FROM y +---- +2 2 +3 3 +4 NULL + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT * FROM + (VALUES (1), (2), (10)) AS v(x), + LATERAL (WITH foo AS MATERIALIZED (SELECT a FROM y WHERE y.a <= x) SELECT * FROM foo) +---- +2 2 +10 2 +10 3 +10 4 + +# Tests with multiple mutation CTEs on different tables. These testcases vary +# the type of mutation as well as the input to the mutation subquery and +# the main query (sometimes another CTE, sometimes the table being mutated, +# sometimes a different table). + +statement ok +CREATE TABLE r (i INT PRIMARY KEY); +CREATE TABLE s (i INT PRIMARY KEY); +INSERT INTO r VALUES (0) + +# Not supported by Materialize. +onlyif cockroach +# Multiple CTEs inserting into different tables. +query I rowsort +WITH + t AS (INSERT INTO r VALUES (1) RETURNING i), + u AS (INSERT INTO s SELECT * FROM r RETURNING i) +SELECT i FROM s +---- + +query I rowsort +SELECT i FROM r +---- +0 + +query I rowsort +SELECT i FROM s +---- + + +# Not supported by Materialize. +onlyif cockroach +# Multiple CTEs deleting from different tables. +query I rowsort +WITH + t AS (DELETE FROM r WHERE i IN (SELECT i FROM s) RETURNING i), + u AS (DELETE FROM s WHERE i IN (SELECT i FROM t) RETURNING i) +SELECT i FROM r WHERE i IN (SELECT i FROM s) +---- +0 + +query I rowsort +SELECT i FROM r +---- +0 + +query I rowsort +SELECT i FROM s +---- + +# Not supported by Materialize. +onlyif cockroach +# Multiple CTEs upserting into different tables. The first CTE will perform both +# a no-op update due to a conflict, and an insert. The second CTE will perform +# two inserts. +query I rowsort +WITH + t AS (UPSERT INTO r VALUES (0), (1) RETURNING i), + u AS (UPSERT INTO s SELECT * FROM t RETURNING i) +SELECT i FROM r UNION ALL SELECT i FROM t +---- +0 +1 +1 + +query I rowsort +SELECT i FROM r +---- +0 + +query I rowsort +SELECT i FROM s +---- + + +# Not supported by Materialize. +onlyif cockroach +# Multiple CTEs updating different tables. Both CTEs will update two rows. +query I rowsort +WITH + t AS (UPDATE r SET i = i + 2 RETURNING i), + u AS (UPDATE s SET i = -r.i FROM r WHERE s.i < r.i RETURNING s.i) +SELECT i FROM u +---- +-1 + +query I rowsort +SELECT i FROM r +---- +0 + +query I rowsort +SELECT i FROM s +---- + + +# Not supported by Materialize. +onlyif cockroach +# Multiple CTEs inserting into different tables. The second CTE will update two +# rows instead of inserting, due to conflicts. +query II rowsort +WITH + t AS (INSERT INTO r SELECT i FROM s ON CONFLICT (i) DO UPDATE SET i = r.i + 2 RETURNING r.i), + u AS (INSERT INTO s SELECT i FROM t ON CONFLICT (i) DO UPDATE SET i = s.i - 2 RETURNING s.i) +SELECT * FROM r, u +---- +2 -3 +2 -1 +3 -3 +3 -1 + +query I rowsort +SELECT i FROM r +---- +0 + +query I rowsort +SELECT i FROM s +---- + + +# Tests with multiple mutations on the same table, modifying different rows. +# These testcases vary the type of mutation, but use a common form of: mutation +# CTE followed by main mutation which reads from the CTE. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE t (i INT PRIMARY KEY, j INT, INDEX (j)); +INSERT INTO t VALUES (0, 0) + +# Not supported by Materialize. +onlyif cockroach +# Multiple inserts of different rows into the same table. +query II rowsort +WITH + u AS (INSERT INTO t VALUES (1, 1) RETURNING *) +INSERT INTO t SELECT i + 1, j + 1 FROM u RETURNING * +---- +2 2 + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT * FROM t +---- +0 0 +1 1 +2 2 + +# Not supported by Materialize. +onlyif cockroach +# For INSERT ON CONFLICT, UPSERT, UPDATE, and DELETE we must explicitly allow +# statements with multiple mutations to the same table, due to issue +# 70731. These statements are safe to execute because the mutations modify +# different rows. +statement ok +SET CLUSTER SETTING sql.multiple_modifications_of_table.enabled = true + +# Not supported by Materialize. +onlyif cockroach +# Multiple deletes of different rows from the same table. The CTE will delete +# one row and the main query will delete one row. +query II rowsort +WITH + u AS (DELETE FROM t WHERE i = 0 RETURNING *) +DELETE FROM t WHERE i IN (SELECT i + 1 FROM u) RETURNING * +---- +1 1 + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT * FROM t +---- +2 2 + +# Not supported by Materialize. +onlyif cockroach +# Multiple upserts of different rows into the same table. The CTE will update +# one row and insert one row. The main query will insert two rows. +query II rowsort +WITH + u AS (UPSERT INTO t VALUES (2, 3), (4, 5) RETURNING *) +UPSERT INTO t SELECT i + 4, j + 4 FROM u RETURNING * +---- +6 7 +8 9 + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT * FROM t +---- +2 3 +4 5 +6 7 +8 9 + +# Not supported by Materialize. +onlyif cockroach +# Multiple updates of different rows in the same table. The CTE will update one +# row and the main query will update the rest of the rows. +query IIII rowsort +WITH + u AS (UPDATE t SET j = j + 1 WHERE i = 2 RETURNING *) +UPDATE t SET j = 99 FROM u WHERE t.i != u.i RETURNING * +---- +4 99 2 4 +6 99 2 4 +8 99 2 4 + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT * FROM t +---- +2 4 +4 99 +6 99 +8 99 + +# Not supported by Materialize. +onlyif cockroach +# Multiple inserts of different rows into the same table. The CTE will update +# all rows due to conflicts. The main query will then insert one new row. +query II rowsort +WITH + u AS (INSERT INTO t SELECT i, j - 1 FROM t ON CONFLICT (i) DO UPDATE SET j = 100 RETURNING *) +INSERT INTO t SELECT sum_int(i), sum_int(j) FROM u ON CONFLICT (i) DO UPDATE SET j = 1 RETURNING * +---- +20 400 + +# Not supported by Materialize. +onlyif cockroach +query II rowsort +SELECT * FROM t +---- +2 100 +4 100 +6 100 +8 100 +20 400 + +# Not supported by Materialize. +onlyif cockroach +# Check for corruption. (There should be none!) +query TTTTTTTT +EXPERIMENTAL SCRUB TABLE t WITH OPTIONS INDEX ALL +---- + +# Not supported by Materialize. +onlyif cockroach +statement ok +RESET CLUSTER SETTING sql.multiple_modifications_of_table.enabled + +# Multiple mutations can also be explicitly allowed with a session setting. +statement ok +SET enable_multiple_modifications_of_table = true + +# Not supported by Materialize. +onlyif cockroach +# Multiple updates of different rows in the same table. +query II rowsort +WITH + u1 AS (UPDATE t SET j = j - 40 WHERE i < 20 RETURNING *), + u2 AS (UPDATE t SET j = j + 40 WHERE i >= 20 RETURNING *) +TABLE u1 UNION ALL TABLE u2 +---- +2 60 +4 60 +6 60 +8 60 +20 440 + +# Not supported by Materialize. +onlyif cockroach +# Check for corruption. +query TTTTTTTT +EXPERIMENTAL SCRUB TABLE t WITH OPTIONS INDEX ALL +---- + +statement ok +RESET enable_multiple_modifications_of_table + +# Tests with multiple mutations on the same table, modifying the same +# rows. These testcases vary the type of mutation and the form. All should fail +# with an error. When issue 70731 is fixed, some might no longer fail. + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE u (i INT PRIMARY KEY, j INT, INDEX (j)); +INSERT INTO u VALUES (0, 0) + +# Not supported by Materialize. +onlyif cockroach +# Multiple inserts of the same row into the same table. Should always fail. +query error pgcode 23505 duplicate key value violates unique constraint +WITH + v AS (INSERT INTO u VALUES (1, 1) RETURNING *) +INSERT INTO u SELECT * FROM v + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_pkey +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_j_idx +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +# Multiple upserts of the same row. Might succeed after issue 70731 is fixed, +# depending on the implementation, but should not cause corruption. +query error pgcode 0A000 multiple modification subqueries of the same table +WITH + v AS (UPSERT INTO u VALUES (0, 1) RETURNING *), + w AS (UPSERT INTO u SELECT i, j + 1 FROM v RETURNING *) +SELECT * FROM w + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_pkey +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_j_idx +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +# Multiple updates of the same row. Might succeed after issue 70731 is fixed, +# depending on the implementation, but should not cause corruption. The order of +# CTE execution is not necessarily defined here. +query error pgcode 0A000 multiple modification subqueries of the same table +WITH + v AS (UPDATE u SET j = 3 WHERE i = 0 RETURNING *), + w AS (UPDATE u SET j = 4 WHERE i = 0 RETURNING *) +SELECT * FROM u + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_pkey +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_j_idx +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +# Multiple updates of the same row. Might succeed after issue 70731 is fixed, +# depending on the implementation, but should not cause corruption. The order of +# CTE execution should be deterministic. +query error pgcode 0A000 multiple modification subqueries of the same table +WITH + v AS (UPDATE u SET j = 5 WHERE i = 0 RETURNING *), + w AS (UPDATE u SET j = v.j + 1 FROM v WHERE u.i = v.i RETURNING *) +SELECT * FROM w + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_pkey +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_j_idx +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +# Multiple inserts of the same row into the same table, most should become +# updates due to conflicts. Might succeed after issue 70731 is fixed. +query error pgcode 0A000 multiple modification subqueries of the same table +WITH + v AS (INSERT INTO u VALUES (0, 42), (1, 42) ON CONFLICT (i) DO UPDATE SET j = 52 RETURNING *) +INSERT INTO u SELECT i, j + 1 FROM v ON CONFLICT (i) DO UPDATE SET j = v.j + 100 RETURNING * + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_pkey +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_j_idx +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +# Multiple deletes of the same row. Might succeed after issue 70731 is fixed, +# though the order of CTE execution is undefined. +query error pgcode 0A000 multiple modification subqueries of the same table +WITH + v AS (DELETE FROM u ORDER BY i LIMIT 1 RETURNING *), + w AS (DELETE FROM u ORDER BY i LIMIT 2 RETURNING *) +SELECT * FROM w + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_pkey +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +query II +SELECT i, j FROM u@u_j_idx +---- +0 0 + +# Not supported by Materialize. +onlyif cockroach +# Check for corruption. (There should be none!) +query TTTTTTTT +EXPERIMENTAL SCRUB TABLE u WITH OPTIONS INDEX ALL +---- + +# Example pulled from a blog post. +# https://malisper.me/the-missing-postgres-scan-the-loose-index-scan +statement ok +CREATE TABLE ints (n BIGINT, INDEX (n)); + +statement ok +INSERT INTO ints +VALUES (1), (1), (1), (2), (4), (4), (4), (4), (5), (5), + (6), (7), (7), (7), (8), (9), (9), (9), (9), (9); + +# Not supported by Materialize. +onlyif cockroach +query I +WITH RECURSIVE temp (i) AS ( + (SELECT n FROM ints ORDER BY n ASC LIMIT 1) +UNION ALL ( + SELECT n FROM temp, + LATERAL ( + SELECT n + FROM ints + WHERE n > i + ORDER BY n ASC + LIMIT 1 + ) sub + ) +) +SELECT count(*) FROM temp; +---- +8 + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +WITH RECURSIVE temp (i) AS ( + (SELECT n FROM ints ORDER BY n ASC LIMIT 1) +UNION ALL ( + SELECT n FROM temp, + LATERAL ( + SELECT n + FROM ints + WHERE n > i + ORDER BY n ASC + LIMIT 1 + ) sub + ) +) +SELECT * FROM temp; +---- +1 +2 +4 +5 +6 +7 +8 +9 + +# Not supported by Materialize. +onlyif cockroach +# Added limit to the recursive branch. +query I +WITH RECURSIVE temp (i) AS ( + (SELECT n FROM ints ORDER BY n ASC LIMIT 1) +UNION ALL ( + SELECT n FROM temp, + LATERAL ( + SELECT n + FROM ints + WHERE n > i + ORDER BY n ASC + LIMIT 1 + ) sub LIMIT 1 + ) +) +SELECT count(*) FROM temp; +---- +8 + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +WITH RECURSIVE temp (i) AS ( + (SELECT n FROM ints ORDER BY n ASC LIMIT 1) +UNION ALL ( + SELECT n FROM temp, + LATERAL ( + SELECT n + FROM ints + WHERE n > i + ORDER BY n ASC + LIMIT 1 + ) sub LIMIT 1 + ) +) +SELECT * FROM temp; +---- +1 +2 +4 +5 +6 +7 +8 +9 + +# Regression test for #95360. A NOT MATERIALIZED CTE should not be inlined if it +# has a mutation. +statement ok +CREATE TABLE t95360 (a INT, b INT) + +# Not supported by Materialize. +onlyif cockroach +# Note: The correlated subquery with a UNION ALL forces the optimizer to use an +# apply-join, which would execute the INSERT once for each row in v if the +# INSERT was inlined. +statement ok +WITH insVals AS NOT MATERIALIZED (INSERT INTO t95360 VALUES (1, 10) RETURNING a) +SELECT * FROM (VALUES (1), (2), (3)) v(a) +WHERE EXISTS (SELECT * FROM insVals WHERE a = v.a UNION ALL SELECT a FROM (VALUES (4)) w(a) WHERE a = v.a) + +query II +SELECT * FROM t95360 +---- + + +# Not supported by Materialize. +onlyif cockroach +# Regression tests for #93370. Do not convert a non-recursive CTE +# that uses UNION ALL and WITH RECURSIVE to UNION. +query I rowsort +WITH RECURSIVE + x(id) AS + (SELECT 1 UNION ALL SELECT id+1 FROM x WHERE id < 3 ), + y(id) AS + (SELECT * FROM x UNION ALL SELECT * FROM x) + SELECT * FROM y +---- +1 +2 +3 +1 +2 +3 + +statement ok +CREATE TABLE t93370 (i INT); +INSERT INTO t93370 VALUES (1), (2), (3) + +# Not supported by Materialize. +onlyif cockroach +query I rowsort +WITH RECURSIVE + y(id) AS (SELECT * FROM t93370 UNION ALL SELECT * FROM t93370) + SELECT * FROM y +---- +1 +2 +3 +1 +2 +3 diff --git a/test/sqllogictest/cockroach/zero.slt b/test/sqllogictest/cockroach/zero.slt index 8db17ad590ef4..c86c28822a033 100644 --- a/test/sqllogictest/cockroach/zero.slt +++ b/test/sqllogictest/cockroach/zero.slt @@ -1,4 +1,4 @@ -# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved. +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. # Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License @@ -9,12 +9,15 @@ # by the Apache License, Version 2.0. # # This file is derived from the logic test suite in CockroachDB. The -# original file was retrieved on June 10, 2019 from: +# original file was retrieved on July 6, 2026 from: # -# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/zero +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/zero # -# The original source code is subject to the terms of the Apache -# 2.0 license, a copy of which can be found in the LICENSE file at the +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the # root of this repository. mode cockroach @@ -72,17 +75,17 @@ INSERT INTO f VALUES query IR select * FROM f ORDER BY i ---- -1 0 -2 -0 -3 0 -4 -0 -5 -0 -6 0 -7 -0 -8 0 -9 -0 -10 0 -11 -0 +1 0 +2 0 +3 0 +4 -0 +5 0 +6 0 +7 -0 +8 0 +9 -0 +10 0 +11 0 query RRRRRIIRRRR colnames SELECT 0.0::float as a, @@ -97,8 +100,8 @@ SELECT 0.0::float as a, '0.0000'::float as j, '-0.0000'::float as k ---- -a b c d e f g h i j k -0 -0 0 -0 -0 0 0 0 -0 0 -0 +a b c d e f g h i j k +0 -0 0 -0 0 0 0 0 -0 0 -0 # decimals @@ -113,8 +116,8 @@ SELECT 0.0::decimal as a, '0.0000'::decimal as h, '-0.0000'::decimal as i ---- -a b c d e f g h i -0.0 0.0 0.00 0.00 0.000 0 0 0.0000 0.0000 +a b c d e f g h i +0 0 0 0 0 0 0 0 0 statement ok CREATE TABLE d (i INT, v DECIMAL) @@ -136,17 +139,17 @@ INSERT INTO d VALUES query IR select * FROM d ORDER BY i ---- -1 0.0 -2 0.0 -3 0.00 -4 0.00 -5 0.000 -6 0 -7 0 -8 0.0000 -9 0.0000 -10 0 -11 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 +10 0 +11 0 statement ok CREATE TABLE didx (i INT, v DECIMAL, INDEX vidx (v)) @@ -165,6 +168,8 @@ INSERT INTO didx VALUES (10, 0), (11, -0) +# Not supported by Materialize. +onlyif cockroach query R SELECT v FROM didx ORDER BY INDEX didx@vidx ---- @@ -183,7 +188,7 @@ SELECT v FROM didx ORDER BY INDEX didx@vidx query RRRR SELECT - -0.00::decimal, - - -0.00::decimal, - - -0.00, - -0.00 ---- -0.00 0.00 0.00 0.00 +0 0 0 0 # TODO(mjibson): # @@ -200,7 +205,7 @@ SELECT - -0.00::decimal, - - -0.00::decimal, - - -0.00, - -0.00 query R SELECT * FROM (VALUES (-0.0::DECIMAL), (-0::DECIMAL), (0::DECIMAL), (-0.00::DECIMAL)) ORDER BY 1 ---- -0.0 0 0 -0.00 +0 +0 diff --git a/test/sqllogictest/cockroach/zigzag_join.slt b/test/sqllogictest/cockroach/zigzag_join.slt new file mode 100644 index 0000000000000..c3955818e3b45 --- /dev/null +++ b/test/sqllogictest/cockroach/zigzag_join.slt @@ -0,0 +1,448 @@ +# Copyright 2015 - 2023 The Cockroach Authors. All rights reserved. +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. +# +# This file is derived from the logic test suite in CockroachDB. The +# original file was retrieved on July 6, 2026 from: +# +# https://github.com/cockroachdb/cockroach/blob/358e0d87912365b8976c55ab9b3292e999cf720d/pkg/sql/logictest/testdata/logic_test/zigzag_join +# +# That commit is tagged v23.1.0. CockroachDB v23.1 is licensed under +# the Business Source License 1.1 with a Change Date of 2026-04-01 and +# a Change License of Apache 2.0, so as of the retrieval date the +# original source code is subject to the terms of the Apache 2.0 +# license, a copy of which can be found in the LICENSE file at the +# root of this repository. + +mode cockroach + +# ------------------------------------------------------------------------------ +# Zigzag join tests on non-inverted indexes. +# ------------------------------------------------------------------------------ + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE TABLE a (n INT PRIMARY KEY, a INT, b INT, c STRING, INDEX a_idx(a), INDEX b_idx(b), INDEX bc_idx(b,c)); +INSERT INTO a SELECT a,a,a%3,'foo' FROM generate_series(1,10) AS g(a) ; +SET enable_zigzag_join = true + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT n,a,b FROM a WHERE a = 4 AND b = 1 +---- +4 4 1 + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT n,a,b FROM a WHERE a = 5 AND b = 2 +---- +5 5 2 + +# Not supported by Materialize. +onlyif cockroach +query IIIT rowsort +SELECT * FROM a WHERE a = 4 AND b = 1 +---- +4 4 1 foo + +# Not supported by Materialize. +onlyif cockroach +query IIIT rowsort +SELECT * FROM a WHERE a = 4 AND b = 2 +---- + +# Not supported by Materialize. +onlyif cockroach +query IIIT rowsort +SELECT * FROM a WHERE a = 5 AND b = 2 AND c = 'foo' +---- +5 5 2 foo + +# Not supported by Materialize. +onlyif cockroach +# Turn off zigzag joins and verify output. First with a hint, then with the +# session variable. +query III rowsort +SELECT n,a,b FROM a@{NO_ZIGZAG_JOIN} WHERE a = 4 AND b = 1 +---- +4 4 1 + +statement ok +SET enable_zigzag_join = false + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT n,a,b FROM a WHERE a = 4 AND b = 1 +---- +4 4 1 + +# Not supported by Materialize. +onlyif cockroach +query III rowsort +SELECT n,a,b FROM a WHERE a = 5 AND b = 2 +---- +5 5 2 + +statement ok +SET enable_zigzag_join = true + +# Not supported by Materialize. +onlyif cockroach +# Regression test for 42164 ("invalid indexIdx" error). +statement ok +DROP INDEX a@a_idx; +DROP INDEX a@b_idx; + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX c_idx ON a(c); +CREATE INDEX a_idx ON a(a); +CREATE INDEX b_idx ON a(b); + +# Not supported by Materialize. +onlyif cockroach +statement ok +SELECT n,a,b FROM a WHERE a = 4 AND b = 1; + +# Not supported by Materialize. +onlyif cockroach +# Regression test for 48003 ("non-values node passed as fixed value to zigzag +# join" error). +statement ok +SELECT n FROM a WHERE b = 1 AND (((a < 1) AND (a > 1)) OR (a >= 2 AND a <= 2)) + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #71655. Zig-zag joins should only be planned with implicit +# equality columns that are non-nullable. +statement ok +CREATE TABLE t71655 ( + k INT PRIMARY KEY, + a INT, + b INT, + c INT, + d INT NOT NULL, + INDEX ac (a, c), + INDEX bc (b, c) +); +INSERT INTO t71655 VALUES (1, 10, 20, NULL, 11); +INSERT INTO t71655 VALUES (2, 10, 20, NULL, 12) + +# Not supported by Materialize. +onlyif cockroach +# A zig-zag join is not performed here with ac and bc because c is nullable and +# cannot be an implicit equality column. +query I rowsort +SELECT k FROM t71655 WHERE a = 10 AND b = 20 +---- +1 +2 + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INDEX ad ON t71655 (a, d); +CREATE INDEX bd ON t71655 (b, d) + +# Not supported by Materialize. +onlyif cockroach +# A zig-zag join is performed here with ad and bd because d is non-nullable and +# can be an implicit equality column. +query I rowsort +SELECT k FROM t71655 WHERE a = 10 AND b = 20 +---- +1 +2 + +# ------------------------------------------------------------------------------ +# Zigzag join tests on inverted indexes. +# ------------------------------------------------------------------------------ + +statement ok +CREATE TABLE d ( + a INT PRIMARY KEY, + b JSONB +) + +# Not supported by Materialize. +onlyif cockroach +statement ok +CREATE INVERTED INDEX foo_inv ON d(b) + +# Not supported by Materialize. +onlyif cockroach +statement ok +SHOW INDEX FROM d + +statement ok +INSERT INTO d VALUES(1, '{"a": "b"}') + +statement ok +INSERT INTO d VALUES(2, '[1,2,3,4, "foo"]') + +statement ok +INSERT INTO d VALUES(3, '{"a": {"b": "c"}}') + +statement ok +INSERT INTO d VALUES(4, '{"a": {"b": [1]}}') + +statement ok +INSERT INTO d VALUES(5, '{"a": {"b": [1, [2]]}}') + +statement ok +INSERT INTO d VALUES(6, '{"a": {"b": [[2]]}}') + +statement ok +INSERT INTO d VALUES(7, '{"a": "b", "c": "d"}') + +statement ok +INSERT INTO d VALUES(8, '{"a": {"b":true}}') + +statement ok +INSERT INTO d VALUES(9, '{"a": {"b":false}}') + +statement ok +INSERT INTO d VALUES(10, '"a"') + +statement ok +INSERT INTO d VALUES(11, 'null') + +statement ok +INSERT INTO d VALUES(12, 'true') + +statement ok +INSERT INTO d VALUES(13, 'false') + +statement ok +INSERT INTO d VALUES(14, '1') + +statement ok +INSERT INTO d VALUES(15, '1.23') + +statement ok +INSERT INTO d VALUES(16, '[{"a": {"b": [1, [2]]}}, "d"]') + +statement ok +INSERT INTO d VALUES(17, '{}') + +statement ok +INSERT INTO d VALUES(18, '[]') + +statement ok +INSERT INTO d VALUES (29, NULL) + +statement ok +INSERT INTO d VALUES (30, '{"a": []}') + +statement ok +INSERT INTO d VALUES (31, '{"a": {"b": "c", "d": "e"}, "f": "g"}') + +# Not supported by Materialize. +onlyif cockroach +statement ok +ANALYZE d; + +## Multi-path contains queries with zigzag joins enabled. + +query IT +SELECT * from d where b @> '{"a": {"b": "c"}, "f": "g"}' +---- +31 {"a":{"b":"c","d":"e"},"f":"g"} + +query IT +SELECT * from d where b @> '{"a": {"b": "c", "d": "e"}, "f": "g"}' +---- +31 {"a":{"b":"c","d":"e"},"f":"g"} + +query IT +SELECT * from d where b @> '{"c": "d", "a": "b"}' +---- +7 {"a":"b","c":"d"} + +query IT +SELECT * from d where b @> '{"c": "d", "a": "b", "f": "g"}' +---- + +query IT +SELECT * from d where b @> '{"a": "b", "c": "e"}' +---- + +query IT +SELECT * from d where b @> '{"a": "e", "c": "d"}' +---- + +query IT +SELECT * from d where b @> '["d", {"a": {"b": [1]}}]' +---- +16 [{"a":{"b":[1,[2]]}},"d"] + +query IT +SELECT * from d where b @> '["d", {"a": {"b": [[2]]}}]' +---- +16 [{"a":{"b":[1,[2]]}},"d"] + +query IT +SELECT * from d where b @> '[{"a": {"b": [[2]]}}, "d"]' +---- +16 [{"a":{"b":[1,[2]]}},"d"] + +# Zigzag hinting tests, functional tests in opt.xform coster tests, syntax tests +# in parser select_clauses. + +statement error unexpected character in input: \{ +SELECT * FROM a@{FORCE_ZIGZAG=foo} WHERE a = 3 AND b = 7 + +# c_idx can't be used to zigzag so this is an error. +statement error unexpected character in input: \{ +SELECT * FROM a@{FORCE_ZIGZAG=a_idx,FORCE_ZIGZAG=c_idx} WHERE a = 3 AND b = 7 + +# Need two equalities to plan a zigzag. +statement error unexpected character in input: \{ +SELECT * FROM a@{FORCE_ZIGZAG=a_idx,FORCE_ZIGZAG=b_idx} WHERE a = 3 + +# Need two suitable indexes to plan a zigzag. +statement error unexpected character in input: \{ +SELECT * FROM a@{FORCE_ZIGZAG=a_idx,FORCE_ZIGZAG=bc_idx} WHERE a = 3 AND b = 7 + +# Not supported by Materialize. +onlyif cockroach +# Basic form w/o indexes. +statement ok +SELECT * FROM a@{FORCE_ZIGZAG} WHERE a = 3 AND b = 7 + +# Consider this an error, certainly its a typo. +statement error unexpected character in input: \{ +SELECT * FROM a@{FORCE_ZIGZAG,FORCE_ZIGZAG=a_idx} WHERE a = 3 AND b = 7 + +# Dupes are an error. +statement error unexpected character in input: \{ +SELECT * FROM a@{FORCE_ZIGZAG=a_idx,FORCE_ZIGZAG=a_idx} WHERE a = 3 AND b = 7 + +# Not supported by Materialize. +onlyif cockroach +# Full indexes specified. +statement ok +SELECT * FROM a@{FORCE_ZIGZAG=a_idx,FORCE_ZIGZAG=b_idx} WHERE a = 3 AND b = 7 + +# Not supported by Materialize. +onlyif cockroach +statement ok +DROP INDEX a@c_idx + +# Check error if no index. +statement error unexpected character in input: \{ +SELECT * FROM a@{FORCE_ZIGZAG} WHERE a = 3 AND c = 'foo' + +# Dupes are an error. +statement error unexpected character in input: \{ +SELECT * FROM a@{FORCE_ZIGZAG=[1],FORCE_ZIGZAG=[1]} WHERE a = 3 AND b = 7 + +# Not supported by Materialize. +onlyif cockroach +# Some of the test depend on the IDs of the exact indexes. If this +# test fails, then the tests below may also need to change. +query TT +WITH indexes AS ( + SELECT json_array_elements(crdb_internal.pb_to_json('cockroach.sql.sqlbase.Descriptor', descriptor)->'table'->'indexes') AS idx + FROM system.descriptor AS d + JOIN system.namespace AS n + ON d.id = n.id + WHERE n.name = 'a' +) +SELECT idx->>'name', idx->>'id' FROM indexes +---- +bc_idx 4 +a_idx 7 +b_idx 9 + +# Not supported by Materialize. +onlyif cockroach +# Full indexes specified. 7 is a_idx and 9 is b_idx. +statement ok +SELECT * FROM a@{FORCE_ZIGZAG=[7],FORCE_ZIGZAG=[9]} WHERE a = 3 AND b = 7 + +# Not supported by Materialize. +onlyif cockroach +# Combining name and id is allowed. +statement ok +SELECT * FROM a@{FORCE_ZIGZAG=[7],FORCE_ZIGZAG=b_idx} WHERE a = 3 AND b = 7 + +# Duplicate name and id is not allowed. +statement error unexpected character in input: \{ +SELECT * FROM a@{FORCE_ZIGZAG=[7],FORCE_ZIGZAG=a_idx} WHERE a = 3 AND b = 7 + +statement error unexpected character in input: \{ +SELECT * FROM a@{FORCE_ZIGZAG,NO_ZIGZAG_JOIN} WHERE a = 3 AND b = 7 + +# Not supported by Materialize. +onlyif cockroach +# Regression tests for not fetching columns that are only needed by the ON +# expression (#71093). +statement ok +CREATE TABLE t71093 (a INT, b INT, c INT, d INT, INDEX a_idx(a) STORING (b), INDEX c_idx(c) STORING (d)); +INSERT INTO t71093 VALUES (0, 1, 2, 3) + +# Not supported by Materialize. +onlyif cockroach +# ON expr needs the stored column from the left side. +query I +SELECT count(*) FROM t71093 WHERE a = 0 AND b = 1 AND c = 2 +---- +1 + +# Not supported by Materialize. +onlyif cockroach +# ON expr needs the stored column from the right side. +query I +SELECT count(*) FROM t71093 WHERE a = 0 AND c = 2 AND d = 3 +---- +1 + +# Not supported by Materialize. +onlyif cockroach +# ON expr needs the stored columns from both sides. +query I +SELECT count(*) FROM t71093 WHERE a = 0 AND b = 1 AND c = 2 AND d = 3 +---- +1 + +# Regression test for mistakenly attempting to fetch columns not needed by ON +# expr that are not in the index (#71271). +statement ok +CREATE TABLE t71271(a INT, b INT, c INT, d INT, INDEX (c), INDEX (d)) + +statement ok +SELECT d FROM t71271 WHERE c = 3 AND d = 4 + +# Not supported by Materialize. +onlyif cockroach +# Regression test for #97090. We should not plan a zigzag join when the +# direction of the equality columns doesn't match. +statement ok +CREATE TABLE t97090 ( + c INT NOT NULL, + l INT NOT NULL, + r INT NOT NULL, + INDEX (l ASC, c DESC), + INDEX (r ASC, c ASC) +); +INSERT INTO t97090 VALUES (1, 1, -1), (2, 1, -2) + +# Not supported by Materialize. +onlyif cockroach +# This query should return one row. +query III +SELECT * FROM t97090 WHERE l = 1 AND r = -1 +---- +1 1 -1 diff --git a/test/sqllogictest/current_user.slt b/test/sqllogictest/current_user.slt index 1b55fa8e9fbac..6d17e9913b197 100644 --- a/test/sqllogictest/current_user.slt +++ b/test/sqllogictest/current_user.slt @@ -23,3 +23,22 @@ query T SELECT user() = current_user() ---- true + +# SQL-502 (https://linear.app/materializeinc/issue/SQL-502): PG reserves +# CURRENT_USER / SESSION_USER as role specifications and rejects them as role +# names. Materialize accepts them, creating roles literally named "current_user" +# / "session_user", which is ambiguous in later "GRANT ... TO CURRENT_USER" +# forms. Sourced from the imported CockroachDB role logic test. +# PG: ERROR: CURRENT_USER cannot be used as a role name here +statement ok +CREATE ROLE CURRENT_USER + +statement ok +DROP ROLE CURRENT_USER + +# PG: ERROR: SESSION_USER cannot be used as a role name here +statement ok +CREATE ROLE SESSION_USER + +statement ok +DROP ROLE SESSION_USER diff --git a/test/sqllogictest/mzcompose.py b/test/sqllogictest/mzcompose.py index 9a926e7ae4dbc..e3cf575389c9c 100644 --- a/test/sqllogictest/mzcompose.py +++ b/test/sqllogictest/mzcompose.py @@ -804,103 +804,187 @@ def compileFastSltConfig() -> SltRunConfig: # "test/sqllogictest/sqlite/test/select4.test", # "test/sqllogictest/sqlite/test/select5.test", "test/sqllogictest/cockroach/alias_types.slt", - "test/sqllogictest/cockroach/alter_column_type.slt", - "test/sqllogictest/cockroach/alter_table.slt", + "test/sqllogictest/cockroach/alter_database_convert_to_schema.slt", + "test/sqllogictest/cockroach/alter_database_owner.slt", + "test/sqllogictest/cockroach/alter_default_privileges_for_all_roles.slt", + "test/sqllogictest/cockroach/alter_default_privileges_for_schema.slt", + "test/sqllogictest/cockroach/alter_role_set.slt", + "test/sqllogictest/cockroach/alter_schema_owner.slt", + "test/sqllogictest/cockroach/alter_sequence_owner.slt", + "test/sqllogictest/cockroach/alter_table_owner.slt", + "test/sqllogictest/cockroach/alter_type_owner.slt", + "test/sqllogictest/cockroach/alter_view_owner.slt", + "test/sqllogictest/cockroach/and_or.slt", "test/sqllogictest/cockroach/apply_join.slt", - "test/sqllogictest/cockroach/array.slt", "test/sqllogictest/cockroach/as_of.slt", "test/sqllogictest/cockroach/bit.slt", - # "test/sqllogictest/cockroach/builtin_function.slt", + "test/sqllogictest/cockroach/builtin_function.slt", "test/sqllogictest/cockroach/bytes.slt", "test/sqllogictest/cockroach/case_sensitive_names.slt", - # "test/sqllogictest/cockroach/collatedstring_constraint.slt", + "test/sqllogictest/cockroach/collatedstring.slt", + "test/sqllogictest/cockroach/collatedstring_constraint.slt", "test/sqllogictest/cockroach/collatedstring_index1.slt", "test/sqllogictest/cockroach/collatedstring_index2.slt", "test/sqllogictest/cockroach/collatedstring_normalization.slt", "test/sqllogictest/cockroach/collatedstring_nullinindex.slt", "test/sqllogictest/cockroach/collatedstring_uniqueindex1.slt", "test/sqllogictest/cockroach/collatedstring_uniqueindex2.slt", - "test/sqllogictest/cockroach/collatedstring.slt", - "test/sqllogictest/cockroach/computed.slt", - # "test/sqllogictest/cockroach/conditional.slt", - "test/sqllogictest/cockroach/create_as.slt", + "test/sqllogictest/cockroach/column_families.slt", + "test/sqllogictest/cockroach/comment_on.slt", + "test/sqllogictest/cockroach/composite_types.slt", + "test/sqllogictest/cockroach/conditional.slt", + "test/sqllogictest/cockroach/connect_privilege.slt", + "test/sqllogictest/cockroach/create_index.slt", + "test/sqllogictest/cockroach/create_statements.slt", "test/sqllogictest/cockroach/custom_escape_character.slt", - "test/sqllogictest/cockroach/database.slt", - # "test/sqllogictest/cockroach/datetime.slt", - # "test/sqllogictest/cockroach/decimal.slt", + "test/sqllogictest/cockroach/datetime.slt", + "test/sqllogictest/cockroach/decimal.slt", + "test/sqllogictest/cockroach/default.slt", "test/sqllogictest/cockroach/delete.slt", + "test/sqllogictest/cockroach/dependencies.slt", "test/sqllogictest/cockroach/discard.slt", - "test/sqllogictest/cockroach/drop_database.slt", + "test/sqllogictest/cockroach/disjunction_in_join.slt", + "test/sqllogictest/cockroach/distinct.slt", + "test/sqllogictest/cockroach/drop_index.slt", + "test/sqllogictest/cockroach/drop_role_with_default_privileges.slt", + "test/sqllogictest/cockroach/drop_role_with_default_privileges_in_schema.slt", + "test/sqllogictest/cockroach/drop_schema.slt", "test/sqllogictest/cockroach/drop_table.slt", + "test/sqllogictest/cockroach/drop_temp.slt", "test/sqllogictest/cockroach/drop_user.slt", "test/sqllogictest/cockroach/drop_view.slt", + "test/sqllogictest/cockroach/edge.slt", "test/sqllogictest/cockroach/errors.slt", - # "test/sqllogictest/cockroach/exec_hash_join.slt", + "test/sqllogictest/cockroach/exec_hash_join.slt", # "test/sqllogictest/cockroach/exec_merge_join.slt", - "test/sqllogictest/cockroach/exec_window.slt", + "test/sqllogictest/cockroach/external_connection_privileges.slt", "test/sqllogictest/cockroach/extract.slt", - # "test/sqllogictest/cockroach/float.slt", + "test/sqllogictest/cockroach/family.slt", + "test/sqllogictest/cockroach/float.slt", + "test/sqllogictest/cockroach/format.slt", + "test/sqllogictest/cockroach/function_lookup.slt", + "test/sqllogictest/cockroach/fuzzystrmatch.slt", + "test/sqllogictest/cockroach/grant_database.slt", + "test/sqllogictest/cockroach/grant_in_txn.slt", + "test/sqllogictest/cockroach/grant_on_all_sequences_in_schema.slt", + "test/sqllogictest/cockroach/grant_on_all_tables_in_schema.slt", + "test/sqllogictest/cockroach/grant_role.slt", + "test/sqllogictest/cockroach/grant_schema.slt", + "test/sqllogictest/cockroach/grant_table.slt", + "test/sqllogictest/cockroach/grant_type.slt", + "test/sqllogictest/cockroach/group_join.slt", + "test/sqllogictest/cockroach/hash_join.slt", + "test/sqllogictest/cockroach/hidden_columns.slt", + "test/sqllogictest/cockroach/impure.slt", "test/sqllogictest/cockroach/inet.slt", - "test/sqllogictest/cockroach/information_schema.slt", - "test/sqllogictest/cockroach/insert.slt", + "test/sqllogictest/cockroach/inner-join.slt", "test/sqllogictest/cockroach/int_size.slt", + "test/sqllogictest/cockroach/interval.slt", "test/sqllogictest/cockroach/join.slt", - # "test/sqllogictest/cockroach/json_builtins.slt", - # "test/sqllogictest/cockroach/json.slt", + "test/sqllogictest/cockroach/json.slt", + "test/sqllogictest/cockroach/json_builtins.slt", "test/sqllogictest/cockroach/like.slt", "test/sqllogictest/cockroach/limit.slt", - # "test/sqllogictest/cockroach/lookup_join.slt", + "test/sqllogictest/cockroach/lock_timeout.slt", + "test/sqllogictest/cockroach/lookup_join.slt", + "test/sqllogictest/cockroach/lookup_join_local.slt", + "test/sqllogictest/cockroach/materialized_view.slt", + "test/sqllogictest/cockroach/merge_join.slt", + "test/sqllogictest/cockroach/multi_statement.slt", "test/sqllogictest/cockroach/namespace.slt", - # "test/sqllogictest/cockroach/no_primary_key.slt", + "test/sqllogictest/cockroach/no_primary_key.slt", + "test/sqllogictest/cockroach/notice.slt", + "test/sqllogictest/cockroach/numeric_references.slt", + "test/sqllogictest/cockroach/operator.slt", + "test/sqllogictest/cockroach/optimizer_timeout.slt", "test/sqllogictest/cockroach/order_by.slt", "test/sqllogictest/cockroach/ordinal_references.slt", "test/sqllogictest/cockroach/ordinality.slt", - "test/sqllogictest/cockroach/orms-opt.slt", "test/sqllogictest/cockroach/orms.slt", - "test/sqllogictest/cockroach/pg_catalog.slt", + "test/sqllogictest/cockroach/overflow.slt", + "test/sqllogictest/cockroach/partitioning.slt", + "test/sqllogictest/cockroach/pg_builtins.slt", + "test/sqllogictest/cockroach/pg_catalog_pg_default_acl_with_grant_option.slt", + "test/sqllogictest/cockroach/pg_extension.slt", + "test/sqllogictest/cockroach/pgcrypto_builtins.slt", "test/sqllogictest/cockroach/pgoidtype.slt", - # "test/sqllogictest/cockroach/postgres_jsonb.slt", - # "test/sqllogictest/cockroach/postgresjoin.slt", - "test/sqllogictest/cockroach/prepare.slt", + "test/sqllogictest/cockroach/postgres_jsonb.slt", + "test/sqllogictest/cockroach/postgresjoin.slt", + "test/sqllogictest/cockroach/privilege_builtins.slt", + "test/sqllogictest/cockroach/privileges_comments.slt", + "test/sqllogictest/cockroach/propagate_input_ordering.slt", + "test/sqllogictest/cockroach/record.slt", + "test/sqllogictest/cockroach/rename_atomic.slt", "test/sqllogictest/cockroach/rename_column.slt", "test/sqllogictest/cockroach/rename_constraint.slt", - "test/sqllogictest/cockroach/rename_database.slt", + "test/sqllogictest/cockroach/rename_index.slt", + "test/sqllogictest/cockroach/rename_sequence.slt", "test/sqllogictest/cockroach/rename_table.slt", "test/sqllogictest/cockroach/rename_view.slt", + "test/sqllogictest/cockroach/reset.slt", "test/sqllogictest/cockroach/returning.slt", "test/sqllogictest/cockroach/rows_from.slt", + "test/sqllogictest/cockroach/savepoints.slt", "test/sqllogictest/cockroach/scale.slt", + "test/sqllogictest/cockroach/secondary_index_column_families.slt", + "test/sqllogictest/cockroach/select.slt", + "test/sqllogictest/cockroach/select_for_update.slt", + "test/sqllogictest/cockroach/select_index.slt", "test/sqllogictest/cockroach/select_index_flags.slt", # "test/sqllogictest/cockroach/select_index_span_ranges.slt", - # "test/sqllogictest/cockroach/select_index.slt", "test/sqllogictest/cockroach/select_search_path.slt", "test/sqllogictest/cockroach/select_table_alias.slt", - # "test/sqllogictest/cockroach/select.slt", + "test/sqllogictest/cockroach/set.slt", + "test/sqllogictest/cockroach/set_role.slt", + "test/sqllogictest/cockroach/set_time_zone.slt", "test/sqllogictest/cockroach/shift.slt", - # "test/sqllogictest/cockroach/sqlsmith.slt", + "test/sqllogictest/cockroach/show_create.slt", + "test/sqllogictest/cockroach/show_create_all_schemas.slt", + "test/sqllogictest/cockroach/show_create_all_tables.slt", + "test/sqllogictest/cockroach/show_create_all_tables_builtin.slt", + "test/sqllogictest/cockroach/show_create_all_types.slt", + "test/sqllogictest/cockroach/show_create_redact.slt", + "test/sqllogictest/cockroach/show_default_privileges.slt", + "test/sqllogictest/cockroach/show_indexes.slt", + "test/sqllogictest/cockroach/show_tables.slt", + "test/sqllogictest/cockroach/show_var.slt", + "test/sqllogictest/cockroach/sqlsmith.slt", "test/sqllogictest/cockroach/srfs.slt", - # "test/sqllogictest/cockroach/statement_source.slt", - # "test/sqllogictest/cockroach/suboperators.slt", + "test/sqllogictest/cockroach/statement_source.slt", + "test/sqllogictest/cockroach/storing.slt", + "test/sqllogictest/cockroach/suboperators.slt", # "test/sqllogictest/cockroach/subquery-opt.slt", "test/sqllogictest/cockroach/subquery.slt", - "test/sqllogictest/cockroach/table.slt", - # "test/sqllogictest/cockroach/target_names.slt", - # "test/sqllogictest/cockroach/time.slt", + "test/sqllogictest/cockroach/target_names.slt", + "test/sqllogictest/cockroach/temp_table_txn.slt", + "test/sqllogictest/cockroach/time.slt", "test/sqllogictest/cockroach/timestamp.slt", "test/sqllogictest/cockroach/truncate.slt", + "test/sqllogictest/cockroach/tsvector.slt", "test/sqllogictest/cockroach/tuple.slt", - # "test/sqllogictest/cockroach/typing.slt", - # "test/sqllogictest/cockroach/union-opt.slt", + "test/sqllogictest/cockroach/tuple_local.slt", + "test/sqllogictest/cockroach/txn_as_of.slt", + "test/sqllogictest/cockroach/type_privileges.slt", + "test/sqllogictest/cockroach/typing.slt", + "test/sqllogictest/cockroach/udf_in_constraints.slt", + "test/sqllogictest/cockroach/udf_oid_ref.slt", + "test/sqllogictest/cockroach/udf_setof.slt", + "test/sqllogictest/cockroach/udf_star.slt", + "test/sqllogictest/cockroach/udf_volatility_check.slt", + "test/sqllogictest/cockroach/union-opt.slt", "test/sqllogictest/cockroach/union.slt", - "test/sqllogictest/cockroach/update.slt", - "test/sqllogictest/cockroach/upsert.slt", + "test/sqllogictest/cockroach/update_from.slt", + "test/sqllogictest/cockroach/user.slt", "test/sqllogictest/cockroach/uuid.slt", "test/sqllogictest/cockroach/values.slt", - # "test/sqllogictest/cockroach/views.slt", + "test/sqllogictest/cockroach/views.slt", + "test/sqllogictest/cockroach/virtual_table_privileges.slt", + "test/sqllogictest/cockroach/void.slt", "test/sqllogictest/cockroach/where.slt", "test/sqllogictest/cockroach/window.slt", "test/sqllogictest/cockroach/with.slt", - # "test/sqllogictest/cockroach/zero.slt", + "test/sqllogictest/cockroach/zero.slt", + "test/sqllogictest/cockroach/zigzag_join.slt", "test/sqllogictest/postgres/float4.slt", "test/sqllogictest/postgres/float8.slt", "test/sqllogictest/postgres/join-lateral.slt",