0

Begging newbie forgiveness here

I've gotten a bunch of POC's working but now that I am working on my production dataset the CSV file I am parsing has the ID field as a string but in Postgres it's an Integer.

The basic error I get is: Unhandled promise rejection (rejection id: 1): error: invalid input syntax for integer: "contact_id"

and the Insert statement looks as follows:

insert into "tbl_contact"("contact_id","last_name","first_name") values('contact_id','last_name','first_name'),('33383971','Dxxx','Jxxx'),('33383973','Dxxx','Sxxx') ...

I could transform the array before I send it to the helper ... but I've been looking at some of the override functions in ColumnSet ... like setting the column to int[] ... here is what happens there:

Unhandled promise rejection (rejection id: 1): error: malformed array literal: "contact_id"

insert into "tbl_contact"("contact_id","last_name","first_name") values('contact_id'::int[],'last_name','first_name'),('33383971'::int[],'Dxxx','Jxxx'),('33383973'::int[],'Dxxx','Sxxxx') ...

Before I go do my own transform ... am I missing something simple? Another helper? A param? etc.

Barry Smith
  • 105
  • 1
  • 2
  • 10
  • 1
    Why the first set of values is the column names? - `values('contact_id','last_name','first_name')` - that doesn't look right at all. Those should be values. – vitaly-t Jan 28 '18 at 18:02
  • Yeah, I just came back here to "answer" my question ... the column names is what was throwing off the whole thing ... it was the first row of my CSV ... dummmmmmb! Thanks for chiming in and thanks for your library! – Barry Smith Jan 29 '18 at 00:23

2 Answers2

0

Column syntax supports property cast, among others, which you can set:

{
    name: 'contact_id',
    cast: 'int[]'
}

Alternatively, if you want to convert a string into integer on-the-fly, you can use property init:

{
    name: 'column-name',
    init: c => parseInt(c.value)
}
vitaly-t
  • 24,279
  • 15
  • 116
  • 138
0

So the true answer was what vitaly said in his comment ... I had a row in my CSV that I was including in my INSERT ... but his Column answer also will be useful to those who need it!

Yay Vitaly!

Barry Smith
  • 105
  • 1
  • 2
  • 10