@
@
@postgres2016-09-03 15:39:07
PostgreSQL
@postgres, 2016-09-03 15:39:07

How to use variables in a query in Postgre SQL 8.4?

Can you please tell me whether it is possible to use variables in the queries themselves (not in functions) in Postgre SQL 8.4?
rummaging through the internet, I realized that there are none ((
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, --Table
'company_id' AS column1 --column ;
SELECT * FROM (SELECT imptable FROM tempp) a
where (SELECT column1 FROM tempp) >1;

I thought that it would work, and he 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 the result to be as if I had written
SELECT * FROM test.ss

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
terrier, 2016-09-03
@terrier

prepared statements

https://www.postgresql.org/docs/current/static/sql...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question