pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[Beginner Question]What's the use of ResTarget?
2+ messages / 2 participants
[nested] [flat]

* [Beginner Question]What's the use of ResTarget?
@ 2023-07-02 11:19  Wen Yi <wen-yi@qq.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Wen Yi @ 2023-07-02 11:19 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

Hi community
When I read the Internals document (41.1. The Query Tree),
the introduction of  the 'the result relation' confuse me.


In the document, it says


> This is an index into the range table that identifies the relation where the results of the query go.


And I cheak the corresponding code:



In parsenodes.h (A part)



typedef struct ResTarget
{
    NodeTag        type;
    char       *name;            /* column name or NULL */
    List       *indirection;    /* subscripts, field names, and '*', or NIL */
    Node       *val;            /* the value expression to compute or assign */
    int            location;        /* token location, or -1 if unknown */
} ResTarget;


In gram.y (A part)


insert_column_item:
            ColId opt_indirection
                {
                    $$ = makeNode(ResTarget);


My question is:


I really don't the the use of ResTarget, in my original understand, I guess the use of ResTarget is to store the columns of the result, like:


SELECT row_1, row_2 FROM table;


After the parse, the ResTarget will store the row_1, row_2 in the ResTarget.



But the turth is, it also be used in the another clause, like INSERT, far from what I imagined.
So what's the use of ResTarget?



Can someone give me some advice?
Thanks in advance!


Yours,
Wen Yi

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [Beginner Question]What's the use of ResTarget?
@ 2023-07-09 10:59  Alvaro Herrera <alvherre@alvh.no-ip.org>
  parent: Wen Yi <wen-yi@qq.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Alvaro Herrera @ 2023-07-09 10:59 UTC (permalink / raw)
  To: Wen Yi <wen-yi@qq.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

On 2023-Jul-02, Wen Yi wrote:

> Hi community
> When I read the Internals document (41.1. The Query Tree),
> the introduction of&nbsp; the 'the result relation' confuse me.

There are "result relations" in commands that modify a relation, such as
insert or update.  The result relation is where the new tuples are
inserted, or where the modified tuples are.


> in my original understand, I guess the use of ResTarget is to store
> the columns of the result, like:
> 
> SELECT row_1, row_2 FROM table;

Yeah.  Those aren't necessarily in the result relation, because (as the
doc says) a SELECT does not even *have* a result relation.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
"Once again, thank you and all of the developers for your hard work on
PostgreSQL.  This is by far the most pleasant management experience of
any database I've worked on."                             (Dan Harris)
http://archives.postgresql.org/pgsql-performance/2006-04/msg00247.php





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-07-09 10:59 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-07-02 11:19 [Beginner Question]What's the use of ResTarget? Wen Yi <wen-yi@qq.com>
2023-07-09 10:59 ` Alvaro Herrera <alvherre@alvh.no-ip.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox