mysql - Handling SQL reserved table and column names -


is there way handle reserved table & column names in app can work through kinds of databases oracle, mysql, sql server, postgresql etc.

currently, have following :

oracle - use double quotes. mysql - use backtick or double quotes (depends if ansi_quotes mode enabled) sql server - use brackets postgresql - use double quotes.

i aware ansi standard states use double quotes unfortunately not dbms seem support them.

use double quotes. that's standard says, , surprisingly, works on platforms.

require mysql have ansi_quotes enabled, or set @ session level:

set session sql_mode = 'ansi' 

(i used ansi not ansi_quotes here because makes mysql bit saner).

postgresql doesn't require special settings identifiers (though old versions need standard_conforming_strings = on handle literals sensibly).

neither oracle.

modern ms-sql shouldn't require special settings support double quoted identifiers:

when set quoted_identifier on (default), strings delimited double quotation marks interpreted object identifiers

the docs suggest case in ms-sql 2008, , if still care 2005 in new application have bigger problems.

sqlfiddles:

interestingly, found sqlfiddle postgresql failed odd error. suspect sqlfiddle bug, it's fine on postgresql command line , via pgjdbc. fails there no table match following pattern [with].

all said, if you're trying write ansi sql, hope don't plan on using:

  • date/time maths
  • string concatenation
  • non-trivial aggregates
  • window functions (mysql still doesn't support them)
  • common table expressions
  • sql/xml
  • arbitrary precision decimal data types
  • any kind of user defined procedure or function
  • any kind of user-defined type
  • ... lots more

because different vendors use different names, have different support features, etc.

(on side note, if ever meet person decided call microsoft sql server "sql" in dark alley...)


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -