Next value function error

為{幸葍}努か 提交于 2019-12-25 05:28:11

问题


I get the following error during postgresql execution: ERROR [HY000] ERROR: you can only use a 'next value(s)' function within a target list

What is wrong with this sql statement:

SELECT TRFCON.ID       
       ,   
       case when DDDCON.ID_CON = 0
       then
        NEXT VALUE FOR SEQ_DDD_CON   
        else
       DWHCON.ID_CON
       end ID_CON

  FROM TTT_CONSUMPTION TTTCON 

join DDDDWH_CON DWHCON on TTTCON.ID_ORG = DDDCON.ID_ORG
and TTTCON.ID_PRO = DDDCON.ID_PRO
and TTTCON.ID_REF = DDDCON.ID_REF

The DDL of the sequence is the following:

CREATE SEQUENCE SEQ_DDD_CON AS BIGINT
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE 
    NO MAXVALUE 
    NO CYCLE;

回答1:


From the docs for CREATE SEQUENCE

Compatibility

CREATE SEQUENCE conforms to the SQL standard, with the following exceptions:

  • [...]
  • Obtaining the next value is done using the nextval() function instead of the standard's NEXT VALUE FOR expression.


来源:https://stackoverflow.com/questions/17829458/next-value-function-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!