Re: Extensions, this time with a patch

From: Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr>, David Fetter <david(at)fetter(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Extensions, this time with a patch
Date: 2010-10-17 19:30:47
Message-ID: m2bp6sy5ug.fsf@2ndQuadrant.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
>> Eh, I realize now that the right way to go about this is to use SPI.
>
> Yeah, that would be one way to go about it. But IMO postgres.c should
> be solely concerned with interactions with the client.

I didn't notice it's "possible" to use SPI from within the backend core
code, and now see precedent in xml.c where the user can give a query
string. I've used SPI_execute() in the new (attached) version of the
patch, that's not touching postgres.c at all anymore.

The bulk of it is now short enough to be inlined in the mail, and if you
have more comments I guess they'll be directed at this portion of the
patch, so let's make it easy:

/*
* We abuse some internal knowledge from spi.h here. As we don't know
* which queries are going to get executed, we don't know what to expect
* as an OK return code from SPI_execute(). We assume that
* SPI_OK_CONNECT, SPI_OK_FINISH and SPI_OK_FETCH are quite improbable,
* though, and the errors are negatives. So a valid return code is
* considered to be SPI_OK_UTILITY or anything from there.
*/
SPI_connect();
if (SPI_execute(query_string, false, 0) < SPI_OK_UTILITY)
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("File '%s' contains invalid query", filename)));
SPI_finish();

Regards,
--
Dimitri Fontaine
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support

Attachment Content-Type Size
pg_execute_from_file.v3.patch text/x-patch 7.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2010-10-17 19:31:17 Re: WIP: extensible enums
Previous Message Tom Lane 2010-10-17 19:17:09 Re: WIP: extensible enums