Re: I can't get row type from tuple (SPI)

Lists: pgsql-hackers
From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: I can't get row type from tuple (SPI)
Date: 2005-11-05 17:34:33
Message-ID: BAY20-F5EA78637DC0E29C45E7F0F9630@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

I execute "select anyrowfce(..)" in plpgsql via exec_run_select

I need to get inner row, but I can't find good way for it

retval = SPI_getbinval(estate->eval_tuptable->vals[0],
estate->eval_tuptable->tupdesc,1);

rettype = SPI_gettypeid(estate->eval_tuptable->tupdesc,1);
rettupdesc = lookup_rowtype_tupdesc(rettype,0);

rettupdesc is ok, but when I try SPI_getbinval(retval, rettupdesc, ...) I
kill backend.

What I do wrong? What is optimal process to get first field in row, when
this first field is row too.

for example I need to way for value 1 in select

select row(row(1,2,3)); => "("(1,2,3)")"

Can I get inner tupdesc without lookup_rowtype_tupdesc?

Thank you very much

Pavel Stehule

_________________________________________________________________
Citite se osamele? Poznejte nekoho vyjmecneho diky Match.com.
http://www.msn.cz/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: I can't get row type from tuple (SPI)
Date: 2005-11-07 01:59:01
Message-ID: 24458.1131328741@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
> rettupdesc = lookup_rowtype_tupdesc(rettype,0);

This is wrong --- if you don't know what typmod to use, *always* pass -1
not 0. (I suspect that rettype is RECORD and that -1 would have
resulted in a NULL result.)

It seems like SPI is missing a needed function: it should have an
SPI_gettypmod to go along with SPI_gettypeid. This would probably
give you the correct typmod to pass to lookup_rowtype_tupdesc here.

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)hotmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: I can't get row type from tuple (SPI)
Date: 2005-12-04 04:14:51
Message-ID: 200512040414.jB44Epq10958@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Added to TODO:

* Add SPI_gettypmod() to return the typemod for a TupleDesc

---------------------------------------------------------------------------

Tom Lane wrote:
> "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
> > rettupdesc = lookup_rowtype_tupdesc(rettype,0);
>
> This is wrong --- if you don't know what typmod to use, *always* pass -1
> not 0. (I suspect that rettype is RECORD and that -1 would have
> resulted in a NULL result.)
>
> It seems like SPI is missing a needed function: it should have an
> SPI_gettypmod to go along with SPI_gettypeid. This would probably
> give you the correct typmod to pass to lookup_rowtype_tupdesc here.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073