2009-12-09 97 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

相关问题