Jump to content
Fórum Script Brasil
  • 0
Sign in to follow this  
Lucas Naldo

Passando valores por linha de comando

Question

Tenho uma query pronta e pretendo chama-lá por linha de comando quando necessário. gostaria de alterar a variável de data pela chamada.

por exemplo:
psql  -f /mnt/Download/testeMeuBanco.sql -o /mnt/Download/resultado_meu_teste.csv

gostaria de alterar duas variáveis declaradas nessa linha. pDataInicial e pDataFinal. vi artigos dizendo para usar -v.

 

segue a query exemplo

 

--Teste
DO $$
declare
        pHostname varchar(100) = 'localhost';
    pDataInicial timestamp(0) = '2017-07-30';
        pDataFinal timestamp  = '2017-08-20';

begin

        DROP TABLE IF EXISTS resultado;

        create temp table resultado as
        SELECT a.cod as CODIGO, a.valor as VALOR, a.data as DATA, a.status as STATUS
        FROM history a
        WHERE a.data BETWEEN pDataInicial AND pDataFinal
        GROUP BY  a.cod, a.valor, a.data, a.status
        ORDER BY a.valor;

end
$$ language 'plpgsql';

select * from resultado;

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  



  • Forum Statistics

    • Total Topics
      148431
    • Total Posts
      643863
×
×
  • Create New...