views:

40

answers:

1

I have a table in a MySQL table with a fieldname 'product', and want to rename it to 'ds-product'.

The CMS type system I am using uses the id of formfields as the name of the table field to insert into.

For most this works fine, but for a particular field it prepends 'ds-' to whatever ID I give it, so I must make the table field name match.

However, when trying to do a query I get the error that

Unknown column 'sales.ds' in 'field list'

Is there any way I can have a field called ds-product?

+3  A: 

Yes, you can use punctuation, white space, international characters, and SQL reserved words if you use delimited identifiers:

SELECT * FROM `my-table`;

In MySQL, use the back-ticks. In standard SQL, use double-quotes.

Or if you use MySQL you can set the ANSI_QUOTES SQL mode:

SET SQL_MODE = ANSI_QUOTES;
SELECT * FROM "my-table";
Bill Karwin
I don´t actually have access to the query which gets used. Is there any way to have a field called ds-product and have it used in a standard query?
Jacob
No, the hyphen is an operator, and you can't use that in the middle of an identifier. What if you also had columns `ds` and `product`? Then `ds-product` would be an arithmetic expression: one column minus the other column. SQL supports delimited identifiers so you can resolve this ambiguity. FWIW, I don't know any other programming language that would allow this at all!
Bill Karwin
Aye, thanks bill.
Jacob