Re: table.column in cursor.description?

James Henstridge <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Thu, Jul 23, 2009 at 3:53 AM, Andrew Klaassen<clawsoon-/[email protected]> wrote:
> Hi,
>
> Is it possible to get psycopg2 to return full column names (i.e. "table.column" instead of just "column") in cursor.description?  This would be handy when executing joins.
>
> I.e.
>
>>>> cursor.execute("select * from document, element")
>>>> print cursor.description
> [('document.id', ...), ('document.name', ...), ('element.id', ...), ('element.text', ...)]
>
> ...instead of the current behaviour, which is:
>
>>>> print cursor.description
> [('id', ...), ('name', ...), ('id', ...), ('text', ...)]

The column names for result sets come directly from PostgreSQL.
Psycopg2 isn't adding or removing any information here.  I don't know
if it is possible to change PostgreSQL's behaviour here, but if you
can it is likely that the change would be reflected in Psycopg2 with
no extra effort.

Perhaps someone on one of the PostgreSQL lists will know the answer?


> The SQLite Python module has something like this with "pragma
> full_column_names=ON;":
>
> http://mail.python.org/pipermail/python-bugs-list/2009-January/069202.html

That is an example of telling SQLite to provide different column
names, which then gets passed through by the Python bindings.  So
again, it depends on the underlying database rather than the adapter
for that database.

James.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.