Allowing COPY into views

From: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Allowing COPY into views
Date: 2007-04-19 13:41:55
Message-ID: 1176990115l.10180l.1l@mofo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

I would like to submit a patch so that the
COPY statement can import data into a view.
(Maybe if this works I'll see about copying
out of a view.)

Rather than spend a whole lot of time figuring
out all the calls to use and all the detail,
I'm going to go ahead and post now. That way
if this is simply not going to fly I don't have
to spend any more time on it. Otherwise,
I'll post more as I work it out.

Any and all help and/or comment is appreciated.

The basic approach I'm thinking of is to:

1) Check to see if the
view has an rule that allows INSERT, if not
then exit with an error. I thought I would use
a stored procedure for this but having read the
FAQ_DEV perhaps I'll use SearchSysCache().

2) Allocate memory for char* and construct an
'INSERT ...' statement corresponding
to the COPY command that inserts into the view.
(Just how much memory should be allocated?
Is there a standard buffer pre-alocated somewhere or a
standard buffer size?)

3) makeNode(T_PrepareStmt)
(What should name be?)

4) Iterate over COPY statement's stmnt->options
to produce prepared statement's argtypes. The
DefElem arg values can be used without further
ado. (I don't need to check to see that they
are type T_TypeName because the parser would
have taken care of that for the COPY statement,
right? (I didn't look.) There's no point
in doing a copyObject on the TypeName, right?)

5) Parse the (char*) 'INSERT...' statement.

6) Call PrepareQuery() on the parsed INSERT statement.
I'm thinking this will result in a query plan
with the rules expanded.

7) Execute the prepared statement for each row
of data.

Deallocate memory for (char*) 'INSERT...' statement.

Karl <kop(at)meme(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Karl O. Pinc 2007-04-19 14:22:20 Re: Allowing COPY into views
Previous Message Marcin Waldowski 2007-04-19 12:50:19 Re: BUG #3242: FATAL: could not unlock semaphore: error code 298