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 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

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 3097
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 2, 20222022-06-02T02:17:02+00:00 2022-06-02T02:17:02+00:00

python – How to access list elements gotton from postgres-function in sqlalchemy?

  • 0

[ad_1]

I’m using python 3.8, sqlalchemy 1.4.21 & PostgreSQL 12.8.

I have no idea how to access the elements of list (array) gotten from postgres-function.
It’s easy to get the elements of list from Column object, but in the case of ColumnClause object, the same method didn’t work.

from sqlalchemy import Colum, Integer, String, ARRAY, func
from sqlalchemy.orm import Session
from sqlalchemy.ext.declarative import declarative_base

session = Session(autocommit=False, autoflush=True, bind=engine)
Base = declarative_base()

class Process(Base):
    __tablename__ = 'process'
    id = Column(Integer(), primary_key=True)
    product = Column(String(100))
    processes = Column(ARRAY(String()))

process = Process

q1 = session.query(
    process.id
    , process.product
    , process.processes[1] # <- It's OK.
    , func.array_positions(process.processes, 'process_A').label('proc_idx')
    ).select_from(process).cte('q1')

q2 = session.query(
    q1.c.id
    , q1.c.product
    , q1.c.proc_idx[1] # <- Error has occurred here!!
    ).select_from(q1).order_by(q1.c.id)

Error

NotImplementedError
Operator ‘getitem’ is not supported on this expression

To my understanding, “q1.c.proc_idx” (gotten from postgres-function: func.array_positions) is ColumnClause object and getitem operator (square brackets of list[]) is not implemented in ColumnClause object.
On the other hand, “process.proccesses[1]” is valid syntax because getitem operator is implemented in Column object.

How do I get the elements of list gotten from postgres-function?

Thanks in advance.

[ad_2]

  • 0 0 Answers
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 3 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 5 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 4 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

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.