Running SQL script through psql gives syntax errors that don't occur in PgAdmin

前端 未结 4 1003
悲哀的现实
悲哀的现实 2020-12-02 02:24

I have the following script to create a table:

-- Create State table.
DROP TABLE IF EXISTS \"State\" CASCADE;
CREATE TABLE \"State\" (
 StateID SERIAL PRIMAR         


        
相关标签:
4条回答
  • 2020-12-02 02:31

    What version(-s) do you use? IF EXISTS came with version 8.2, maybe you're connection with version 8.1 or older when you use psql.

    0 讨论(0)
  • 2020-12-02 02:38

    To remove BOM sequence on Ubuntu you can use bomstrip, bomstrip-files

    0 讨论(0)
  • 2020-12-02 02:46

    Run your file 00101-CreateStateTable.sql through a hex dumper. I'll bet you have a UTF-16 marker at the beginning of the file (before the "--" comment characters).

    0 讨论(0)
  • 2020-12-02 02:51

    Thank you guys. I have been struggling with this issue for a few weeks. I could not run my SQL scripts using PSQL. I thought I have some issues with my OS, now I know it is the BOM issue in my text file. I installed bomstrip packet in Ubuntu and now all my SQL scripts are working again.

    0 讨论(0)
提交回复
热议问题