Lists: | pgsql-hackers |
---|
From: | "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | strange tuple from ExecutorRun |
Date: | 2007-11-16 10:49:38 |
Message-ID: | 162867790711160249t4dc97060hac858993f93d7e82@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hello
I cannot find my bug. I would to get tuple via ExecutorRun. But it
works only with one field in target. With more fields I got last
fileld on first position and others fields are null. Can somebody help
me?
Pavel Stehule
postgres=# call print(10,20,30);
NOTICE: nargs 3
NOTICE: 30 0
NOTICE: 2139062143 0
NOTICE: 2139062143 0
code:
dest = CreateDestReceiver(DestNone, NULL);
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
qdesc = CreateQueryDesc(plan, ActiveSnapshot,
InvalidSnapshot,
dest,
paramLI, false);
ExecutorStart(qdesc, 0);
result = ExecutorRun(qdesc, ForwardScanDirection, 1L);
tuple = ExecMaterializeSlot(result);
values = (Datum *) palloc(nargs * sizeof(Datum));
nulls = (char *) palloc(nargs * sizeof(char));
/* copy typle to current context */
tuple = heap_copytuple(tuple);
heap_deform_tuple(tuple, qdesc->tupDesc, values, nulls);
for(i = 0; i < nargs; i++)
elog(NOTICE, "%d %d", values[i], nulls[i]);
NOTICE: plan:
DETAIL: {PLANNEDSTMT
:commandType 1
:canSetTag true
:planTree
{RESULT
:startup_cost 0.00
:total_cost 0.01
:plan_rows 1
:plan_width 0
:targetlist (
{TARGETENTRY
:expr
{CONST
:consttype 23
:consttypmod -1
:constlen 4
:constbyval true
:constisnull false
:constvalue 4 [ 10 0 0 0 ]
}
:resno 1
:resname ?Parameter?
:ressortgroupref 0
:resorigtbl 0
:resorigcol 0
:resjunk false
}
{TARGETENTRY
:expr
{CONST
:consttype 23
:consttypmod -1
:constlen 4
:constbyval true
:constisnull false
:constvalue 4 [ 20 0 0 0 ]
}
:resno 1
:resname ?Parameter?
:ressortgroupref 0
:resorigtbl 0
:resorigcol 0
:resjunk false
}
{TARGETENTRY
:expr
{CONST
:consttype 23
:consttypmod -1
:constlen 4
:constbyval true
:constisnull false
:constvalue 4 [ 30 0 0 0 ]
}
:resno 1
:resname ?Parameter?
:ressortgroupref 0
:resorigtbl 0
:resorigcol 0
:resjunk false
}
)
:qual <>
:lefttree <>
:righttree <>
:initPlan <>
:extParam (b)
:allParam (b)
:resconstantqual <>
}
:rtable <>
:resultRelations <>
:utilityStmt <>
:intoClause <>
:subplans <>
:rewindPlanIDs (b)
:returningLists <>
:rowMarks <>
:relationOids <>
:nParamExec 0
}
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: strange tuple from ExecutorRun |
Date: | 2007-11-16 16:22:23 |
Message-ID: | 13367.1195230143@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
[ not directly related to your bug, but... ]
"Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
> result = ExecutorRun(qdesc, ForwardScanDirection, 1L);
> tuple = ExecMaterializeSlot(result);
> values = (Datum *) palloc(nargs * sizeof(Datum));
> nulls = (char *) palloc(nargs * sizeof(char));
> /* copy typle to current context */
> tuple = heap_copytuple(tuple);
> heap_deform_tuple(tuple, qdesc->tupDesc, values, nulls);
Surely that's the hard way, considering that the output tupleslot is
probably *already* a values/nulls array. Use slot_getattr(), or call
slot_getallattrs() and then reference the slot's arrays directly.
regards, tom lane