2009-12-09 95 views
1

我是SQL語言和PostgreSQL的新手。我是越來越熟悉的語言,是繼PostgreSQL的教程,直到我被困在約窗口函數一章(link text我創建完全相同的表「empsalary」作爲示例所示:錯誤:在「OVER」處或附近的語法錯誤

 
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) 

和複製-pasted使用窗函數的第一條語句:

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

但是,我得到了以下錯誤消息:

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

其他EF使用OVER子句的堡壘也不起作用。 我做錯了什麼?
謝謝。

版本信息:在x86_64-PC-Linux的GNU 的PostgreSQL 8.3.8,GCC通過CC(GCC)4.2.4(Ubuntu的4.2.4-1ubuntu3)

+1

所以你讀了8.5開發文檔,但他們嘗試用8.3說什麼? – 2009-12-09 10:40:00

+0

@ MilenA.Radev:從來沒有8.5版本。 – 2013-06-30 17:38:09

+0

@wtouw:8.3不再支持,你應該儘快升級到9.2。 – 2013-06-30 17:39:53

回答

4

是否有可能編譯,這不是受你的版本支持?

3.5. Window Functions您使用完全相同的功能

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;

,但它指出

PostgreSQL 8.4.1 Documentation

+0

OVER是PostgreSQL的保留SQL關鍵字(http://www.postgresql.org/docs/8.3/interactive/sql-keywords-appendix.html)8.3.8 – wtouw 2009-12-09 10:12:01

+0

是的,但似乎沒有8.3.8支持窗口函數。 – 2009-12-09 10:16:57

+3

旁觀者是正確的,窗口函數在8.4中引入Postgresql:http://people.planetpostgresql.org/andrew/index.php?/archives/29-First-play-with-window-functions.html – 2009-12-09 17:52:33

相關問題