On 05/09/2018 02:59 AM, John McKown wrote:
I just wanted to throw this out to the users before I made a complete fool of myself by formally requesting it. But I would like what I hope would be a minor change (enhancement) to the psql command. If you look on this page, https://wiki.postgresql.org/wiki/Shared_Database_ ,Hosting you will see a number of example which look like:
psql -U postgres template1 -f - << EOT REVOKE ALL ON DATABASE template1 FROM public; REVOKE ALL ON SCHEMA public FROM public; GRANT ALL ON SCHEMA public TO postgres; CREATE LANGUAGE plpgsql; EOT
To me this looks similar to a UNIX shell script.
Because it is a Unix shell script. The "<< EOT" is part of a heredoc, which is designed to keep everything in one place instead of needing a second file for the SQL commands.
https://en.wikipedia.org/wiki/Here_document
(The concept is as old as computing. Anyone who's worked on mainframes or proprietary minicomputers from DEC will instantly recognize it.)
Yes, I use HERE docs in my shell scripts. I was just, sort of, wanting to avoid that by making a "slight" change to the psql program to ignore the first (and only the first) line of any file referenced via a "-f". This is NOT any kind of critical necessity. I just think it would be "nice" simply because _I_ have a habit of use the "magic" #! at the start of the first like in order to have other "languages" (such as python, perl, gawk), be invoked with the script file name as a parameter. One reason to avoid a HERE doc is from what I've learned about how BASH at least implements them. The BASH shell sees the HERE document and copies it into a "temporary" disk file. It then opens this file and supplies that file descriptor to whatever is being fed the HERE document as input. So, in effect, using a HERE document, at least in BASH, does a lot more I/O to the disk system.
Again, this is just a discussion point. And I'm quite willing to admit defeat if most people don't think that it is worth the effort.
--
Angular momentum makes the world go 'round.
We all have skeletons in our closet.
Mine are so old, they have osteoporosis.
Maranatha! <><
John McKown
John McKown