sql-language-server icon indicating copy to clipboard operation
sql-language-server copied to clipboard

Syntax error on correct SQL file

Open pedropombeiro opened this issue 2 years ago • 1 comments

I've just managed to install the language server together with NeoVim/CoC, and I'm getting this error:

db/structure.sql|1 col 2-3 error| [sql] Expected "$", "(", "--", "/*", "CREATE TABLE", "DELETE", "INSERT", "REPLACE", "SELECT", "UPDATE", "return", [ \t\n\r], or end of input but "C" found. [E]

2022-04-22 at 19 28

Here's my configuration file (inside .config/nvim/coc-settings.json):

  {
      "command": "sql-language-server",
      "args" : ["up", "--method", "stdio"],
      "filetypes": ["sql"],
      "settings": {
        "connections": [
          {
            "name": "GDK postgresql",
            "adapter": "postgres",
            "hostname": "${env:HOME}/src/gitlab-development-kit/postgresql",
            "user": "${env:USER}",
            "projectPaths": ["${env:HOME}/src/gitlab-development-kit"]
          }
        ]
      }
    }

Is CREATE SCHEMA supported, or is this some kind of encoding error?

pedropombeiro avatar Apr 22 '22 17:04 pedropombeiro

Same issue here

wongjiahau avatar Jun 17 '22 05:06 wongjiahau

I have the same error happening, but mine is complaining about "DROP". Too bad this seems to not be working with coc.nvim

znoble360 avatar Nov 15 '22 21:11 znoble360

I am also using postgresql as well, maybe the issue has something to do with that?

znoble360 avatar Nov 15 '22 21:11 znoble360

Same here.

kapitanluffy avatar Mar 10 '23 08:03 kapitanluffy

HI. We've not implemented some statements or clauses yet. For @pedropombeiro 's case, it's because of CREATE FUNCTION statement. @znoble360 's case, it'a because of DROP TABLE statement. I've created issues for both of them and we'll have plans to deal with it. If you find any inconvenient, please share us some sql examples as much as you can. It's very useful to identify the problem. And don't hesitate to give us any feedback, we can use your feedback to prioritize what we need to do. Of course, your PR is always welcome! Thanks.

joe-re avatar Mar 14 '23 23:03 joe-re

I'm writing my migration files in pure SQL. CREATE and DROP statements are very essential for a lot of use case.

adonespitogo avatar Apr 16 '23 20:04 adonespitogo

@adonespitogo HI, thanks for your feedback. It supports CREATE TABLE but not yet for DROP TABLE statement. If you can share something examples of CREATE TABLE statement that has an error, it would be great to catch your use case, thanks 🙏

joe-re avatar Apr 17 '23 03:04 joe-re

Hi @joe-re , thanks for the quick response. Here are the create table statements I use in my migrations:

CREATE TABLE IF NOT EXISTS devices (
	id INT AUTO_INCREMENT PRIMARY KEY,
	ip_address VARCHAR(15) NOT NULL,
	mac_address VARCHAR(17) NOT NULL,
	hostname VARCHAR(64),
	created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS sessions (
	id INT AUTO_INCREMENT PRIMARY KEY,
  device_id INT NOT NULL,
  session_type VARCHAR(20) NOT NULL,
	time_secs INT DEFAULT 0,
	data_mb INT DEFAULT 0,
	time_consumption_secs INT DEFAULT 0,
  data_consumption_mb INT DEFAULT 0,
	created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

  FOREIGN KEY (device_id) REFERENCES devices(id)
);
CREATE TABLE IF NOT EXISTS purchases (
	id INT AUTO_INCREMENT PRIMARY KEY,
  device_id INT NOT NULL,
  method VARCHAR(255) NOT NULL,
  confirmed_at TIMESTAMP,
  cancelled_at TIMESTAMP,
	created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

  FOREIGN KEY (device_id) REFERENCES devices(id)
);
CREATE TABLE IF NOT EXISTS purchase_items (
	id INT AUTO_INCREMENT PRIMARY KEY,
  purchase_id INT NOT NULL,
  name VARCHAR(255) NOT NULL,
  description VARCHAR(255) NOT NULL,
  price DECIMAL(5, 2),
	created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

  FOREIGN KEY (purchase_id) REFERENCES purchases(id)
);
CREATE TABLE IF NOT EXISTS payments (
	id INT AUTO_INCREMENT PRIMARY KEY,
  purchase_id INT NOT NULL,
  source VARCHAR(255) NOT NULL,
  price DECIMAL(5, 2),
	created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

  FOREIGN KEY (purchase_id) REFERENCES purchases(id)
);
CREATE TABLE IF NOT EXISTS wallets (
	id INT AUTO_INCREMENT PRIMARY KEY,
  device_id INT NOT NULL,
  balance DECIMAL(5, 2),
	created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

  FOREIGN KEY (device_id) REFERENCES devices(id)
);
CREATE TABLE IF NOT EXISTS wallet_transactions (
	id INT AUTO_INCREMENT PRIMARY KEY,
  wallet_id INT NOT NULL,
  amount DECIMAL(5, 2),
  description VARCHAR(255),
	created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

  FOREIGN KEY (wallet_id) REFERENCES wallets(id)
);

Each of these statements are contained in a separate file. Hope it helps.

adonespitogo avatar Apr 17 '23 04:04 adonespitogo

@adonespitogo Hi, thank you for your report. I have fixed the syntax errors in your SQL queries. If you find any further problems, please raise a new issue. This issue has already been closed and I may not be aware of any other reports from you. Thank you 🙏

joe-re avatar Apr 17 '23 16:04 joe-re

@joe-re thanks for quickly implementing this feature. I can confirm all my migration codes are indeed not showing diagnostic errors anymore.

adonespitogo avatar Apr 17 '23 20:04 adonespitogo

Thanks for your work on this!

Here's a directive that returns this same error

CREATE TYPE foo AS ENUM ('bar', 'vaz');

eboody avatar Jun 04 '23 15:06 eboody