I am calling PostgreSQL function that returns me the text, How can I store this value in local variable and use the value/variable in another query. ?
Postgresql – How to use value return by postgresSQL function in another query
postgresqlpostgresql-9.2
Related Question
- Postgresql – Use variables within a function with INSERT INTO
- PostgreSQL – How to Use a 1-Argument Function in ANY/ALL Query
- PostgreSQL – Return Both One Value and One Column from pl/pgsql Function
- PostgreSQL – How to Prepend an Element to a JSON Array?
- Postgresql – How to sort aggregate function call
- PLPGSQL – Using Parameters Inside a Function Query in PostgreSQL 12
- PostgreSQL Functions – Pass Variable as Input Argument to Function Inside Another Function
Best Answer
It's not very clear what exactly you mean by a local variable - there is no such thing in SQL. In this case, just use the function in the place where you would put your variable (like a_horse_with_no_name suggested in his comment), like
now()
is a function, and illustrates the case nicely.If you are about PL/pgSQL variables, you can do
Note that you can do this only inside a PL/pgSQL function or a
DO
block.Last, if you mean a
psql
(that is, client-side) variable, you can use the\gset
command:Note that
\gset
is available frompsql
version 9.3 only.