[OPEN-ILS-DEV] MARC Record Import from txt

Dan Scott dan at coffeecode.net
Wed Dec 14 12:40:02 EST 2011


On Wed, Dec 14, 2011 at 05:29:15PM +0000, Elliot Voris wrote:
> Update:
> 
> I noticed that when I was saving the sql file in Notepad++, it was encoded using ANSI. I switched that to UTF-8, and I received the same result. Is PostgreSQL interpreting the single-quote (') as an escape character? Or is the issue something else?

Hi Elliot:

Yes, single quotes in SQL can escape other single quotes. For example,
if you need a singl quote in the middle of a string that you're
inserting into the database, you would place another single quote in
front of it like so:

'So that''s what the fuss is about'

I'm guessing that in your case, PostgreSQL saw something like:

'<record><datafield tag="440" ind1="0" ind2=" "><subfield code="a">So that's the
problem</subfield></datafield></record>'

and got confused by the unescaped single quote in the text of the
subfield.

To avoid problems with embedded single quotes in MARC records in that
example SQL file, I ran a regular expression to escape all of the
existing single quotes before wrapping them with the start / end single
quotes. In vim, the command was :%s/'/''/g but your editor of choice
will vary.

Dan


More information about the Open-ils-dev mailing list