How to insert a string with single quotes in the text

From: "Louise Cofield" <lcofield(at)box-works(dot)com>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: How to insert a string with single quotes in the text
Date: 2003-09-19 21:02:07
Message-ID: 030701c37ef1$493739c0$7801a8c0@Louise
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Greetings:

I am creating a Libpq program that reads a text file, and inserts values
into a Postgres table. An example of my insert statement looks like
this:

SPRINTF(str, "INSERT INTO itm_table (itm_num, itm_desc) values ('%s',
'%s');", sitmnum, sitmdesc);

The insert blows up when it hits an item description that contains a
single quote in the text.

Other than stripping the offending quote-marks from the text prior to
processing, does anybody have any ideas how I can deal with this?

I appreciate all help!

Louise

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tom Lane 2003-09-19 21:10:57 Re: observations about temporary tables and schemas
Previous Message Hiroshi Inoue 2003-09-18 23:46:13 Re: [HACKERS] Killing the backend to cancel a long waiting query