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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:58:25+00:00 2026-06-13T06:58:25+00:00

In using Python with a connection to a PostgreSQL database, we are using SQLAlchemy,

  • 0

In using Python with a connection to a PostgreSQL database, we are using SQLAlchemy, but not the ORM. We have a table where one of the columns is an array of strings, and we want to retrieve all the rows for which an input parameter is NOT present in the array column. Please do note that we can retrieve the results of other queries for SQLAlchemy, so the problem has to be in the query creation.

The SQL we need to implement looks like this:

select pk from table where 'paramstring' NOT IN(array_column);
-- returns several rows

The function that we have come up with in Python is like this:

def get_not_matching(param):

    select_statement = select([the_table.c.pk]).where(
        ~data_table.c.array_column.in_([param])
    )

    #... execute and retrieve ResultProxy
    # the result_set comes back empty

Any suggestions would be greatly appreciated.

  • 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-13T06:58:27+00:00Added an answer on June 13, 2026 at 6:58 am

    Your issue is that you are using the in statement backwards. It is used to find rows that have a filed that is in a list, not to find rows that have a list which contains a string.

    In other words, what you have is generating:

    select pk from table where array_column NOT IN(paramstring);
    

    According to https://groups.google.com/forum/?fromgroups=#!topic/sqlalchemy/QAfTDrNYaFI SQLAlchemy does not yet support querying for items in a Postgres array column.

    They suggest using a raw filter in order to acomplish what you want:

    select([the_table.c.pk]).where(text("array_column @> ARRAY[:element_value]"))).params(element_value='paramstring')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django-created tables in PostgreSQL 8.4 database, where one table extends another.
I am trying to insert data into a PostgreSQL database table using Python. I
I am new to TCP/IP connection using python I have this simple code: import
I'm using Psycopg2 in Python to access a PostgreSQL database. I'm curious if it's
I have been using python with RDBMS' (MySQL and PostgreSQL), and I have noticed
I'm using Python 2.6.1 on Mac OS X. I have two simple Python files (below), but
I am using python poplib . Does a POP3 connection timeout after a period
I'm making a secure SSL connection to a server using python and M2Crypto. See
Using Python, how does one parse/access files with Linux-specific features, like ~/.mozilla/firefox/*.default ? I've
I'm using Python 2.6.4 and its module sqlite3 for a small database project and

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.