[ts-gen] How to widen decimal database attributes

Bill Pippin pippin at owlriver.net
Mon Sep 28 16:57:45 EDT 2009


Ken,

As discussed previously, the format control for the display width of
shim floating point data needs work, and for now you might as well
edit the sources as you've been doing to affect the shim's output.

The database, however, is a separate issue, and is up to you.  As for
how you could find the places to change:

     sql$ grep decimal *.sql | sed -e 's/[)].*/)/'

The query above gives the following result:

    proc.sql:    lmt_price   decimal(10,4)
    proc.sql:    aux_price   decimal(10,4)
    subs.sql:    open        decimal(10,4)
    subs.sql:    high        decimal(10,4)
    subs.sql:    low         decimal(10,4)
    subs.sql:    close       decimal(10,4)
    subs.sql:    wap         decimal(10,4)
    syms.sql:    strike       decimal(10,4)
    syms.sql:--  min_tick   decimal(10,8)
    syms.sql:    strike      decimal(10,4)
    xact.sql:    lmt_price   decimal(10,4)
    xact.sql:    aux_price   decimal(10,4)
    xact.sql:     avg_fill decimal(10,4)
    xact.sql:    last_fill decimal(10,4)
    xact.sql:    strike      decimal(10,4)
    xact.sql:    lmt_price   decimal(10,4)
    xact.sql:    aux_price   decimal(10,4)
    xact.sql:    strike      decimal(10,4)
    xact.sql:    price       decimal(10,4)
    xact.sql:    value       decimal(10,4)
    xact.sql:    avg_cost    decimal(10,4)
    xact.sql:    un_pnl      decimal(10,4)
    xact.sql:    real_pnl    decimal(10,4)
    xact.sql:    strike      decimal(10,4)
    xact.sql:    price       decimal(10,4)

As you noted, the common case is decimal(10,4), in just four files,
and in fact it is sufficient to change the occurrences for (10,4)
in just those files.  So, if you want five digits to the right of
the decimal point, and eleven digits total, then working from within
the directory where your sql sources are found:

    sql$ sed -i -e 's/decimal(10,4)/decimal(11,5)/' proc.sql \
                                                    subs.sql \
                                                    syms.sql \
                                                    xact.sql

Then recreate your database, which will use your newly modified
create table statements, since the sed command includes the -i option
for in-place update.

I've added a script bin/decimals.sh to the distribution, consisting
only of the above command.  That's really all there is to it, so feel
free to use the command above even before I've pushed another release.

Thanks,

Bill


More information about the ts-general mailing list