MySql + underscores + dashes

Hi!
I have some problem with MySql syntax. I’ getting error when trying to

SELECT * FROM database_name_com_-_mambo.mos_sections;

.
Database database_name_com_-_mambo is a valid database name, i can use it:

USE database_name_com_-_mambo

without error.
Table is valid, I can browse with:

SELECT * FROM mos_sections;

without error.
What is wrong?
Thanks.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Is this a table name: database_name_com_-_mambo.mos_sections ?

If not you’re not doing it right. If some of that is a database name
it’s also probably wrong… Post the output of ‘show tables’ from
within mysql.

Good luck.

ram88 wrote:
> Hi!
> I have some problem with MySql syntax. I’ getting error when trying to
>
> Code:
> --------------------
> SELECT * FROM database_name_com_-_mambo.mos_sections;
> --------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIr9ej3s42bA80+9kRAnC2AJ9h9sXJB5MN1M8M25yguTFvRCCnZgCfXdjN
8OmBQgecv7nCY6CEPbd5JfM=
=nnnI
-----END PGP SIGNATURE-----

show db:
±--------------------------+
| Database |
±--------------------------+
| information_schema |
| dombosfest_org_yu_-_mambo | ** In my first post I’m replaced with “database_name_com_-_mambo”.
| test |
| testDb |
| testDb2 |
±--------------------------+

show table:
±------------------------------------+
| Tables_in_dombosfest_org_yu_-_mambo |
±------------------------------------+
| mos_banner |
| mos_bannerclient |
| mos_bannerfinish |
| mos_categories |
| mos_components |
| mos_contact_details |
| mos_content |
| mos_content_frontpage |
| mos_content_rating |
| mos_core_acl_aro |
| mos_core_acl_aro_groups |
| mos_core_acl_aro_sections |
| mos_core_acl_groups_aro_map |
| mos_core_log_items |
| mos_core_log_searches |
| mos_groups |
| mos_guestbook |
| mos_mambots |
| mos_menu |
| mos_messages |
| mos_messages_cfg |
| mos_mgm |
| mos_mgm_cnf |
| mos_mgm_img |
| mos_mgm_template |
| mos_modules |
| mos_modules_menu |
| mos_newsfeeds |
| mos_poll_data |
| mos_poll_date |
| mos_poll_menu |
| mos_polls |
| mos_redirection |
| mos_sections |
| mos_session |
| mos_siteFtpAccnt |
| mos_stats_agents |
| mos_template_positions |
| mos_templates_menu |
| mos_users |
| mos_usertypes |
| mos_weblinks |
±------------------------------------+

ps.: I can execute this:

SELECT * FROM testDb.testTable1;

without any problems. (testTable1 is a TABLE from testDb DATABASE)
±-----------------+
| Tables_in_testDb |
±-----------------+
| testTable1 |
±-----------------+

MySQL :: MySQL 5.0 Reference Manual :: 8.2 Schema Object Names makes it clear that identifiers that contain more than alphanumerics, _ and $ must be quoted. It is possible that the mysql parser lets you get away without the quoting using the backtick character ` in some situations, but in general you need to quote whenever you have a special character.

Presumably the hyphen in your expression could be confused as the minus operator by the parser in some contexts and so the identifiers there need quoting.

Why not just stay out of trouble and not use names with hyphens?

I don’t like to use dashes and underscores, this is one backup from phpMyAdmin. :slight_smile:
Thanks for help!

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Try the following:

SELECT * FROM dombosfest_org_yu_-_mambo.mos_sections;

Note that those are backticks surrounding the DB/table names… I
couldn’t make single-quotes (ticks) or double-quotes work.

Good luck.

ram88 wrote:
> ken_yap;1861006 Wrote:
>> Why not just stay out of trouble and not use names with hyphens?
> I don’t like to use dashes and underscores, this is one backup from
> phpMyAdmin. :slight_smile:
> Thanks for help!
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIsFhd3s42bA80+9kRAlZkAJ4oK5oIrGEjP7lRBq5VTGzbLhvADQCfWlFg
cuyEEoAZ1hFhXg1eemODoYk=
=MdZV
-----END PGP SIGNATURE-----

And one wouldn’t expect them to. The doco states that the quoting character for names with special characters is the backtick. Single and double quotes would create string literals.