Обсуждение: Bug: enum types in schema other than public and Connection.createArrayOf

Поиск
Список
Период
Сортировка

Bug: enum types in schema other than public and Connection.createArrayOf

От
Hans Klett
Дата:
Hello,

I found an issue with Connection.createArrayOf() when using qualified
enum type names. It doesn't like the qualified type name, and when you
give it the unqualified type name it just picks an enum type even if it's not
in the public schema. If the enum type name exists in multiple schemas it just
picks one, seemingly at random.

For instance, in database foo:
CREATE SCHEMA bar;
CREATE SCHEMA baz;
CREATE TYPE bar.mood AS ENUM ('happy', 'sad');
CREATE TYPE baz.mood AS ENUM ('grumpy', 'sassy');

Java:
    final Properties props = new Properties();
    props.setProperty("user", "postgres");
    props.setProperty("password", "postgres");
    try (final Connection conn = DriverManager.getConnection("jdbc:postgresql:foo", props)) {
        final String[] strings = { "sad", "happy" };

        // Works, but picks either baz.mood or bar.mood.
        // I haven't figured out how it picks which one to use.
        conn.createArrayOf("mood", strings);

        // Throws org.postgresql.util.PSQLException:
        //        Unable to find server array type for provided name bar.mood
        conn.createArrayOf("bar.mood", strings);
    }

Thanks!
- Hans