# SQL Syntax Error?

**URL:** <https://community.forestadmin.com/t/sql-syntax-error/839>\
**Category:** Help me!\
**Created:** [August 19, 2020, 3:21pm UTC](https://community.forestadmin.com/t/sql-syntax-error/839 "2020-08-19T15:21:13Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![j.cange](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@j.cange](https://community.forestadmin.com/u/j.cange)\
**Post date:** [August 19, 2020, 3:21pm UTC](https://community.forestadmin.com/t/sql-syntax-error/839/1 "2020-08-19T15:21:13Z")

</div>

## Expected behavior

Access the datas in my database

## Actual behavior

When i try to access one of my table, i got a server error

This happen with only ONE of my table, the other is fully working without any problem.

Any idea on how i can resolve this?

## Failure Logs

SequelizeDatabaseError: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '\*) AS `count` FROM `db_mcs` AS `dbMcs`’ at line 1  
at Query.formatError (C:\laragon\www\VHC\node\_modules\sequelize\lib\dialects\mysql\query.js:243:16)  
at Query.handler [as onResult] (C:\laragon\www\VHC\node\_modules\sequelize\lib\dialects\mysql\query.js:50:23)  
at Query.execute (C:\laragon\www\VHC\node\_modules\mysql2\lib\commands\command.js:30:14)  
at Connection.handlePacket (C:\laragon\www\VHC\node\_modules\mysql2\lib\connection.js:408:32)  
at PacketParser.onPacket (C:\laragon\www\VHC\node\_modules\mysql2\lib\connection.js:70:12)  
at PacketParser.executeStart (C:\laragon\www\VHC\node\_modules\mysql2\lib\packet\_parser.js:75:16)  
at Socket. (C:\laragon\www\VHC\node\_modules\mysql2\lib\connection.js:77:25)  
at Socket.emit (events.js:315:20)  
at addChunk (\_stream\_readable.js:295:12)  
at readableAddChunk (\_stream\_readable.js:271:9)  
at Socket.Readable.push (\_stream\_readable.js:212:10)  
at TCP.onStreamRead (internal/stream\_base\_commons.js:186:23)

## Context

Please provide any relevant information about your setup.

- Package Version: Lastest
- Express Version: Lastest
- Sequelize Version: Lastest
- Database Dialect: MySQL
- Database Version: Lastest
- Project Name: VHC

---

<div class="post-metadata">

**Author:** ![arnaud](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud/32/32_2.png) [@arnaud](https://community.forestadmin.com/u/arnaud)\
**Post date:** [August 20, 2020, 7:30am UTC](https://community.forestadmin.com/t/sql-syntax-error/839/2 "2020-08-20T07:30:10Z")

</div>

Hi @j.cange, welcome to the Forest Admin community 🌲

I guess the name of the table that does not display properly is `db_mcs`.  
Could you share the [DDL](https://en.wikipedia.org/wiki/Data_definition_language) of the table to let us investigate with a similar table?

Do you have the full SQL query that fails in your server logs?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![j.cange](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@j.cange](https://community.forestadmin.com/u/j.cange)\
**Post date:** [August 20, 2020, 7:48am UTC](https://community.forestadmin.com/t/sql-syntax-error/839/3 "2020-08-20T07:48:29Z")

</div>

Hi @arnaud,

I don’t have the full SQL query since it’s not one i created… The only informations i have is this :

'\*) AS `count` FROM `db_mcs` AS `dbMcs` ’

For the DDL : Sorry but i don’t understand what is it… (I’m still learning about database management)

---

<div class="post-metadata">

**Author:** ![arnaud](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud/32/32_2.png) [@arnaud](https://community.forestadmin.com/u/arnaud)\
**Post date:** [August 20, 2020, 8:11am UTC](https://community.forestadmin.com/t/sql-syntax-error/839/4 "2020-08-20T08:11:31Z")

</div>

About the full SQL query, you can add the `NODE_ENV=development` environment variable in your `.env` file, it should activate the SQL queries logs once your server restarted.

About the DDL, it is basically the set of SQL instructions that builds you table structure (name, columns, types, indexes,…). If you don’t know how to find that, a screenshot of the table definition could also help.

---

<div class="post-metadata">

**Author:** ![j.cange](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@j.cange](https://community.forestadmin.com/u/j.cange)\
**Post date:** [August 20, 2020, 8:46am UTC](https://community.forestadmin.com/t/sql-syntax-error/839/5 "2020-08-20T08:46:24Z")

</div>

![DDL](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/1X/08aa9f66c984819a65de99daf36af43832e57973.png)

Is that what you need? 😕

I’ve added the NODE\_ENV variable to my .env i get the same message with extra informations :

[forest] ­ƒî│­ƒî│­ƒî│ Unexpected error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '_) AS `count` FROM `db_mcs` AS `dbMcs`’ at line 1  
SequelizeDatabaseError: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '_) AS `count` FROM `db_mcs` AS `dbMcs`’ at line 1  
at Query.formatError (C:\laragon\www\VHC\node\_modules\sequelize\lib\dialects\mysql\query.js:243:16)  
at Query.handler [as onResult] (C:\laragon\www\VHC\node\_modules\sequelize\lib\dialects\mysql\query.js:50:23)  
at Query.execute (C:\laragon\www\VHC\node\_modules\mysql2\lib\commands\command.js:30:14)  
at Connection.handlePacket (C:\laragon\www\VHC\node\_modules\mysql2\lib\connection.js:408:32)  
at PacketParser.onPacket (C:\laragon\www\VHC\node\_modules\mysql2\lib\connection.js:70:12)  
at PacketParser.executeStart (C:\laragon\www\VHC\node\_modules\mysql2\lib\packet\_parser.js:75:16)  
at Socket. (C:\laragon\www\VHC\node\_modules\mysql2\lib\connection.js:77:25)  
at Socket.emit (events.js:315:20)  
at addChunk (\_stream\_readable.js:295:12)  
at readableAddChunk (\_stream\_readable.js:271:9)  
at Socket.Readable.push (\_stream\_readable.js:212:10)  
at TCP.onStreamRead (internal/stream\_base\_commons.js:186:23)  
From previous event:  
at Query.run (C:\laragon\www\VHC\node\_modules\sequelize\lib\dialects\mysql\query.js:39:12)  
at C:\laragon\www\VHC\node\_modules\sequelize\lib\sequelize.js:641:29  
From previous event:  
at C:\laragon\www\VHC\node\_modules\sequelize\lib\sequelize.js:641:12  
From previous event:  
at C:\laragon\www\VHC\node\_modules\sequelize\lib\sequelize.js:637:10  
at C:\laragon\www\VHC\node\_modules\retry-as-promised\index.js:70:21  
at new Promise ()  
at retryAsPromised (C:\laragon\www\VHC\node\_modules\retry-as-promised\index.js:60:10)  
at C:\laragon\www\VHC\node\_modules\sequelize\lib\sequelize.js:627:30  
From previous event:  
at Sequelize.query (C:\laragon\www\VHC\node\_modules\sequelize\lib\sequelize.js:576:23)  
at QueryInterface.rawSelect (C:\laragon\www\VHC\node\_modules\sequelize\lib\query-interface.js:1160:27)  
at Function.aggregate (C:\laragon\www\VHC\node\_modules\sequelize\lib\model.js:1990:32)  
at C:\laragon\www\VHC\node\_modules\sequelize\lib\model.js:2042:19  
at processImmediate (internal/timers.js:456:21)  
From previous event:  
at Function.count (C:\laragon\www\VHC\node\_modules\sequelize\lib\model.js:2026:8)  
at C:\laragon\www\VHC\node\_modules\forest-express-sequelize\dist\services\resources-getter.js:357:30

---

<div class="post-metadata">

**Author:** ![arnaud](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud/32/32_2.png) [@arnaud](https://community.forestadmin.com/u/arnaud)\
**Post date:** [August 20, 2020, 9:18am UTC](https://community.forestadmin.com/t/sql-syntax-error/839/6 "2020-08-20T09:18:51Z")

</div>

Could you share your `.env` file values (hidding your `DATABASE_URL`, `FOREST_ENV_SECRET`, `FOREST_AUTH_SECRET` that are sensitive values)?

---

<div class="post-metadata">

**Author:** ![j.cange](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@j.cange](https://community.forestadmin.com/u/j.cange)\
**Post date:** [August 20, 2020, 9:31am UTC](https://community.forestadmin.com/t/sql-syntax-error/839/7 "2020-08-20T09:31:55Z")

</div>

APPLICATION\_PORT=3310  
CORS\_ORIGINS=  
DATABASE\_SSL=false  
NODE\_ENV=development

---

<div class="post-metadata">

**Author:** ![arnaud](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud/32/32_2.png) [@arnaud](https://community.forestadmin.com/u/arnaud)\
**Post date:** [August 20, 2020, 1:02pm UTC](https://community.forestadmin.com/t/sql-syntax-error/839/8 "2020-08-20T13:02:44Z")

</div>

With this `.env` configuration, on top of this log:

```javascript
[forest] ­ƒî│­ƒî│­ƒî│ Unexpected error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' *) AS `count` FROM `db_mcs` AS `dbMcs` ’ at line 1*

```

you should have the full SQL query that fails.  
That is really strange that you can’t see it in your server console.

---

<div class="post-metadata">

**Author:** ![j.cange](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@j.cange](https://community.forestadmin.com/u/j.cange)\
**Post date:** [August 20, 2020, 1:32pm UTC](https://community.forestadmin.com/t/sql-syntax-error/839/9 "2020-08-20T13:32:52Z")

</div>

Okay i’ve found the query sorry i didn’t correctly open my eyes…

Executing (default): SELECT count(`dbMcs`.\*) AS `count` FROM `db_mcs` AS `dbMcs`;

---

<div class="post-metadata">

**Author:** ![arnaud](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud/32/32_2.png) [@arnaud](https://community.forestadmin.com/u/arnaud)\
**Post date:** [August 20, 2020, 1:49pm UTC](https://community.forestadmin.com/t/sql-syntax-error/839/10 "2020-08-20T13:49:53Z")

</div>

Thanks!

Can you run this SQL query directly in your database and try to find what’s wrong with it?  
I guess:  
`SELECT count(*) AS count FROM db_mcs;`  
should works right?

---

<div class="post-metadata">

**Author:** ![arnaud](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud/32/32_2.png) [@arnaud](https://community.forestadmin.com/u/arnaud)\
**Post date:** [August 20, 2020, 1:55pm UTC](https://community.forestadmin.com/t/sql-syntax-error/839/11 "2020-08-20T13:55:55Z")

</div>

Another question I have in mind about [case sensitivity](https://mariadb.com/kb/en/identifier-case-sensitivity/):  
on what machine OS (linux, mac, windows) is running your database?

---

<div class="post-metadata">

**Author:** ![j.cange](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@j.cange](https://community.forestadmin.com/u/j.cange)\
**Post date:** [August 20, 2020, 2:04pm UTC](https://community.forestadmin.com/t/sql-syntax-error/839/12 "2020-08-20T14:04:33Z")

</div>

Our server is under Linux (Debian 9)

For the query here’s the result (sorry our phpmyadmin is in french)

 ![query](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/1X/b54ac039b65461a86e84a34e5189584a0c18a317.png)

---

<div class="post-metadata">

**Author:** ![arnaud](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud/32/32_2.png) [@arnaud](https://community.forestadmin.com/u/arnaud)\
**Post date:** [August 20, 2020, 2:13pm UTC](https://community.forestadmin.com/t/sql-syntax-error/839/13 "2020-08-20T14:13:38Z")

</div>

Thank you, and what about `SELECT count(dbMcs.*) AS count FROM db_mcs AS dbMcs;` query?

---

<div class="post-metadata">

**Author:** ![j.cange](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@j.cange](https://community.forestadmin.com/u/j.cange)\
**Post date:** [August 20, 2020, 2:26pm UTC](https://community.forestadmin.com/t/sql-syntax-error/839/14 "2020-08-20T14:26:03Z")

</div>

> [@arnaud](#):
>
> SELECT count(dbMcs.\*) AS count FROM db\_mcs AS dbMcs;

It return me an error :

#1064 - Syntax error near ‘\*) AS count FROM db\_mcs AS dbMcs LIMIT 0, 25’ on line 1

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [August 21, 2020, 8:30am UTC](https://community.forestadmin.com/t/sql-syntax-error/839/15 "2020-08-21T08:30:15Z")

</div>

Hi @j.cange,

I just pulled a docker database using mariadb and generated a lumber project, and I’m sadly not able to reproduce your issue.

This is weird to me though, since running `SELECT COUNT(*) FROM foo;` works fine on mariadb, but `SELECT COUNT(foo.*) FROM foo;` does not.

Also, I would suggest to try specifying the sequelize dialect to `mariadb` inside the `models/index.js` of your project, just in case this would help (But since I’m not able to reproduce, I cannot check if it would help or not). You can see the syntax [here](https://sequelize.org/master/manual/getting-started.html)

Let me know if that helps

---

<div class="post-metadata">

**Author:** ![j.cange](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@j.cange](https://community.forestadmin.com/u/j.cange)\
**Post date:** [August 21, 2020, 8:55am UTC](https://community.forestadmin.com/t/sql-syntax-error/839/16 "2020-08-21T08:55:38Z")

</div>

Hi !

So i’ve followed your link and i managed to specify the dialect. Now the log return the same error as previously but with a little more info :

sql: SELECT count(`dbMcs`.\*) AS `count` FROM `db_mcs` AS `dbMcs`; - parameters:[]

The “Parameters:[]” is new …

Something strange is that, i have another table in this database and i can access it without any problem :

Executing (default): SELECT count(`employees`.`ID`) AS `count` FROM `employees` AS `employees`;  
GET /forest/employees/count?fields%5Bemployees%5D=accessLevel%2Cemail%2Cid%2Cpass&searchExtended=0&timezone=Europe%2FBrussels 304 - - 16.592 ms

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [August 21, 2020, 9:05am UTC](https://community.forestadmin.com/t/sql-syntax-error/839/17 "2020-08-21T09:05:40Z")

</div>

If the dialect does not fix your issue, I think you should remove it.

Since I cannot reproduce your issue, could you answer a few question related to your DBMS :

Could you tell me which version of mariadb you are using ?  
Is there any specific configuration related to that particular table ?  
Are you using a all-in-one software (Like MAMP/LAMP/WAMP) to host your database (From the stack trace it looks like it, but I just want to be sure) ?

---

<div class="post-metadata">

**Author:** ![j.cange](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@j.cange](https://community.forestadmin.com/u/j.cange)\
**Post date:** [August 21, 2020, 9:10am UTC](https://community.forestadmin.com/t/sql-syntax-error/839/18 "2020-08-21T09:10:52Z")

</div>

Well it looks like i figured out what the problem was…

Basically i used an old CSV to populate my table. In this CSV there was no ID as primary key. So i added an ID and everything work now !

Pretty dumb problem…

Thanks for your time and very sorry for the incovenience due to my stupidity ☹
