Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite: "Row value misused" error in sqlite

Tags:

sqlite

I'm getting an error from an sqlite3 query for which I can't find any reference material. Googling the string takes me deep in the SQLite code itself, and that's so opaque I can't make heads or tails of it.

The table schema:

CREATE TABLE quote (
    seqnum INTEGER,
    session STRING,
    timestamp_sip INTEGER,
    timestamp_1 INTEGER,
    market_center STRING,
    symbol STRING,
    bid_price INTEGER,
    bid_lots INTEGER,
    offer_price INTEGER,
    offer_lots INTEGER,
    flags INTEGER,
    PRIMARY KEY (symbol, seqnum) );

The query:

select (seqnum, session, timestamp_sip, timestamp_1, market_center, symbol)
    from quote
    where symbol = 'QQQ';

The error:

Error: row value misused

I have no idea how to proceed here. There is plenty of data in the table that would match the query:

sqlite> select count(*) from quote where symbol = 'QQQ';
2675931

Can anyone offer any guidance here? Sqlite version is 3.16.2.

like image 555
John S Avatar asked Feb 08 '17 20:02

John S


3 Answers

Nevermind. Those parentheses around the select columns (left over from a copy/paste) are the problem. Poor error message, maybe. But my fault.

like image 51
John S Avatar answered Nov 09 '22 00:11

John S


I had a similar when working with a Rails 5.2 Application.

For my case I was trying to write a search query for a model in application:

def self.search(params)
  applications = all.order('created_at DESC') # for not existing params args
  applications = applications.where("cast(id as text) like ?, email like ?, first_name like ?, last_name like ?, appref like ?", "#{params[:search]}", "%#{params[:search]}%", "#{params[:search]}", "#{params[:search]}", "#{params[:search]}",) if params[:search]
  applications
end

The issue was that I was using a comma (,) to separate the search parameters, I simply corrected by using an OR instead:

def self.search(params)
  applications = all.order('created_at DESC') # for not existing params args
  applications = applications.where("cast(id as text) like ? OR email like ? OR first_name like ? OR last_name like ? OR appref like ?", "#{params[:search]}", "%#{params[:search]}%", "#{params[:search]}", "#{params[:search]}", "#{params[:search]}",) if params[:search]
  applications
end
like image 3
Promise Preston Avatar answered Nov 09 '22 00:11

Promise Preston


I deleted brackets from query and it work for me: from SELECT (column1, column2, ...) FROM table to SELECT column1, column2, ... FROM table

like image 2
Otniel Avatar answered Nov 09 '22 00:11

Otniel