PostgreSQL next value of the sequences?

后端 未结 7 1865
天命终不由人
天命终不由人 2020-12-01 14:20

I am using PostgreSQL for my Codeigniter website. I am using grocery crud for add, edit and delete operations. While doing an edit or add, I want to rename an uploaded file

7条回答
  •  情话喂你
    2020-12-01 14:32

    To answer your question literally, here's how to get the next value of a sequence without incrementing it:

    SELECT
     CASE WHEN is_called THEN
       last_value + 1
     ELSE
       last_value
     END
    FROM sequence_name
    

    Obviously, it is not a good idea to use this code in practice. There is no guarantee that the next row will really have this ID. However, for debugging purposes it might be interesting to know the value of a sequence without incrementing it, and this is how you can do it.

提交回复
热议问题