Allowing COPY into views - Mailing list pgsql-hackers

From Karl O. Pinc
Subject Allowing COPY into views
Date
Msg-id 1176990115l.10180l.1l@mofo
Whole thread Raw
Responses Re: Allowing COPY into views  ("Karl O. Pinc" <kop@meme.com>)
Re: Allowing COPY into views  (Andrew Dunstan <andrew@dunslane.net>)
Re: Allowing COPY into views  (Gregory Stark <stark@enterprisedb.com>)
List 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@meme.com>
Free Software:  "You don't pay back, you pay forward."                 -- Robert A. Heinlein



pgsql-hackers by date:

Previous
From: Markus Schiltknecht
Date:
Subject: Re: Hacking on PostgreSQL via GIT
Next
From: "Karl O. Pinc"
Date:
Subject: Re: Allowing COPY into views