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

Asked

Viewed 698 times

0

In a crud 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 template in html:

<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>

I happen to fill in label "Product" the valor: "test" or any other value, and Node returns that message to column there is no.

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

  • Maybe it’s missing quotes in the req.body.produto ?

  • from a.log(sql) console and post the result.

  • @Cassioalves returned: Insert into vendors values (1,'test', 22,)

1 answer

0

Based on your review, 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 + '\')';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.