为了账号安全,请及时绑定邮箱和手机立即绑定

MySQL Serverless RDSDataService.batchExecute

MySQL Serverless RDSDataService.batchExecute

尚方宝剑之说 2023-05-19 17:43:29
我需要将数据从一个 json 文件加载到名为 Locality 的 MySQL 数据库表中。下面的代码返回一个 MySQL 语法错误。适用于 Aurora MySQL Serverless 的 MySQL 版本 5.7.30。我正在使用 aws-sdk,导入所有库,创建 RDS 实例。但出于某种原因,它返回 SQL 语法错误。如果我能看到 rds.batchExecuteStatement 生成的 SQL 内容,它也会有所帮助。我已经试过了,但没能找到 SQL 语句是什么。(帮助?)const loadLocalities = () => {    // Read data from the json file    const data = require('./GeoDyDB.json')    // Extract the data from the JSON into a format RDSDataService.batchExecuteStatement expects for the parameterSets argument    const localityParameterSets = data.map(function(location){        return [            {name: 'code', value: {stringValue: generate_locality_sort_key(location)}},            {name: 'synonyms', value: {stringValue: location.formatted_address}},            {name: 'country', value: {stringValue: location.Country}},            {name: 'state', value: {stringValue: location.State}},            {name: 'city', value: {stringValue: location.City}},            {name: 'zone', value: {stringValue: location.Zone}},            {name: 'ward', value: {stringValue: location.Ward}},            {name: 'colony', value: {stringValue: location.Colony}},            {name: 'pincode', value: {isNull: true}},            {name: 'lat', value: {stringValue: location.Lat.toString()}},            {name: 'lng', value: {stringValue: location.Lng.toString()}},            {name: 'geohash', value: {stringValue: location.Country}},            {name: 'obj', value: {stringValue: location.Country}}            /* more columns */        ]    })    // Create the SQL statement to run for all the items to insert as per AWS Docs linked above    sqlStatement = `INSERT INTO Locality (code, synonyms, country, state, city, zone, ward, colony, pincode, lat, lng, geohash, obj) VALUES (:code, :synonyms, :country, :state, :city, :zone, :ward, :colony, :pincode, :lat, :lng, :geohash, :obj);`    };}
查看完整描述

3 回答

?
aluckdog

TA贡献1847条经验 获得超7个赞

我遇到了同样的问题。调试了好几个小时才发现不能在sql语句末尾包含分号...



查看完整回答
反对 回复 2023-05-19
?
叮当猫咪

TA贡献1776条经验 获得超12个赞

请注意整数的值为 longValue,还记得添加“JSON”类型提示并将其作为字符串值传递到 RDS 中,这非常有效。

BatchExecuteStatementCommand 似乎对命令数量没有设置限制,但它应该受到 4MB 输入限制,因此值得考虑是否可以超过该限制。


查看完整回答
反对 回复 2023-05-19
?
米琪卡哇伊

TA贡献1998条经验 获得超6个赞

您忘记将 SQL 查询 ( sqlStatement ) 提供给rds.batchExecuteStatement函数,您正在为其提供参数,但没有 SQL 代码可以应用它。



查看完整回答
反对 回复 2023-05-19
  • 3 回答
  • 0 关注
  • 99 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信