Re: Sort a column that does not exist

From: Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>
To: Werner Echezuria <wercool(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Sort a column that does not exist
Date: 2009-04-01 10:13:40
Message-ID: e08cc0400904010313s69fb7b69hc65826dad4f6fc13@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2009/4/1 Werner Echezuria <wercool(at)gmail(dot)com>:
> 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 the targetlist as a sort node. I know that it creates the
> node on the parser, but it does not work, it seems the executor don't see
> it.

See include/nodes/primnodes.h around line 1075:
bool resjunk; /* set to true to eliminate the attribute from
* final target list */

If the TargetEntry is set resjunk = false, the final result is
filtered as junk. So more accurately the executor sees but drops it.

>
> How could I sort a column like this?, I know i'm missing something, but i
> just don't see it. What is the process to sort a column?
>

Use makeTargetEntry in makefuncs.c
TargetEntry *
makeTargetEntry(Expr *expr,
AttrNumber resno,
char *resname,
bool resjunk)

by the 4th argument you can set resjunk = false if you don't want it
to be in the result.

Regards,

--
Hitoshi Harada

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2009-04-01 11:31:33 Re: More message encoding woes
Previous Message Nikhil Sontakke 2009-04-01 05:07:44 Re: Partitioning feature ...