Java type in JDBC to Postgres ltree

后端 未结 2 545
抹茶落季
抹茶落季 2021-01-03 09:43

Does anyone know what Java type maps to a Postgres ltree type?

I create a table like so:

CREATE TABLE foo (text name, path ltree);

相关标签:
2条回答
  • 2021-01-03 10:00

    This is yet another variant of the strict casting issues in PostgreSQL interacting with client drivers and ORMs that send everything they don't understand as String.

    You need to use setObject with Types.OTHER, IIRC.

        ps.setObject(2, foos.get(i).getName(), Types.OTHER);
    

    which PgJDBC should send as a bind param of type unknown. Because you're working with PgJDBC directly this is easy for you to deal with, luckily; it's a real pain when people are using ORM layers.

    See:

    • Macaddr/Inet type of postgres in slick
    • Mapping postgreSQL JSON column to Hibernate value type
    • http://www.postgresql.org/message-id/CACTajFZ8+hg_kom6QiVBa94Kx9L3XUqZ99RdUsHBFkSb1MoCPQ@mail.gmail.com

    for background.

    0 讨论(0)
  • 2021-01-03 10:04

    Why not create stored procedure and call it from CallableStatement with String param to insert row with ltree via it, if preparedStatemnt.setString() isn't working?

    Other solution may be ps.setObject(2, foos.get(i).getPath(), Types.OTHER);, but I can't check it now.

    0 讨论(0)
提交回复
热议问题