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

Make it possible to insert raw SQL types to cast if I really know what I'm doing and SQLDelight does not #5332

Open
digitalheir opened this issue Jul 6, 2024 · 1 comment
Labels

Comments

@digitalheir
Copy link

digitalheir commented Jul 6, 2024

Description

Consider #5331. I am so close to making my database work with SQLDelight, except for the one XML column for which I know for sure it is correct.

I'm fine if SQLDelight treats the XML as a String. I do too and Postgres does too for most purposes except data validation.

But I NEED to cast it! Postgresql will throw if I try to insert a Text value into an XML column.

It would be nice to have a little escape hatch when SQLDelight development lags behind database capabilities. I propose something like:

CREATE TABLE IF NOT EXISTS my_table(xml TEXT) -- fake TEXT type, the actual database has XML type
insert:
INSERT INTO my_table(xml) VALUES(CAST('<root></root>' AS `XML`));

When the type is put in backticks, SQLDelight may forgo type checking and just dump the SQL as is.

@digitalheir digitalheir changed the title Make it possible to insert raw SQL if I really know what I'm doing and SQLDelight does not Make it possible to insert raw SQL types to case if I really know what I'm doing and SQLDelight does not Jul 6, 2024
@digitalheir digitalheir changed the title Make it possible to insert raw SQL types to case if I really know what I'm doing and SQLDelight does not Make it possible to insert raw SQL types to cast if I really know what I'm doing and SQLDelight does not Jul 6, 2024
@griffio
Copy link
Contributor

griffio commented Jul 8, 2024

Currently the escape hatch to run ad-hoc queries is to use driver.execute directly - same api the compiler uses in the generated Queries

e.g

 driver.execute(-1, "INSERT INTO my_table(xml) VALUES(?)", 1) {
        check(this is JdbcPreparedStatement)
        bindObject(0, "<root></root>", SQLXML) // assumes the actual table is XML column type
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants