Open TheCedarPrince opened 1 year ago
When you connect to PostgreSQL using JDBC (or ODBC) rather than using the standard LibPQ driver, you need to customize the dialect object. This is because JDBC expects query parameters to be represented as ?
while the standard PostgreSQL expects parameters to be in the form $1
, $2
, and so on. Internally, JDBC driver rewrites the query into the standard PostgreSQL form before submitting it to the server.
To create a custom dialect in FunSQL, run:
const postgresql_jdbc_dialect = FunSQL.SQLDialect(:postgresql, variable_prefix = '?', variable_style = :positional)
Then use this object in place of :postgresql
with all FunSQL functions that take a dialect
parameter.
By the way, you will likely have the same problem with JDBC driver for SQLite as soon as you run any query with a parameter. The reason why your SQLite code haven't triggered an error is because SQLite does not support schemas, and therefore the reflect query does not have any parameters.
Hi @xitology and co!
I am in the process of making an all-in-one package to support connecting to a variety of databases. It is unregistered, but the draft is here: https://github.com/JuliaDatabases/DBConnector.jl
In short, I am running into a problem with the
reflect
statement for PostgreSQL when using a JDBC driver and JDBC.jl. I have a working example of the package here for SQLite:As you can see, the above works perfectly for SQLite. However, when doing something similar for PostgreSQL, it fails. Sadly, I don't have a PostgreSQL DB set-up for reproducibility that you could use, but here is the script:
And I get the following error:
Doing some more digging in the
reflect
source code, I discovered that for some reason here: https://github.com/MechanicalRabbit/FunSQL.jl/blob/2741b750118b2f21b5e2d2fae271f9bae9c148b9/src/reflect.jl#L17-L28My assigned
schema
is not being interpolated correctly into the SQL block despite my prepare statement in DBConnector accepting the interpolation syntax. I have isolated the error to my extension of the functionDBInterface.prepare
in DBConnector as I can confirm that using my dispatch forDBInterface.connect
andDBInterface.execute
does work with code querying a PostgreSQL DB likeDBInterface.execute(conn, "SELECT * FROM person LIMIT 1;") |> DataFrame
Here is the source code for my JDBC
DBInterface.prepare
dispatch (link here too: https://github.com/JuliaDatabases/DBConnector.jl/blob/main/src/jdbc.jl):Any thoughts as to what I may be doing wrong?
Thanks!