Postgre SQL 8.4 variables in a query

Question:

Can you please tell me if Postgre SQL 8.4 can use variables in the queries themselves (not in functions)? rummaging in the internet, I realized that they are not ((

so I decided to cheat and use a temporary table to take the necessary parameters from it

For example:

CREATE TEMP TABLE tempp ON COMMIT DROP
AS
SELECT  'test.ss' AS imptable, --Таблица
    'company_id'  AS column1   --столбец ;

SELECT * FROM  (SELECT imptable FROM tempp) a
where (SELECT column1 FROM tempp) >1;

Thought it would work and it would look in test.ss, but no:

SELECT * FROM  (SELECT imptable FROM tempp)

makes a choice not from test.ss but from tempp , because in fact it sees my subquery as a table, and not as a word that I want to substitute in the script

I want to get the result as if I wrote

SELECT * FROM  test.ss

Tell me what to do if there are normal variables without using functions? If not, then how else can you use something like variables in queries, change something in one place, so as not to edit the entire query

Answer:

    UPDATE "STA_User" b
SET "ID" = a."ID", "Username"=a."Username"
FROM  (
   SELECT *
   FROM dblink('port=5432 dbname=Bekap user=postgres  password=123456'
               , 'SELECT "ID", "Username" FROM public."STA_User"')
               AS t("ID" INTEGER, "Username" TEXT)
      )a
WHERE b."ID" = a."ID";
-- Обновить таблицу с такими же ID как у исходной

'a' and 'b' are awkward

Scroll to Top
AllEscort