我有一个大约的 SQL 数据库。我要导出到json
的 200 列与此类似:
id ab1 cd2 ef3 ...
1 1 0 NULL
2 0 1 1
3 NULL 0 NULL
4 -9 NULL NULL
....
通常,我对 MySQL Workbench 的导出向导很满意,它可以选择:
SELECT ab1,cd2,ef3,... FROM myDatabase
但是,当我以正常方式导出时,和json
之间的差异会丢失,因为值和值都显示为. 所以我咬了酸苹果,然后按照这个解决方案来面对我的问题:0
NULL
NULL
0
0
json
SELECT
COALESCE(id,-9) AS id,
COALESCE(ab1,-9) AS ab1,
COALESCE(cd2,-9) AS cd2,
COALESCE(ef3,-9) AS ef3,
...
FROM myDatabase
但是导出向导向我抛出了这个错误:
Traceback (most recent call last):
File "C:\Program Files\MySQL\MySQL Workbench 6.3 CE\workbench\
wizard_progress_page_widget.py", line 192, in thread_work
self.func()
File "C:\Program Files\MySQL\MySQL Workbench 6.3 CE\modules\
sqlide_power_export_wizard.py", line 264, in start_export
retval = self.module.start(self.stop)
File "C:\Program Files\MySQL\MySQL Workbench 6.3 CE\modules\
sqlide_power_import_export_be.py", line 273, in start
ret = self.start_export()
File "C:\Program Files\MySQL\MySQL Workbench 6.3 CE\modules\
sqlide_power_import_export_be.py", line 601, in start_export
rset = self._editor.executeManagementQuery(query, 1)
DBError: ("You have an error in your SQL syntax; check the manual that corresponds
to your MariaDB server version for the right syntax to use near
'id,-9) AS id, COALESCE(ab1,-9) AS ab1, COALESCE(cd2,-9) AS cd2, COALESCE(ef3,-9)'
at line 1", 1064)
ERROR: Export data to file: ("You have an error in your SQL syntax; check the
manual that corresponds to your MariaDB server version
for the right syntax to use near 'id,-9) AS id,
COALESCE(ab1,-9) AS ab1, COALESCE(cd2,-9) AS cd2, COALESCE(ef3,-9)'
at line 1", 1064)
Failed
我不知道这只是语法错误还是其他原因。我已经尝试过id
,COALESCE(id,-9) AS ab1,
因为它是唯一标识符,但它没有用。受影响的是整数列。
NULL 是默认值对我来说似乎是合理的,但我依赖于提到的区别。MariaDB
(我希望这个问题与我可耻地使用with的事实无关MySQLWorkbench
。)
在将具有 200 列的 SQL 数据库导出到时,如何更改NULL
为另一个值?-9
NA
json
编辑:
还有一个问题读起来类似,但实际上是不同的,因为答案是关于一个带有
WHERE
子句的非常特殊的情况。但是我的代码中根本没有WHERE
子句,我想为所有没有子句的列提供一个简单的通用解决方案WHERE
。