簡體   English   中英

NodeJs PG 查詢未按預期執行

[英]NodeJs PG query not executed as expected

我有以下,AWS lambda 代碼插入到表中:

let queryString = "INSERT INTO orders(order_id, channel, channel_order_id, channel_order_code, channel_merchant, merchant, min_time, max_time, delivery_expected_time, status, observations, total, sub_total, voucher_discount, delivery_tax, fk_customer_id, fk_address_id, order_contact, order_type, payment_pending, payment_prepaid, channel_merchant_id, order_timming, picker, delivered_by, delivery_obs, takeout, takeout_date_time, takeout_obs, indoor, table)VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31) RETURNING *";

const newOrder = await client.query(queryString, [order_id, channel, channel_order_id, channel_order_code, channel_merchant, merchant, min_time, max_time, delivery_expected_time, status, observations, total, sub_total, voucher_discount, delivery_tax, fk_customer_id, fk_address_id, order_contact, order_type, payment_pending, payment_prepaid, channel_merchant_id, order_timming, picker, delivered_by, delivery_obs, takeout, takeout_date_time, takeout_obs, indoor, table], (err, res) => {
        if(err)console.log(res, err)
    });

然后在具有引用order(order_id)的外鍵的表中進行另一個插入,該外鍵應該是在第一次插入時創建的

我在第二次插入時遇到錯誤,表示order(order_id)不存在。 所以這意味着訂單沒有被創建,第一個插入沒有被執行,但是在console.log(err)中沒有被捕獲

現在有趣的部分。 如果我從第一個插入中刪除table列,一切都會按預期進行

如果我console.log(table)我得到null並且該列是NotNull = False ,這意味着它可以是 null,就像我在插入時使用的其他值一樣

關於這里可能發生什么的任何提示? 插入時可以有多少列有限制嗎?

tablePostgres 中的關鍵字。

如果您堅持要繼續使用名稱table維護架構中的列(不建議),則在引用它時需要將其用引號括起來:

INSERT INTO orders ("table") /* ... */

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM