The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

380960 (6) [Avatar] Offline
#1
I'm running PostgreSQL 9.5 on Windwos 10

This is the list 16.7


CREATE OR REPLACE FUNCTION ch16.write_bin_file(
param_bytes bytea,
param_filename text
)
RETURNS text AS
$$
f = open('C:/temp/' + param_filename, 'wb+') -- <co id="co_code_plpython_write_bin_file_1"/>
f.write(param_bytes) -- <co id="co_code_plpython_write_bin_file_2"/>
f.close()
return param_filename -- <co id="co_code_plpython_write_bin_file_3"/>
$$ LANGUAGE plpython3u IMMUTABLE;

I Get this error:

ERROR: could not compile PL/Python function "write_bin_file"
DETAIL: SyntaxError: invalid syntax (<string>, line 3)

********** Error **********

ERROR: could not compile PL/Python function "write_bin_file"
SQL state: 38000
Detail: SyntaxError: invalid syntax (<string>, line 3)
regina.leo (265) [Avatar] Offline
#2
I think the cue ball markup stuff got in the way.

Try changing the -- to # or just get rid of those -- <co things entirely

I'll update the source code to not have that get in the way.