Inline BLOB / BINARY data types in SQL / JDBC

后端 未结 3 668
遇见更好的自我
遇见更好的自我 2020-12-15 10:52

Let\'s say I want to avoid using bind variables in JDBC and run SQL using \"ad-hoc\" statements, e.g:

connection.createStatement().executeQuery(\"SELECT ...\         


        
3条回答
  •  半阙折子戏
    2020-12-15 11:28

    I'd like to add some PostgreSQL specific stuff to Lukas' answer:

    The shortest and most easiest solution would be (since PostgreSQL 9.0 at least):

    insert into lob_table (data) values( E'\\x0102030405FF' )
    

    without any cast (if the column is already a bytea one) and only one \\x mark right at the beginning. This is the "hex format" documented in the section Binary Data Types.

    Regarding the X'01FF' syntax: According to the string constant documentation PostgreSQL does support it - for bit strings. And it seems, that there is no standard conversion from bit to bytea.

提交回复
热议问题