You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If this is not appropriate place to ask, please go ahead and close this ticket. I apologize in the advance if that's the case.
Does anyone know if Kotlin can be used with this library to execute Kotlin code on Postgres server? I mean, Kotlin runs on JVM and I'm assuming this library uses JVM inside of Postgres server, right?
The text was updated successfully, but these errors were encountered:
There should be no particular difficulty. The Kotlin compiler can produce class files, and you can put those into a jar file and load that into PL/Java. Functions that you intend to call from PostgreSQL must be compiled into Java static methods, which is possible as described in Calling Kotlin from Java.
PostgreSQL then needs SQL CREATE FUNCTION commands that declare functions to be available in SQL and map them to named static methods in your jar with compatible signatures. You can include such commands in a deployment descriptor file in the jar, so that PL/Java can declare the SQL functions at the same time it loads your jar.
Writing the SQL commands for the deployment descriptor can be a bit like repeating yourself, as they are really just SQL-language declarations of the same methods and argument types that you have already declared in Java (or Kotlin). And if you write them by hand, it is possible not to keep them up to date with code changes, and the problems might not be detected until the jar is loaded into PostgreSQL and you try to call the functions.
To avoid repeating yourself, when you are writing in Java, you can use certain Java annotations to cause a correct deployment descriptor to be written at the same time the Java sources are compiled. If there would be declaration inconsistencies, those can be reported at compile time, instead of only discovered after loading the code into PostgreSQL.
I am not very knowledgeable about annotation support in Kotlin, or whether it would be easy or hard to make use of the existing Java annotations to generate deployment code at compile time, or easy or hard to develop similar annotations for Kotlin specifically. That might be an interesting area that you could explore. In any case, you can always write the SQL declarations by hand, which is exactly how PL/Java was always used before the Java annotation support was added.
Hello,
If this is not appropriate place to ask, please go ahead and close this ticket. I apologize in the advance if that's the case.
Does anyone know if Kotlin can be used with this library to execute Kotlin code on Postgres server? I mean, Kotlin runs on JVM and I'm assuming this library uses JVM inside of Postgres server, right?
The text was updated successfully, but these errors were encountered: