0

Surely this will be flagged as a dupe within seconds but I cannot for the life of me figure out what's wrong with this query:

MariaDB [nextcloud]> describe oc_file_locks;
+-------+---------------------+------+-----+---------+----------------+
| Field | Type                | Null | Key | Default | Extra          |
+-------+---------------------+------+-----+---------+----------------+
| id    | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
| lock  | int(11)             | NO   |     | 0       |                |
| key   | varchar(64)         | NO   | UNI | NULL    |                |
| ttl   | int(11)             | NO   | MUL | -1      |                |
+-------+---------------------+------+-----+---------+----------------+
4 rows in set (0.003 sec)

MariaDB [nextcloud]> select * from oc_file_locks where lock <> 0;
ERROR 1064 (42000): 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 'lock <> 0' at line 1
MariaDB [nextcloud]> select * from oc_file_locks where lock != 0;
ERROR 1064 (42000): 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 'lock != 0' at line 1

Am I crazy, or should this work? I'm a little rusty on my SQL but I didn't think it was that bad.

Big McLargeHuge
  • 14,841
  • 10
  • 80
  • 108

1 Answers1

2

key and lock are reserved words. Pick different names, or enclose them in backticks:

select * from oc_file_locks where `lock` <> 0;
Amadan
  • 191,408
  • 23
  • 240
  • 301