简体   繁体   中英

NodeJs PG query not executed as expected

I have the following, AWS lambda code inserting into a table:

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)
    });

And then another insert in a table that has a foreign key that references an order(order_id) , which should be the one being created at the first insert

I'm getting an error, on the second insert, that says that the order(order_id) does not exist. So it means that the order is not being created, the first insert is not being executed, but nothing is being caught in the console.log(err)

Now the interesting part. If I remove the table column from the first insert everything goes as expected

If I console.log(table) I get null And the column is NotNull = False , which means that it can be null, just like as other values I'm using on the insert

Any hint on what could be happening here? Is there a limit of how many columns I can have on an insert?

table is a keyword in Postgres.

If you're insisting on continuing to maintain a column in your schema with the name table (not advisable), you'll need to pass it in quotes when referencing it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM