Re: using vars in scripts - Mailing list pgsql-novice

From LLC
Subject Re: using vars in scripts
Date
Msg-id 1151359292.v2.fusewebmail-164106@f
Whole thread Raw
In response to using vars in scripts  ("pablo sebastian rodriguez" <psrodriguez@gmail.com>)
List pgsql-novice
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...


pgsql-novice by date:

Previous
From: "Andrej Ricnik-Bay"
Date:
Subject: Re: insert more than one rows
Next
From: Hoványi Dániel
Date:
Subject: Signal problems