oceanbase / oceanbase/oceanbase
[Bug]: Incorrect value Error When Creating an Empty Table Using "CREATE TABLE empty_table AS SELECT * FROM t EXCEPT SELECT * FROM t"
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
This is a common scenario in practice—wanting to quickly create an empty table from an existing view or table using a query like the one below. Especially when there are many columns, manually recreating the table structure can be very time-consuming.
use oceanbase;
CREATE TABLE empty_table1 AS SELECT * FROM CDB_TABLES EXCEPT SELECT * FROM CDB_TABLES;
Query OK, 0 rows affected (0.333 sec)
CREATE TABLE empty_table2 AS SELECT * FROM CDB_TAB_COLS EXCEPT SELECT * FROM CDB_TAB_COLS;
ERROR 1292 (22007): Incorrect value
[172.17.0.5:2882] [2025-05-09 15:14:35.455371] [YB42AC110005-0006338932A0940D-0-0]
The SQL statements CREATE TABLE empty_table AS SELECT * FROM t EXCEPT SELECT * FROM t should always create an empty table with the same column definitions as the source view or table, but without copying any data. However, the second statement fails and returns "ERROR 1292 (22007): Incorrect value". It may be that the underlying view CDB_TAB_COLS is larger.
Environment
Linux ubuntu 6.5.0-18-generic #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 11:40:03 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
5.7.25-OceanBase_CE-v4.2.1.10
Fast Reproduce Steps(Required)
Steps to reproduce the behavior:
use oceanbase;
CREATE TABLE empty_table1 AS SELECT * FROM CDB_TABLES EXCEPT SELECT * FROM CDB_TABLES;
Query OK, 0 rows affected (0.333 sec)
CREATE TABLE empty_table2 AS SELECT * FROM CDB_TAB_COLS EXCEPT SELECT * FROM CDB_TAB_COLS;
ERROR 1292 (22007): Incorrect value
[172.17.0.5:2882] [2025-05-09 15:14:35.455371] [YB42AC110005-0006338932A0940D-0-0]
Expected behavior
CREATE TABLE empty_table2 AS SELECT * FROM CDB_TAB_COLS EXCEPT SELECT * FROM CDB_TAB_COLS;
Query OK, 0 rows affected (x.xxx sec)
Actual Behavior
CREATE TABLE empty_table2 AS SELECT * FROM CDB_TAB_COLS EXCEPT SELECT * FROM CDB_TAB_COLS;
ERROR 1292 (22007): Incorrect value
[172.17.0.5:2882] [2025-05-09 15:14:35.455371] [YB42AC110005-0006338932A0940D-0-0]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two CREATE TABLE ... AS SELECT ... EXCEPT ... statements in the reported OceanBase 4.2.1.10 environment, comparing the successful CDB_TABLES case with the failing CDB_TAB_COLS case. Locate the database execution path responsible for the incorrect-value error and add a regression test; done means the second statement creates an empty table successfully with the expected column definitions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100