Re: SQL equivalint of #incude directive ?

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: stan <stanb(at)panix(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: SQL equivalint of #incude directive ?
Date: 2019-08-31 08:11:38
Message-ID: CA+bJJbx=QbMx+z_8AH4h=E-bfPbsBmUaU4PtD11F13bLMpppjw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Stan:

On Fri, Aug 30, 2019 at 3:49 PM stan <stanb(at)panix(dot)com> wrote:
...
> I am defining a bunch of functions, and I would prefer to store them in a
> separate file, which then gets "source" by the main DB init file.
> Is there a standard way to do this?

I assume you mean "standard for postgres", AFAIK there is not even a
(multidb) standard way to feed an sql script to a server (content of
queries / results are standard, how to send them / get them from the
server is not ).

\i in psql has been pointed. I do not know if this is one of your
"workarounds", but what I normally do for this is trat the "init"
script as a program and "make" it. I've done it using many of the
preprocessor freely available around ( i.e. m4, cpp ) and also using a
perl program ( but this is becuase I'm quite fluent in it and it makes
some thing easier ), and even doing "cat *.sql | psql" and naming the
scripts appropiately. You'll probably have it easier going by that
route ( generating the sql script from chunks using a tool of your
choice, it's just a big text chunk and you can easily debug it with a
text editor ), and it is not that complex.

Francisco Olarte.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message stan 2019-08-31 14:05:10 Problems with using function input paramaters
Previous Message Morris de Oryx 2019-08-31 02:46:12 Re: Aggregate functions on groups