Hello I am not in clear what your use case is, but you may have a look at that: http://www.depesz.com/2013/02/25/variables-in-sql-what-how-when/ The bottom line is that in a psql interactive session you cannot really set a variable as the result of a select statement (or at least I did not fine a way). Instead, depending on what you actually want to achieve, you may use a workaround storing a statement or part of it in a variable. Here an example: db=> create table test (id int); CREATE TABLE db => insert into test select generate_series(1,10); INSERT 0 10 db => \set testvar 'sum(id) from test' db => select :testvar; sum ----- 55 (1 row) Bye Charles From: pgsql-general-owner@xxxxxxxxxxxxxx [mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Edson F. Lidorio Hello, ERROR: relation "v_saldo_ini" already exists |