溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Postgresql中DDL的雙引號問題

發(fā)布時間:2020-08-05 00:10:49 來源:ITPUB博客 閱讀:325 作者:xz43 欄目:編程語言
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,發(fā)現(xiàn)表名、字段名都有雙引號,去掉雙引號重新創(chuàng)建表,還是報錯,最后發(fā)現(xiàn)是由于雙引號里面的字符區(qū)分大小寫。

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

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI