Skip site navigation (1) Skip section navigation (2)

Re: pg_execute_from_file review

From: Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr>
To: Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr>
Cc: Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>, Joshua Tolley <eggyknap(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_execute_from_file review
Date: 2010-12-01 22:00:48
Message-ID: m239qh6tm7.fsf@2ndQuadrant.fr (view raw or flat)
Thread:
Lists: pgsql-hackers
Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr> writes:
> Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)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


Attachment: pg_execute_from_file.v7.patch
Description: text/x-patch (21.5 KB)

In response to

Responses

pgsql-hackers by date

Next:From: Jeff DavisDate: 2010-12-01 22:24:22
Subject: Re: crash-safe visibility map, take three
Previous:From: Florian PflugDate: 2010-12-01 21:57:18
Subject: Re: improving foreign key locks

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group