Parse record type into tuple

From: Dmytro Starosud <d(dot)starosud(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Parse record type into tuple
Date: 2017-09-05 15:40:17
Message-ID: CANC2W+A88-8b9VzEkTh1cma9ezTtvNa7Z6gK6_LL1e7udZLjFA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Hello guys

I do following interactions with DB:

In [48]: conn = psycopg2.connect("dbname=... user=... password=...")
In [49]: cur = conn.cursor()
In [50]: cur.execute("select (1, 2)")
In [51]: cur.fetchone()
Out[51]: ('(1,2)',)

Is it possible to get that tuple parsed into python tuple in the same way
array works?

In [55]: cur.execute("select array[1, 2]")
In [56]: cur.fetchone()
Out[56]: ([1, 2],)

Looks like that can be done if I register composite type for that tuple.
But I would like it to work with any tuple.

Please assist.

Thanks in advance!
Dmytro

Responses

Browse psycopg by date

  From Date Subject
Next Message Rory Campbell-Lange 2017-09-05 21:39:10 Re: Parse record type into tuple
Previous Message Daniele Varrazzo 2017-08-26 13:34:45 Psycopg 2.7.3.1 released