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;
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
add a comment
|
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
add a comment
|
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
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
python python-3.x postgresql psycopg2 postgresql-11
asked Mar 28 at 14:55
madtynmadtyn
80212 silver badges29 bronze badges
80212 silver badges29 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
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.
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment
|
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.
add a comment
|
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.
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.
answered Mar 29 at 13:46
madtynmadtyn
80212 silver badges29 bronze badges
80212 silver badges29 bronze badges
add a comment
|
add a comment
|
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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