RE: SQL equivalint of #incude directive ?

From: Kevin Brannen <KBrannen(at)efji(dot)com>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: RE: SQL equivalint of #incude directive ?
Date: 2019-09-06 15:05:33
Message-ID: DM6PR19MB3451C2CCF6BD06E3F83442ACA4BA0@DM6PR19MB3451.namprd19.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> From: stan <stanb(at)panix(dot)com>
>
> I thought this would be common. But a quick Google only revealed what look to be workarounds.
>
> 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?

Besides what the others have said, not if you stick to SQL. This is really
more of an application level question where you have something that
will do your init/load process.

If you're willing to use other tools, then there are solutions. IIRC, your
other thread had "#include" in the title. You could build a small file with:

#include "function1.sql"
#include "function2.sql"
...

Then run it thru "cpp" and use the output of that. Might need some
post-processing if you're unlucky; I'd have to try it to see if there are
extraneous lines.

Personally, I'd probably just have a shell script that goes into that dir
and does something like:

cat *.sql | psql -d DB # and other args

and call it done...translate if you're not on a Unix-like system.

I could write a Perl program to do it because Perl can do almost anything. ;)

Your imagination is the limit.

HTH,
Kevin
This e-mail transmission, and any documents, files or previous e-mail messages attached to it, may contain confidential information. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are hereby notified that any disclosure, distribution, review, copy or use of any of the information contained in or attached to this message is STRICTLY PROHIBITED. If you have received this transmission in error, please immediately notify us by reply e-mail, and destroy the original transmission and its attachments without reading them or saving them to disk. Thank you.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Brannen 2019-09-06 15:32:17 RE: pg_restore issues with intarray
Previous Message Arnaud L. 2019-09-06 10:26:03 Bad estimates on GIN bigint[] index