Re: Parser - Query Analyser

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Giannakopoulos <miccagiann(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Parser - Query Analyser
Date: 2012-11-17 15:17:51
Message-ID: 8393.1353165471@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Michael Giannakopoulos <miccagiann(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message T. E. Lawrence 2012-11-17 15:33:40 Re: 9.2 streaming replication issue and solution strategy
Previous Message Adrian Klaver 2012-11-17 15:12:56 Re: 9.2 streaming replication issue and solution strategy

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2012-11-17 15:48:21 Re: Materialized views WIP patch
Previous Message Hannu Krosing 2012-11-17 14:57:39 Re: logical changeset generation v3 - comparison to Postgres-R change set format