Postgresql中DDL的双引号问题

org.jooq.exception.DataAccessException: SQL [insert into "public"."tb_purchase" ("id", "billId", "detid", "productid", "num", "price", "create_time", "update_time", "status") values (?, ?, ?, ?, ?, ?, cast(? as timestamp), cast(? as timestamp), ?)]; ERROR: column "billId" of relation "tb_purchase" does not exist
  Position: 57
        at org.jooq.impl.Tools.translate(Tools.java:1941)
        at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:659)
        at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:362)
        at org.jooq.impl.AbstractDelegatingQuery.execute(AbstractDelegatingQuery.java:135)
        ... ...
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.postgresql.util.PSQLException: ERROR: column "billId" of relation "tb_purchase" does not exist
  Position: 57
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2310)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2023)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:217)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:421)
        at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:166)
        at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:159)
        at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)
        at org.jooq.tools.jdbc.DefaultPreparedStatement.execute(DefaultPreparedStatement.java:194)
        at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:430)
        at org.jooq.impl.AbstractDMLQuery.execute(AbstractDMLQuery.java:334)
        at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:348)
        ... 101 more


查看数据库,这个表确实有这个字段,导出ddl,发现表名、字段名都有双引号,去掉双引号重新创建表,还是报错,最后发现是由于双引号里面的字符区分大小写。

PostgreSQL is following the SQL standard and in that case that means that identifiers (table names, column names, etc) are forced to lowercase, except when they are quoted. So when you create a table like this:

CREATE TABLE APP_USER ... 

you actually get a table app_user. You apparently did:

CREATE TABLE "APP_USER" ... 

and then you get a table "APP_USER".

In Spring, you specify a regular string for the table name, in capital letters, but that gets spliced into a query to the PostgreSQL server without quotes. You can check this by reading the PostgreSQL log files: it should show the query that Spring generated followed by the error at the top of your message.

Since you have very little control over how Spring constructs queries from entities, you are better off using SQL-standard lower-case identifiers

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9399028/viewspace-2132619/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9399028/viewspace-2132619/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值