如何在 Azure 存储 Table 中插入数字列?
How to insert numeric columns in an Azure Storage Table?
当我尝试在一列中插入带有数值的行时,插入失败。
下一个示例在使用 msg.registryTimestamp.toString()
.
将数字转换为字符串时有效
Azure Storage Table Output Binding 的 Azure 函数文档没有提及任何有关如何定义架构或如何插入不同类型的列等的内容。
这是输出定义,其中msg.registryTimestamp
是数字:
context.bindings.registry = [];
context.bindings.registry.push({
PartitionKey : msg.eventId,
RowKey : msg.id,
registryTimestamp: msg.registryTimestamp
});
这是function.json:
{
"bindings": [
{
"type": "eventGridTrigger",
"name": "message",
"direction": "in"
},
{
"tableName": "Registry",
"connection": "AZURE_STORAGE_CONNECTION_STRING",
"name": "registry",
"type": "table",
"direction": "out"
}
]
}
在我这边,插入数字列没问题,这是我的代码:
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
var msg = new Object();
msg.registryTimestamp = 222
context.bindings.tableBinding = [];
context.bindings.tableBinding.push({
PartitionKey: "rtbhtrehtre",
RowKey: "afwegfergrweg",
registryTimestamp: msg.registryTimestamp
});
if (req.query.name || (req.body && req.body.name)) {
context.res = {
// status: 200, /* Defaults to 200 */
body: "Hello " + (req.query.name || req.body.name)
};
}
else {
context.res = {
status: 400,
body: "Please pass a name on the query string or in the request body"
};
}
};
这是我的 function.json:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"tableName": "MyTable",
"connection": "MyStorageConnectionAppSetting",
"name": "tableBinding",
"type": "table",
"direction": "out"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
触发后,我可以插入数据:
也许你的其他代码有一些错误,你能证明一下吗?
当我尝试在一列中插入带有数值的行时,插入失败。
下一个示例在使用 msg.registryTimestamp.toString()
.
Azure Storage Table Output Binding 的 Azure 函数文档没有提及任何有关如何定义架构或如何插入不同类型的列等的内容。
这是输出定义,其中msg.registryTimestamp
是数字:
context.bindings.registry = [];
context.bindings.registry.push({
PartitionKey : msg.eventId,
RowKey : msg.id,
registryTimestamp: msg.registryTimestamp
});
这是function.json:
{
"bindings": [
{
"type": "eventGridTrigger",
"name": "message",
"direction": "in"
},
{
"tableName": "Registry",
"connection": "AZURE_STORAGE_CONNECTION_STRING",
"name": "registry",
"type": "table",
"direction": "out"
}
]
}
在我这边,插入数字列没问题,这是我的代码:
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
var msg = new Object();
msg.registryTimestamp = 222
context.bindings.tableBinding = [];
context.bindings.tableBinding.push({
PartitionKey: "rtbhtrehtre",
RowKey: "afwegfergrweg",
registryTimestamp: msg.registryTimestamp
});
if (req.query.name || (req.body && req.body.name)) {
context.res = {
// status: 200, /* Defaults to 200 */
body: "Hello " + (req.query.name || req.body.name)
};
}
else {
context.res = {
status: 400,
body: "Please pass a name on the query string or in the request body"
};
}
};
这是我的 function.json:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"tableName": "MyTable",
"connection": "MyStorageConnectionAppSetting",
"name": "tableBinding",
"type": "table",
"direction": "out"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
触发后,我可以插入数据:
也许你的其他代码有一些错误,你能证明一下吗?