Re: Perl and psql variables

From: Mark Campbell <mdc(at)ucs(dot)co(dot)za>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Perl and psql variables
Date: 2006-04-27 09:19:18
Message-ID: 44508C96.2050203@ucs.co.za
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Thx for the replies

What I found after really reading the man pages of psql is the -v switch

So the following now works for me:

psql -f sql.file -v month=$month

and I have the variable :month in the sql.file

Regards

Mark Campbell

Confidentiality Notice: http://ucs.co.za/conf.html

Tom Lane wrote:
> Mark Campbell <mdc(at)ucs(dot)co(dot)za> writes:
>
>> the perl script generates a variable called $month (which is the current
>> month), I then need that month variable passed as a command line line
>> parameter to psql. eg psql -f sql.file --variable "month = $month"
>> then do a SELECT with the variable called :month
>>
>
> How about something like
>
> (
> echo "\set :month = $month"
> cat sql.file
> ) | psql
>
> regards, tom lane
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Verena Ruff 2006-04-27 13:29:07 error handling
Previous Message Leonardo Boiko 2006-04-26 19:52:55 Trigger to force fields to lowercase at insert/update