sql scripts

Started by Joseph Shraibmanover 24 years ago4 messagesgeneral
Jump to latest
#1Joseph Shraibman
jks@selectacast.net

FYI anyone who wants to have a psql shell script:

#!/bin/bash
tail +4 $0 | /usr/local/pgsql/bin/psql -U postgres -d playpen
exit

select version();

--
Joseph Shraibman
jks@selectacast.net
Increase signal to noise ratio. http://xis.xtenit.com

#2David Link
dlink@soundscan.com
In reply to: Joseph Shraibman (#1)
Re: sql scripts

Joseph Shraibman wrote:

FYI anyone who wants to have a psql shell script:

#!/bin/bash
tail +4 $0 | /usr/local/pgsql/bin/psql -U postgres -d playpen
exit

select version();

Very cool. And very clever. Thanks.

#3Alvaro Herrera
alvherre@atentus.com
In reply to: David Link (#2)
Re: sql scripts

El jue, 20-12-2001 a las 16:48, David Link escribi�:

Joseph Shraibman wrote:

FYI anyone who wants to have a psql shell script:

#!/bin/bash
tail +4 $0 | /usr/local/pgsql/bin/psql -U postgres -d playpen
exit

select version();

Very cool. And very clever. Thanks.

It should be possible to do things like

#!/usr/local/bin/psql -U someuser -d dbname
select version();

But the current psql implementation doesn't allow that for various
reasons. I don't know if it can be "fixed"...

--
Alvaro Herrera (<alvherre[a]atentus.com>)
"Tiene valor aquel que admite que es un cobarde" (Fernandel)

#4Joseph Shraibman
jks@selectacast.net
In reply to: Joseph Shraibman (#1)
Re: sql scripts

When bash interprets the magic line starting with #! it appends the filename to the end of
the command, it doesn't pipe the contents of the file to stdin. So when I was trying to
write the shells script first I tried something like

#!/usr/local/bin/psql -U someuser -d dbname -f

but psql couldn't handle the magic line itself, and you can't have pipes in the magic
line, so I finally settled on using tail on the script itself (inspired by the jdk
installers from sun).

Alvaro Herrera wrote:

El jue, 20-12-2001 a las 16:48, David Link escribi�:

Joseph Shraibman wrote:

FYI anyone who wants to have a psql shell script:

#!/bin/bash
tail +4 $0 | /usr/local/pgsql/bin/psql -U postgres -d playpen
exit

select version();

Very cool. And very clever. Thanks.

It should be possible to do things like

#!/usr/local/bin/psql -U someuser -d dbname
select version();

But the current psql implementation doesn't allow that for various
reasons. I don't know if it can be "fixed"...

--
Joseph Shraibman
jks@selectacast.net
Increase signal to noise ratio. http://xis.xtenit.com