Python3 psycopg2: “No results to fetch” using RETURNINGHow do I return multiple values from a function?Why does comparing strings using either '==' or 'is' sometimes produce a different result?What's the difference between raw_input() and input() in python3.x?How to install psycopg2 with “pip” on Python?How to install python3 version of package via pip on Ubuntu?StringIO in Python3psycopg2 not returning resultsWhy does “not(True) in [False, True]” return False?TypeError: a bytes-like object is required, not 'str' when writing to a file in Python3In (python3) psycopg2 return results as string rather than dict

Manager encourages me to take day of sick leave instead of PTO, what's in it for him?

Are actors contractually obligated to certain things like going nude/ Sensual Scenes/ Gory Scenes?

What was the deeper meaning of Hermione wanting the cloak?

Leaving a job that I just took based on false promise of a raise. What do I tell future interviewers?

How could artificial intelligence harm us?

As a discovery writer, how do I complete an unfinished novel (which has highly diverged from the original plot ) after a time-gap?

Cheap antenna for new HF HAM

How do I extract the path back out from a brush?

How to ask a man to not take up more than one seat on public transport while avoiding conflict?

Is there an in-universe reason Harry says this or is this simply a Rowling mistake?

Can Bless or Bardic Inspiration help a creature from rolling a 1 on a death save?

How to make interviewee comfortable interviewing in lounge chairs

Escape the labyrinth!

Did Apollo carry and use WD40?

Did HaShem ever command a Navi (Prophet) to break a law?

Do things made of adamantine rust?

Gas leaking in base of new gas range?

What is meaning of active low input in combinational logic circuits?

Algorithm that spans orthogonal vectors: Python

Is Zack Morris's 'time stop' ability in "Saved By the Bell" a supernatural ability?

As an employer, can I compel my employees to vote?

US entry with tourist visa but past alcohol arrest

Circle divided by lines between a blue dots

Repeat elements in list, but the number of times each element is repeated is provided by a separate list



Python3 psycopg2: “No results to fetch” using RETURNING


How do I return multiple values from a function?Why does comparing strings using either '==' or 'is' sometimes produce a different result?What's the difference between raw_input() and input() in python3.x?How to install psycopg2 with “pip” on Python?How to install python3 version of package via pip on Ubuntu?StringIO in Python3psycopg2 not returning resultsWhy does “not(True) in [False, True]” return False?TypeError: a bytes-like object is required, not 'str' when writing to a file in Python3In (python3) psycopg2 return results as string rather than dict






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm using:



  • psvcopg2

  • python3.6

  • postgresql-11.2

  • kubuntu 18.10

and I'm inserting successfully a row but the cursor.fetchall() is raising



psycopg2.ProgrammingError: no results to fetch


even when I'm using RETURNING inside the SQL for retrieving an id.



I found out about cursor.description but it's empty (cursor.description == None).



The SQL works correctly used within psql terminal returning the id as requested.



python code:



import psycopg2
from psycopg2.pool import ThreadedConnectionPool

pool = ThreadedConnectionPool(3, 20,
user="user",
password='xxxxxxxxx',
host="127.0.0.1",
port="5432",
database="my_database")

query = 'INSERT INTO market.item(item_store_id, title, price, url, image_url, aff_url, store_id) '
'VALUES(%(item_store_id)s, %(title)s, %(price)s, %(url)s, %(image_url)s, %(aff_url)s, %(store_id)s) '
'ON CONFLICT (item_store_id) DO '
'UPDATE SET (price, url, image_url, aff_url) = (excluded.price, excluded.url, excluded.image_url, excluded.aff_url) '
'RETURNING item_id '
args = [
'item_store_id': 1,
'title': 'My title',
'price': 15,
'url': 'http://www.url.com',
'image_url': 'http://www.url.com',
'aff_url': 'http://www.url.com',
'store_id': 1,
]
try:
result = []
connection = pool.getconn()
connection.autocommit = True
with connection.cursor() as cursor:
try:
cursor.executemany(query, args)
if cursor.rownumber > 0:
subresult = cursor.fetchall()
result.append(subresult)

print(result)
except (Exception, psycopg2.DatabaseError) as e:
raise
except (Exception, psycopg2.DatabaseError) as error:
print(e)
else:
print(result)
finally:
pool.putconn(connection)









share|improve this question






























    0















    I'm using:



    • psvcopg2

    • python3.6

    • postgresql-11.2

    • kubuntu 18.10

    and I'm inserting successfully a row but the cursor.fetchall() is raising



    psycopg2.ProgrammingError: no results to fetch


    even when I'm using RETURNING inside the SQL for retrieving an id.



    I found out about cursor.description but it's empty (cursor.description == None).



    The SQL works correctly used within psql terminal returning the id as requested.



    python code:



    import psycopg2
    from psycopg2.pool import ThreadedConnectionPool

    pool = ThreadedConnectionPool(3, 20,
    user="user",
    password='xxxxxxxxx',
    host="127.0.0.1",
    port="5432",
    database="my_database")

    query = 'INSERT INTO market.item(item_store_id, title, price, url, image_url, aff_url, store_id) '
    'VALUES(%(item_store_id)s, %(title)s, %(price)s, %(url)s, %(image_url)s, %(aff_url)s, %(store_id)s) '
    'ON CONFLICT (item_store_id) DO '
    'UPDATE SET (price, url, image_url, aff_url) = (excluded.price, excluded.url, excluded.image_url, excluded.aff_url) '
    'RETURNING item_id '
    args = [
    'item_store_id': 1,
    'title': 'My title',
    'price': 15,
    'url': 'http://www.url.com',
    'image_url': 'http://www.url.com',
    'aff_url': 'http://www.url.com',
    'store_id': 1,
    ]
    try:
    result = []
    connection = pool.getconn()
    connection.autocommit = True
    with connection.cursor() as cursor:
    try:
    cursor.executemany(query, args)
    if cursor.rownumber > 0:
    subresult = cursor.fetchall()
    result.append(subresult)

    print(result)
    except (Exception, psycopg2.DatabaseError) as e:
    raise
    except (Exception, psycopg2.DatabaseError) as error:
    print(e)
    else:
    print(result)
    finally:
    pool.putconn(connection)









    share|improve this question


























      0












      0








      0








      I'm using:



      • psvcopg2

      • python3.6

      • postgresql-11.2

      • kubuntu 18.10

      and I'm inserting successfully a row but the cursor.fetchall() is raising



      psycopg2.ProgrammingError: no results to fetch


      even when I'm using RETURNING inside the SQL for retrieving an id.



      I found out about cursor.description but it's empty (cursor.description == None).



      The SQL works correctly used within psql terminal returning the id as requested.



      python code:



      import psycopg2
      from psycopg2.pool import ThreadedConnectionPool

      pool = ThreadedConnectionPool(3, 20,
      user="user",
      password='xxxxxxxxx',
      host="127.0.0.1",
      port="5432",
      database="my_database")

      query = 'INSERT INTO market.item(item_store_id, title, price, url, image_url, aff_url, store_id) '
      'VALUES(%(item_store_id)s, %(title)s, %(price)s, %(url)s, %(image_url)s, %(aff_url)s, %(store_id)s) '
      'ON CONFLICT (item_store_id) DO '
      'UPDATE SET (price, url, image_url, aff_url) = (excluded.price, excluded.url, excluded.image_url, excluded.aff_url) '
      'RETURNING item_id '
      args = [
      'item_store_id': 1,
      'title': 'My title',
      'price': 15,
      'url': 'http://www.url.com',
      'image_url': 'http://www.url.com',
      'aff_url': 'http://www.url.com',
      'store_id': 1,
      ]
      try:
      result = []
      connection = pool.getconn()
      connection.autocommit = True
      with connection.cursor() as cursor:
      try:
      cursor.executemany(query, args)
      if cursor.rownumber > 0:
      subresult = cursor.fetchall()
      result.append(subresult)

      print(result)
      except (Exception, psycopg2.DatabaseError) as e:
      raise
      except (Exception, psycopg2.DatabaseError) as error:
      print(e)
      else:
      print(result)
      finally:
      pool.putconn(connection)









      share|improve this question














      I'm using:



      • psvcopg2

      • python3.6

      • postgresql-11.2

      • kubuntu 18.10

      and I'm inserting successfully a row but the cursor.fetchall() is raising



      psycopg2.ProgrammingError: no results to fetch


      even when I'm using RETURNING inside the SQL for retrieving an id.



      I found out about cursor.description but it's empty (cursor.description == None).



      The SQL works correctly used within psql terminal returning the id as requested.



      python code:



      import psycopg2
      from psycopg2.pool import ThreadedConnectionPool

      pool = ThreadedConnectionPool(3, 20,
      user="user",
      password='xxxxxxxxx',
      host="127.0.0.1",
      port="5432",
      database="my_database")

      query = 'INSERT INTO market.item(item_store_id, title, price, url, image_url, aff_url, store_id) '
      'VALUES(%(item_store_id)s, %(title)s, %(price)s, %(url)s, %(image_url)s, %(aff_url)s, %(store_id)s) '
      'ON CONFLICT (item_store_id) DO '
      'UPDATE SET (price, url, image_url, aff_url) = (excluded.price, excluded.url, excluded.image_url, excluded.aff_url) '
      'RETURNING item_id '
      args = [
      'item_store_id': 1,
      'title': 'My title',
      'price': 15,
      'url': 'http://www.url.com',
      'image_url': 'http://www.url.com',
      'aff_url': 'http://www.url.com',
      'store_id': 1,
      ]
      try:
      result = []
      connection = pool.getconn()
      connection.autocommit = True
      with connection.cursor() as cursor:
      try:
      cursor.executemany(query, args)
      if cursor.rownumber > 0:
      subresult = cursor.fetchall()
      result.append(subresult)

      print(result)
      except (Exception, psycopg2.DatabaseError) as e:
      raise
      except (Exception, psycopg2.DatabaseError) as error:
      print(e)
      else:
      print(result)
      finally:
      pool.putconn(connection)






      python python-3.x postgresql psycopg2 postgresql-11






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 14:55









      madtynmadtyn

      80212 silver badges29 bronze badges




      80212 silver badges29 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0
















          My bad. I didn't notice this in the docs:



          The function is mostly useful for commands that update the database: any result set returned by the query is discarded.





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );














            draft saved

            draft discarded
















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400707%2fpython3-psycopg2-no-results-to-fetch-using-returning%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0
















            My bad. I didn't notice this in the docs:



            The function is mostly useful for commands that update the database: any result set returned by the query is discarded.





            share|improve this answer





























              0
















              My bad. I didn't notice this in the docs:



              The function is mostly useful for commands that update the database: any result set returned by the query is discarded.





              share|improve this answer



























                0














                0










                0









                My bad. I didn't notice this in the docs:



                The function is mostly useful for commands that update the database: any result set returned by the query is discarded.





                share|improve this answer













                My bad. I didn't notice this in the docs:



                The function is mostly useful for commands that update the database: any result set returned by the query is discarded.






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 29 at 13:46









                madtynmadtyn

                80212 silver badges29 bronze badges




                80212 silver badges29 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















                    draft saved

                    draft discarded















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400707%2fpython3-psycopg2-no-results-to-fetch-using-returning%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현