Subject: Re: Finding error in long input file

From: Rich Shepard <[email-masked]>
Date: Wed, 10 Jul 2024 05:52:58 -0700 (PDT)

On Tue, 9 Jul 2024, Craig McIlwee wrote:

> The input file is 488 lines (presumably, since Rich said the file should
> insert 488 rows). It seems like too much of a coincidence that the last
> character of the last line is really the error. My guess is that there is
> an unmatched character, perhaps a parenthesis, that is throwing off the
> parser because it doesn't expect the statement to terminate yet. Maybe
> that unmatched char really is on the last line, but '85250 Red House Rd'
> doesn't seem like the issue. I don't know anything about the joe editor,
> but I'd hope that any decent editor with syntax highlighting would make it
> apparent where things went awry.

Craig, et al.,

I use emacs for scripts and coding, joe's only for small jobs.

I added a line to the file so the bottom line is now 489. The attached image
shows that line is the only one terminated with a semicolon rather than a
comma.

psql would tell me if there was no closing parenthesis on a line, if the
terminating comma was missing, or other similar error, and would tell me the
number of the line or following line. Having the error marked at the end of
the file does not tell _me_ just where the error actually is.

Partial screenshot attached.

Thanks all,

Rich

---

From: "David G. Johnston" <[email-masked]>
Date: Wed, 10 Jul 2024 05:59:29 -0700

> Partial screenshot attached.

And what are the first few lines of the file? Use text, not screenshots.

David J.

---

From: Hans Schou <[email-masked]>
Date: Wed, 10 Jul 2024 15:01:13 +0200

If the file has these line breaks you show, then can make it to multiple
'INSERT INTO' instead.

Search for lines starting with parentese begin '(' and replace it with the
correct INSERT and last comma to semi-colon:
  cat i.sql | sed -e 's/^(/INSERT INTO foo VALUES(/' -e 's/,$/;/'

Does the file come from mysqldump? Then try option --extended-insert=FALSE

-- 
𝕳𝖆𝖓𝖘 𝕾𝖈𝖍𝖔𝖚
☏ ➁➁ ➅➃ ➇⓪ ➁⓪

---

From: Hans Schou <[email-masked]>
Date: Wed, 10 Jul 2024 15:03:39 +0200

> And what are the first few lines of the file? Use text, not screenshots.

Yes the line with 'INSERT'

grep -ni 'INSERT INTO' scripts/insert-addrs.sql

-- 
𝕳𝖆𝖓𝖘 𝕾𝖈𝖍𝖔𝖚
☏ ➁➁ ➅➃ ➇⓪ ➁⓪

---

From: Rich Shepard <[email-masked]>
Date: Wed, 10 Jul 2024 06:32:16 -0700 (PDT)

> And what are the first few lines of the file? Use text, not screenshots.

David,

insert into locations (company_nbr,loc_nbr,loc_name,addr1,city,state_code,postcode) values
(2564,1,default,'4250 Hopkins Rd','Ontario','OR','97914'),
(2565,1,default,'10695 Meridian Rd','Mount Angel','OR','97362'),
(2566,1,default,'6963 Keene Rd NE','Gervais ','OR','97026'),
(2567,1,default,'31250 S Bond Rd','Hubbard','OR','97032'),

Rich

---

From: Rich Shepard <[email-masked]>
Date: Wed, 10 Jul 2024 06:33:47 -0700 (PDT)

> If the file has these line breaks you show, then can make it to multiple

Hans,

I thought of that, but forgot it. This makes more sense than dividing the
file in small chunks.

Thanks,

Rich

---

From: "David G. Johnston" <[email-masked]>
Date: Wed, 10 Jul 2024 08:11:46 -0700

> (2567,1,default,'31250 S Bond Rd','Hubbard','OR','97032'),

My first easy look for this setup is for any single quotes not adjacent to
either a comma or a parenthesis.  Syntax highlighting should ideally have
caught this but I’d look anyway.

David J.

---

From: Rich Shepard <[email-masked]>
Date: Wed, 10 Jul 2024 08:26:07 -0700 (PDT)

David,

I found an error on line 21 that I missed seeing every time I slowly scanned
the file: missing the terminal `);'. A common situation when I look at the
file so many times.

Rich

---

From: Rich Shepard <[email-masked]>
Date: Wed, 10 Jul 2024 10:06:52 -0700 (PDT)

On Wed, 10 Jul 2024, Rob Sargent wrote:

> I'm an emacs user too. Do you have show-paren enabled? This would show
> that your file was ill-formed. M-p and M-n go previous/next matching
> parentheses of all types.

Rob,

No, I haven't enabled show-paren.

Thanks for the tip,

Rich