Re: [GENERAL] psql scripting tutorials

2008-09-20 Thread Michelle Konzack
Am 2008-09-11 10:03:03, schrieb Roderick A. Anderson: > Whatever happened to pgbash? I see the last update was Feb 2003 but > that was for Pg v7.3. I have tried it soe times ago with 7.4 but goten to many errors... ...and gaved up. Thanks, Greetings and nice Day/Evening Michelle Konzack

Re: [GENERAL] psql scripting tutorials

2008-09-12 Thread Blazej
> Ok then. Does anyone have any tips or best practices for scripting psql? > > I'll probably write some bash scripts to pull csv files over then script > psql to do a COPY into an import schema then run a pl/pgsql procedure, er > function, to do all ETL. > > Who else is doing something like this? C

Re: [GENERAL] psql scripting tutorials

2008-09-12 Thread Peter Eisentraut
Alvaro Herrera wrote: Doesn't say about variable expansion ... And it seems to be in a different realm, because the point is that the command is going to have a single destination (either \-processing or sending it to the server). Is psql being just lazy here and avoiding parsing the command?

Re: [GENERAL] psql scripting tutorials

2008-09-11 Thread Artacus
$ TEST=16; psql -c "select $TEST as \"input1\";" $ TEST=16; echo "select $TEST as \"input1\";" | psql Yep that works. My coworker also suggested using

Re: [GENERAL] psql scripting tutorials

2008-09-11 Thread Adrian Klaver
-- Original message -- From: "Roderick A. Anderson" <[EMAIL PROTECTED]> > Kevin Hunter wrote: > > At 7:13am -0400 on Thu, 11 Sep 2008, Harald Fuchs wrote: > >> Nice trick, but when I try the following variant: > >> > >> psql -v TEST=16 -c 'select :TEST as "input"'

Re: [GENERAL] psql scripting tutorials

2008-09-11 Thread Roderick A. Anderson
Kevin Hunter wrote: At 7:13am -0400 on Thu, 11 Sep 2008, Harald Fuchs wrote: Nice trick, but when I try the following variant: psql -v TEST=16 -c 'select :TEST as "input"' I get [a syntax error] This seems to be contrary to the psql manual page: Nope. Take a look at the -c option. Spe

Re: [GENERAL] psql scripting tutorials

2008-09-11 Thread Kevin Hunter
At 7:13am -0400 on Thu, 11 Sep 2008, Harald Fuchs wrote: > Nice trick, but when I try the following variant: > > psql -v TEST=16 -c 'select :TEST as "input"' > > I get [a syntax error] > This seems to be contrary to the psql manual page: Nope. Take a look at the -c option. Specifically "Thu

Re: [GENERAL] psql scripting tutorials

2008-09-11 Thread Alvaro Herrera
Peter Eisentraut escribió: > psql manual page: > >-c command > >--command command > Specifies that psql is to execute one command string, command, > and then exit. This is useful in shell scripts. > > command must be either a command string that is completely

Re: [GENERAL] psql scripting tutorials

2008-09-11 Thread Peter Eisentraut
Harald Fuchs wrote: In article <[EMAIL PROTECTED]>, Greg Smith <[EMAIL PROTECTED]> writes: On Tue, 9 Sep 2008, Artacus wrote: Can psql access environmental variables or command line params? $ cat test.sql select :TEST as "input"; $ psql -v TEST=16 -f test.sql input --- 16 (1 row)

Re: [GENERAL] psql scripting tutorials

2008-09-11 Thread Alvaro Herrera
Harald Fuchs escribió: > Nice trick, but when I try the following variant: > > psql -v TEST=16 -c 'select :TEST as "input"' > > I get > > ERROR: syntax error at or near ":" > LINE 1: select :TEST as "input" > > This seems to be contrary to the psql manual page: > > These assignments a

Re: [GENERAL] psql scripting tutorials

2008-09-11 Thread Harald Fuchs
In article <[EMAIL PROTECTED]>, Greg Smith <[EMAIL PROTECTED]> writes: > On Tue, 9 Sep 2008, Artacus wrote: >> Can psql access environmental variables or command line params? > $ cat test.sql > select :TEST as "input"; > $ psql -v TEST=16 -f test.sql > input > --- > 16 > (1 row) Nice tr

Re: [GENERAL] psql scripting tutorials

2008-09-10 Thread Greg Smith
On Tue, 9 Sep 2008, Artacus wrote: Can psql access environmental variables or command line params? $ cat test.sql select :TEST as "input"; $ psql -v TEST=16 -f test.sql input --- 16 (1 row) You can find out more about what you can do with variable substitution at http://www.postgres

Re: [GENERAL] psql scripting tutorials

2008-09-10 Thread Scott Marlowe
On Wed, Sep 10, 2008 at 10:14 PM, Artacus <[EMAIL PROTECTED]> wrote: >> This sounds a lot like what I did in my last job using bash for most >> things, and php for the more complicated stuff. Wrote a simple oracle >> to pgsql table replicator in php that worked pretty well. > > Well we do this stu

Re: [GENERAL] psql scripting tutorials

2008-09-10 Thread Artacus
This sounds a lot like what I did in my last job using bash for most things, and php for the more complicated stuff. Wrote a simple oracle to pgsql table replicator in php that worked pretty well. Well we do this stuff all the time with Oracle and sql*plus. And I've heard people hear say about

Re: [GENERAL] psql scripting tutorials

2008-09-10 Thread Scott Marlowe
On Wed, Sep 10, 2008 at 12:46 AM, Artacus <[EMAIL PROTECTED]> wrote: > Artacus wrote: >> >> I'd like to learn a little more about writing psql scripts does anyone >> know of any resources outside of the manual? > > Ok then. Does anyone have any tips or best practices for scripting psql? > > I'll pr

Re: [GENERAL] psql scripting tutorials

2008-09-10 Thread John DeSoi
On Sep 10, 2008, at 2:46 AM, Artacus wrote: Who else is doing something like this? Can psql access environmental variables or command line params? Or do I have to have my bash script write a psql script every time? The psql \! command can execute shell commands. You can also use ``, e.g

Re: [GENERAL] psql scripting tutorials

2008-09-09 Thread Artacus
Artacus wrote: I'd like to learn a little more about writing psql scripts does anyone know of any resources outside of the manual? Ok then. Does anyone have any tips or best practices for scripting psql? I'll probably write some bash scripts to pull csv files over then script psql to do a