简体   繁体   中英

syntax error at or near $1 value pg-promise node.js

i have this code

this.createtablePy = function(){
 db.none("CREATE TABLE IF NOT EXISTS $1 ( $2 serial NOT NULL, data jsonb", ["pyTable", "id_py"])
 .then(()=> 
 {
     console.log("done pyme table ");
 })
 .catch(error =>{
     console.log("Error; " + error);
 });
};

and i get this error (is a SQL error?)

Error; error: syntax error at or near "'pyTable'"

but when i try on this way, it's ok

this.createtablePy = function(){
 db.none("CREATE TABLE IF NOT EXISTS pyTable ( id_py serial NOT NULL, data jsonb")
 .then(()=> 
 {
     console.log("done pytable ");
 })
 .catch(error =>{
     console.log("Error; " + error);
 });
};

result

done pytable

and pytable is created on database, what i'm doing wrong?

why the db.none statement is not accepting parameters?

Update

i dont know why but this works:

this.createtablePyme = function(){
 db.any("CREATE TABLE IF NOT EXISTS $[table:name] ( $[id:name] serial NOT NULL, data jsonb)", {table: 'pytable', id: 'idPyme'})
 .then(()=> 
 {
     console.log("Creada base de datos py");
 })
 .catch(error =>{
     console.log("Error; " + error);
 });
};

and using $1:name and pasing values with [] works too.

根据文档 ,Postgres表名称必须以字母或下划线开头。

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