Re: SQL equivalint of #incude directive ? - Mailing list pgsql-general

From Tony Shelver
Subject Re: SQL equivalint of #incude directive ?
Date
Msg-id CAG0dhZDvx5cUwb3OKkfZn1Khb8DgoH93xwYFQwNKFwG=sKuXjw@mail.gmail.com
Whole thread Raw
In response to Re: SQL equivalint of #incude directive ?  (Francisco Olarte <folarte@peoplecall.com>)
Responses Re: SQL equivalint of #incude directive ?
List pgsql-general
Similar to what Francisco said.  Not exactly sure what your use case is though..

In the past I have usually used a DB modeling / design front end tool to design my database, and then maintain and generate most of the build scripts.
Datanamic Dezign used to be my go-to for SQL Server when i still paid money for tools, and I maintained that as a central repository for all SQL scripts for functions, tables, views, procedures and so on, and it would generate create / diff scripts as necessary.

On Postgres I use pgmodeler, the only issue there is that I find it quicker and easier to create procedures and functions and so on directly in code, then have those in a script file that is run after the schema creation.
There are other (commercial) tools out there that will allow SQL script preprocessing and generation.

I think you will find that most DBAs build their own scripts using tools like Perl or Python, or a commercial product.

A similar situation exists for HTML, there is no standard pre-processor directive.  I started off creating a Python utility to replace include directives with input from external files, which worked fine.  Fairly trivial if you are reasonably familiar with a scripting language.
Eventually i switched to an open source site generator that included that capability along with a lot more functionality.



On Sat, 31 Aug 2019 at 10:12, Francisco Olarte <folarte@peoplecall.com> wrote:
Stan:

On Fri, Aug 30, 2019 at 3:49 PM stan <stanb@panix.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.


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Question about password character in ECPG's connection string
Next
From: Francisco Olarte
Date:
Subject: Re: SQL equivalint of #incude directive ?