Managing differences in behavior
Babelfish tries to be as compatible with MS SQL as possible. However, some variances still persist. In this section you will learn how things differ from each other and which incompatibilities are known to exist.
Application roles
- MS SQL: Application roles are set with
CREATE APPLICATION ROLEor sp_setapprole - Babelfish: This is currently not supported.
COMPATIBILITY_LEVEL
- MS SQL: Backwards compatibility is set with
COMPATIBILITY_LEVEL - Babelfish:
ALTER DATABASE... SET COMPATIBILITY LEVELwill be accepted and ignored
sysdatabases.cmptlevel
- MS SQL:
sysdatabases.cmptlevelwill always be NULL - Babelfish:
ALTER DATABASE... SET COMPATIBILITY LEVELwill be accepted and ignored
Hints
- MS SQL: Supports table hints, query hints, and join hints.
- Babelfish: Accepted and ignored.
Assembly modules and CLR routines
- MS SQL: Assembly modules and common language runtime (CLR) routines are not supported (
CREATE ASSEMBLY). - Babelfish: Currently not supported
Backup and restore
- MS SQL: Completely different behavior
- Babelfish: Use backup tools as for standard PostgreSQL
bcp, bulk copy, bulk insert
- MS SQL: Microsoft SQL Server offers a command line utility called
bcpas a common way of importing and exporting data. - Babelfish: This is currently not supported.
Blank column names when there is no column alias
- MS SQL: Allows column names to be blank when sending a result set to a client application. This can happen when the column is an expression involving more than a table column reference and no column alias is specified. sqlcmd and psql handle columns with blanks differently. MS SQL sqlcmd returns a blank column name.
- Babelfish: psql returns a generated column name.
Case-sensitivity for identifiers
- MS SQL: By default, SQL Server is case-insensitive for identifiers. So
MyTableandMYTABLEreference the same object. However, SQL Server can be configured so that identifiers are case-sensitive. In this setting,MyTableandMYTABLEwould identify two different objects. - Babelfish: For PostgreSQL, only case-insensitive identifiers are supported. For example, the identifiers
MyTableandMYTABLErefer to the same object. If your SQL Server database is configured to be case-sensitive for identifiers, Babelfish will identifyMyTableandMYTABLEas the same object.
Column default
- MS SQL: Supports creating a column default with an explicitly specified constraint name. For example:
ALTER TABLE ADD CONSTRAINT...DEFAULT...FOR.... SQL Server also supports dropping the default using that same name.ALTER TABLE...DROP CONSTRAINT.... - Babelfish: PostgreSQL handles column defaults in a different manner than SQL Server does, and there is no constraint name associated with a column default. Therefore, when creating a column default this way, the constraint name is ignored. To drop a column default use the following:
ALTER TABLE...ALTER COLUMN...DROP DEFAULT....
Common language runtime (CLR)
- MS SQL: Supports Microsoft common language runtime (CLR) procedures, functions, and triggers.
- Babelfish: Currently not supported.
Constraints
- MS SQL: SQL Server supports enabling and disabling individual constraints such as the following.
ALTER TABLE...[NO]CHECK CONSTRAINT.... - Babelfish: PostgreSQL does not support enabling and disabling individual constraints. The statement is ignored and a warning is raised.
Contained databases
- MS SQL: Contained databases have logins authenticated at the database level rather than at the server level.
- Babelfish: Currently not supported.
Data encryption
- MS SQL: Encrypting data in the database. An example is for an entire database with
CREATE DATABASE ENCRYPTION KEY(TDE) or for finer-grained encryption withENCRYPTBYKEY,CREATE SYMMETRIC KEY, etc., is not supported. - Babelfish: Currently not supported.
IDENTITY columns support
- MS SQL:
IDENTITYcolumns are supported for data typestinyint,smallint,int,bigint.numeric, anddecimal. SQL Server supports precision up to 38 for data typesnumericanddecimalinIDENTITYcolumns. - Babelfish: PostgreSQL supports precision up to 19 for data types
numericanddecimalinIDENTITYcolumns.
Identifiers exceeding 63 characters
- MS SQL: Supports using up to 128 characters for identifiers.
- Babelfish: PostgreSQL supports a maximum of 63 characters for identifiers. Babelfish converts identifiers longer than 63 characters to a name that uses a hash of the original name. Use the original name with T-SQL but the converted name when accessing the database using PostgreSQL.
Language customization
- MS SQL: Supports using a non-default language for error messages and for day and month names.
- Babelfish: For PostgreSQL, only English error messages and date names are currently supported.
NEWSEQUENTIALID() function
- MS SQL: SQL Server supports the
NEWSEQUENTIALID()function to generate a GUID value, which is guaranteed to have a higher value than a set of previously generated GUID values. - Babelfish: When calling
NEWSEQUENTIALID(), PostgreSQL cannot guarantee a higher GUID value so it will just generate a new GUID value, just likeNEWID()does.
Procedure or function parameter limit
- MS SQL: SQL Server supports up to 2100 parameters for a SQL stored procedure or SQL function.
- Babelfish: PostgreSQL supports a maximum of 100 parameters for a procedure or function.
Remote object access
- MS SQL: SQL Server can access objects on a remote server including tables, views, and procedures.
- Babelfish: Currently not supported.
ROWGUIDCOL
- Babelfish: Currently ignored. Queries referencing
$GUIDGOLwill cause a syntax error.
Row-level security
- Babelfish: Row-level security with
CREATE SECURITY POLICYand inline table-valued functions is currently not supported.
SEQUENCE objects support
- MS SQL:
SEQUENCEobjects are supported for data typestiny int,smallint,int,bigint.numeric, anddecimal. SQL Server supports precision up to 38 for data typesnumericanddecimalinSEQUENCEobjects. - Babelfish: PostgreSQL supports precision up to 19 for data types
numericanddecimalinSEQUENCEobjects.
SQL keywords CLUSTERED and UNCLUSTERED constraints
- Babelfish: Currently not supported. PostgreSQL ignores
CLUSTEREDandUNCLUSTEREDkeywords for indexes or constraints. Babelfish does not support this storage structure (whereby the index key defines the physical storage order of the rows). A clustered index can impact query plans and performance aspects, though the precise effects are non-trivial.
SQL keyword FILLFACTOR
- MS SQL: Related to SQL Server-specific aspects of data storage.
- Babelfish: Currently ignored.
SQL keyword NONCLUSTERED for indexes and constraints
- MS SQL: SQL Server uses
NONCLUSTEREDkeywords for indexes and constraints. - Babelfish: Currently ignored. PostgreSQL supports heap structures.
SQL keyword clause NOT FOR REPLICATION
- MS SQL: Related to SQL Server-specific aspects of data storage.<
- Babelfish: Currently ignored
SQL keyword clause ON filegroup
- MS SQL: For SQL Server, the commands
CREATE TABLEandCREATE INDEXsupport the object placement clauseONfilegroup. This is related to SQL Server-specific aspects of data storage. - Babelfish: Currently ignored because it is irrelevant for PostgreSQL.
SQL keyword SPARSE
- MS SQL: Related to SQL Server-specific aspects of data storage.
- Babelfish: Currently ignored.
SQL keyword TEXTIMAGE_ON filegroup
- MS SQL: or SQL Server, the commands
CREATE TABLEandCREATE INDEXsupport the object placement clauseTEXTIMAGE_ONfilegroup - Babelfish: PostgreSQL ignores the
TEXTIMAGE_ONfilegroup clause because it is irrelevant for PostgreSQL.
SQL statement USE database name
- Babelfish: Currently not supported
Sort order with DESC
- MS SQL: Allows the column sorting order in
UNIQUEandPRIMARY KEYconstraints to be specified asDESC. This helps to optimize queries that can benefit from this ordering. - Babelfish: PostgreSQL does not support
DESCfor constraints. PostgreSQL constraints are created with the defaultASCordering. However, PostgreSQL does supportDESCordering for columns in explicitly created indexes.
Time precision
- MS SQL: SQL Server supports fractions of a second for precision of the
datetime2data type to 7 digits with 3 fractional digits. SQL Server rounds this to 3-millisecond precision. This means that when you store a particular time value, the milliseconds might be rounded and end up being stored differently than what you specified. For example, the commandSELECT CAST('2016-12-26 23:59:59.999' as datetime)returns the value 2016-12-27 00:00:00.000. - Babelfish: PostgreSQL supports 6-digit precision for fractional seconds. PostgreSQL does not perform SQL Server 3-millisecond rounding. No adverse effects are anticipated with this behavior.
Transaction isolation levels
- MS SQL: Choosing a transaction isolation level doesn’t affect the locks that are acquired to protect data modifications. A transaction always gets an exclusive lock on any data it modifies and holds that lock until the transaction completes, regardless of the isolation level set for that transaction. For read operations, transaction isolation levels primarily define the level of protection from the effects of modifications made by other transactions.
- Babelfish: We use standard PostgreSQL MVCC behavior. This implies that
READ UNCOMMITEDis automatically mapped toREAD COMMITTEDas PostgreSQL does not have a lower isolation level.REPEATABLE READandSERIALIZABLEare currently not supported. MS SQLsnapshot> is treated as the equivalent of.
Triggers for LOGON and DDL
- Babelfish: Currently this is not supported.
@@version
- Babelfish: The contents of
@@versionin Babelfish differs from the native content for SQL Server. Your code might not work correctly if it depends on the native formatting of@@version, such as to extract specific minor version numbers.
Unsupported stored procedures
MS SQL comes with a huge set of predefined stored procedures which make database handling easier, or in some cases make it possible at all. However, some of these procedures are not supported by Babelfish.
Missing catalog-related procedures
The following catalog procedures are currently not supported:
sp_column_privilegessp_databasessp_fkeyssp_pkeyssp_server_infosp_special_columnssp_sproc_columnssp_statisticssp_stored_proceduressp_table_privileges
Missing cursor-related procedures
The following list contains an overview of missing cursor-related procedures:
sp_describe_cursor_columnssp_describe_cursor_tables
Missing database engine-related procedures
This is a list of database engine-related functionality which is not yet available:
sp_add_data_file_recover_suspect_dbsp_add_log_file_recover_suspect_dbsp_addextendedprocsp_addextendedpropertysp_addmessagesp_addtypesp_addumpdevicesp_altermessagesp_attach_dbsp_attach_single_file_dbsp_autostatssp_bindefaultsp_bindrulesp_bindsessionsp_certify_removablesp_clean_db_file_free_spacesp_clean_db_free_spacesp_configuresp_control_plan_guidesp_create_plan_guidesp_create_plan_guide_from_handlesp_create_removablesp_createstatssp_cycle_errorlogsp_db_increased_partitionssp_dbcmptlevelsp_dbmmonitoraddmonitoringsp_dbmmonitorchangealertsp_dbmmonitorchangemonitoringsp_dbmmonitordropalertsp_dbmmonitordropmonitoringsp_dbmmonitorhelpalertsp_dbmmonitorhelpmonitoringsp_dbmmonitorresultssp_delete_backuphistorysp_dependssp_detach_dbsp_dropdevicesp_dropextendedprocsp_dropextendedpropertysp_dropmessagesp_droptypesp_getbindtokensp_helpsp_helpconstraintsp_helpdevicesp_helpextendedprocsp_helpfilesp_helpfilegroupsp_helpindexsp_helplanguage"sp_helpserversp_helpsortsp_helpstatssp_helptextsp_helptriggersp_indexoptionsp_invalidate_textptrsp_locksp_monitorsp_prepexecrpcsp_procoptionsp_recompilesp_refreshviewsp_renamesp_renamedbsp_resetstatussp_sequence_get_rangesp_serveroptionsp_set_session_contextsp_setnetnamesp_settriggerordersp_spaceusedsp_tableoptionsp_unbindefaultsp_unbindrulesp_updateextendedpropertysp_updatestatssp_validnamesp_who
Missing security-related procedures
sp_add_trusted_assemblysp_addapprolesp_addlinkedserversp_addlinkedsrvloginsp_addloginsp_addremoteloginsp_addrolesp_addrolemembersp_addserversp_addsrvrolemembersp_addusersp_approlepasswordsp_audit_writesp_change_users_loginsp_changedbownersp_changeobjectownersp_control_dbmasterkey_passwordsp_dbfixedrolepermissionsp_defaultdbsp_defaultlanguagesp_denyloginsp_describe_parameter_encryptionsp_dropaliassp_drop_trusted_assemblysp_dropapprolesp_droplinkedsrvloginsp_droploginsp_dropremoteloginsp_droprolesp_droprolemembersp_dropserversp_dropsrvrolemembersp_dropusersp_generate_database_ledger_digestsp_grantdbaccesssp_grantloginsp_helpdbfixedrolesp_helplinkedsrvloginsp_helploginssp_helpntgroupsp_helpremoteloginsp_helprolesp_helprolemembersp_helprotectsp_helpsrvrolesp_helpsrvrolemembersp_helpusersp_migrate_user_to_containedsp_MShasdbaccesssp_passwordsp_refresh_parameter_encryptionsp_remoteoptionsp_revokedbaccesssp_revokeloginsp_setapprolesp_srvrolepermissionsp_testlinkedserversp_unsetapprolesp_validateloginssp_verify_database_ledgersp_verify_database_ledger_from_digest_storagesp_xp_cmdshell_proxy_account
Dealing with limitations
In this section, we’ve written a lot about limitations, unsupported features and such. However, how do you deal with these things in real life? If Babelfish runs a SQL statement that doesn’t return a result set that is identical to the result set when run against SQL Server, the SQL statement will fail. To better deal with statements that might fail, Babelfish allows you to define escape hatches. An escape hatch is a flag that specifies Babelfish behavior when it encounters an unsupported feature or syntax. Babelfish can either return an error or ignore the condition if the PostgreSQL result set is not a perfect match for the result set returned by SQL Server.
You can use the sp_babelfish_configure stored procedure to control the settings of each escape hatch. Use the script to specify if each escape hatch should be set to ignored or strict.
If set to strict, Babelfish will return an error that you must correct before continuing. Include the clusterkeyword to apply the changes to the current session as well as on a cluster level.
The following types of hatches exist. The list should give you an impression of what is possible:
storage_options: Controls treatment of …- Column options (sparse files, file streams,
ROWGUIDCOL) - Index options (
PAD_INDEX, FILLFACTOR, SORT_IN_TEMPDB, IGNORE_DUP_KEY, STATISTICS_NORECOMPUTE, STATISTICS_INCREMENTAL, ALLOW_ROW_LOCKS, ALLOW_PAGE_LOCKS, OPTIMIZE_FOR_SEQUENTIAL_KEY, MAXDOP, DATA_COMPRESSION)
- Column options (sparse files, file streams,
storage_on_partition: Handle invalid partition streamsdatabase_misc_options: Handle database chaining, database propertyTRUSTWORTHY, databases with persistent log bufferslanguage_non_english: Create databases with default languages other than englishcompatibility_level: Currently no options.-
CHARINDEX</index>: not supported on case-insensitive or accent-insensitive collations fulltext: Databases with default fulltext languages.CREATE FULLTEXT INDEX, ALTER FULL TEXT INDEX, DROP FULL TEXT INDEXschemabinding_function: Handles errors when no SCHEMABINDING option is givenschemabinding_trigger: Throw an error when it is not givenschemabinding_procedure: Throw an error when it is not givenschemabinding_view: Throw an error when it is not givenindex_clustering: CLUSTERED columns are not supported. Control this behavior.index_columnstore: Column stores are not supported. Ignore or error out.for_replication: Handle unsupportedALTER PROCEDURE ... ENCRYPTION, ALTER PROCEDURE ... NATIVE_COMPILATION, ALTER PROCEDURE ... RECOMPILE.rowguidcol_column: Handle unsupportedROWGUIDCOLcolumnsnocheck_add_constraint: Handle unsupportedALTER TABLE WITH [NO]CHECK ADDnocheck_existing_constraint: HandleALTER TABLE [NO]CHECKconstraint_name_for_default: HandleCONSTRAINT DEFAULTtable_hints: PostgreSQL does not support table hintsquery_hints: PostgreSQL does not support query hintsjoin_hints: PostgreSQL does not support join hintssession_settings: HandleSET SHOWPLAN_TEXT ON, FORCEPLAN, OFFSETS, PARSEONLY, REMOTE_PROC_TRANSACTIONS, SHOWPLAN_ALL, SHOWPLAN_TEXT, SHOWPLAN_XML, STATISTICS, DATEFORMAT, DEADLOCK_PRIORITY, LOCK_TIMEOUT, CONTEXT_INFO, QUERY_GOVERNOR_COST_LIMIT, STATISTICS, XML modify method.