Dimitri Fontaine <dimitri@2ndQuadrant.fr> writes:
> Itagaki Takahiro <itagaki.takahiro@gmail.com> writes:
>> My suggestion is to introduce pg_read_binary_file() function that can
>> read any files in the server, and make CREATE EXTENSION to use the
>> function. Of course, pg_execute_[sql|from]_file() can simplify queries
>
> It seems like all you're missing in the current patch is the encoding
> option in there. Exposing the internal functions is simple enough and
> solves it, but I much prefer the current simple-case user API. Do you
> want me to add a variant with an extra 'encoding' parameter?
Here's the result:
dim=# \df pg_exe*|replace_*|*binary*
List of functions
Schema | Name | Result data type | Argument data types | Type
------------+-----------------------+------------------+---------------------------+--------
pg_catalog | pg_execute_sql_file | void | text | normal
pg_catalog | pg_execute_sql_file | void | text, name | normal
pg_catalog | pg_execute_sql_file | void | text, name, VARIADIC text | normal
pg_catalog | pg_execute_sql_string | void | text | normal
pg_catalog | pg_execute_sql_string | void | text, VARIADIC text | normal
pg_catalog | pg_read_binary_file | bytea | text, bigint, bigint | normal
pg_catalog | replace_placeholders | text | text, VARIADIC text | normal
(7 rows)
I think that answers fine to your concerns, in that you can manipulate
the low-level functions in order to control each step, or you can use
the higher-level functions and just pass them the arguments you want.
Note that the "name" arguments here are the encoding.
The documentation of the pg_execute_sql_string() function should close
the gap noted by Joshua Tolley about how to format placeholder names,
because it gives examples both using '@schema@' and 's' as names.
Regards,
--
Dimitri Fontaine
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support