Skip to content

exception on cursor.description from COPY #235

@dvarrazzo

Description

@dvarrazzo

Here is a minimal reproduction case:

import psycopg

conn = psycopg.connect(
    user='postgres',
    host='127.0.0.1',
    password='',
    port=5432,
    dbname=None
)
conn.autocommit = True
with conn.cursor() as cur:
    with cur.copy("COPY (select 'This', 'Is', 'Text') TO STDOUT") as copy:
        for row in copy.rows():
            print(row)
    print('---')
    print(cur.description)
    print('---')

The exception is thrown on line print(cur.description):

Traceback (most recent call last):
  File "/Users/irinatruong/Library/Application Support/JetBrains/PyCharm2020.2/scratches/scratch.py", line 16, in <module>
    print(cur.description)
  File "/Users/irinatruong/.pyenv/versions/pgspecial/lib/python3.9/site-packages/psycopg/cursor.py", line 127, in description
    return [Column(self, i) for i in range(res.nfields)]
  File "/Users/irinatruong/.pyenv/versions/pgspecial/lib/python3.9/site-packages/psycopg/cursor.py", line 127, in <listcomp>
    return [Column(self, i) for i in range(res.nfields)]
  File "/Users/irinatruong/.pyenv/versions/pgspecial/lib/python3.9/site-packages/psycopg/_column.py", line 32, in __init__
    raise e.InterfaceError(f"no name available for column {index}")
psycopg.InterfaceError: no name available for column 0

Originally posted by @j-bennet in dbcli/pgspecial#123 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions