Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hUFnd-0004e8-D9 for pgsql-general@arkaria.postgresql.org; Fri, 24 May 2019 19:24:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hUFna-0005jZ-Ak for pgsql-general@arkaria.postgresql.org; Fri, 24 May 2019 19:24:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hUFnZ-0005ge-JV for pgsql-general@lists.postgresql.org; Fri, 24 May 2019 19:24:13 +0000 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hUFnW-0007Ph-ST for pgsql-general@lists.postgresql.org; Fri, 24 May 2019 19:24:12 +0000 Received: by mail-ot1-x342.google.com with SMTP id 66so9718735otq.0 for ; Fri, 24 May 2019 12:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=hJ2yY9YnA2g/g0bzmMV7dvNxW2A0HH/ET0h5xNbmkis=; b=SsVTZNugDqcuwkH0iQQ8rfPeZXajo0y99UtH6zw0idZFM5U/M90n9igLm6FmMz0NUU rSdH710gg329grO747xcbvQnY8Pl8nzhtjr1Rgtqs89++CR83xy9Z5wCd08SA6+L7jAm UpRggYcPvt91G/gjQa/TG1sUbbyHOZwRuotTcl+soiDAnTvlHBvC6Inf+vSlZ+g09uLK U/Gh39bUsGWIPbKZ56rjJZf4B81r6gFcLjBN9ssJrxpb0HcfKoBPUdf8dKD4SJCaUbxN 0TiZQw6WLIBCu9dD8SUAKGnTLNuCYR9KoKclcXxNjTgvrrOqEO3JRnSBqTeQ/0P8prAv qJlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=hJ2yY9YnA2g/g0bzmMV7dvNxW2A0HH/ET0h5xNbmkis=; b=I9ly2mp3QGx197THKWUsQKqC59EPKpLDEk8D5dc4NzlUqrAFg3uycHPlQr5X+68Zyq i8dP5HJMfr9CCx4/6AHq7ZwRW7pBrn2ORlxsU8LRZZwATsV5Xi78UC63OMW3WedItv9h IyEhgnMCSQzoWwO/fx4FI8a3k0LLSqDoMAxB6Yf+Sl9qahyWnca89rF4a5is8IBdX0j4 ECzaS3LtEzbslkGIBwXkTwbTWfZMsUwk+OqT2EYo23kOo4lrFO5l9Fa+0TUtKIcHRjBU vnArRtlKGrii6EHSvZMWdK9KXWryhkocUSLw+mqQHBLWHQdAGx5vvC0L7FrKnRSl4dCY jslg== X-Gm-Message-State: APjAAAUgKfzC8m5XLuFx2oNj+7+mdYZd+oF2IcCYpGjqdfElmmHzNZ8o 8yzGvHCi5JrlUGDZ/0Q1nJHY/WWP5Zaa+A== X-Google-Smtp-Source: APXvYqz+YK5C6rJ3Z+PUrHnhzt5eltyzdMTB5U/5qsESyvFBqGLX3NZJG9PTb3W4guPFd3wBLxOTdg== X-Received: by 2002:a9d:69d1:: with SMTP id v17mr34244317oto.249.1558725849736; Fri, 24 May 2019 12:24:09 -0700 (PDT) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id c204sm1642298oih.19.2019.05.24.12.24.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 12:24:08 -0700 (PDT) Subject: Re: Snippets? To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: <665912f2-754c-f95c-62b2-37d5dc3a1b8b@gmail.com> Date: Fri, 24 May 2019 14:24:07 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 5/24/19 1:27 PM, Adrian Klaver wrote: > On 5/24/19 11:15 AM, Ken Lacrosse wrote: >> Is there any way in postgresql to have a "snippet" of SQL code which you >> could apply to all tables. Something you could add which would ensure >> that every table always has a Created, Changed and Deleted column for >> example. Sort of like a C include I suppose.  Of course if I’m building a >> DB schema by hand I could just copy and paste those columns but it still >> seems a bit too, darn humans!, error prone. > > Not that I know of. > > Things I have done: > 1) Template table that I includes those fields that I then add to. > > FYI the Sqitch schema management system allows you to do the above: > https://sqitch.org/docs/manual/sqitch-add/#templates > > 2) A script that I run over table definition to add the fields. What about INHERITS? test=# create table CCD_template ( test(#  Created timestamptz, test(#  Changed timestamptz, test(#  Deleted timestamptz ); CREATE TABLE test=# create table foobar (   field1 integer,   field2 bytea ) inherits (CCD_template); CREATE TABLE test=# test=# \d foobar              Table "public.foobar"  Column  |           Type           | Modifiers ---------+--------------------------+-----------  created | timestamp with time zone |  changed | timestamp with time zone |  deleted | timestamp with time zone |  field1  | integer                  |  field2  | bytea                    | Inherits: ccd_template > >> >> Ken LaCrosse >> >> Senior IT InfoSec and Infrastructure Monitoring Specialist >> >> I.T. | American Recovery Service & Skipbusters >> >> Phone: (800)398-6480 x3758 >> >> Email: KLacrosse@pkwillis.com >> >> www.pkwillis.com >> >> * Visibility is key. * >> >> Without visibility you can't see. >> >> What you can't see you can't measure. >> >> What you can't measure you can’t planfully change. >> >> What you can’t planfully change you can't manage. >> >> And if we can’t manage then why are we here? >> >> NOTICE: The information contained in this transmission, including >> attachments, may contain confidential information that is privileged, >> confidential and/or exempt from disclosure by applicable law. It is >> intended only for the use of the person(s) or entity to which it is >> addressed. If the reader of this transmission is not the intended >> recipient, the reader is hereby notified that any review, use, >> dissemination, distribution or duplication of this communication >> (including any reliance thereon) is strictly prohibited. If you have >> received this transmission in error, please contact the sender by reply >> email, then delete and destroy the material in its entirety, whether in >> electronic or hard copy format. WE SPECIFICALLY DISCLAIM RESPONSIBILITY >> FOR ANY UNAUTHORIZED USE OF THIS COMMUNICATION OR ANY ATTACHMENTS TO IT. >> Thank you. > > -- Angular momentum makes the world go 'round.