Search Postgresql Archives

PQescapeStringConn

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Hi all,

What's the best way to insert long strings that contain numerous special characters into a PG database?  

I'm assuming that importing an SQL script with prepared statements is the way to go.  If so, how to escape all the special characters?

I've found documentation on PQescapeStringConn but haven't found any examples of it in use. 

I have a number of very long strings that each contain many instances of semi-colons, single quotes, forward and back slashes, etc.  I'm looking for an efficient and safe way to write them to my db using a prepared statement.

An example follows.

Thanks in advance!
Scott


CREATE TABLE foo (
foo_id SERIAL PRIMARY KEY,
name VARCHAR(32) UNIQUE NOT NULL,
description TEXT,
body TEXT DEFAULT NULL,
created timestamp DEFAULT CURRENT_TIMESTAMP,
UNIQUE (name));


PREPARE fooprep (VARCHAR(32), text, text) AS
    INSERT INTO foo (name, description, body) VALUES ($1, $2, $3);
EXECUTE fooprep('foo1', 'this is foo1', 

'#!()[]{};
qwe'poi'asdlkj"zxcmnb";
/\1\2\3\4\5\6\7\8\9/'

);




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux