【问题标题】:postgres ERROR: column "id" does not exist?postgres 错误:列“id”不存在?
【发布时间】:2014-09-02 23:49:21
【问题描述】:

我使用下面的 StaticSentence 在 postgres 中创建了一个表。读取的表是从另一个表产品创建的,并且其中的数据被删除,因为我只想要架构(我对这件事真的很陌生,但我确信有更好的方法来处理这个问题)。

public void syncProductsBefore() throws BasicException {
    new StaticSentence(s,"CREATE TABLE PRODUCTS_imports(ID) WITH OIDS  AS SELECT * FROM PRODUCTS ").exec();
    new StaticSentence(s, "DELETE FROM PRODUCTS_imports").exec();
}

然后我尝试在下面的方法中使用 PreparedSentence 写入该表。首先运行更新命令,以了解是插入新数据还是更新现有数据。

public void syncProduct(final ProductInfoExt prod) throws BasicException {

    Transaction t = new Transaction(s) {
        public Object transact() throws BasicException {
            /*Sync the Product in a transaction*/

            /* Try to update*/
            if (new PreparedSentence(
                    s,
                    "UPDATE PRODUCTS SET REFERENCE = ?, CODE = ?, NAME = ?, PRICEBUY = ?, PRICESELL = ?, CATEGORY = ?, TAXCAT = ?, IMAGE = ? WHERE ID = ?",
                    SerializerWriteParams.INSTANCE).exec(new DataParams() {
                public void writeValues() throws BasicException {
                    setString(1, prod.getReference());
                    setString(2, prod.getCode());
                    setString(3, prod.getName());
                    // setBoolean(x, p.isCom());
                    // setBoolean(x, p.isScale());
                    setDouble(4, prod.getPriceBuy());
                    setDouble(5, prod.getPriceSell());
                    setString(6, prod.getCategoryID());
                    setString(7, prod.getTaxCategoryID());
                    setBytes(8, ImageUtils.writeImage(prod.getImage()));
                    // setDouble(x, 0.0);
                    // setDouble(x, 0.0);
                    setString(9, prod.getID());
                }
            }) == 0) {


                /* leyonce */
                /**
                 * If not updated, try to insert insert into the import
                 * temporary table create temporary sorted copies of product
                 * catalog and products
                 */
                new PreparedSentence(
                        s,
                        "INSERT INTO PRODUCTS_imports(ID, REFERENCE, CODE, NAME, ISCOM, ISSCALE, PRICEBUY, PRICESELL, CATEGORY, TAXCAT, IMAGE, STOCKCOST, STOCKVOLUME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                        SerializerWriteParams.INSTANCE)
                        .exec(new DataParams() {                            
                            public void writeValues() throws BasicException{

                            /*leyonce --insert values into temporary import table*/ 
                                setString(1, prod.getID());
                                setString(2, prod.getReference());
                                setString(3, prod.getCode());
                                setString(4, prod.getName());
                                setBoolean(5, prod.isCom());
                                setBoolean(6, prod.isScale());
                                setDouble(7, prod.getPriceBuy());
                                setDouble(8, prod.getPriceSell());
                                setString(9, prod.getCategoryID());
                                setString(10, prod.getTaxCategoryID());
                                setBytes(11, ImageUtils.writeImage(prod
                                        .getImage()));
                                setDouble(12, 0.0);
                                setDouble(13, 0.0);

); }

现在更新运行完美,但是当编译器进入插入语句时,它会回滚并返回错误

org.postgresql.util.PSQLException: 
ERROR: column "id" does not exist
  Position: 84

我真的不明白为什么。

【问题讨论】:

  • StaticSentencePreparedSentence 是什么?这些自定义包装器是否围绕 JDBC 类,即PreparedStatement?谷歌搜索PreparedSentence 发现了一些从 JDBC 类派生的不同自定义类...
  • 向我们展示create tableproducts 的声明

标签: postgresql jdbc


【解决方案1】:
psql
\d PRODUCTS_imports
\d PRODUCTS

他们有 ID 列吗?

如果原始表(产品)缺少可以解释错误的 ID 列。

【讨论】:

  • 产品表存在。
  • PRODUCTS 表中是否存在列 ID?如果是这样,那么我无法解释错误消息。
  • 这里发布了一个类似的问题(至少问题的原因似乎相同):#10015531
猜你喜欢
  • 1970-01-01
  • 2019-01-16
  • 1970-01-01
  • 1970-01-01
  • 2012-03-19
  • 2021-10-22
  • 2018-09-01
  • 2020-11-12
  • 1970-01-01
相关资源
最近更新 更多