Re: PHP pg_escape_string

From: Andy Shellam <andy-lists(at)networkmail(dot)eu>
To: Zdravko Balorda <zdravko(dot)balorda(at)siix(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: PHP pg_escape_string
Date: 2009-06-15 16:10:41
Message-ID: 4A367281.2020900@networkmail.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Carol Cheung 2009-06-16 20:59:59 left outer join on more than 2 tables?
Previous Message Zdravko Balorda 2009-06-15 08:14:46 PHP pg_escape_string