I am trying to update the value of a generator id. Trying to update the stream using a script throws me an error.
This is the script I'm trying to run
set term ^ ;
execute block
as
declare variable codigo integer ;
begin
select first 1 (peo2.codigo+1)
from presupuestosestadosoportunidad peo2
order by peo2.codigo desc
into :codigo;
execute statement
'ALTER SEQUENCE GEN_PRESUPESTADOSOPORTUNIDAD RESTART WITH ' + cast(codigo as varchar(10))+ ';';
end ^
commit work ^
set term ; ^
This is the error that throws me:
can't format message 13:198 -- message file C:\Windows\firebird.msg not found. arithmetic exception, numeric overflow, or string truncation. string right truncation. At block line: 12, col: 1.
I can't understand why I get this error. My understanding is that to update a sequence, the value passed in has to be a constant. This is why I convert the code value to varchar. The value that the id should be having is approximately 453788.
I suggest that you make sure what is the value that you are getting in the query that you do.
I have adapted the code to run on firebird 3.0 (I don't have 2.5 at hand now), and when the value of the sequence exceeds 10 digits, I get an error similar to yours (only I do have the message file).
My code is:
This runs without a problem, however if I change to:
I get this:
The funny thing is that line 6 is not the execution of the
alter sequence
, but the assignment of the value to the variable. If I change the data type to bigint, the error again disappears, in fact, the following code runs without problems.One last thing: it strikes me that you do a
select first 1 xxx order by xxx desc
, I suspect that the plan for this equivalent version could be more efficient:As long as there is an index on the column
talcosa
.