Thread: using vars in scripts

using vars in scripts

From
"pablo sebastian rodriguez"
Date:
hi,

i know this is silly, but i can't find the way...

with mssql i can do this:

declare @my_var varchar(20) ;
set @my_var = 'something' ;
select @my_var ;


with mysql it's even easier:

set @my_var = 'something' ;
select @my_var ;


but, with postgre ? i don't know how to do that...


Re: using vars in scripts

From
"LLC"
Date:
Postgres offers several methods. I'll assume you're running Linux/bash, if not try and convert the following to whatever OS/shell you're using:
 
# Bash script 1 using a here document:
 
tabname='mytab'
tabcol='username'
 
 
psql <dbname> <<EOF
select $tabcol from $tabname;
EOF!
 
 
# Bash script 2 - using echo:
tabname='mytab'
tabcol='username'
 
echo "select $tabcol from $tabname" | psql <dbname> 
 

There are many variations on these examples, hope this helps...
 
 


----- Original Message -----
Subject: [NOVICE] using vars in scripts
From: "pablo sebastian rodriguez" <psrodriguez@gmail.com>
Date: Fri, June 23, 2006 18:37

hi,

i know this is silly, but i can't find the way...

with mssql i can do this:

declare @my_var varchar(20) ;
set @my_var = 'something' ;
select @my_var ;


with mysql it's even easier:

set @my_var = 'something' ;
select @my_var ;


but, with postgre ? i don't know how to do that...