Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-31 Thread Tom Lane
Merlin Moncure writes: > This is just awesome. Anyways, I was looking around the docs for > references to the old methodology of select list SRF function calls. > This paragraph: > http://www.postgresql.org/docs/devel/static/xfunc-sql.html#XFUNC-SQL-FUNCTIONS-RETURNING-SET > could probably use s

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-08 Thread Merlin Moncure
On Tue, Aug 7, 2012 at 6:08 PM, Tom Lane wrote: > I wrote: >> What I'd like to do next, barring objections, is to band-aid the places >> where the planner could crash on a LATERAL query (probably just make it >> throw FEATURE_NOT_SUPPORTED errors), write some documentation, and >> then commit what

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-07 Thread Tom Lane
I wrote: > What I'd like to do next, barring objections, is to band-aid the places > where the planner could crash on a LATERAL query (probably just make it > throw FEATURE_NOT_SUPPORTED errors), write some documentation, and > then commit what I've got. After that I can go back to improve the > p

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-07 Thread Tom Lane
Here's an updated version of my LATERAL patch. * Accepts "LATERAL func_name(args)". * Handles LATERAL in JOIN nests now. I rewrote the way transformFromClause manages visibility of previously-parsed FROM items. Rather than my previous idea of adding more namespace lists to a ParseState, I change

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-06 Thread Amit Kapila
From: Robert Haas [mailto:robertmh...@gmail.com] Sent: Monday, August 06, 2012 8:07 PM On Mon, Aug 6, 2012 at 10:07 AM, Amit Kapila wrote: > I think you can always simulate CROSS APPLY using LATERAL. The syntax > is different but the functionality is the same. However, OUTER APPLY > allows you

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-06 Thread Tom Lane
Robert Haas writes: > On Mon, Aug 6, 2012 at 11:09 AM, Tom Lane wrote: >> Uh, what exactly? AFAICT from that blog entry, "x OUTER APPLY y" is >> exactly the same as "x LEFT JOIN LATERAL y ON true". Okay, so you >> saved three words, but is that a good enough reason to invent a >> nonstandard sy

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-06 Thread Robert Haas
On Mon, Aug 6, 2012 at 11:09 AM, Tom Lane wrote: > Robert Haas writes: >> I think you can always simulate CROSS APPLY using LATERAL. The syntax >> is different but the functionality is the same. However, OUTER APPLY >> allows you to do something that I don't think is possible using >> LATERAL.

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-06 Thread Tom Lane
Robert Haas writes: > I think you can always simulate CROSS APPLY using LATERAL. The syntax > is different but the functionality is the same. However, OUTER APPLY > allows you to do something that I don't think is possible using > LATERAL. Uh, what exactly? AFAICT from that blog entry, "x OUTE

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-06 Thread Tom Lane
Robert Haas writes: > Apparently Sybase and Microsoft SQL server use a slightly different > syntax, CROSS APPLY, for this. > http://iablog.sybase.com/paulley/2008/07/cross-and-outer-apply/ Well, this is only a blog entry and not their manual, but AFAICT that is just a useless deviation from SQL-

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-06 Thread Robert Haas
On Mon, Aug 6, 2012 at 10:07 AM, Amit Kapila wrote: >>> Currently the patch only implements the syntax called out in the > standard, >>> namely that you can put LATERAL in front of a , which is >>> to say a parenthesized sub-SELECT in FROM. It strikes me that it might > be >>> worth allowing LATE

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-06 Thread Amit Kapila
From: pgsql-hackers-ow...@postgresql.org [mailto:pgsql-hackers-ow...@postgresql.org] On Behalf Of Tom Lane Sent: Monday, August 06, 2012 3:28 AM To: pgsql-hackers@postgreSQL.org Subject: [HACKERS] WIP patch for LATERAL subqueries > I've been idly amusing myself by trying to hack up sup

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-06 Thread Amit Kapila
From: pgsql-hackers-ow...@postgresql.org [mailto:pgsql-hackers-ow...@postgresql.org] On Behalf Of Robert Haas Sent: Monday, August 06, 2012 6:16 PM On Sun, Aug 5, 2012 at 5:58 PM, Tom Lane wrote: >> Currently the patch only implements the syntax called out in the standard, >> namely that you can

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-06 Thread Robert Haas
On Sun, Aug 5, 2012 at 5:58 PM, Tom Lane wrote: > I've been idly amusing myself by trying to hack up support for > SQL-standard LATERAL subqueries. Cool! > Currently the patch only implements the syntax called out in the standard, > namely that you can put LATERAL in front of a , which is > to s

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-05 Thread Pavel Stehule
2012/8/6 Tom Lane : > Andrew Dunstan writes: >> On 08/05/2012 05:58 PM, Tom Lane wrote: >>> Currently the patch only implements the syntax called out in the standard, >>> namely that you can put LATERAL in front of a , which is >>> to say a parenthesized sub-SELECT in FROM. It strikes me that it

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-05 Thread Tom Lane
Andrew Dunstan writes: > On 08/05/2012 05:58 PM, Tom Lane wrote: >> Currently the patch only implements the syntax called out in the standard, >> namely that you can put LATERAL in front of a , which is >> to say a parenthesized sub-SELECT in FROM. It strikes me that it might be >> worth allowing

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-05 Thread Tom Lane
I wrote: > While fooling around in the planner I realized that I have no idea what > outer-level aggregates mean in a LATERAL subquery, and neither does > Postgres: > regression=# select 1 from tenk1 a, lateral (select * from int4_tbl b where > f1 = max(a.unique1)) x; > ERROR: plan should not ref

Re: [HACKERS] WIP patch for LATERAL subqueries

2012-08-05 Thread Andrew Dunstan
On 08/05/2012 05:58 PM, Tom Lane wrote: I've been idly amusing myself by trying to hack up support for SQL-standard LATERAL subqueries. I've got something that turns over, more or less: Awesome!! Currently the patch only implements the syntax called out in the standard, namely that you ca

[HACKERS] WIP patch for LATERAL subqueries

2012-08-05 Thread Tom Lane
I've been idly amusing myself by trying to hack up support for SQL-standard LATERAL subqueries. I've got something that turns over, more or less: regression=# select * from int4_tbl a, lateral (select unique1,unique2 from tenk1 b where a.f1 = unique1) x; f1 | unique1 | unique2 +-+-