pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedstoring special characters
2+ messages / 2 participants
[nested] [flat]
* storing special characters
@ 2001-06-17 13:24 BORGULYA Gergely <bg057@hszk.bme.hu>
0 siblings, 1 reply; 2+ messages in thread
From: BORGULYA Gergely @ 2001-06-17 13:24 UTC (permalink / raw)
To: pgsql-sql
Helo,
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. The string converted from the
variable is full of characters that are treated specially by the
query-language, so I always get error messages if I try them to store with
the INSERT INTO command.
To save them to files, COPY them one-by-one to a temporary table then move
them to the appropriate table and row, delete the file, drop the table seems
to be a very long procedure.
Is there a simple and smart way to store such strings in databases? I could
not find solution for such a problem in the documentation.
Gergely BORGULYA
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: storing special characters
@ 2001-06-19 02:13 Hugh Mandeville <hughmandeville@hotmail.com>
parent: BORGULYA Gergely <bg057@hszk.bme.hu>
0 siblings, 0 replies; 2+ messages in thread
From: Hugh Mandeville @ 2001-06-19 02:13 UTC (permalink / raw)
To: 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\\!@#$%^&*()_\n\012');
see http://www.postgresql.org/idocs/index.php?sql-syntax.html
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-06-19 02:13 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-17 13:24 storing special characters BORGULYA Gergely <bg057@hszk.bme.hu>
2001-06-19 02:13 ` Hugh Mandeville <hughmandeville@hotmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox