tags:

views:

109

answers:

1

Hi, I'm new to the SQL language and PostgreSQL. I was getting familiar with the language and was following a PostgreSQL tutorial until I got stuck at a chapter about Window Functions (link text. I created the exact same table 'empsalary' as shown in the example:

wtouw=# SELECT * FROM empsalary;
  depname  | empno | salary 
-----------+-------+--------
 develop   |    11 |   5200
 develop   |     7 |   4200
 develop   |     9 |   4500
 develop   |     8 |   6000
 develop   |    10 |   5200
 personnel |     5 |   3500
 personnel |     2 |   3900
 sales     |     3 |   4800
 sales     |     1 |   5000
 sales     |     4 |   4800
(10 rows)

and copy-pasted the first statement that uses a window function:

SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM empsalary;

However, I got the following error message:

ERROR:  syntax error at or near "OVER"
LINE 1: SELECT depname, empno, salary, avg(salary) OVER (PARTITION B...
                                                   ^

Other efforts to use the OVER clause also didn't work. What did I do wrong?
Thanks.

Version info: PostgreSQL 8.3.8 on x86_64-pc-linux-gnu, compiled by GCC cc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3)

+4  A: 

Is it possible that this is not supported by your version?

From 3.5. Window Functions you use the exact same function

Here is an example that shows how to compare each employee's salary with the average salary in his or her department:

SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM empsalary;

but it states

PostgreSQL 8.4.1 Documentation

astander
OVER is a reserved SQL keyword (http://www.postgresql.org/docs/8.3/interactive/sql-keywords-appendix.html) for PostgreSQL 8.3.8
wtouw
Yes, but it does not seem that 8.3.8 supports Window Functions.
astander
astander is correct, window functions were introduced to Postgresql in 8.4: http://people.planetpostgresql.org/andrew/index.php?/archives/29-First-play-with-window-functions.html
Dave Costa
(And I just find it amusing ... the doc wtouw linked to in fact states "the presence of a key word does not indicate the existence of a feature.")
Dave Costa