From: | "Hugh Mandeville" <hughmandeville(at)hotmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: storing special characters |
Date: | 2001-06-19 02:13:06 |
Message-ID: | 9gmcep$28ni$1@news.tht.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
> I'm using postgresql 7.1, with suse linux 7.1 on i386.
> I'm programming in python and I'm going to store many, long (approx. 600
> bytes) python-variables in a postgres database. There is a way to convert
> python-variables into string (either binary or text) format to make them
> possible to be stored in files or databases.
if the python-variable strings contain just printable characters (ASCII 32 -
126) you should only need to escape out the single quote (') and blackslash
(\) characters for postgresql.
replace ' with '' and \ with \\. i don't know about Python but Perl DBI has
a function called quote() used to correctly quote and escape SQL statements.
my $quotedString = $dbh->quote( $string );
if the python-variable strings contain other special characters you can
escape those characters to slash followed by their 3 digit ASCII octal value
(decimal 10 = \n = \012).
INSERT INTO foo (varname) VALUES ('var''s name\\!(at)#$%^&*()_\n\012');
see http://www.postgresql.org/idocs/index.php?sql-syntax.html
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2001-06-19 02:33:52 | A cute little function |
Previous Message | Stephan Szabo | 2001-06-18 22:59:25 | Re: Referential Integrity Question (Delete/Insert during Transaction) |