• [Info-ingres] Calculated column defaults

    From Roy Hann@21:1/5 to Martin Bowes on Tue Feb 9 15:09:36 2021
    Martin Bowes wrote:

    OK. Feeling a little lazy and not wanting to write another
    before triggered procedure to do the deed for me...

    Has anyone thought of gunning up the column defaults so we
    can specify a calculation to perform using the standard default values
    only. Ie not using some other column as a basis for the calculation...

    Eg. Loading up standard defaults of date('today') and user:

    Create table test(

    tom integer not null not default,

    dick ingresdate not null with default date_part('month', 'today'),

    harry varchar(32) not null with default uppercase(user)

    )

    I know you are at ease with your own self-loathing but much more of this
    and I'm going to go off you too.

    Eg. Of something that would be insane:
    tom integer not null not default,
    dick integer not null with default (tom / 2),
    harry float4 not null with default float(dick)

    It's insane because the order of calculation would be unclear,
    and even if you could make it clear the thought of the dependency tree
    scares the tripe out of me.

    It is insane but that is not the reason. In SQL things happen as if simultaneously, which is why

    UPDATE foo SET a=b, b=a

    works to swap the values of columns a and b.

    Roy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Martin Bowes@21:1/5 to All on Tue Feb 9 14:38:17 2021
    Hi All,

    OK. Feeling a little lazy and not wanting to write another before triggered procedure to do the deed for me...

    Has anyone thought of gunning up the column defaults so we can specify a calculation to perform using the standard default values only. Ie not using some other column as a basis for the calculation...

    Eg. Loading up standard defaults of date('today') and user:

    Create table test(

    tom integer not null not default,

    dick ingresdate not null with default date_part('month', 'today'),

    harry varchar(32) not null with default uppercase(user)

    )

    Eg. Of something that would be insane:
    tom integer not null not default,
    dick integer not null with default (tom / 2),
    harry float4 not null with default float(dick)

    It's insane because the order of calculation would be unclear, and even if you could make it clear the thought of the dependency tree scares the tripe out of me.

    Martin Bowes

    <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
    <meta name="Generator" content="Microsoft Word 15 (filtered medium)"> <style><!--
    /* Font Definitions */
    @font-face
    {font-family:"Cambria Math";
    panose-1:2 4 5 3 5 4 6 3 2 4;}
    @font-face
    {font-family:Calibri;
    panose-1:2 15 5 2 2 2 4 3 2 4;}
    @font-face
    {font-family:Consolas;
    panose-1:2 11 6 9 2 2 4 3 2 4;}
    /* Style Definitions */
    p.MsoNormal, li.MsoNormal, div.MsoNormal
    {margin:0cm;
    margin-bottom:.0001pt;
    font-size:11.0pt;
    font-family:"Calibri",sans-serif;
    mso-fareast-language:EN-US;}
    a:link, span.MsoHyperlink
    {mso-style-priority:99;
    color:#0563C1;
    text-decoration:underline;}
    a:visited, span.MsoHyperlinkFollowed
    {mso-style-priority:99;
    color:#954F72;
    text-decoration:underline;}
    p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
    {mso-style-priority:99;
    mso-style-link:"Plain Text Char";
    margin:0cm;
    margin-bottom:.0001pt;
    font-size:10.5pt;
    font-family:Consolas;
    mso-fareast-language:EN-US;}
    span.EmailStyle17
    {mso-style-type:personal-compose;
    font-family:"Calibri",sans-serif;
    color:windowtext;}
    span.PlainTextChar
    {mso-style-name:"Plain Text Char";
    mso-style-priority:99;
    mso-style-link:"Plain Text";
    font-family:Consolas;}
    .MsoChpDefault
    {mso-style-type:export-only;
    font-family:"Calibri",sans-serif;
    mso-fareast-language:EN-US;}
    @page WordSection1
    {size:612.0pt 792.0pt;
    margin:72.0pt 72.0pt 72.0pt 72.0pt;}
    div.WordSection1
    {page:WordSection1;}
    </style><!--[if gte mso 9]><xml>
    <o:shapedefaults v:ext="edit" spidmax="1026" />
    </xml><![endif]--><!--[if gte mso 9]><xml>
    <o:shapelayout v:ext="edit">
    <o:idmap v:ext="edit" data="1" />
    </o:shapelayout></xml><![endif]-->
    </head>
    <body lang="EN-GB" link="#0563C1" vlink="#954F72">
    <div class="WordSection1">
    <p class="MsoNormal">Hi All,<o:p></o:p></p>
    <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
    <p class="MsoNormal">OK. Feeling a little lazy and not wanting to write another before triggered procedure to do the deed for me&#8230;<o:p></o:p></p>
    <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
    <p class="MsoNormal">Has anyone thought of gunning up the column defaults so we can specify a calculation to perform using the standard default values only. Ie not using some other column as a basis for the calculation&#8230;<o:p></o:p></p>
    <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
    <p class="MsoNormal">Eg. Loading up standard defaults of date(&#8216;today&#8217;) and user:<o:p></o:p></p>
    <p class="MsoPlainText"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">Create table test(<o:p></o:p></span></p>
    <p class="MsoPlainText" style="margin-left:18.0pt"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">tom integer not null not default,<o:p></o:p></span></p>
    <p class="MsoPlainText" style="margin-left:18.0pt"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">dick ingresdate not null with default date_part(&#8216;month&#8217;, &#8216;today&#8217;),<o:p></o:p></span></p>
    <p class="MsoPlainText" style="margin-left:18.0pt"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">harry varchar(32) not null with default uppercase(user)<o:p></o:p></span></p>
    <p class="MsoPlainText"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">)<o:p></o:p></span></p>
    <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
    <p class="MsoNormal">Eg. Of something that would be insane:<o:p></o:p></p>
    <p class="MsoNormal"><span style="color:#1F497D">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tom integer not null not default,<o:p></o:p></span></p>
    <p class="MsoNormal"><span style="color:#1F497D">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dick integer not null with default (tom / 2),
    <o:p></o:p></span></p>
    <p class="MsoNormal"><span style="color:#1F497D">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; harry float4 not null with default float(dick)<o:p></o:p></span></p>
    <p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal" style="margin-left:36.0pt"><span style="color:#1F497D">It&#8217;s insane because the order of calculation would be unclear, and even if you could make it clear the thought of the dependency tree scares the tripe out of me.<o:p></o:p><
    /span></p>
    <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
    <p class="MsoNormal">Martin Bowes<o:p></o:p></p>
    </div>
    </body>
    </html>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)