简体   繁体   中英

Why doesn't the where query work in postgresql?

I have a ruby on rails app in which I am querying for a boolean column, Flag. The code is:

Merchant.where("Flag=?",false)

However this does not work at all and the only result is that the Merchants table does not have a column name "flag". Is there any way to fix this? The column name starts with an uppercase letter, but the search is being done for a lower case "flag"

If the column name was quoted when the table was created then you will have to quote it forever. So, if you started with this:

create table merchants (
    -- ...
    "Flag" boolean
    -- ...
)

Then you'll have to refer to it using

Merchant.where('"Flag" = ?', false)

PostgreSQL normalizes all unquoted identifiers to lower case (not upper case as the standard says), that's why the error message complains about flag rather than Flag .

If you can, you might want to rebuild your table with only lower case column names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM