Postgres quoted identifiers

38 views
Skip to first unread message

Álvaro J. Iradier

unread,
Jul 27, 2011, 3:34:31 PM7/27/11
to web2py-users
Hi,

migrating my application to Postgres, I've been hit by the "user"
reserved keyword problem previously commented on
http://groups.google.com/group/web2py/browse_thread/thread/f23c03ff8143b55/15602d3158ae5e6c.

According to PostgreSQL documentation,
http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html,
section 4.1.1:

-----

There is a second kind of identifier: the delimited identifier or
quoted identifier. It is formed by enclosing an arbitrary sequence of
characters in double-quotes ("). A delimited identifier is always an
identifier, never a key word. So "select" could be used to refer to a
column or table named "select", whereas an unquoted select would be
taken as a key word and would therefore provoke a parse error when
used where a table or column name is expected. The example can be
written with quoted identifiers like this:

UPDATE "my_table" SET "a" = 5;

-----

Shouldn't web2py use this syntax by default in order to avoid keyword
collisions? Probably there is a similar syntax for other DB engines as
well (for example, quote using [name] in SQL Server, etc.). Is there
something against this?

Thanks.

Massimo Di Pierro

unread,
Jul 27, 2011, 4:16:26 PM7/27/11
to web2py-users
Yes. The dal was rewritten to allow this. The reason it was never
implemented fully is that I cannot find documentation about this for
all supported db engines. Implementing this only for mysql and pgsql
is a pain.

On Jul 27, 2:34 pm, Álvaro J. Iradier <airad...@gmail.com> wrote:
> Hi,
>
> migrating my application to Postgres, I've been hit by the "user"
> reserved keyword problem previously commented onhttp://groups.google.com/group/web2py/browse_thread/thread/f23c03ff81....
>
> According to PostgreSQL documentation,http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html,

Álvaro J. Iradier

unread,
Jul 28, 2011, 11:35:54 AM7/28/11
to web2py-users
Couldn't it be implemented by calling a engine-dependent method like
sql_quote(name), which in other engines would by default return the
unquoted string, but return the quoted name in mysql and postgres?

Greets.

On 27 jul, 22:16, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:

Massimo Di Pierro

unread,
Jul 29, 2011, 6:03:55 AM7/29/11
to web2py-users
This is a good idea. Let me give this some thought.

Álvaro J. Iradier

unread,
Aug 7, 2011, 3:39:04 PM8/7/11
to web2py-users
Hi Massimo, any progress on this? I need to migrato from MySql to
Postgres and this issue is stopping me (I'd like to avoid making
changes on the database right now). If you think it might be good to
include this, I can start working on it and provide patches. I don't
like the idea of keeping my own modified version of web2py forever,
that is why I am asking if this might be included in a future version.

Just let me know.

Greets.

On 29 jul, 12:03, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
> This is a good idea. Let me give this some thought.
>
> On Jul 28, 10:35 am, Álvaro J. Iradier <airad...@gmail.com> wrote:
>
> > Couldn't it be implemented by calling a engine-dependent method like
> > sql_quote(name), which in other engines would by default return the
> > unquoted string, but return the quoted name in mysql andpostgres?
>
> > Greets.
>
> > On 27 jul, 22:16, Massimo Di Pierro <massimo.dipie...@gmail.com>
> > wrote:
>
> > > Yes. The dal was rewritten to allow this. The reason it was never
> > > implemented fully is that I cannot find documentation about this for
> > > all supported db engines. Implementing this only for mysql and pgsql
> > > is a pain.
>
> > > On Jul 27, 2:34 pm, Álvaro J. Iradier <airad...@gmail.com> wrote:
>
> > > > Hi,
>
> > > > migrating my application toPostgres, I've been hit by the "user"
Reply all
Reply to author
Forward
0 new messages