Closed ksze closed 1 year ago
hi, there's really not much documentation on this :( so did a simple experiment
var statement = connection.execute({
sqlText: 'insert into /* search for queryid */ mydb.myschema.mytable select 1;',
complete: function(err, stmt, rows) {
if (err) {
console.error('Failed to execute statement due to the following error: ' + err.message);
} else {
console.log(statement);
console.log('Number of rows produced: ' + rows.length);
for (row of rows) {
console.log(row);
}
}
}
});
yielded:
RowStatementPreExec {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
getSqlText: [Function (anonymous)],
getStatus: [Function (anonymous)],
getColumns: [Function (anonymous)],
getColumn: [Function (anonymous)],
getNumRows: [Function (anonymous)],
getNumUpdatedRows: [Function (anonymous)],
getSessionState: [Function (anonymous)],
getRequestId: [Function (anonymous)],
getStatementId: [Function (anonymous)],
cancel: [Function (anonymous)],
fetchRows: [Function (anonymous)],
streamRows: [Function (anonymous)],
[Symbol(kCapture)]: false
}
Number of rows produced: 1
{ 'number of rows inserted': 1 }
where getStatementId
looked promising, so then calling statement.getStatementId()
in a subsequent attempt yielded the same id (queryID) which is visible in Snowflake Query History for the particular INSERT INTO
statement, as the queryID.
Not sure why it's exposed as statementID and not queryID, but even the unit tests suggests they are the same. Hope this helps. I'll also reach out to the Documentation team to consider providing documentation for this.
closing this for now but please feel free to reopen if further assistance is needed or you found an issue.
Please answer these questions before submitting your issue. Thanks!
What version of NodeJS are you using (
node --version
andnpm --version
)? node v18.12.1 npm 8.19.2What operating system and processor architecture are you using?
What are the component versions in the environment (
npm list
)?What did you do? I have a table with an autoincrement column. And I want to INSERT some rows using the nodejs connector. After executing the INSERT statement, how do I get the last insert ID? The documentation is painfully silent about this.
What did you expect to see? Clear documentation about this. And if I inspect the returned results of the INSERT statement, I expect to somehow see the last insert ID.
What did you see instead? Nothing in the documentation. And if I inspect the returned results, there is only one returned row, which is this:
{"number of rows inserted":1}
While we are at it, please ensure that any solution works nicely for inserting and upserting (i.e. MERGE) multiple rows.