-1

why am i having syntax error when i try to execute this:

TRUNCATE TABLE   CONCAT(' schemaExample.','nameTable ') CONTINUE IDENTITY RESTRICT;

Thanks

Ayoub_75
  • 25
  • 6
  • You can simply write the `schemaExaple.nameTable` if this is the actual names instead of `CONCAT(' schemaExample.','nameTable ')` – Popeye Jan 07 '21 at 06:42
  • thank you for the answer, but litterly i will make a loop and call it from java native query , where schemaExaple will be a parametere and i will loop over sevral table names. Thats why i'm trying this – Ayoub_75 Jan 07 '21 at 06:56
  • Does this answer your question? [Truncating all tables in a Postgres database](https://stackoverflow.com/questions/2829158/truncating-all-tables-in-a-postgres-database) – Nico Haase Jan 07 '21 at 06:59
  • thank you for the answer its very halpfull, but im still wondering why simple truncate table with concate don't work on pgAdmin – Ayoub_75 Jan 07 '21 at 07:10

1 Answers1

0

You cannot use an expression or parameter for an identifier like a table nane. Besides, TRUNCATE does not support parameters at all.

You will have to issue two SQL statements and construct the TRUNCATE statement from the first one.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • Thank you man for the answer, could you please give a example of what you are saying ? – Ayoub_75 Jan 07 '21 at 07:21
  • What is unclear about my answer? I won't write your. code; look for "dynamic SQL" in the documentation and use `format` to avoid SQL injection. – Laurenz Albe Jan 07 '21 at 07:26