sql scripts

Поиск
Список
Период
Сортировка
Искать

sql scripts

От:
Joseph 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

Re: sql scripts

От:
David Link <dlink@soundscan.com>
Дата:
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.

Re: sql scripts

От:
Alvaro Herrera <alvherre@atentus.com>
Дата:
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 ()
"Tiene valor aquel que admite que es un cobarde" (Fernandel)

Re: sql scripts

От:
Joseph Shraibman <jks@selectacast.net>
Дата:
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

FAQ