Octo.jl icon indicating copy to clipboard operation
Octo.jl copied to clipboard

Allow inserting nothing as null value

Open bryaan opened this issue 2 years ago • 1 comments

Instead of having to write conversion code for nothing => missing then wrap a bunch of calls in it can this lib just support inserting values of nothing as null?

bryaan avatar Jun 11 '23 04:06 bryaan

about missing, NULL from docs https://docs.julialang.org/en/v1/manual/missing/ "missing is equivalent to NULL in SQL and NA in R, and behaves like them in most situations."

there was a question, How to pass a null value to a prepared statement with LibPQ.jl https://discourse.julialang.org/t/how-to-pass-a-null-value-to-a-prepared-statement-with-libpq-jl/25068

testing NULL in test/adapters/postgresql/null.jl https://github.com/wookay/Octo.jl/blob/master/test/adapters/postgresql/null.jl

but you could try this code that nothing for NULL

julia> using Octo.Adapters.PostgreSQL

julia> using Octo.AdapterBase: ElementStyle, SqlPartElement

julia> Octo.AdapterBase.sqlrepr(::Octo.DBMS.PostgreSQL, ::Nothing) = SqlPartElement(ElementStyle(:cyan), "NULL")

julia> to_sql([nothing])
"NULL"

wookay avatar Jun 11 '23 06:06 wookay