
Hi,

i notice that when HeapTuple data are populated by a trigger
then the table oid can be retrieved from HeapTuple->t_tableOid.

When HeapTuple is populated by 
SPI_exec("select * from foobar when id=667");
tuple = SPI_tuptable->tvals[0] (id is PK and row with 667 exists)
then tuple->t_tableOid is always 0.

Is it a known issue??
Am i missing something?

-Achilleus


Fri, 3 Oct 2003 15:56:07 +0300 (EEST)
achill@matrix.gatewaynet.com
HeapTuple->t_tableOid==0 after SPI_exec
achill@matrix.gatewaynet.com writes:
> When HeapTuple is populated by 
> SPI_exec("select * from foobar when id=667");
> tuple = SPI_tuptable->tvals[0] (id is PK and row with 667 exists)
> then tuple->t_tableOid is always 0.

The result of a SELECT is never a raw table tuple, not even when it's a
straight "select * from foo".  It's a constructed tuple that belongs to
no particular table --- which makes sense because in general it wouldn't
match any particular table's rowtype.

I think in 7.4 there may be an optimization that skips the tuple
projection step in this particular case, but if you can in fact see
t_tableOid in 7.4, it'd be an implementation artifact rather than
something we will promise to support in future.  The correct way if you
want to see tableoid is to select it:

	select tableoid,* from foobar where ...

and then extract it from the result using the usual field-access
routines.

			regards, tom lane

Fri, 03 Oct 2003 10:43:36 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: HeapTuple->t_tableOid==0 after SPI_exec 
achill@matrix.gatewaynet.com writes:
> are there gonna be changes in SPI or internal structs in 7.4?

No more than usual ;-).  You will need to recompile shared libraries,
but (in theory) source code changes shouldn't be needed.  You might want
to think about upgrading elog() calls to ereport() though.

			regards, tom lane

Fri, 03 Oct 2003 11:03:19 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: HeapTuple->t_tableOid==0 after SPI_exec 
On Fri, 3 Oct 2003, Tom Lane wrote:

> 
> I think in 7.4 there may be an optimization that skips the tuple
> projection step in this particular case, but if you can in fact see
> t_tableOid in 7.4, it'd be an implementation artifact rather than
> something we will promise to support in future.  The correct way if you
> want to see tableoid is to select it:
> 
> 	select tableoid,* from foobar where ...
> 
> and then extract it from the result using the usual field-access
> routines.

Thanx.

P.S.

are there gonna be changes in SPI or internal structs in 7.4?

> 
> 			regards, tom lane
> 

-- 
-Achilleus


Fri, 3 Oct 2003 18:04:47 +0300 (EEST)
achill@matrix.gatewaynet.com
Re: HeapTuple->t_tableOid==0 after SPI_exec 