1

I'm creating a custom extension for PostgreSQL. I can get the extension to create successfully, but my foo--0.1.sql is getting rather large and complex. I'd like to break it out into multiple files for ease of maintenance but I can't figure out from the docs how to do this.

It seems like I could go one of two routes:

  1. Use a built-in functionality with PG's extension building infrastructure to automatically use all of my .sql files.
  2. Use the Makefile to concatenate all of my .sql files when the extension is first built.

My questions are whether #1 is even possible (I can't see anything in the docs - it only references the single extension--version.sql file that is required).

Also, how would I do #2? I don't have much experience with Makefiles and can't quite figure it out.

Thanks!

asked Aug 6, 2015 at 1:19

2 Answers 2

3

You could probably achieve #1 with "\i" directives to import snippets. I wouldn't advise it, though, I'd use a Makefile to concatenate the desired chunks.

It's as simple as something like:

myext--1.0.sql: myext-types.sql myext-tables.sql myext-views.sql
 cat $< $@

Note that the indent must be a tab, not spaces.

There's lots of good info out there on writing basic Makefiles, so I won't go on further.

answered Aug 6, 2015 at 2:24
1

I came across this blog post which put me on the right track.

answered Aug 6, 2015 at 23:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.