statement error value type void cannot be used for table columns
CREATE TABLE invalid_void_table(col void)

query T
SELECT 'this will be ignored'::void
----
·

# 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}

query T
select row (''::void, 2::int)
----
("",2)

query T
select row ('':::void, 2::int)
----
("",2)

statement error pq: incompatible type annotation for 'foo' as void, found type: string
select row ('foo':::void, 2::int)

query T
SELECT ('this will disappear too'::text)::void
----
·

query T
SELECT ('gone'::void)::text
----
·

query T
SELECT crdb_internal.void_func()
----
·

# 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

query B
SELECT ''::VOID IS DISTINCT FROM NULL::UNKNOWN
----
true

statement ok
SET vectorize=on

# 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 pq: incompatible NULLIF expressions: unsupported comparison operator: <void> = <unknown>
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 pq: incompatible NULLIF expressions: unsupported comparison operator: <void> = <void>
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;

# 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

# 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 pq: incompatible NULLIF expressions: unsupported comparison operator: <void> = <unknown>
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 pq: incompatible NULLIF expressions: unsupported comparison operator: <void> = <void>
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;

# Regression test for #83754.
# Non-vectorized and vectorized results should match.
skipif config fakedist-disk
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

# 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

query B
WITH tab(x) AS (VALUES (NULL:::VOID)) SELECT x IS NULL FROM tab
----
true

query B
WITH tab(x) AS (VALUES ('':::VOID)) SELECT x IS NOT NULL FROM tab
----
true

query B
WITH tab(x) AS (VALUES (NULL:::VOID)) SELECT x IS NOT NULL FROM tab
----
false
