DDC-1360: Reserved words escaping fails when using multiple reserved words #1705

Closed
opened 2026-01-22 13:22:43 +01:00 by admin · 13 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 3, 2011).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user elnur:

Everything works fine when I use the @Table annotation like this: @Table(name="user"). But when the user table is in the user schema and I try to use the annotion in this way: @Table(name="user.user") — everything falls apart.

A quick look into the code showed that it checks if the table name starts with , and if it does, it sets the quotedparameter totrue and removes the characters on the both sides. So, if I quote the both words like @Table(name="user.user"), the table name becomes "user.user" and it, of course, fails. If I quote it just like @Table(name="user.user"), the table name becomes "user.user", which fails too.

If Doctrine allows to escape the reserved words, it should take into account this kind of usage as well.

Originally created by @doctrinebot on GitHub (Sep 3, 2011). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user elnur: Everything works fine when I use the `@Table` annotation like this: `@Table(name="`user`")`. But when the `user` table is in the `user` schema and I try to use the annotion in this way: `@Table(name="`user`.`user`")` — everything falls apart. A quick look into the code showed that it checks if the table name starts with `, and if it does, it sets the `quoted` parameter to `true` and removes the` characters on the both sides. So, if I quote the both words like `@Table(name="`user`.`user`")`, the table name becomes `"user`.`user"` and it, of course, fails. If I quote it just like `@Table(name="`user.user`")`, the table name becomes `"user.user"`, which fails too. If Doctrine allows to escape the reserved words, it should take into account this kind of usage as well.
admin added the Bug label 2026-01-22 13:22:43 +01:00
admin closed this issue 2026-01-22 13:22:45 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 5, 2011):

Comment created by @guilhermeblanco:

By now, it's currently impossible to do cross database joins in an easy way.
We have planned it through the schema support in @Table.

I'll be working on this support for 2.2, but until there, my only recommendation is to not use a keyword as a table name.

Cheers,

@doctrinebot commented on GitHub (Sep 5, 2011): Comment created by @guilhermeblanco: By now, it's currently impossible to do cross database joins in an easy way. We have planned it through the schema support in @Table. I'll be working on this support for 2.2, but until there, my only recommendation is to not use a keyword as a table name. Cheers,
Author
Owner

@doctrinebot commented on GitHub (Sep 5, 2011):

Comment created by elnur:

It's not cross database; it's just schema.table in PostgreSQL. It works when not using reserved words, but fails with them.

@doctrinebot commented on GitHub (Sep 5, 2011): Comment created by elnur: It's not cross database; it's just `schema.table` in PostgreSQL. It works when not using reserved words, but fails with them.
Author
Owner

@doctrinebot commented on GitHub (Oct 28, 2011):

Comment created by @beberlei:

How much of this ticket does your commit from some weeks ago cover guilherme?

@doctrinebot commented on GitHub (Oct 28, 2011): Comment created by @beberlei: How much of this ticket does your commit from some weeks ago cover guilherme?
Author
Owner

@doctrinebot commented on GitHub (Nov 16, 2011):

Comment created by @beberlei:

Fixed for 2.2

@doctrinebot commented on GitHub (Nov 16, 2011): Comment created by @beberlei: Fixed for 2.2
Author
Owner

@doctrinebot commented on GitHub (Dec 21, 2011):

Comment created by elnur:

It still doesn't work. Tried on master.

@doctrinebot commented on GitHub (Dec 21, 2011): Comment created by elnur: It still doesn't work. Tried on `master`.
Author
Owner

@doctrinebot commented on GitHub (Dec 21, 2011):

Comment created by @beberlei:

what kind of error do you get?

@doctrinebot commented on GitHub (Dec 21, 2011): Comment created by @beberlei: what kind of error do you get?
Author
Owner

@doctrinebot commented on GitHub (Dec 28, 2011):

Comment created by @beberlei:

could reproduce the problem with table names and sequence names.

@doctrinebot commented on GitHub (Dec 28, 2011): Comment created by @beberlei: could reproduce the problem with table names and sequence names.
Author
Owner

@doctrinebot commented on GitHub (Dec 28, 2011):

Comment created by @beberlei:

Fixed.

@doctrinebot commented on GitHub (Dec 28, 2011): Comment created by @beberlei: Fixed.
Author
Owner

@doctrinebot commented on GitHub (Dec 29, 2011):

Comment created by elnur:

I've just got fresh clones of doctrine-doctrine2, doctrine-dbal and doctrine-common — all on their master branches.

My entity has this annotation:

@ORM\Table(name="`user`.`user`")

I'm getting the following exception:

SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "user.user" 
does not exist LINE 1: ... is_private9,
u0*.created_at AS created*at10 FROM "user.user... 

So, it's translating user.user to "user.user", while it should be "user"."user".

@doctrinebot commented on GitHub (Dec 29, 2011): Comment created by elnur: I've just got fresh clones of `doctrine-doctrine2`, `doctrine-dbal` and `doctrine-common` — all on their `master` branches. My entity has this annotation: ``` @ORM\Table(name="`user`.`user`") ``` I'm getting the following exception: ``` SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "user.user" does not exist LINE 1: ... is_private9, u0*.created_at AS created*at10 FROM "user.user... ``` So, it's translating `user`.`user` to `"user.user"`, while it should be `"user"."user"`.
Author
Owner

@doctrinebot commented on GitHub (Dec 29, 2011):

Comment created by elnur:

What changed is that earlier user.user was translated to "user.user", while now it's translated to "user.user", but should be to "user"."user".

I saw the commit related to this ticket (959a68694e) and I want to note that I'm getting this error not when creating a table, but when querying it. I don't use Doctrine for creating tables anyway — I do it via plain SQL.

@doctrinebot commented on GitHub (Dec 29, 2011): Comment created by elnur: What changed is that earlier `user`.`user` was translated to `"user`.`user"`, while now it's translated to `"user.user"`, but should be to `"user"."user"`. I saw the commit related to this ticket (https://github.com/doctrine/doctrine2/commit/959a68694e5827a74ad5b8c8216996ffff6196ba) and I want to note that I'm getting this error _not_ when creating a table, but when _querying_ it. I don't use Doctrine for creating tables anyway — I do it via plain SQL.
Author
Owner

@doctrinebot commented on GitHub (Dec 31, 2011):

Comment created by @beberlei:

I keep trying until i fixed this, now with a commit into DBAL: 4cb8a99b65

Will be included in Beta 2

@doctrinebot commented on GitHub (Dec 31, 2011): Comment created by @beberlei: I keep trying until i fixed this, now with a commit into DBAL: https://github.com/doctrine/dbal/commit/4cb8a99b65fb08e01fbc02cf9c0e07255e3f8463 Will be included in Beta 2
Author
Owner

@doctrinebot commented on GitHub (Dec 31, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Dec 31, 2011): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 31, 2011):

Comment created by elnur:

Now user.user,user.useranduser.userget escaped properly, ending up as "user"."user". Interestingly enough, even only the beginning tick like inuser.userends up as"user"."user"`.

user.user, though, results in user.user — that is, nothing gets escaped. I don't think this is a big deal, because if I can escape both schema and table name parts, then I won't run into problems. I'm pointing this out in case it was intended to affect the escaping too.

Good job, thanks.

@doctrinebot commented on GitHub (Dec 31, 2011): Comment created by elnur: Now `user`.user`,`user`.`user`and`user.user`get escaped properly, ending up as `"user"."user"`. Interestingly enough, even only the beginning tick like in`user.user`ends up as`"user"."user"`. `user.`user`, though, results in `user.`user` — that is, nothing gets escaped. I don't think this is a big deal, because if I can escape both schema and table name parts, then I won't run into problems. I'm pointing this out in case it was intended to affect the escaping too. Good job, thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1705