-
Notifications
You must be signed in to change notification settings - Fork 112
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
Fetching Binary Data #3
Comments
Hm, the data should be copied into the memory segment without alteration. Is it possible to cast it into a bytea and use it? |
The problem is with bytes with a value of zero. There is no length field for varchar, it's null terminated. So your data will be truncated at the first zero. |
I've updated the documentation, and ensured the core code treats all data in a "binary clean" way, so you just need to use the right magic function to convert the WITH
http AS (
SELECT * FROM http_get('http://localhost/PoweredByMacOSXLarge.gif')
),
headers AS (
SELECT (unnest(headers)).* FROM http
)
SELECT
http.content_type,
length(textsend(http.content)) AS length_binary,
headers.value AS length_headers
FROM http, headers
WHERE field = 'Content-Length'; And for my example, I get this.
You can see the underlying data is still there, and the length retrieved (as noted in the headers) is the same as the length in the underlying object (as measured after casting to |
This recommendation does not work, when client charset is different from database charset. For example, when my database charset is UTF-8 and client charset is WINDOWS-1250, then I get error about conversion: I have solved it be force defining SET client_encoding = 'UTF8' for the function, which calls the http_post:
|
The fact that http_get returns varchar prevents this from being used to return binary data. I was specifically trying to fetch some images from a webserver.
The text was updated successfully, but these errors were encountered: