0
In Mysql we can do:
SET @pedido = 123;
Afterward:
SELECT @pedido
We have something like that in postgres?
I have looked on the web, but only found in the construction of functions and procedures
The need is because sometimes I need to make some select in several tables in the base having in common a request number, more or less like this:
SET @pedido = 1234;
SELECT * FROM TABELA_1 WHERE (pedido = @pedido);
SELECT * FROM TABELA_2 WHERE (pedido = @pedido);
SELECT * FROM TABELA_3 WHERE (pedido = @pedido);
SELECT * FROM TABELA_4 WHERE (pedido = @pedido);
Each select opens a new tab in the DB manager (this is an application resource)
In psql you can use the variable set value and refer to the contents of the variable with :variable.
– anonimo
I tried here set xpedido = 123; select * from table Where request = :request; but it did not work, he complains about the code, I did not understand how to write this variable
– Marcelo
If you have set set set set set set 123 then use SELECT * FROM table WHERE request = :xpedido; [https://www.postgresql.org/docs/current/app-psql.html]
– anonimo
Sorry I had to repeat both, at the time of typing here I was wrong... but he from syntax error on set I think the version of my postgres does not accept this command I am using 9.6
– Marcelo
Note that there is no this = in set.
– anonimo