首页 > 解决方案 > 单引号中的 Javascript 查询字符串

问题描述

我在使用字符串时遇到了一些问题,我总是 在 """" 处或附近得到错误的零长度分隔标识符

我想要这个查询是 JSON 格式的结果,使用这个参考

https://sikandar89dubey.wordpress.com/2015/12/23/how-to-dump-data-from-redshift-to-json/

我在 dbeaver 中运行查询是工作

这是我在 dbeaver 中的代码

UNLOAD ('SELECT \'{ \' || 
                case when "id" is null then \'\' else \'"id": "\' || "id" END ||
                case when "topid" is null then \'\' else \'", "topid": \' || "topid" END ||
                case when "parentid" is null then \'\' else \', "parentid": \' || "parentid" END ||
                case when "category" is null then \'\' else \', "category": "\' || "category" END ||
                case when "createdon" is null then \'\' else \'", "createdon": "\' || "createdon" END ||
                case when "updatedon" is null then \'\' else \'", "updatedon": "\' || "updatedon" END ||
       \'" }\' FROM table')

但是当我在 javascript 中尝试时,它的错误是我在 javascript 中的查询

`UNLOAD ('SELECT \"{ \" || 
                    case when \"id\" is null then \'\' else \"\"id\": \"\" || \"id\" END ||
                    case when \"topid\" is null then \'\' else \"\", \"topid\": \" || \"topid\" END ||
                    case when \"parentid\" is null then \'\' else \", \"parentid\": \" || \"parentid\" END ||
                    case when \"category\" is null then \'\' else \", \"category\": \"\" || \"category\" END ||
                    case when \"createdon\" is null then \'\' else \"\", \"createdon\": \"\" || \"createdon\" END ||
                    case when \"updatedon\" is null then \'\' else \"\", \"updatedon\": \"\" || \"updatedon\" END ||
                    \"\" }\" FROM table')`

标签: javascriptstring

解决方案


推荐阅读