Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7954811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:32:39+00:00 2026-06-04T03:32:39+00:00

I have this statement: myuser.orders.exists?([‘(orderstatus = ?) ‘, statusid]) It returns true since there

  • 0

I have this statement:

myuser.orders.exists?(['(orderstatus = ?) ', statusid])

It returns true since there is an orderstatus that matches the statusid.

Next I have:

myuser.orders.where('id not in (?)', nil).exists?(['(orderstatus = ?) ', statusid])

This returns false where I thought it might return true since there are no ids that are nil.

Then I have:

myuser.orders.where(nil).exists?(['(orderstatus = ?) ', statusid])

This returns true.

My question is why does the middle statement return false? It doesn’t complain or throw any errors. I guess I’m using nil wrong, but can someone explain?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:32:41+00:00Added an answer on June 4, 2026 at 3:32 am

    You’re having trouble with SQL’s NULL. The where in the middle one:

    where('id not in (?)', nil)
    

    becomes this SQL:

    id not in (null)
    

    and that’s equivalent to this:

    id != null
    

    But the result of id != null is neither true nor false, the result is NULL and NULL in a boolean context is false; in fact, x = null and x != null result in NULL for all x (even when x itself is NULL); for example, in PostgreSQL:

    => select coalesce((11 = null)::text, '-NULL-');
     coalesce 
    ----------
     -NULL-
    (1 row)
    
    => select coalesce((11 != null)::text, '-NULL-');
     coalesce 
    ----------
     -NULL-
    (1 row)
    
    => select coalesce((null = null)::text, '-NULL-');
     coalesce 
    ----------
     -NULL-
    (1 row)
    
    => select coalesce((null != null)::text, '-NULL-');
     coalesce 
    ----------
     -NULL-
    (1 row)
    

    MySQL and every other reasonably compliant database will do the same thing (with possibly different casting requirements to make the NULL obvious).

    The result is that where(id not in (?)', nil) always yields an empty set and your existence check will always fail on an empty set.

    If you want to say “all the rows where id is not NULL” then you want to say:

    where('id is not null')
    

    If your id is a primary key (as it almost certainly is), then id will never be NULL and you can leave that where out completely.


    When you hand where just a nil:

    where(nil)
    

    where‘s argument parsing logic will ignore the nil completely and where(nil) will be the same as where() and where() does nothing at all to the query. The result is that the first and third queries are identical as far as the database is concerned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this MySQL statement from a search page, the user enters there postcode
I have this if statement that tests for the 2 conditions below. The second
I have this statement: String cap = Regex.Replace(winCaption, @[^\w\.@-], ); that transforms Hello |
I have this if statement if (!(@$donnees['mode']['delete'] === true || @$donnees['mode']['display'] === true)){ //doSomething
I have this statement: SELECT passwdlib.piv_insertPasswd(:A1, :A2) FROM DUAL I am guessing that piv_insertPasswd
I have this statement that im trying to figure out how to use in
I currently have this statement in my SQL View (SQL Server 2008 R2) which
I have this sql statement: CREATE TABLE [dbo].[User]( [UserId] [int] IDENTITY(1,1) NOT NULL, [FirstName]
I have this update statement: mysql_query (UPDATE loan SET loan_reff_id='$_POST[loan_reff_id]', commit_date='$_POST[commit_date]',app_loan_type='Tertiary Loan', app_ln_amnt='$_POST[app_ln_amnt]', institution_name='$_POST[institution_name]',
I have seen this statement in many of the documention samples, like here This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.