## Summary
<!--Explain briefly what goes wrong and explain why you believe this is a bug and not the intended behavior of SQLite (if it is not a crash).-->**No review yet**

## Minimized query

```sql
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (x'3572322269d7',2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (2147483647, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;

PRAGMA table_info(users);
SELECT * FROM t1;
WITH cte AS (SELECT b FROM t1) SELECT * FROM cte;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (2147483647, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;

PRAGMA table_info(users);
SELECT * FROM t1;
WITH cte AS (SELECT b FROM t1) SELECT * FROM cte;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (2147483647, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;

PRAGMA table_info(users);
SELECT * FROM t1;
WITH cte AS (SELECT b FROM t1) SELECT * FROM cte;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (2147483647, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;

PRAGMA table_info(users);
SELECT * FROM t1;
WITH cte AS (SELECT b FROM t1) SELECT * FROM cte;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (2147483647, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;

PRAGMA table_info(users);
SELECT * FROM t1;
WITH cte AS (SELECT b FROM t1) SELECT * FROM cte;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (2147483647, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;

PRAGMA table_info(users);
SELECT * FROM t1;
WITH cte AS (SELECT b FROM t1) SELECT * FROM cte;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (2147483647, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INT, d INT);
INSERT INTO t1 VALUES (1, 'Wernher', 10, 100);
INSERT INTO t1 VALUES (2, 'von', 20, 200);
INSERT INTO t1 VALUES (3, 'Braun', 30, 300);

CREATE INDEX t1bc ON t1(b, c);

PRAGMA writable_schema = ON;

.imposter t1bc t2

SELECT * FROM t2;

SELECT b, c FROM t1 ORDER BY b, c;

.quit
.limit COLUMN -jsonb_replace(x'606c0de7fb1f7e9901fff8a917ca96f0', '$.key', abs('123'))
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (-CAST(-NULL AS CHAR(10)),2.0,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
PRAGMA parser_trace = TRUE;
CREATE TABLE main.t1(a INTEGER, b INTEGER, c INTEGER);
INSERT INTO t1 VALUES(2147483646, 1, 1);
INSERT INTO t1 VALUES(1, 2, 2);
SELECT c, sum(c) OVER win1 FROM t1 WINDOW win1 AS (ORDER BY b);

ANALYZE t1;
SELECT TOTAL(c) FROM t1;
DELETE FROM t1 WHERE NOT b > (SELECT AVG(b) FROM t1);
SELECT * FROM t1 AS a FULL OUTER JOIN t1 AS b ON a.rowid = b.rowid;
SELECT GROUP_CONCAT(a) FROM t1;
UPDATE t1 SET c = -71 RETURNING *;
SELECT * FROM T AS a JOIN t1 AS b ON a.rowid = b.rowid;
SELECT * FROM T AS a JOIN T AS b ON a.rowid = b.rowid;

SELECT COUNT(*) FROM t1;
INSERT OR ROLLBACK INTO T VALUES (4, 0, '');
UPDATE t1 SET a = '' WHERE a BETWEEN 0 AND 100;
PRAGMA auto_vacuum = 0;
INSERT INTO t1 SELECT * FROM t1;
REINDEX t1;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE 1/0 = 0);SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 LIMIT -1);
WITH cte AS (SELECT b FROM t1 WHERE b IS NULL) SELECT * FROM cte;
END TRANSACTION;

PRAGMA table_info(users);
SELECT * FROM t1;
WITH cte AS (SELECT b FROM t1) SELECT * FROM cte;

SELECT * FROM t1 AS a INNER JOIN T AS b ON a.rowid = b.rowid;
SELECT COUNT(*) FILTER (WHERE c IS NOT NULL), SUM(rowid) FILTER (WHERE c > 0), COUNT(*) FILTER (WHERE 1=0), COUNT(*) FILTER (WHERE 1=1), COUNT(*) FILTER (WHERE NULL), AVG(c) FILTER (WHERE c > 0 AND c < 100), COUNT(*) FILTER (WHERE typeof(c) = "text") FROM T;
INSERT INTO T SELECT * FROM T;
INSERT OR FAIL INTO T VALUES ('x', '', '');
```

## Actual output

```sql
1|-70.875
2|-Inf
5r2"i×|21.0
CREATE TABLE "t2"("b","c","_ROWID_",PRIMARY KEY("b","c","_ROWID_"))WITHOUT ROWID;
WARNING: writing to an imposter table will corrupt the "t1bc" index!
Braun|30|3
Wernher|10|2147483647
von|20|2
Braun|30
Wernher|10
von|20
```

## Expectation

```sql
1|-70.875
2|-Inf
5r2"i×|21.0
CREATE TABLE "t2"("b","c","_ROWID_",PRIMARY KEY("b","c","_ROWID_"))WITHOUT ROWID;
Braun|30|3
Wernher|10|2147483647
von|20|2
Braun|30
Wernher|10
von|20
```

## Flag

```

```

