1

this_id is a string, that is an array, the_other is a boolean (from before I learned to default: false).

I do not know the format a search where the arrays('that') are not empty, [], i.e., have at least one thing in it. Thanks!

This.where("this_id = ? and that = ? and the_other IS NOT NULL", "#{@this.id}", ...NOT_EMPTY?)
3
  • is an empty array NULL? Commented Mar 29, 2020 at 0:20
  • Are you using PostgreSQL and an array column for that? Commented Mar 29, 2020 at 0:59
  • Yes and yes thanks.. Commented Mar 29, 2020 at 9:55

1 Answer 1

2

According to the PostgreSQL array documentation here, To compare with array type column you can use '{}', so you can write your query like this

This.where("this_id = ? and that != '{}' and the_other IS NOT NULL", "#{@this.id}") 

This should return the required rows.

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

3 Comments

Ok thanks! ... so ruby array [ ] and postres array { }. whats a postgres hash, [ ] ?
there is no hash type in postgresSQL, but there is a json type or hstore. here are documentation links for both. postgresqltutorial.com/postgresql-json postgresqltutorial.com/postgresql-hstore
my pleasure. :)

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.