Closed psoo closed 10 months ago
Can one of the admins verify this patch?
Test this, please
Hi @psoo,
Thanks for the patch!
If this new option is only supported for MS SQL Server, should a condition be put in-place to determine if the server is MS SQL server before the call to tdsSetSqlServerAnsiMode()? There is some code in tdsImportForeignSchema() that shows how to do this. For example, see here: https://github.com/tds-fdw/tds_fdw/blob/2323efe2007d012b043fe91ea97a736b85eddce3/src/tds_fdw.c#L3874
Yeah, probably a good idea to protect against misconfinguration...
I'd go forward and make this a separate function, i don't want to repeat that stuff in tdsSetSqlServerAnsiMode()
and tdsImportForeignSchema()
code-wise.
What do you think about moving that check into a separate function, like
int tdsIsSqlServer()
and calling that.
That sounds like a great plan. Thanks!
Test PASSed.
Also, would you be willing to squash the commits into a single commit to make the changes easier to review?
I am going to create a new PR, since squashing the already pushed changes into a single commit for this existing branch doesn't seem to work.
Pls see https://github.com/tds-fdw/tds_fdw/pull/348 for review.
This has been merged via #348.
Specific feature in SQL Server forces us to set ANSI-compliant options during database sessions.
One example are XML features, especially when exposed when using views like this example:
SQL Server:
Map/Import the view as a
FOREIGN TABLE
in PostgreSQL:The view gets correctly mapped (the
exist()
XML function returns1
to indicate it found a matching key):Though a
SELECT
from this view with its single column returning the result of theXMLQuery
yields the followingERROR
(msg_handler set tonotice
so the details of the error can be seen):SQL Server forces
ANSI
compliant settings when using specific functions/features, like documented here (and the notice message also gives a hint regarding theXML
datatype used):https://learn.microsoft.com/en-us/sql/t-sql/statements/set-ansi-defaults-transact-sql?view=sql-server-ver16
There is a single
ANSI_DEFAULTS
setting, which can be used to make such constructs usable with TDS clients, according to the documentation it aggregates the following settings:ANSI_NULLS
ANSI_NULL_DFLT_ON
ANSI_PADDING
QUOTED_IDENTIFIER
ANSI_WARNINGS
CURSOR_CLOSE_ON_COMMIT
IMPLICIT_TRANSACTIONS
I've decided not to use
ANSI_DEFAULTS
directly, since i am not sureCURSOR_CLOSE_ON_COMMIT
and especiallyIMPLICIT_TRANSACTIONS
is something we want intds_fdw
. In fact, according to the documentation above, the native ODBC and OLEDB drivers are setting this two parameters back toOFF
by default after having setANSI_DEFAULTS ON
.ANSI_DEFAULTS ON
also doesn't setCONCAT_NULL_YIELD_NULL
, too. So i decided to set all requiredANSI
parameters explicitly by the new helper functiontdsSetSqlServerAnsiMode()
. Please note that SQL Server will forceCONCAT_NULL_YIELDS_NULL ON
in future releases, documented here:https://learn.microsoft.com/en-us/sql/t-sql/statements/set-concat-null-yields-null-transact-sql?view=sql-server-ver16
So after all i've decided to set all options explicitly as we need.
The parameters need to be set at connection start, so i made it a new foreign server option
sqlserver_ansi_mode
, used e.g. like this:First i used to name it
ansi_mode
, but research revealed that Sybase seems to have a completely different behavior here, thus i renamed it tosqlserver_ansi_mode
to reflect its purpose better. Please see the updated documentation inForeignServerCreation.md
.Since these properties are session specific i am not sure it make sense to make them available on table-level, too.
With all this in place, selecting such views just works: