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 7859063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:45:26+00:00 2026-06-02T21:45:26+00:00

In pure postgres we can write: SELECT * FROM my_table WHERE 10000 = ANY

  • 0

In pure postgres we can write:

SELECT * FROM my_table WHERE 10000 = ANY (array_field);

or

SELECT * FROM my_table WHERE 10000 = ALL (array_field);

How to do the same with the help of sqlalchemy without raw sql?

  • 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-02T21:45:32+00:00Added an answer on June 2, 2026 at 9:45 pm

    a = ANY(b_array) is equivalent to aIN(elements_of_b_array)1.

    Therefore you can use the in_() method.

    I can’t remember ever having used a = ALL(b_array) in all my years with PostgreSQL. Have you?


    If you are dealing with an array column and want to test whether it contains a given element (or all elements of a given array) in that column, then you can utilize PostgreSQL array operators @> (contains) or more appropriately the inverse sibling <@ (is contained by).

    Array operators carry the advantage that they can be supported with a GIN index on the array column (unlike the ANY construct).

    Your SQL statement:

    SELECT * FROM my_table WHERE 10000 = ANY (array_field);
    

    is (almost)1 equivalent to

    SELECT * FROM my_table WHERE 10000 <@ array_field;
    

    I am no expert with SQLAlchemy, but according to the tutorial in the SQLAlchemy manual, you can use any operator:

    If you have come across an operator which really isn’t available, you
    can always use the op() method; this generates whatever
    operator you need:

    >>> print users.c.name.op('tiddlywinks')('foo') users.name tiddlywinks :name_1
    

    Bold emphasis mine. Your statement could look like this in SQLA:

    s = select([my_table], array_field.op('@>')('ARRAY[10000]'))
    

    Or with alternative input syntax for PostgreSQL array values:

    s = select([my_table], array_field.op('@>') (cast('{10000}', int[])))
    

    1 There is a subtle difference with NULL handling:

    SELECT '{NULL}'::int[] <@ ... -- that's an array with a single NULL element
    

    always yields FALSE.

    SELECT NULL IN (...)
    SELECT NULL = ANY (...)
    SELECT NULL::int[] <@ ...
    

    always yield NULL.

    If you are not going to query for NULL values, you can ignore this.

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

Sidebar

Related Questions

using pure javascript can i select all a tags with href=#xyz. And also i
I have a pure-SQL queryset: SELECT ft2.user_id, avg(...) figure, count(...) as figure_count FROM figures_table
How to create a pure JavaScript (without using any library) plugin which looks like:
I have a pure text file without any HTML formatting. I want to search
I have this postgres sql query: select * from stats where athlete_id = 5
Using pure functional languages can have a lot of benefits over using impure imperatives,
In a pure C++ world we can generate interfacing or glue code between different
just in pure gdi. thoughts or code are all welcome.
pure is a function attribute which says that a function does not modify any
I'm using the Pure CSS menu from here: http://csswizardry.com/2011/02/creating-a-pure-css-dropdown-menu/ It works fine, but I

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.