Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过postgres sql插入数据库_Javascript_Node.js_Postgresql - Fatal编程技术网

Javascript 如何通过postgres sql插入数据库

Javascript 如何通过postgres sql插入数据库,javascript,node.js,postgresql,Javascript,Node.js,Postgresql,我有下面的代码将这些值插入数据库 db.one('INSERT INTO transactions (transaction_id) VALUES (a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11)') .then(user => { console.log(user.name); // print user name; }) .catch(error => { console.log(error, '

我有下面的代码将这些值插入数据库

db.one('INSERT INTO transactions (transaction_id) VALUES (a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11)')
    .then(user => {
        console.log(user.name); // print user name;
    })
    .catch(error => {
        console.log(error, 'jjjjjjjjjjjj'); // print the error;
    });
我想插入三个字段

1) transaction_id 
2) amount 
3) currencies_currency_id
但是得到了错误

错误:“c0b”处或附近出现语法错误


请帮助我在这里做错了什么

我认为SQL值需要单引号

试一试


我认为SQL值需要单引号

试一试



如果您想插入3个字段,那么您应该指定这3列,并且字符串应该是单引号<代码>插入交易(交易id、金额、货币id)值('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',?,?)谢谢,但给我错误
错误:语法错误在或接近“金额”
什么是
db.one
?它不是PostgreSQL的一部分。那是哪种语言?也给它贴上标签。当您正确替换其他值
(?,?)
时,我的查询应该在PostgreSQL中工作。我不知道它在您的编程语言中是如何工作的。@KaushikNayak它是nodej如果您想插入3个字段,那么您应该指定这3个列,并且字符串应该是单引号<代码>插入交易(交易id、金额、货币id)值('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',?,?)谢谢,但给我错误
错误:语法错误在或接近“金额”
什么是
db.one
?它不是PostgreSQL的一部分。那是哪种语言?也给它贴上标签。当您正确替换其他值
(?,?)
时,我的查询应该在PostgreSQL中工作。我不知道它在您的编程语言中是如何工作的。@KaushikNayak它是nodejst谢谢您如何插入第二个字段?您好,我需要调用一个字段进行查询,以获取特定用户的详细信息\u id
“从用户详细信息\u iwant\u用户id=1的钱包中选择*”
,但这在nodejs中生成sql语句时不起作用,我想您会发现使用ES6模板文本更容易。另外,请尝试将您的值类型转换为它们要用于的列的类型。@FirozShams
ES6模板文字。
这是什么?使用模板文字,您的查询可以重写为
INSERT-INTO-transactions(transaction\u-id,amount,currency\u-currency\u-id)值(“${”a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11“,${29},”${“某些货币id”}')
谢谢,我如何插入第二个字段?您好,我需要调用一个字段进行查询,以获取特定用户的详细信息\u id
“从钱包中选择*,其中用户\u详细信息\u iwant\u用户\u id=1“
但在nodejs中构建sql语句时,这不起作用,我想您会发现使用ES6模板文本更容易。另外,请尝试将您的值类型转换为它们要用于的列的类型。@FirozShams
ES6模板文字。
这是什么?使用模板文字,您的查询可以重写为
INSERT-INTO-transactions(transaction\u-id,amount,currency\u-currency\u-id)值(“${”a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11“,${29},”${“某些货币id”}')
db.one('INSERT INTO transactions (transaction_id, amount, currencies_currency_id) VALUES (\'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11\', \'enter amount\', \'enter currencies_currency_id\')')
.then(user => {
    console.log(user.name); // print user name;
})
.catch(error => {
    console.log(error, 'jjjjjjjjjjjj'); // print the error;
});