Variables in SQL scripts

Поиск
Список
Период
Сортировка
От Machiel Richards
Тема Variables in SQL scripts
Дата
Msg-id 008e01cb07c8$4cc56690$e65033b0$@co.za
обсуждение исходный текст
Ответы Additional info on request: Variables in SQL scripts  ("Machiel Richards" <machielr@rdc.co.za>)
Список 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 по дате отправления:

Предыдущее
От: "coviolo@libero.it"
Дата:
Сообщение: problem with variable
Следующее
От: "Machiel Richards"
Дата:
Сообщение: Additional info on request: Variables in SQL scripts