1

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"

1
  • And is it "Flag" or "flag"? In RoR the convention is to use lower-case letters. Commented Sep 28, 2011 at 4:10

1 Answer 1

1

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.

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

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.