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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:49:48+00:00 2026-06-13T00:49:48+00:00

Since the query returns more than 1 result, at the Get_results class how could

  • 0

Since the query returns more than 1 result, at the Get_results class how could i return the data_out as an array in order to iterate on the results of the query?

import psycopg2
import sys

class Get_results():
    def db_call(self,query,dbHost,dbName,dbUser,dbPass):
        try:
            con = None
            con = psycopg2.connect(host=dbHost, database=dbName,
                                   user=dbUser, password=dbPass)
            cur = con.cursor()
            cur.execute(query)
            data = cur.fetchall()
            for data_out in data:
                return data_out
        except psycopg2.DatabaseError, e:
                print 'Error %s' % e
                sys.exit(1)
        finally:
            if con:
                con.close()

 sql = " some sql "
 w = Get_results()
 for i in  w.db_call(sql, dbHost, dbName, dbUser, dbPass):
     print "The result is : " + i

For aditional info, when if i add print data right after data = cur.fetchall() i have the result:

[('The_Galaxy', 'The_Galaxy:star'),
 ('The_Galaxy', 'The_Galaxy:planet')]
  • 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-13T00:49:49+00:00Added an answer on June 13, 2026 at 12:49 am
    import psycopg2
    import sys
    
    class Get_results():
        def db_call(self,query,dbHost,dbName,dbUser,dbPass):
            try:
                con = None
                con = psycopg2.connect(host=dbHost, database=dbName,
                                       user=dbUser, password=dbPass)
                cur = con.cursor()
                cur.execute(query)
                data = cur.fetchall()  
                resultList = []  
                for data_out in data:  
                    resultList.append(data_out[1])  
    
    
                return resultList   
            except psycopg2.DatabaseError, e:
                    print 'Error %s' % e
                    sys.exit(1)
            finally:
                if con:
                    con.close()
    
     sql = " some sql "
     w = Get_results()
     for i in  w.db_call(sql, dbHost, dbName, dbUser, dbPass):
         print "The result is : " + i
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that needs to return results that are NOT matched in
Edit - restating my need since two guys with way more rank than me
For this question, we want to avoid having to write a special query since
Since i'm a poor sql developer, i need support to write a sql query
-webkit-device-pixel-ratio query is supported by both iOS and Android but since iOS does not
Here is the snapshot of the query that doesn't work since I added the
Goodmorning, I'm doing a query to fill a MFC Recordset in my program. Since
okay, my problem is a little bit more difficult than the title would tell...
I'm creating a linq query to get some data that will return a list
In my rails app, I am running a sql query using find_by_sql() since 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.