Error inserting data in postgree: column "test" does not exist

0

In% basic%, I'm getting the following node error:

"Erro na inserção dos dados { error: column "teste" does not exist
    at Connection.parseE (C:\Users\SUPORTE\Desktop\NodeFINAL\appFinal\app1\nod
modules\pg\lib\connection.js:546:11)
    at Connection.parseMessage (C:\Users\SUPORTE\Desktop\NodeFINAL\appFinal\ap
\node_modules\pg\lib\connection.js:371:19)
    at Socket.<anonymous> (C:\Users\SUPORTE\Desktop\NodeFINAL\appFinal\app1\no
_modules\pg\lib\connection.js:114:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:547:20)
  name: 'error',
  length: 117,
  severity: 'ERROR',
  code: '42703',
  detail: undefined,
  hint: undefined,
  position: '48',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'src\backend\parser\parse_relation.c',
  line: '2985',
  routine: 'errorMissingColumn' }"

My route:

app.post('/insere', function (req, res){
// conecta no banco a partir do canal
canal.connect(function(erro, conexao, feito){
    if (erro){ // ocorreu um erro
        return console.error('erro ao conectar no banco', erro);
    }
    var sql = 'insert into fornecedores values (' + req.body.codigo + 
              ',\'' + req.body.nome + 
              '\', '+ req.body.idade + 
              ',' + req.body.produto + ')';
    conexao.query(sql, function(erro, resultado){
        feito(); // libera a conexão
        if (erro){
            return console.error('Erro na inserção dos dados', erro);
        }
        res.json(resultado.rows); // retorna ao cliente o resultado da inserção
    });
});

});

My non-html template:

<div class="form-group">
                <label class="control-label col-sm-2"> Produto </label>
                <div class="col-sm-6"> 
                    <input type="text" class="form-control" ng-model="fornecedor.produto"/>
                </div>
            </div>

It happens that I fill in crud "Product" label : "test" or any other value, and the node returns that message that valor does not exist.

In my database ( column ) the postgree table was created and the fields: fornecedores , codigo , nome and idade .

    
asked by anonymous 27.09.2017 / 16:13

1 answer

0

Based on your comment, just put the product name in quotation marks:

var sql = 'insert into fornecedores values (' + req.body.codigo + 
                                            ',\'' + req.body.nome + 
                                            '\', '+ req.body.idade + 
                                            ',\'' + req.body.produto + '\')';
    
27.09.2017 / 21:00