Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbExistsTable() throws error for DB2 temporary tables in version 1.6.0 #905

Open
nattomi opened this issue Mar 25, 2025 · 2 comments
Open

Comments

@nattomi
Copy link

nattomi commented Mar 25, 2025

dbExistsTable(conn, Id(schema = "SESSION", table = "MY_TEMP"))

throws

Error in `$<-.data.frame`(`*tmp*`, table_remarks, value = NA_character_) : 
  replacement has 1 row, data has 0
Calls: print ... tryCatchList -> tryCatchOne -> doTryCatch -> $<- -> $<-.data.frame`

in version 1.6.0 when applied to DB2 global temporary tables (SESSION.* tables).

In version 1.5.0 dbExistsTable returns FALSE in the same scenario.

Please refer to https://github.com/nattomi/odbc-dbexiststable-issue for a reproducible example.

Whether dbExistsTable should theoretically return FALSE or TRUE is not quite clear, because temporary tables are also not visible in the system catalog (syscat,tables). However, it should definitely not throw.

@detule
Copy link
Collaborator

detule commented Apr 5, 2025

Hey - thanks for the report!

If you have time, can you check if this PR yields results that are more along what you would expect?

Thanks again.

@nattomi
Copy link
Author

nattomi commented Apr 7, 2025

Hi, it seems like it got better, but I could still trigger the error:

> dbExecute(conn, "DECLARE GLOBAL TEMPORARY TABLE SESSION.my_temp (id INT, name VARCHAR(100)) ON COMMIT PRESERVE ROWS")
[1] -1
> dbExecute(conn, "INSERT INTO SESSION.MY_TEMP (id, name) VALUES (1, 'Alice'), (2, 'Bob')")
[1] 2
> dbGetQuery(conn, "select * from SESSION.MY_TEMP")
  ID  NAME
1  1 Alice
2  2   Bob
> dbExistsTable(conn, Id(schema = "SESSION", table = "MY_TEMP"))
[1] TRUE
> dbExistsTable(conn, Id(schema = "SESSION", table = "MY_TEM"))
Error in `$<-.data.frame`(`*tmp*`, table_remarks, value = NA_character_) : 
  replacement has 1 row, data has 0
> dbExistsTable(conn, "SESSION.MY_TEMP") 
Error in `$<-.data.frame`(`*tmp*`, table_remarks, value = NA_character_) : 
  replacement has 1 row, data has 0
> dbExistsTable(conn, SQL('"SESSION"."MY_TEMP"'))
[1] TRUE
> dbExistsTable(conn, "MY_TEMP")
[1] TRUE
> dbExistsTable(conn, "MY_TEM")
Error in `$<-.data.frame`(`*tmp*`, table_remarks, value = NA_character_) : 
  replacement has 1 row, data has 0

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

No branches or pull requests

2 participants