Jump to content
Fórum Script Brasil
  • 0

Passando valores por linha de comando


Lucas Naldo

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;

Link to comment
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.



  • Forum Statistics

    • Total Topics
      152.1k
    • Total Posts
      652k
×
×
  • Create New...