Setting schema in PostgreSQL JDBC doesn't seem to work

后端 未结 1 1759
一向
一向 2020-12-11 22:38

I created schema \"customer1\" with table \"user\" and I\'m trying to connect it from JDBC using Connection.setSchema():

String url = \"jdbc:postgresql://loc         


        
相关标签:
1条回答
  • 2020-12-11 23:23

    user is a built-in function (and a keyword). So you can't really use it as a table name:

    psql (10.4)
    Type "help" for help.
    
    postgres=# select user;
       user
    ----------
     postgres
    (1 row)
    
    postgres=# select * from user;
       user
    ----------
     postgres
    (1 row)
    

    And because it's a function it does not have a column name.

    postgres=# select name from user;
    ERROR:  column "name" does not exist
    LINE 1: select name from user;
                   ^
    postgres=#
    

    If you qualify the table, then it's clear that you are not referencing the function, but the table.

    You can either always qualify the table name with the schema, or use double quotes: select name from "user"; or simply find a table name that does not collide with built-in functions.

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