Sequence in DB Postgresql

116 views Asked by At

I have a Java system that uses Sequence in PK in database (postgreSQL and PGadmin) This sequence should take the current month (with two digits) followed by the current year. It turns out that a certain time of day arrives and the command below is executed (Java project class):

String sql = "select case when trim(substring(cast((SELECT last_value FROM  sequencia.Tb_um) as varchar),1,4)) <> trim(to_char(current_date,'MMYY')) then"
                + " setval(‘sequencia.Tb_um', cast(trim(to_char(current_date,'MMYY')||'001') as integer), true) "
                + " else 0 end as valor";

But I don't know what happens when the leading zero of the month is removed, leaving for example: “422001” in the DB (the corret: "0422001"), the question is: what is it that is deleting this zero?

Thanks for any help!

0

There are 0 answers