Sometime a model will return an empty log file, or a log file will have gaps in it. The most common cause is bad SQL table column definition, either, trying to log a string to a numeric column, or trying to log a number to a column that was guess as "varchar(1)" due to a null value at first time step. 9 out of 10 times this is due to a problem with dataMatrix variables, since they are the only entity that can have multiple evaluation types, that is, the column values could be a string, or a variable reference, or a numeric value, and the default value type is "auto", which means the system guesses... which is a design flaw that has only recently come to light as such (and will be eliminated in the new python version of the model).
Finding it
Watch the database log
sudo su - postgres
tail -f logfile.model_scratch
find the element id (in the table name) that is broken in the log (this will be recurring if there are large gaps in your model data, or the model data is missing altogether)
Ex: ERROR: value too long for type character varying(1) \n 2023-05-11 18:04:02.253 UTC [3374197] STATEMENT: insert into "tmp339146_047_datalog"
Check more detail def to see which column it is:
cd om
php test_sqldef.php 245105 401 339146
SQL Def for Greensville County Raw Water Reservoir and Intake:Nottoway River = create TEMP table "tmp339146_058_datalog" ( "local_impoundment_Qin" float8 , "local_impoundment_evap_mgd" float8 ...
Look for varchar(1) in there (I just copy and paste the def table into notepad++ and search)
Once you find it, it is pretty clear. See Re-Creating the Error in psql CMD line
Alternate method to find the table definition from the last model run is stored in a separate log file:
DataMatrix lookup tables without a specific DB Value Type -- can be set in the interface
Re-Creating the Error in psql CMD line
Find an erroneous line (use one from the tail -f above, or fgrep for a specific one
fgrep for a specific line: fgrep 219133 logfile.model_scratch |grep '2008-12-30'
Note: in this example the error is value too long for type character varying(1)
Get the recent definition log; cat /var/www/html/data/proj3/out/def.219133.-1.sql
Find the varchar(1) -- in this example there are 6 columns with varchar(1):
"description", "historic_annual", "Send to Parent", "Listen on Parent", "current_monthly_discharge", and "local_impoundment"
Of these, only "historic_annual" and "current_monthly_discharge" can have any time varying data (broadcast variables don't actually log any specific data, nor do impoundment and channel type, or rather, impoundment and channel types log null under their own name, and store specific sub data, like local_impoundment_Qout
This ends up being easy, current_monthly_discharge can be deleted, and historic_annual can be set to have type float8 and default value of 0.
SQL 1: Logfile for SQL definition of element 219133
Sometime a model will return an empty log file, or a log file will have gaps in it. The most common cause is bad SQL table column definition, either, trying to log a string to a numeric column, or trying to log a number to a column that was guess as "varchar(1)" due to a null value at first time step. 9 out of 10 times this is due to a problem with dataMatrix variables, since they are the only entity that can have multiple evaluation types, that is, the column values could be a string, or a variable reference, or a numeric value, and the default value type is "auto", which means the system guesses... which is a design flaw that has only recently come to light as such (and will be eliminated in the new
python
version of the model).Finding it
sudo su - postgres
tail -f logfile.model_scratch
ERROR: value too long for type character varying(1) \n 2023-05-11 18:04:02.253 UTC [3374197] STATEMENT: insert into "tmp339146_047_datalog"
cd om
php test_sqldef.php 245105 401 339146
SQL Def for Greensville County Raw Water Reservoir and Intake:Nottoway River = create TEMP table "tmp339146_058_datalog" ( "local_impoundment_Qin" float8 , "local_impoundment_evap_mgd" float8 ...
varchar(1)
in there (I just copy and paste the def table into notepad++ and search)/var/www/html/data/proj3/out/def.[elementid].-1.sql
cat /var/www/html/data/proj3/out/def.219133.-1.sql
Common Causes
DataMatrix
lookup tables without a specificDB Value Type
-- can be set in the interfaceRe-Creating the Error in psql CMD line
tail -f
above, or fgrep for a specific onefgrep
for a specific line:fgrep 219133 logfile.model_scratch |grep '2008-12-30'
value too long for type character varying(1)
cat /var/www/html/data/proj3/out/def.219133.-1.sql
varchar(1)
-- in this example there are 6 columns withvarchar(1)
:local_impoundment_Qout
current_monthly_discharge
can be deleted, andhistoric_annual
can be set to have typefloat8
and default value of 0.SQL 1: Logfile for SQL definition of element 219133
SQL 2: Find a specific data error using
fgrep
, ex:fgrep 219133 logfile.model_scratch |grep '2008-12-30'
.