I am facing issue with DROP table command in Linux (backend : Postgres). I have a table named "prabhu2016-02-08--2016-02-15". when I drop this table using below commend i am receiving error.... ERROR: syntax error at or near "-" LINE 1: ...op table prabhu2016-02-08--2016-02...

code is: psql -d DBname -c "Drop table myschema.prabhu2016-02-08--2016-02-15

Looks like Hyphen issue.

  • What do you mean by "partition table"?
    – schaiba
    Feb 29, 2016 at 8:35
  • It is a child table.. (inherited table)...
    – Prabhu
    Feb 29, 2016 at 8:53
  • Please edit the question accordingly then. The term "partition table" might be easily confusing as it usually refers to storage devices rather than DBs.
    – schaiba
    Feb 29, 2016 at 8:54
  • 1
    have you tried wrapping the table name with single quotes? e.g. drop table 'prabhu2016-02-08--2016-02-15';
    – cas
    Feb 29, 2016 at 9:32
  • xkcd.com/327
    – UVV
    Feb 29, 2016 at 13:56

1 Answer 1


This is what I do when the query is complex shellwize or I have to use any names/variables that better be quoted:

  1. Use all the names as variables: tablename="bla"
  2. Call psql this way:

    su - postgres -c "/usr/local/ctera/postgres/bin/psql << EOF
    drop table "$tablename";

  • Issue is, the table name has (hyphen) - symbol, hence drop command is failing,. how to skip/make hyphen as a word and run the command ?
    – Prabhu
    Mar 1, 2016 at 14:10
  • any help here ?
    – Prabhu
    Mar 2, 2016 at 7:52
  • Wait, how did you create this table?
    – csny
    Mar 2, 2016 at 11:05
  • It is dynamic child table creation. I have a trigger, that will create a Child Table including current_date in table name, whenever new data coming into Parent table. When DB size is full, I need to drop the child table. now I stuck here with drop table command.
    – Prabhu
    Mar 2, 2016 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .