Re: Parser - Query Analyser - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Parser - Query Analyser
Date
Msg-id 8393.1353165471@sss.pgh.pa.us
Whole thread Raw
In response to Parser - Query Analyser  (Michael Giannakopoulos <miccagiann@gmail.com>)
List pgsql-hackers
Michael Giannakopoulos <miccagiann@gmail.com> writes:
> What I am trying to explore is if it is possible to extend postgreSQL in
> order to accept queries of the form:

> Select function(att1, att2, att3) AS output(out1, out2, ..., outk) FROM
> [database_name];

> where att1, att2, att3 are attributes of the relation [database_name] while
> output(out1, out2, out3) expresses the output that comes from 'function'
> and the fields that this output should have are (out1, out2, out3).

You're not being terribly clear about what you intend this to mean,
but the standard interpretation of AS is that it just provides a column
renaming and doesn't for instance change datatypes.  If that's what you
have in mind then it can be done today using AS in the FROM clause:

select * from foo() AS output(out1, out2, ...);

That doesn't allow passing data from a table to the function, but as of
HEAD we have LATERAL, so you could do

select output.* from tab, LATERAL foo(att1, att2) AS output(out1, out2, ...);

If you really insist on doing the renaming within a single composite
column in the SELECT output list then you're going to have a lot of
issues.  Column name aliases are normally only associated with RTEs
(FROM-list entries) and SELECT output columns.  Column names for columns
of a composite data type are properties of the type and so are out of
the reach of AS-renaming in the current system design.  I think you'd
have to cons up an anonymous record type and treat the AS as an implicit
cast to that type.  Seems like an awful lot of work in order to have a
nonstandard way to do something that can be done already.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Hannu Krosing
Date:
Subject: Re: logical changeset generation v3 - comparison to Postgres-R change set format
Next
From: Tom Lane
Date:
Subject: Re: Materialized views WIP patch