pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andy Shellam <andy-lists@networkmail.eu>
To: Zdravko Balorda <zdravko.balorda@siix.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: PHP pg_escape_string
Date: Mon, 15 Jun 2009 17:10:41 +0100
Message-ID: <4A367281.2020900@networkmail.eu> (raw)
In-Reply-To: <4A3602F6.5050907@siix.com>
References: <4A3602F6.5050907@siix.com>

Hi,

Zdravko Balorda wrote:
> there are both pg_(un)escape_bytea() functions
> but only one pg_escape_string()... I wonder if I may be
> missing something here?

Yeah, I think you are.  pg_escape_string (funnily enough) escapes string 
data which is then stored in the database.  You would use this for 
escaping things like apostrophes in a text field so PostgreSQL wouldn't 
think the apostrophe in the field is the "end of data" marker.  However 
this string is *not* stored in the database in an escaped form, as it's 
only escaped for the SQL command, therefore it makes no sense to 
unescape it.

bytea columns on the other hand, are a way of sending and receiving 
binary data as a textual representation to/from the database server.  
The data you send and receive is both encoded, therefore you need to 
unescape it to read it back out.  For example a null byte (byte value 0) 
cannot be sent or received in a SQL command, because a null byte 
represents an end-of-string in C.  Other byte values similarly cannot be 
sent in a string because they cannot be converted to a character (e.g. 
ASCII newline/linefeed.)

Regards,
Andy



view thread (2+ messages)

Message-ID: <4A367281.2020900@networkmail.eu>
Permalink:  ../4A367281.2020900@networkmail.eu/
Also on:    postgresql.org/message-id/4A367281.2020900@networkmail.eu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: andy-lists@networkmail.eu, zdravko.balorda@siix.com
  Subject: Re: PHP pg_escape_string
  In-Reply-To: <4A367281.2020900@networkmail.eu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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