Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f5KGgPa92235 for ; Wed, 20 Jun 2001 12:42:25 -0400 (EDT) (envelope-from pgsql-sql-owner@postgresql.org) Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5J2VUa91108 for ; Mon, 18 Jun 2001 22:31:30 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id f5J2Cga74485 for pgsql-sql@postgresql.org; Mon, 18 Jun 2001 22:12:42 -0400 (EDT) (envelope-from news) From: "Hugh Mandeville" X-Newsgroups: comp.databases.postgresql.sql Subject: Re: storing special characters Date: Mon, 18 Jun 2001 22:13:06 -0400 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 23 Message-ID: <9gmcep$28ni$1@news.tht.net> References: <01061715240605.00537@pc2151> Reply-To: "Hugh Mandeville" X-Complaints-To: scrappy@hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 To: pgsql-sql@postgresql.org X-Archive-Number: 200106/318 X-Sequence-Number: 3592 > 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\\!@#$%^&*()_\n\012'); see http://www.postgresql.org/idocs/index.php?sql-syntax.html