#154 ✓ invalid
Psycopg website

Insert with RETURNING mutilple values returns them in a string

Reported by Psycopg website | March 24th, 2013 @ 07:32 PM

Submitted by: ChMeessen

When performing an SQL insert operation returning multiple values, which is valid, the value returned by fetchone()[0] is a string with values concatenated.

cur.execute("""INSERT INTO items
(userId, count, label, editId) VALUES (%s, %s, %s, %s)
RETURNING (id,editId,count,label)""",
(userId, 0, label, editId)) res = cur.fetchone()[0]

res is the string '(63,8,0,"Test")'
instead of a tuple of values.

When RETURNING id is used, the returned value is the id itself.

Comments and changes to this ticket

  • Daniele Varrazzo

    Daniele Varrazzo March 25th, 2013 @ 09:38 AM

    • State changed from “new” to “invalid”

    That's because you have put the RETURNING values into parenthesis, so postgres is returning a record value for which psycopg doesn't have a typecaster.

    You have to use:

    cur.execute("""INSERT INTO items
        (userId, count, label, editId) VALUES (%s, %s, %s, %s)
        RETURNING id,editId,count,label""",
    

    This is no psycopg bug, so closing. bye!

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.

Shared Ticket Bins

Tags

Pages