SQLITE_MAX_VARIABLE_NUMBER increase or break sql query into chunks

activexplor3

I am trying to automate a Python script with a batch file, and the code works fine on my own computer but runs into an operational error "too many SQL variables" when I run it with the batch file on a remote desktop. This is apparently because the limit on a sql query is 999 parameters, and mine has more than the limit. How do I actually increase this limit or break the data into chunks of 999 cols? I came across many posts saying to increase this limit at compilation but I don't know how to do so, and the to_sql has a field called chunk but that's for rows and not columns.I'm using SQLite My python code to insert data is:

df.tail(1).to_sql("table", sqlcon, if_exists="append", index=True)

Thanks !

Schwern

A schema with more than 999 columns should probably be rethought. That said, here's how to work around it.

You can upgrade to SQLite after 3.32.0 when SQLITE_MAX_VARIABLE_NUMBER defaults to 32766. And if you need more than that, you are not allowed to design databases.

Otherwise, if for some reason upgrading is not an option, the hard coded limits can only be lowered at runtime. If you want to raise them you will have to recompile SQLite with a higher SQLITE_MAX_VARIABLE_NUMBER. This will make your program difficult to deploy using standard dependency managers.


Yes I've thought about that, but for this purpose, because the rows are basically dates and the column names are securities that we need to store stuff for, I don't think I can really change it.

This is a job for a join table.

create table securities (
  id integer primary key,
  symbol text not null unique,
  name text not null
);

create table security_prices (
  security_id integer not null references securities(id),
  retrieved_at datetime not null,
  price integer not null
);

select symbol, price
from security_prices sp
join securities s on s.id = sp.security_id
where retrieved_at = ?

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How do I break out of an sql query infinite loop

分類Dev

POST requests with JSON data, how to break it up into chunks

分類Dev

Break video into (equal or unequal) chunks using ffmpeg in windows

分類Dev

boost::pool default number of chunks

分類Dev

SQL Query data based on a variable

分類Dev

SQL - store a query as a local variable

分類Dev

VBA variable in SQL date query

分類Dev

SQL syntax: passing variable to SQL select query

分類Dev

SQL - Price increase over time

分類Dev

Promotheus - query to get increase percentage of events

分類Dev

SQL Query for max value from subsets

分類Dev

Break on variable being freed

分類Dev

How to use variable in sql query odoo

分類Dev

How to input a NodeJS variable into an SQL query

分類Dev

SQL query result to C# Variable

分類Dev

SQL Query Must Declare the Scalar Variable

分類Dev

Problem passing a datetime variable into a dynamic SQL query

分類Dev

How to assign an array to a variable of a sql query

分類Dev

Using variable as table name in SQL pdo query

分類Dev

Oracle SQL VARCHAR column with Line break

分類Dev

GDB: break if variable equal value

分類Dev

Couchbase query using "\uefff" break the next conditional keys

分類Dev

oracle-sql query select max from each base

分類Dev

Sql query with Joins into Linq query

分類Dev

Translate SQL Query into LINQ Query

分類Dev

Rails 4 sql query interpretation with mysql or sqlite3

分類Dev

SQL query change the two front number from "2048" to "1948"

分類Dev

PostgreSQL SQL query to find number of occurrences of substring in string

分類Dev

How can I limit the number of results of a specific part of an SQL query?

Related 関連記事

ホットタグ

アーカイブ