Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with FreeTDS text comparisons #33

Open
jgoizueta opened this issue Aug 25, 2016 · 0 comments
Open

Problem with FreeTDS text comparisons #33

jgoizueta opened this issue Aug 25, 2016 · 0 comments

Comments

@jgoizueta
Copy link

This is specific to the FreeTDS odbc driver.

If we have a condition on a foreign table, comparing a text column to a text literal,
the condition (qual) will be transferred to the ODBC query and it will fail because FreeTDS does not allow comparing a text to a varchar (which is the type of the literal on the remote side).

A workaround is to cast the text column to varchar (casting the literal to text has no effect on the query executed remotely) because it removes the qual from the remote query.

Example: remote SQL Server database testdb:

create table txt(t text);

With this foreign table:

 CREATE SERVER ms FOREIGN DATA WRAPPER odbc_fdw
   OPTIONS (
     odbc_DRIVER 'FreeTDS',
     "odbc_Server" '...',
     "odbc_Database" 'testdb'
   );
 CREATE USER MAPPING FOR postgres SERVER ms
   OPTIONS (
     "odbc_UID" 'dbo',
     "odbc_PWD" '...'
   );
IMPORT FOREIGN SCHEMA dbo
  FROM SERVER ms
  INTO public
  OPTIONS(
    table 'txt',
    ApplicationIntent 'ReadOnly'
  );

Now this will fail:

SELECT * from txt where t = '';

With this error:

[FreeTDS][SQL Server]The data types text and varchar are incompatible in the equal to operator.

Workaround:

SELECT * from txt where t::varchar = '';
@rafatower rafatower modified the milestone: Pollos - dataservices Sep 19, 2016
@rafatower rafatower modified the milestones: Peloteos - Dataservices, Dataservices - bakclog Oct 24, 2016
@rafatower rafatower removed this from the Dataservices - backlog milestone Jan 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants