The Schemaverse is a space-based strategy game implemented entirely within a PostgreSQL database. Compete against other players using raw SQL commands to command your fleet. Or, if your PL/pgSQL-foo is strong, wield it to write AI and have your fleet command itself!
function upgrade() declares ship_value as smallint, which indicates a signed 2 byte integer.
Thus, the maximum value of ship_value is 32767.
Unfortunately, the value of SHIP_MAX_SPEED is 50000, which is larger than that.
if you try to upgrade a ship's speed to beyond ~32768, you get an error:
schemaverse@db.schemaverse.com-> select upgrade(34131, 'MAX_SPEED', 5000); ERROR: value "41795" is out of range for type smallint CONTEXT: PL/pgSQL function "upgrade" line 53 at SQL statement
Note that 41795 was the previous value of the maximum speed for that ship; that's a failure of
SELECT max_speed INTO ship_value FROM ship WHERE id=reference_id;
The fix should be to change the type of ship_value to integer.
function upgrade() declares ship_value as smallint, which indicates a signed 2 byte integer.
Thus, the maximum value of ship_value is 32767.
Unfortunately, the value of SHIP_MAX_SPEED is 50000, which is larger than that.
if you try to upgrade a ship's speed to beyond ~32768, you get an error:
schemaverse@db.schemaverse.com-> select upgrade(34131, 'MAX_SPEED', 5000); ERROR: value "41795" is out of range for type smallint CONTEXT: PL/pgSQL function "upgrade" line 53 at SQL statement
Note that 41795 was the previous value of the maximum speed for that ship; that's a failure of SELECT max_speed INTO ship_value FROM ship WHERE id=reference_id;
The fix should be to change the type of ship_value to integer.