Variables in SQL scripts - Mailing list pgsql-novice

From Machiel Richards
Subject Variables in SQL scripts
Date
Msg-id 008e01cb07c8$4cc56690$e65033b0$@co.za
Whole thread Raw
Responses Additional info on request: Variables in SQL scripts
List 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 syntax)

 

                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 database.

 

 

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

 

 

Regards

Machiel

pgsql-novice by date:

Previous
From: "coviolo@libero.it"
Date:
Subject: problem with variable
Next
From: "Machiel Richards"
Date:
Subject: Additional info on request: Variables in SQL scripts