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

  • SEARCH
  • Home
  • 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 6879221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:49:09+00:00 2026-05-27T04:49:09+00:00

I have two tables, Foo and Bar, I’d like to join them together so

  • 0

I have two tables, Foo and Bar, I’d like to join them together so BarID gets the prize based on having a key that is in the array, or if there’s no array set up, it defaults as if every key unlocks the prize.

>Table Foo
fooID | someArray    | prize
----------------------------------
 1    | {10,20,30}   | 'Winner'
 2    | {10}         | 'Grand prize'
 3    | null         | 'Participant'

(That’s not a string for someArray, it’s a valid postgresql type.)

>Table Bar 
BarID | Key
------------
 1    | 10
 2    | 20
 3    | 30
 4    | 40
 5    | 40
 6    | 40

I’ve tried this below:

SELECT
    Foo.fooID,
    Bar.prize
FROM Foo
LEFT JOIN Bar ON Bar.Key = ANY(someArray)

I have minimal success with this, when I put in a WHERE clause such as

WHERE Bar.BarID = 3

My results are simply ‘Winner’m but I also want to get ‘Participant’. If I set up my WHERE to include nulls:

WHERE 
    Bar.BarID = 3
  OR
    Foo.someArray = null

I still do not get my null values out.

No where clause returns all combinations of values, including the nulls.

I’m not really sure how to get this behaviour I want. I can get all, or I can get just one set of values, but not both.

To give examples, if I were to do the join for BarID = 1, I should get “Winner”, “Grand prize” and “participant”. If I were to select for BarID 5, I would only get Participant.

  • 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-05-27T04:49:10+00:00Added an answer on May 27, 2026 at 4:49 am

    Try:

    Foo.someArray IS NULL
    

    The equality operator always yields NULL, not TRUE when applied to a NULL value. To test a column whether it holds the NULL value, you need the above expression, not Foo.someArray = NULL.

    More about that in the manual.

    You also have to put it in your JOIN condition, not in a WHERE clause, as @Michael commented. Like:

    LEFT JOIN Bar ON Bar.Key = ANY(Foo.someArray) OR Foo.someArray IS NULL
    

    If you put it in the WHERE clause, you might also find rows where Foo.someArray IS NOT NULL, but has different prizes. With a LEFT JOIN, if (and only if) no row is found in Foo for a given Bar, NULL values will be appended for all columns of Foo, including someArray. This would fool a check for NULL in a WHERE condition.

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

Sidebar

Related Questions

I have two tables, we'll call them Foo and Bar , with a one
I have a database with two tables - let's call them Foo and Bar.
I have two tables named foo and bar , hypothetically speaking. foo has columns
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and
i have two tables in DB: Foo and Bar Using Entity Framework i want
I have two tables, foo and bar : +----+-----+ +----+-----+ | id | val
I have two tables, foo and bar , and I want foo.bar_id to link
I have two classes Foo and Bar mapped to two different tables, and I'd
Let's assume that I have two tables... Foo and Bar. They contain the following
Suppose I have a database table with two fields, foo and bar. Neither of

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.