-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SNOW-1016934: support setting session variables from Connection #756
Comments
hi and thank you for submitting this issue ! contrary to how the Snowflake JDBC driver supports setting session variables on the connection, the Node.js driver does not at this moment, it does not even support setting custom session parameters yet. (#61) I'll marked this request as a feature/enhancement request for the team to pick up some day if it'll be deemed something which we'll want to implement, but at this moment I cannot attach any estimated timelines for this request. But back to the issue, what can you do while the capability gets implemented ? You can utilize the multi-statement functionality as a workaround , to define the session variable as the first SQL statement you execute, then execute the rest of them depending on it. I created this simple script to demonstrate the functionality: # cat multi-statement-with-session-variables.js
var snowflake = require('snowflake-sdk');
require('log-timestamp');
console.log(`\nNode.js process version is: ${process.version}\n`);
var connection = snowflake.createConnection({
validateDefaultParameters: true,
account: process.env.SFACCOUNT,
username: process.env.SFUSER,
password: process.env.SFPASS,
warehouse: process.env.SFWH,
database: process.env.SFDB,
schema: process.env.SFSCHEMA,
application: __filename.slice(__dirname.length + 1)
});
connection.connect(function(err, conn) {
if (err) {
console.error('Unable to connect: ' + err.message);
} else {
console.log('Successfully connected.');
}
});
const orgKey = 'client';
const orgValue = '\'org\'';
var selectStatement = connection.execute({
sqlText: `SET ${orgKey}=${orgValue}; SELECT 1 as one; SELECT 2 as two; SELECT $${orgKey} as result;`,
parameters: { MULTI_STATEMENT_COUNT: 0 },
complete: function (err, stmt, rows) {
if (err) {
console.error('1 Failed to execute statement due to the following error: ' + err.message);
}
else {
console.log(rows);
if (stmt.hasNext())
{
stmt.NextResult();
}
else {
// do something else, e.g. close the connection
}
}
}
}); but probably you'll want to wrap the Running the above simple script results in:
Hopefully this alternative approach with multi-statement queries helps getting you unblocked while the feature gets implemented. |
Please answer these questions before submitting your issue.
In order to accurately debug the issue this information is required. Thanks!
What version of NodeJS driver are you using?
1.9.0
What operating system and processor architecture are you using?
Mac M2
What version of NodeJS are you using?
(
node --version
andnpm --version
)v21.6.0
What are the component versions in the environment (
npm list
)?5.Server version:* E.g. 1.90.1
You may get the server version by running a query:
snowflake.createConnection() receives a config object that specifies a key/value for the session parameter.
Usage in backend middleware function:
I expected the session parameter to be set to whatever I call this function with. Instead, the session parameter remains undefined. I looked through the API documentation and can't seem to find how to do this.
Snowflake Session Variables
What should have happened and what happened instead?
Can you set logging to DEBUG and collect the logs?
https://community.snowflake.com/s/article/How-to-generate-log-file-on-Snowflake-connectors
e.g
Add this to get standard output.
The text was updated successfully, but these errors were encountered: