Обсуждение: What characters need to be quoted?

Поиск
Список
Период
Сортировка

What characters need to be quoted?

От
Jean-Christian Imbeault
Дата:
Are there any characters besides the single quote that need to be
escaped when inserting into PostgresQL?

And am I right in thinking that the SQL standard calls for putting one
single quote in front of a single quote to escape it (and not use a
backslash as some other DBs would have you do?)

Thanks

Jc


Re: What characters need to be quoted?

От
Jeff Davis
Дата:
> Are there any characters besides the single quote that need to be
> escaped when inserting into PostgresQL?

Also escape backslashes, and the NUL byte (0x00), in addition to the single
quote.

Note that bytea will nicely format output into printable text with escape
codes for the unprintable characters. The text types (char,varchar,text)
aren't as nice about that, and you might end up with unprintable characters
if you store them in that type.

> And am I right in thinking that the SQL standard calls for putting one
> single quote in front of a single quote to escape it (and not use a
> backslash as some other DBs would have you do?)

I believe that either two single quotes or a backslash and a single quote are
the same in PostgreSQL.

Regards,
    Jeff