Skip site navigation (1) Skip section navigation (2)

Changing a relation's name in parser stage

From: "Matthias Lenz" <ml134883(at)inf(dot)tu-dresden(dot)de>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Changing a relation's name in parser stage
Date: 2004-05-10 14:57:09
Message-ID: 000a01c4369f$14b0af40$9100a8c0@noctuaeeprwinl (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
I have to rewrite a query after beeing parsed by gram.y but before any transformations are applied to my SelectStmt structure in analyze.c. Therefore I wrote a function that creates a new SelectStmt structure, because I need some UNIONs in the rewritten query. Most of the sub strucure of the original query stays relevant, e.g. the GroupByClause, TargetClause and is assigned to the sub structure of the new SelectStmt structure. But I have to alter the relation names in the FromClause. From_clause is a list of RangeVar nodes I think, generated by the gram.y. And one attribute of the RangeVar node is relname, of type char *. How to alter the relname. Why they use char *, I want to assign something like "relation_x".

the following leads to a crash of psql, without these lines (List... "s_overall"); the modification function on the ApproxStmt (my own type of SelectStmt) works fine, but I need to change the relname!

[in anylze.c]

static SelectStmt *modifyApproxStmt(ApproxStmt *stmt)

List *i;
i=nth(1, stmt->fromClause);
((RangeVar *) lfirst(i))->relname = "s_overall";

Any ideas? It's puzzling me!


pgsql-novice by date

Next:From: David CruzDate: 2004-05-10 15:38:55
Subject: Question about REF / DREF
Previous:From: Bruno Wolff IIIDate: 2004-05-09 15:18:53
Subject: Re: RI / foreign key on VIEW

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group