Home > other >  Node: Failed to execute statement due to the following error: Numeric value
Node: Failed to execute statement due to the following error: Numeric value

Time:10-11

I am really new to Snowflakes. I am using Node Js drive to query Snowflakes database and for that I am using NODE PACKAGE https://www.npmjs.com/package/snowflake-sdk package. I successfully manage to connect my local server to snowflakes. When I query sqlText: select * from Test.deliverydb', I can see all my datas in console rows`.

In my Snowflakes dashboard I am passing conditional value and getting selected value. This is how I did it in my dashboard and getting expected result.

   SELECT 
    online_store_transaction_id AS order_number,
    updated_at_ts,
    progress,
    status,
    service_time,
    site_name
   FROM 
    Test.deliverydb
 
   WHERE
    online_store_transaction_id = '39485727'

I would like to this same query in Code. I am having hard time to understand snowflakes' documentation to implement above dashboard logic to my code.

I would like query my data around template string where user will put hardcode value and it will return the data. When I run this below query "Failed to execute statement due to the following error: Numeric value".Because of this where condition WHERE online_store_transaction_id = ${168141924}

const sql = `
       SELECT
       online_store_transaction_id AS order_number,
       updated_at_ts,
       progress,
       status,
       service_time,
       site_name
       FROM
       Test.deliverydb
       WHERE online_store_transaction_id = ${168141924}
       `;
 

connection.execute({
  sqlText: sql,
  fetchAsString: ['Number'],
  complete: function (err, stmt, rows) {
    if (err) {
      console.error('Failed to execute statement due to the following error: '   err.message);
    } else {
      if (!rows) {
        throw new Error("Data not found");

      }
      console.log('Successfully executed statement: '   stmt.getSqlText());

      let data = {}
      rows.forEach(test => data = test);
      console.log({ data });
    }
  }
});

If I query like this this it works:

const sql = `
       SELECT
       online_store_transaction_id AS order_number,
       updated_at_ts,
       progress,
       status,
       service_time,
       site_name
       FROM
       Test.deliverydb
       WHERE online_store_transaction_id = '168141924'
       `;
 

connection.execute({
  sqlText: sql,
  fetchAsString: ['Number'],
  complete: function (err, stmt, rows) {
    if (err) {
      console.error('Failed to execute statement due to the following error: '   err.message);
    } else {
      if (!rows) {
        throw new Error("Data not found");

      }
      console.log('Successfully executed statement: '   stmt.getSqlText());

      let data = {}
      rows.forEach(test => data = test);
      console.log({ data });
    }
  }
});

CodePudding user response:

Since the online_store_transaction_id is not a numeric column, you need to add quotes around your value, as you did in your first example:

const sql = `
       SELECT
       online_store_transaction_id AS order_number,
       updated_at_ts,
       progress,
       status,
       service_time,
       site_name
       FROM
       Test.deliverydb
       WHERE online_store_transaction_id = '${168141924}'
       `;
  • Related