Senhores, bom dia.
Gostaria de tirar umas duvidas sobre importação de arquivo no postgreSQL.
Preciso concaternar o nome de um arquivo (TXT) com a uma data (variavel), pois
a data não pode ser fixa, e não estou conseguindo.
Segue abaixo a Function que eu estou criando, utilizando Variavel (em Negrito),
e o erro que está dando :
CREATE OR REPLACE FUNCTION import_list_tuvision_call()
RETURNS boolean AS
$BODY$
declare
spath varchar(255);
begin
spath := '/tmp/list_atev001_call_123' || to_date(current_date, 'yyyymmdd') ||
'.txt';
COPY list_tuvision_call FROM spath
with DELIMITER AS '|' NULL AS '';
RETURN 0;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
Segue o Erro:
ERROR: syntax error at or near "$1" at character 31
QUERY: COPY list_tuvision_call FROM $1 with DELIMITER AS '|' NULL AS ''
CONTEXT: SQL statement in PL/PgSQL function "import_list_tuvision_call" near
line 8
Segue abaixo a Function, utilizando PIPE ( || ), e o erro que está dando :
CREATE OR REPLACE FUNCTION import_list_tuvision_call()
RETURNS boolean AS
$BODY$
begin
COPY list_tuvision_call FROM '/tmp/list_atev001_call_123' ||
to_date(current_date, 'yyyymmdd') || '.txt'
with DELIMITER AS '|' NULL AS '';
RETURN 0;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
Segue o Erro :
ERROR: syntax error at or near "||" at character 65
QUERY: COPY list_tuvision_call FROM '/tmp/list_atev001_call_123' ||
to_date(current_date, 'yyyymmdd') || '.txt'
CONTEXT: SQL statement in PL/PgSQL function "import_list_tuvision_call" near
line 7
Quando eu coloco o nome do arquivo sem PIPE (serve para Concatenar) ele cria e
executa normalmente. Segue abaixo um exemplo :
CREATE OR REPLACE FUNCTION import_list_tuvision_call()
RETURNS boolean AS
$BODY$
begin
COPY list_tuvision_call FROM '/tmp/list_atev001_call_123_20070202.txt'
with DELIMITER AS '|' NULL AS '';
RETURN 0;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
Já tentei colocar to_char antes do to_date (to_char (to_date(current_date,
'yyyymmdd'))) e tambem não deu certo.
Procurei na internet e nada.
Gostaria de saber como eu faço para arrumar esse problema ?
Obrigado,
Jimmy
_______________________________________________
Grupo de Usuários do PostgreSQL no Brasil
Antes de perguntar consulte o manual
http://pgdocptbr.sourceforge.net/
Para editar suas opções ou sair da lista acesse a página da lista em:
http://pgfoundry.org/mailman/listinfo/brasil-usuarios