question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inserting from an array

See original GitHub issue

It took me ages to find this syntax:

    // Inserting an array (from a previous query) into Product table 
    //db.tables.Product.data =  data is elegant, but how to use it with varying table names ?
    myTable = "Product";
    db.exec('INSERT INTO ' + myTable + ' SELECT * FROM ?',[data]);  // That's THE syntax !! 
    //Guessed from https://github.com/agershun/alasql/wiki/Insert

(my 2 к. - sorry if it was obvious)

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
agershuncommented, Feb 15, 2015

You can use three different methods to insert data from array into table:

    var data = [{a:1}, {a:2}];
    alasql('CREATE TABLE one');
    // Method 1
    alasql.tables.one.data = data;
    // Method 2
    alasql('SELECT * INTO one FROM ?',[data]);
    // Method 3
    alasql('INSERT INTO one SELECT * FROM ?',[data]);

BTW: If you download data from external file, you can use this syntax:

    alaslq('CREATE one; SELECT * INTO one FROM JSON("data.json")');
0reactions
mathiasrwcommented, May 25, 2021

IndexedDB will not work with this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

C program to Insert an element in an Array - GeeksforGeeks
First get the element to be inserted, say x · Then get the position at which this element is to be inserted, say...
Read more >
How to insert an item into an array at a specific index ...
You want the splice function on the native array object. arr.splice(index, 0, item); will insert item into arr at the specified index (deleting...
Read more >
Array Insertions - Tutorialspoint
When the insertion happens at the beginning, it causes all the existing data items to shift one step downward. Here, we design and...
Read more >
array.insert() - Dev Center - Electric Imp
This method places the value passed as its first parameter into the target array at the specified index, which can be zero —...
Read more >
Insert an element at a particular index in an array - Log2Base2
To insert an element at a particular index in an array, we need to Shift all the elements from last index to position...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found