Sort a column that does not exist
От | Werner Echezuria |
---|---|
Тема | Sort a column that does not exist |
Дата | |
Msg-id | 2485a25e0903311957g60f14a4bg3ae70bc4182920e2@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Sort a column that does not exist
(Hitoshi Harada <umi.tanuki@gmail.com>)
|
Список | pgsql-hackers |
Hi,<br /><br />I'm in a project that probably some of you have heart about, it is called PostgreSQLf and I get some helpbefore from this list. The developer team is been doing some progress about. Now one of us has created an extra columnthat is called membership degree, this performs some calculations over some data that it is store on a data table.We just create a target entry on the parser and the planner, then in the ExecScan function is where the calculationsperforms.<br /><br />Well, I have been assigned a task. I have to sort that target entry. I created this targetentry on parse_clause and then I do this:<br /><br />List *<br />transformSortClause(ParseState *pstate,<br /> List *orderlist,<br /> List **targetlist,<br /> bool resolveUnknown)<br/>{<br /> List *sortlist = NIL;<br /> ListCell *olitem;<br /><br /> foreach(olitem, orderlist)<br/> {<br /> SortBy *sortby = lfirst(olitem);<br /> TargetEntry *tle;<br /> //Tofind out if it is the membership degree<br /> char *namegrmemb = strVal(linitial(((ColumnRef *) sortby->node)->fields));<br/> <br /> if (strcmp(namegrmemb, "grmemb")==0)<br /> tle = createTargetFuzzyEntry(targetlist);<br/> else<br /> tle = findTargetlistEntry(pstate, sortby->node,<br/> targetlist, ORDER_CLAUSE);<br /><br /> sortlist = addTargetToSortList(pstate,tle,<br /> sortlist, *targetlist,<br /> sortby->sortby_dir,<br /> sortby->sortby_nulls,<br/> sortby->useOp,<br /> resolveUnknown);<br /> <br /> <br /><br /> }<br /><br /> return sortlist;<br />}<br /><br />//Tosort the membership degree<br />TargetEntry *<br />createTargetFuzzyEntry(List **targetlist){<br /> <br /> /*Ijust have to create the fuzzy target entry right here */<br /> TargetEntry *tfp = makeNode(TargetEntry);<br /> Const *cn = makeNode(Const);<br /> float val = 1.0;<br /> TargetEntry *tlast = list_nth(*targetlist, list_length(*targetlist)-1);<br/><br /> cn = makeConst(700, -1, 4, (Float4GetDatum(val)), false, true); <br /> tfp->resorigtbl=tlast->resorigtbl;<br/> tfp->expr = (Expr *) cn;<br /> tfp->resno = list_length(*targetlist)+ 1;<br /> tfp->resname = "grmemb";<br /> tfp->resorigcol = list_length(*targetlist)+ 1;<br /> tfp->ressortgroupref = 0;<br /> tfp->resjunk = false;<br /><br /> *targetlist= lappend(*targetlist, tfp);<br /><br /> return tfp;<br />}<br />As you can see if someone do this: SELECT* FROM table WHERE field=some_value ORDER BY grmemb, postgresql creates a new target entry and then assigned to thetargetlist as a sort node. I know that it creates the node on the parser, but it does not work, it seems the executordon't see it.<br /><br />How could I sort a column like this?, I know i'm missing something, but i just don't seeit. What is the process to sort a column?<br />
В списке pgsql-hackers по дате отправления: