Skip to content

docs: Explain CLIENT_IGNORE_SPACE for function names followed by a space - #649

Merged
krlmlr merged 2 commits into
mainfrom
claude/ignore-space-docs
Nov 29, 2026
Merged

krlmlr merged 2 commits into
mainfrom
claude/ignore-space-docs

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

SELECT EXTRACT (YEAR FROM date_col), with a space before the parenthesis, fails with syntax error 1064.
This comes from the server's parser, not from RMariaDB: the mariadb command-line client fails the same way, and the query works once the IGNORE_SPACE SQL mode is set.
RMariaDB already exports CLIENT_IGNORE_SPACE, but nothing pointed users to it.

This PR adds a paragraph and an example to the Client-flags help page.
It explains that some built-in functions, such as EXTRACT and COUNT, fail with a space before the parenthesis and then need CLIENT_IGNORE_SPACE or the IGNORE_SPACE SQL mode, and notes that with this mode built-in function names become reserved words, so tables or columns with such names need backtick quoting.

Verified against a local MariaDB 10.11 server with the query SELECT EXTRACT (YEAR FROM DATE '2024-01-15') AS y.

library(DBI); library(RMariaDB)
q <- "SELECT EXTRACT (YEAR FROM DATE '2024-01-15') AS y"
args <- list(MariaDB(), user = "test", password = "test", dbname = "test", unix.socket = "/run/mysqld/mysqld.sock")

con <- do.call(dbConnect, args)
dbGetQuery(con, q)
#> 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 'FROM DATE '2024-01-15') AS y' at line 1 [1064]

con <- do.call(dbConnect, c(args, client.flag = CLIENT_IGNORE_SPACE))
dbGetQuery(con, q)
#>      y
#> 1 2024

con <- do.call(dbConnect, args)
dbExecute(con, "SET SESSION sql_mode = CONCAT(@@sql_mode, ',IGNORE_SPACE')")
dbGetQuery(con, q)
#>      y
#> 1 2024

The Rd file was regenerated with roxygen2 8.1.1 and the diff contains only the new text.
No NEWS entry, because NEWS.md is generated from commits.

Closes #408.

https://claude.ai/code/session_01Hr1rd43pnoHuAnGBgMih89


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Question: Reply to the reporter on #408

#408's reporter is waiting for an answer (last asked on 2026-06-25). The cause is the server's parser, not RMariaDB: for some built-in functions, such as EXTRACT and COUNT, MariaDB rejects a space before the parenthesis unless the IGNORE_SPACE SQL mode is on. The mariadb command-line client fails the same way; DBeaver presumably connects with that mode. This PR documents the fix. A comment on #408 notifies the reporter, so it is posted only on your say-so. Draft:

Thanks for the detailed report, and sorry for the long wait. This comes from the server, not from RMariaDB: for some built-in functions, such as EXTRACT and COUNT, MariaDB and MySQL only accept a space before the opening parenthesis when the IGNORE_SPACE SQL mode is on, and the mariadb command-line client gives the same error. DBeaver probably connects with that mode. You can enable it in RMariaDB per connection with dbConnect(RMariaDB::MariaDB(), ..., client.flag = RMariaDB::CLIENT_IGNORE_SPACE), or after connecting with dbExecute(con, "SET SESSION sql_mode = CONCAT(@@sql_mode, ',IGNORE_SPACE')"). Note that with IGNORE_SPACE, names of built-in functions become reserved words, so a column named like a function has to be quoted. Writing EXTRACT(YEAR FROM date_col) without the space also works on both MariaDB and Postgres. #649 adds this to the documentation.

If nobody decides, the PR closes #408 on merge without a reply.


Generated by Claude Code

@krlmlr
krlmlr marked this pull request as ready for review November 29, 2026 18:08
@krlmlr
krlmlr merged commit 06992e5 into main Nov 29, 2026
9 checks passed
@krlmlr
krlmlr deleted the claude/ignore-space-docs branch November 29, 2026 18:53

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Confirmed on main 06992e5 (RMariaDB 1.3.5.9007) against MariaDB 10.11.14, on a default connection without CLIENT_IGNORE_SPACE: SELECT EXTRACT(YEAR FROM DATE '2024-01-15') AS y returns y = 2024. With a space before the parenthesis, SELECT EXTRACT (YEAR FROM DATE '2024-01-15') AS y fails with the 1064 syntax error from #408.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Queries with EXTRACT (X FROM date_column) not working with MariaDB

2 participants