https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
m

Mohammed Toufeeq Ahamed

09/26/2023, 6:04 PM
Hey folks, I was setting up
sqldelight
with postgres for ktor server, it turns out that sqldelight doesn't support `Postgres Extension`s, I want to have a non-null column with UUID as default, which is possible with
uuid-ossp
in postgres. Is ther any way that I will be able to set this up with sqldelight?
l

leonhardt

09/26/2023, 9:22 PM
If you're only using UUID v4 and don't care about the underlying differences, I've found that using
GEN_RANDOM_UUID()
instead of
UUID_GENERATE_V4()
just works. Beyond that I'm subscribed to this GitHub issue for updates on postgres extensions in case it's ever supported. You might also want to chime in on this discussion where @griffio has asked for input to prioritize presently unsupported postgres features.
m

Mohammed Toufeeq Ahamed

09/27/2023, 6:02 AM
You mean GEN_RANDOM_UUID in this query just works fine for you, I get the compiler error doing so.
Copy code
CREATE TABLE IF NOT EXISTS user(
    id         UUID PRIMARY KEY NOT NULL GEN_RANDOM_UUID(),
    name      TEXT NOT NULL UNIQUE,
    created_at TIMESTAMP     NOT NULL   DEFAULT CURRENT_TIMESTAMP,
);
Thanks for pointing to the issue, hope extensions are supported soon.
g

griffio

09/27/2023, 8:59 AM
plus green Just to add @Mohammed Toufeeq Ahamed - You should be able to get it compiling with:
Copy code
CREATE TABLE IF NOT EXISTS "user"(
    id        UUID PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
    name      TEXT NOT NULL UNIQUE,
    created_at TIMESTAMP     NOT NULL  DEFAULT CURRENT_TIMESTAMP
);
The
user
is a reserved word in Postgres, remove comma at the end of CURRENT_TIMESTAMP and
gen_random_uuid()
in parentheses for now - there is an issue with function calls in CREATE TABLE.
gen_random_uuid
is built in from
PostgreSQL 13
However, I have a PR for CREATE EXTENSION, but the problem is that extensions define new functions. We can’t know about or define every possible extension function available to PostgreSQL. Once CREATE EXTENSION is available it would have to be down to the user to create an extended custom dialect to add in the functions for the extensions e.g https://github.com/cashapp/sqldelight/tree/master/sqldelight-gradle-plugin/src/test/custom-dialect
m

Mohammed Toufeeq Ahamed

09/27/2023, 9:22 AM
Thanks, this helps!! I will keep an eye on EXTENSION support.👍
l

leonhardt

09/28/2023, 3:10 AM
Once CREATE EXTENSION is available it would have to be down to the user to create an extended custom dialect to add in the functions for the extensions
@griffio that sounds like a great solution