Skip site navigation (1) Skip section navigation (2)

Variables in SQL scripts

From: "Machiel Richards" <machielr(at)rdc(dot)co(dot)za>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Variables in SQL scripts
Date: 2010-06-09 11:38:32
Message-ID: 008e01cb07c8$4cc56690$e65033b0$ (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
HI all


                I am looking for some more suggestions here on ways to use
variables in sql scripts to be run on postgresql


                We have some Sybase reports that needs to be run against a
postgresql database using sql scripts.


                For Sybase they set variables using the declare command for
instance :



                Declare id int    (just an example, not sure about the


                Then they refer to this same variable many times in more
than one query within this script.


                From what I understand, the guys have a problem due to these
variable declarations not working. They did some investigations and they
stated that they found the possibility of using temporary tables to put the
variables in, however the temp table is only valid for the first transaction
so they are unable to use the variable a second time.



              I did some googling as well and found something I tested using
a simple method:


-          I created an sql script to set the variable Name DB

o   \set DB <dbname>

o   \c :DB

-          I connected to postgresql using the postgres database and ran the
sql script which seemed to work fine as it then connected me to the



However will this method work with the above situation as well or are there
other ways of doing this?






pgsql-novice by date

Next:From: Machiel RichardsDate: 2010-06-09 11:48:21
Subject: Additional info on request: Variables in SQL scripts
Previous:From: coviolo@libero.itDate: 2010-06-09 10:37:05
Subject: problem with variable

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group