The following bug has been logged online:
Bug reference: 5160
Logged by: Mike Landis
Email address: mlandis@pnmx.com
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