BUG #5160: complex query parsing bug

View: New views
2 Messages — Rating Filter:   Alert me  

BUG #5160: complex query parsing bug

by Mike Landis-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The following bug has been logged online:

Bug reference:      5160
Logged by:          Mike Landis
Email address:      mlandis@...
PostgreSQL version: 1.8.4
Operating system:   Vista
Description:        complex query parsing bug
Details:

The SQL parser in pgAdmin III v1.8.4 build 7358 thinks that there should be
more input at the end of the following multi-join query. Subqueries have
been verified correct. I think the parser got lost... Mike

SELECT SP.basis,
        SP.shares,
        SP.stock_id,
        SP.portfolio_id,
        HP.last_date,
        HP.price,
        symbol,
        exchange,
        company_name
   FROM stocks
 JOIN
(SELECT HP_LAST.stock_id,
        last_date, price
   FROM (SELECT stock_id, date, close AS price
            FROM historical_stock_prices
        ) AS HP_ALL
        JOIN
        (SELECT stock_id, MAX(date) AS last_date
            FROM historical_stock_prices
            GROUP BY stock_id
        ) AS HP_LAST
        ON  HP_ALL.stock_id = HP_LAST.stock_id
        AND HP_ALL.DATE = HP_LAST.last_date
) AS HP
 JOIN
(SELECT stock_id,
        portfolio_id,
        SUM(num_units) AS shares,
        SUM(cost_basis) AS basis
   FROM stock_positions
        WHERE sale_date IS NULL AND portfolio_id = 1
        GROUP BY stock_id, portfolio_id
    ) AS SP
ON SP.stock_id = HP.stock_id

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

Re: BUG #5160: complex query parsing bug

by Tom Lane-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Mike Landis" <mlandis@...> writes:
> The SQL parser in pgAdmin III v1.8.4 build 7358 thinks that there should be
> more input at the end of the following multi-join query.

I think so too.  You have two JOINs and only one ON clause.

                        regards, tom lane

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