Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 217015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:37:05+00:00 2026-05-11T18:37:05+00:00

How do I bulk insert with SQLite? I looked it up and it seems

  • 0

How do I bulk insert with SQLite?

I looked it up and it seems like I do an insert with a select statement. I googled, looked at the examples and they all look like they are copying data from one table to another or is not compatible with SQLite. I want to do something like

"INSERT INTO user_msg_media (recipientId, mediaId, catagory, current_media_date) " +
"VALUES(@mediaId, @catagory, @current_media_date)";
where the value of recipientId is the watcher from each of
"SELECT watcher FROM userwatch WHERE watched=@watched";

I tried the code below and I get the error “SQLite error no such column: watcher”

        command.CommandText =
            "CREATE TABLE if not exists user_msg_media( " +
            "msgId        INTEGER PRIMARY KEY, " +
            "recipientId  INTEGER, " +
            "mediaId      INTEGER, " +
            "catagory     INTEGER, " +
            "current_date DATE);";
        command.ExecuteNonQuery();

        //user media
        command.CommandText =
            "CREATE TABLE if not exists user_watch( " +
            "indx INTEGER PRIMARY KEY, " +
            "watcher INTEGER, " +
            "watched INTEGER);";
        command.ExecuteNonQuery();
        //...

    command.CommandText = "SELECT watcher FROM user_watch WHERE watched=:watched;";
    command.Parameters.Add(":watched", DbType.Int64).Value = 1;
    command.ExecuteNonQuery(); //is ok

    command.CommandText =
        "INSERT INTO user_msg_media (recipientId, mediaId, catagory, current_media_date) " +
        "SELECT watcher, :mediaId, :category, :current_media_date" +
        "FROM user_watch WHERE watched=:watched;";
    command.Parameters.Add(":mediaId", DbType.Int64).Value = 0;
    command.Parameters.Add(":category", DbType.Int64).Value = 0;
    command.Parameters.Add(":current_media_date", DbType.Int64).Value = 0;
    command.Parameters.Add(":watched", DbType.Int64).Value = 1;
    command.ExecuteNonQuery();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:37:05+00:00Added an answer on May 11, 2026 at 6:37 pm

    SQlite doesn’t support @variable notation, but (using named-placeholder style as supported by the Python binding of sqlite for clarity) this should work:

    INSERT INTO user_msg_media (userId, mediaId, catagory, current_media_date)
    SELECT watcher, :mediaId, :category, :current_media_date
    FROM userwatch WHERE watched=:watched
    

    Edit: SQLite seems to be misdiagnosing what column name is wrong. With column names all fixed, the following Python code works for me (not sure what other language you’re using, Python’s what handiest to me to interact with sqlite):

    import sqlite3 as sq
    
    con = sq.connect(':memory:')
    cur = con.cursor()
    cur.execute("CREATE TABLE if not exists user_msg_media( " +
                "msgId        INTEGER PRIMARY KEY, " +
                "recipientId  INTEGER, " +
                "mediaId      INTEGER, " +
                "catagory     INTEGER, " +
                "current_date DATE)")
    cur.execute("CREATE TABLE if not exists user_watch( " +
                "indx INTEGER PRIMARY KEY, " +
                "watcher INTEGER, " +
                "watched INTEGER)")
    
    cur.execute("INSERT INTO user_watch VALUES (1, 2, 3)")
    
    cur.execute("SELECT watcher FROM user_watch WHERE watched=:watched",
                dict(watched=3))
    print cur.fetchall()
    
    print cur.execute("INSERT INTO user_msg_media (recipientId, mediaId, catagory, current_date) " +
            "SELECT watcher, :mediaId, :category, :current_media_date " +
            "FROM user_watch WHERE watched=:watched;",
            dict(mediaId=0, category=0, current_media_date=0, watched=3)
    )
    
    cur.execute("SELECT * FROM user_msg_media")
    print cur.fetchall()
    

    But if I reproduce mismatches in your SQL such as current_date vs current_media_date, I can get it to mis-diagnose that the missing column is watcher, even though that column is in fact fine. Want to try putting this corrected code back into your favorite language and see how it behaves?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 105k
  • Answers 105k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My first instinct would be to pump your 5000 inputs… May 11, 2026 at 8:41 pm
  • Editorial Team
    Editorial Team added an answer The WCF REST Starter Kit Preview 2, is as the… May 11, 2026 at 8:41 pm
  • Editorial Team
    Editorial Team added an answer There is a Related posts by category plugin, at http://wordpress.org/extend/plugins/related-posts-by-category/.… May 11, 2026 at 8:41 pm

Related Questions

So I am trying to do a bulk insert with SSIS and continually get:
I would like to use SSIS to create database table flat file exports then
A little help needed. I'm receiving an xml file similar to this: <?xml version=1.0
Similar to how database connections made within the scope of a TransactionScope will behave
How do you use a binarywriter to write the correct MS SQL native format

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.