0

I had a project that I shelved for awhile, but recently I dusted it off and updated all the NPM packages. Now when I try to do anything database related (using Knex/Postgresql) I get the error:

error: column "*" does not exist

This will happen with a seemingly harmless query like:

select "*" from "some_table" where "id" = $1

If I run that query directly against the DB:

select * from "some_table" where "id" = 1;

it works fine. But no matter what I try with knex, whether it's running a regular query or trying to reset my whole database, I keep getting that seemingly nonsensical error.

Can anyone explain what it means?

4
  • knex.select().table('books') will result in select * - even though this was not your question, ;] Commented Apr 8, 2019 at 6:18
  • "*" is something different than * Commented Apr 8, 2019 at 6:32
  • Please tell also what kind of code you write for knex to generate that query. It is impossible to tell otherwise why generation of that kind of query happen. Commented Apr 8, 2019 at 20:08
  • Part of the problem is that I don't know which code exactly is the problem: all of the line in the stacktrace are node_modules or system calls, and again I get the error both when trying to run the site or when trying to run migrations (and my site has many queries involving this table). But thanks to the answer, I can now at least start tracking it down. Commented Apr 8, 2019 at 23:39

1 Answer 1

2

The double quotes around the * cause it not to be interpreted as “all columns”, but as a column with that very name.

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

2 Comments

I'm not quite sure why my code went from selecting * to selecting "*", just from an npm update, but apparently that's what happened, and I can work from there. Thanks!
Just a follow-up for anyone else reading this later: I figured out that the problem was that Knex went from using the syntax .select('*') to create a SELECT * FROM ... clause, to a syntax of just .select(). Making that change in your code should fix the issue.

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.