Jump to content

[Resolvido] INTO OUTIFLE update


zppinto

Recommended Posts

Como posso fazer o update do ficheiro?

SELECT * FROM teste.dados INTO OUTFILE 'file.txt';

COLUMNS TERMINATED BY ','

LINES TERMINATED BY '\r\n';

Isto porque da 1ª vez que o ficheiro é criado, o código funciona perfeitamente, mas se o volto a executar diz que o ficheiro já existe e não o reescreve, como eu pretendia...

Obrigado.

Link to comment
Share on other sites

Em principio não consegues. Tens que escrever para um ficheiro diferente.

Na documentação: http://dev.mysql.com/doc/refman/5.0/en/select-into.html

The file is created on the server host, so you must have the FILE privilege to use this syntax. file_name cannot be an existing file, which among other things prevents files such as /etc/passwd and database tables from being destroyed.
Edited by KTachyon

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Link to comment
Share on other sites

Eu trataria disso a partir da shell, apagando ou movendo o ficheiro original.

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Link to comment
Share on other sites

... para não estar constantemente a consultar a base de dados.

Porque???

A consulta a base de dados, num servidor correctamente configurado, é mais rapida e gasta menos recursos que abrir, ler, fechar um ficheiro de texto.

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Link to comment
Share on other sites

Porque me disseram que seria a melhor forma de o fazer, para não estar constantemente a ir ler à base de dados...

É melhor ir constantemente à base de dados, bem configurada! (para isso é que ela foi feita).

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Link to comment
Share on other sites

Tendo em conta que as bases de dados existem para estarem constantemente a ser consultadas... 🙂

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.