Creating unique or "internal-use-only" column names (ColumnRef)

Started by Peter Moserover 10 years ago5 messages
#1Peter Moser
pitiz29a@gmail.com

Good afternoon,
is it possible to create unique column names or to give column names
inside the parser phase that do not interfer with the outside world,
i.e. with column names from tables or aliases given by the user.

Some short background:
I created my own from-clause-item, that gets rewritten into a sub-query.
I do this because I want to re-use existing code as much as possible.
The rewritten sub-query gets transformed with "transformRangeSubselect"...
Within this sub-query I need 3 columns that shouldn't interfer with
columns from the input. We refer to them from a JOIN-ON clause and an
ORDER-BY clause.

Example code:

ColumnRef *ref;
ref = makeNode(ColumnRef);
ref->fields = list_make1(makeString("some_unique_name"));
ref->location = -1; /* Unknown location */

...

sb1 = makeNode(SortBy);
sb1->node = ref;

...

ssResult = makeNode(SelectStmt);
ssResult->withClause = NULL;
ssResult->fromClause = list_make1(joinExpr);
ssResult->targetList = list_make1(rtAStarWithR); /* input = r.* */
ssResult->sortClause = list_make2(sb1, sb2);

Is there a possibility for such column names?

Thanks for your help,
Peter

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Peter Moser (#1)
Re: Creating unique or "internal-use-only" column names (ColumnRef)

Peter Moser wrote:

Good afternoon,
is it possible to create unique column names or to give column names inside
the parser phase that do not interfer with the outside world, i.e. with
column names from tables or aliases given by the user.

Some short background:
I created my own from-clause-item, that gets rewritten into a sub-query. I
do this because I want to re-use existing code as much as possible. The
rewritten sub-query gets transformed with "transformRangeSubselect"...
Within this sub-query I need 3 columns that shouldn't interfer with columns
from the input. We refer to them from a JOIN-ON clause and an ORDER-BY
clause.

This seems pretty much the same as a junk attribute, if I understand you
correctly. I suggest given a look at how those work.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Alvaro Herrera (#2)
Re: Creating unique or "internal-use-only" column names (ColumnRef)

On 09/07/2015 09:28 AM, Alvaro Herrera wrote:

Peter Moser wrote:

Good afternoon,
is it possible to create unique column names or to give column names inside
the parser phase that do not interfer with the outside world, i.e. with
column names from tables or aliases given by the user.

Some short background:
I created my own from-clause-item, that gets rewritten into a sub-query. I
do this because I want to re-use existing code as much as possible. The
rewritten sub-query gets transformed with "transformRangeSubselect"...
Within this sub-query I need 3 columns that shouldn't interfer with columns
from the input. We refer to them from a JOIN-ON clause and an ORDER-BY
clause.

This seems pretty much the same as a junk attribute, if I understand you
correctly. I suggest given a look at how those work.

Is that actually documented anywhere much? I had to use one recently for
the Redis FDW and looked in vain for some docco - not saying it's not
there, just that I didn't find it.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#3)
Re: Creating unique or "internal-use-only" column names (ColumnRef)

Andrew Dunstan <andrew@dunslane.net> writes:

On 09/07/2015 09:28 AM, Alvaro Herrera wrote:

This seems pretty much the same as a junk attribute, if I understand you
correctly. I suggest given a look at how those work.

Is that actually documented anywhere much?

I don't think there's much besides a code comment here and there.
Grepping for functions that touch the "resjunk" field of TargetListEntries
should give you the lay of the land.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Peter Moser
pitiz29a@gmail.com
In reply to: Tom Lane (#4)
Re: Creating unique or "internal-use-only" column names (ColumnRef)

Am 07.09.2015 um 16:40 schrieb Tom Lane:

Andrew Dunstan <andrew@dunslane.net> writes:

On 09/07/2015 09:28 AM, Alvaro Herrera wrote:

This seems pretty much the same as a junk attribute, if I understand you
correctly. I suggest given a look at how those work.

Is that actually documented anywhere much?

I don't think there's much besides a code comment here and there.
Grepping for functions that touch the "resjunk" field of TargetListEntries
should give you the lay of the land.

regards, tom lane

I have marked them as resjunk already. The problem is that the subquery
I build contains another subquery. As SQL it looks something like the
following:

select *
from
(select *, row_number() over () rn from r) r
left outer join
(select *, ts p1 from r union all select *, te p1 from r) s
on p1 >= r.ts and p1 < r.te
order by rn, p1;

I set then the output columns of the outer select to resjunk for rn and
p1, like this...

i = list_length(qry->targetList);
get_tle_by_resno(qry->targetList, i)->resjunk = true;
get_tle_by_resno(qry->targetList, --i)->resjunk = true;

However, I cannot do that inside, because I need them above... or do I
miss something here?

~peter

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers