window-functions

Postgresql Named windows

The documentation for Postgresql window functions seems to imply you can use the same named window in multiple places in your query. However, I can't figure out how do I create a named window? SELECT first_value(vin) OVER( PARTITION BY vin ) AS w, first_value(make) OVER w FROM inventory.vehicles WHERE lot_Id = 9999 AND make is not null;...

Encapsulating Postgres query in view makes it extremely slow

I have a query that runs in about 5 seconds on Postgres 8.4. It selects data from a view joined to some other tables, but also uses the lag() window function, ie. SELECT *, lag(column1) OVER (PARTITION BY key1 ORDER BY ...), lag(...) FROM view1 v JOIN othertables USING (...) WHERE ... For convenience I created a new view that simply h...