85

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.

1
  • 1
    row values. Commented Feb 9, 2017 at 9:27

6 Answers 6

167

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

Sign up to request clarification or add additional context in comments.

3 Comments

Argh. Made exactly the same mistake during an INSERT INTO X (c1, c2...) SELECT... statement. This is a horrible error. And it looks like you have plenty of company.
Same issue with ORDER BY (sections.orderId, items.orderId). You're answer pointed me into the right direction. :)
@Falko Thank you for your comment, ORDER BY (…) was the case for me too
5

JUST

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

then it works.

Comments

4

The same error occurs when putting the elements of a GROUP BY clause inside brackets, as in

SELECT 1 as a, 2 as b FROM (SELECT 1) GROUP BY (a, b);

The correct syntax is, of course

SELECT 1 as a, 2 as b FROM (SELECT 1) GROUP BY a, b;

Comments

3

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

Comments

3

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

Comments

2

Yeah, this bug is happing in my code, and I found this questions, but none of the answers helped me.
I fixed this problem with remove the same column in my SELECT command.
(It's stupid, because I can't select the column if the column is already in the condition subcommand.)

This is the problem SQL command (DO NOT USE THIS):

SELECT (`id`, `username`) FROM `users` WHERE `id` = 'someone_s id'

This is the fixed SQL command (PLEASE USE THIS):

SELECT (`username`) FROM `users` WHERE `id` = 'someone_s id'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.