且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

下一个值函数错误

更新时间:2022-10-14 20:29:39

CREATE SEQUENCE


兼容性

CREATE SEQUENCE 符合SQL标准,以下情况除外:


  • [...]

  • 使用nextval ()函数而不是标准的NEXT VALUE FOR表达式。



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;

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.