Migrating a PostgreSQL Database to SQL Anywhere 12 - Sybase
Migrating a PostgreSQL Database to SQL Anywhere 12 - Sybase
Migrating a PostgreSQL Database to SQL Anywhere 12 - Sybase
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
spaces in the previous example with zeros and add the UNSIGNED attribute <strong>to</strong> the column. For example, ‘1’ is<br />
returned as ‘0001’. The merge of display format and data values in the type definition is not supported by <strong>SQL</strong><br />
<strong>Anywhere</strong>. The CAST and CONVERT functions, along with the various string manipulation functions are<br />
available <strong>to</strong> format data values when they are retrieved from the database.<br />
The following data types differ from <strong>SQL</strong> <strong>Anywhere</strong> more substantially than by syntax:<br />
MEDIUMINT: These are 3-byte integer values. They can easily be simulated using an INTEGER (4 bytes) or<br />
SMALLINT (2 bytes) in <strong>SQL</strong> <strong>Anywhere</strong>, depending on the expected range of values for the column.<br />
YEAR: Year is a 2 or 4 digit value. The <strong>SQL</strong> <strong>Anywhere</strong> DATE data type can be used <strong>to</strong> hold year values, but uses<br />
slightly more s<strong>to</strong>rage space. Date arithmetic and conversion can be performed using the <strong>SQL</strong> <strong>Anywhere</strong> builtin<br />
functions listed under “Date and Time Functions” in the “<strong>SQL</strong> Functions” chapter of the “<strong>SQL</strong> <strong>Anywhere</strong><br />
Server - <strong>SQL</strong> Reference” manual.<br />
The following data types do not match exactly, and will require some work <strong>to</strong> migrate <strong>to</strong> <strong>SQL</strong> <strong>Anywhere</strong>:<br />
NCHAR/NVARCHAR: As of <strong>Postgre<strong>SQL</strong></strong> 5, an NCHAR value is s<strong>to</strong>red in <strong>Postgre<strong>SQL</strong></strong> using the UTF8 character set.<br />
<strong>SQL</strong> <strong>Anywhere</strong> supports a variety of character sets, including UTF8. With a database created using the proper<br />
collation, the use of a special data type <strong>to</strong> s<strong>to</strong>re international values is not required, though <strong>SQL</strong> <strong>Anywhere</strong> does<br />
support the NCHAR data type. To learn more about the latest international character set support in <strong>SQL</strong><br />
<strong>Anywhere</strong>, see the chapter “International Language and Character Sets” in the “<strong>SQL</strong> <strong>Anywhere</strong> Server -<br />
<strong>Database</strong> Administration” manual.<br />
ENUM: An ENUM value is a string object whose value must be chosen from a list of supplied values enumerated<br />
in the column definition when a table is created. The enumerated values can also be inserted or retrieved by<br />
their index position in the ENUM definition. The index value 0 is reserved for the empty string. The ENUM<br />
data type is represented in <strong>SQL</strong> <strong>Anywhere</strong> by a TINYINT column. There are a few options <strong>to</strong> accomplish the<br />
same behavior as the <strong>Postgre<strong>SQL</strong></strong> ENUM, but changes <strong>to</strong> the client application will almost certainly be required.<br />
Some options are:<br />
• Altering the client side application <strong>to</strong> remove the need for ENUM values<br />
• Translating the ENUM values on the client side<br />
• Adding some logic <strong>to</strong> the server side <strong>to</strong> attempt <strong>to</strong> mimic the <strong>Postgre<strong>SQL</strong></strong> behavior of ENUM values<br />
by using s<strong>to</strong>red procedures, triggers, computed columns, view, and/or a mapping table for the<br />
ENUM types<br />
For example, a view could be created on the table containing the ENUM fields <strong>to</strong> allow for the return of the<br />
values as a string, while a regular SELECT could be used <strong>to</strong> return them as a number. Here is an example of a<br />
view that could be used:<br />
CREATE TABLE enumtbl (pkey INTEGER NOT NULL PRIMARY KEY, enumval TINYINT);<br />
CREATE VIEW v_enumtable AS<br />
SELECT pkey<br />
CASE WHEN 0 then ‘’<br />
WHEN 1 then ‘val1’<br />
WHEN 2 then ‘val2’<br />
WHEN 3 then ‘val3’<br />
ELSE NULL<br />
END<br />
FROM enumtbl;<br />
Then, a query may look something like this:<br />
SELECT pkey, enumval FROM v_enumtable;<br />
Alternatively, a mapping table could be created for the ENUM vales and whenever you retrieve data from<br />
enumtbl, a join can be made <strong>to</strong> the mapping table containing the ENUM strings.<br />
<strong>Migrating</strong> a <strong>Postgre<strong>SQL</strong></strong> <strong>Database</strong> <strong>to</strong> <strong>SQL</strong> <strong>Anywhere</strong> <strong>12</strong><br />
December 2011<br />
5