skip to Main Content

I have a sequence in the database, and I wanted to call the sequence through a function.
I have tried below, need an assistance to create the function in a standard process, as this is not working.

select nextval('code_seq')
CREATE FUNCTION code_sequence(integer) RETURNS integer
    LANGUAGE SQL
    IMMUTABLE
    return select nextval('code_seq');

3

Answers


  1. Chosen as BEST ANSWER

    I am able to achieve using below statements,

    CREATE FUNCTION code_sequence(out seq int) 
        LANGUAGE plpgsql
        as $$ 
        begin
        select nextval('code_seq') into seq;
    end;$$
    

  2. CREATE FUNCTION local_accounts_sequence(integer) RETURNS integer
        LANGUAGE SQL
        IMMUTABLE
        RETURN (select nextval('code_seq'));
        
    select local_accounts_sequence(1)   
    

    enter image description here
    check out this solution

    Login or Signup to reply.
  3. try this :

    CREATE FUNCTION local_accounts_sequence() RETURNS integer   
        AS 'SELECT nextval(''code_seq'');'
        LANGUAGE SQL;
    

    call it like this :

    select local_accounts_sequence();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search