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

zero byte in middle of binary array #38

Closed
tskenb opened this issue Oct 16, 2015 · 5 comments
Closed

zero byte in middle of binary array #38

tskenb opened this issue Oct 16, 2015 · 5 comments

Comments

@tskenb
Copy link

tskenb commented Oct 16, 2015

When there is a zero byte in the middle of a binary array postgresql interprets it as end-of-string in BuildTupleFromCStrings, so the rest of the array gets cut off.

This issue might be resolved as part of issue 37, in which case I'll close this one. But in case it isn't I'm opening this so it doesn't get forgotten.

@tskenb
Copy link
Author

tskenb commented Oct 21, 2015

Interestingly, if my input value (in SQL Server) is a binary(n) or varbinary(n) then I get the error I described before, but if it is a varbinary(max) then the srctype comes in as SYBIMAGE, the bytes are converted to an actual string, which is then converted to a hex value for each ascii character. So \xFA00BC comes back as \x666130306263, since \x66 is hex for 'F', etc.

I still expect this to be fixed as part of issue 37, and I'll include SYBIMAGE in the case selection.

@GeoffMontee
Copy link
Collaborator

After pushing the commit for issue #37, this does appear to be fixed.

Created a table on MS SQL Server:

CREATE TABLE dbo.binary (
    id int primary key,
    value binary(4)
);

INSERT INTO dbo.binary (id, value) VALUES (1, 0x01020304);

Then in PostgreSQL:

CREATE FOREIGN TABLE binary4 (
    id int,
    value bytea
)
    SERVER mssql_svr
    OPTIONS (table 'dbo.binary', row_estimate_method 'showplan_all');   

The results look good:

postgres=# SELECT * FROM binary4;
 id |   value
----+------------
  1 | \x01020304
(1 row)

@tskenb
Copy link
Author

tskenb commented Oct 22, 2015

Actually, the constant needs to have two zeros in a row, since each pair is a byte - e.g., \x01020004. I did a similar test and found that it was indeed fixed.

@GeoffMontee
Copy link
Collaborator

Ah, of course! My mistake.

I'm glad it's fixed.

@tskenb tskenb closed this as completed Oct 22, 2015
@GeoffMontee
Copy link
Collaborator

Fixed in 1.0.6.

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