COPY table FROM STDIN via SPI

Started by James Sewellover 2 years ago6 messages
#1James Sewell
james.sewell@gmail.com

Is $subject possible?

I feel like maybe the answer is no, but then I can also see some backend
code for similar things in copy.h.

Perhaps it’s possible via a function call not sending the SQL?

- James

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: James Sewell (#1)
Re: COPY table FROM STDIN via SPI

James Sewell <james.sewell@gmail.com> writes:

Is $subject possible?

No. It'd be a wire protocol break, and even if it weren't I would not
expect many clients to be able to deal with it. They're in the middle
of a query cycle (for the SELECT or CALL that got you into SPI), and
suddenly the backend asks for COPY data? What are they supposed to
send, or where are they supposed to put it for the COPY-out case?
There's just not provision for nesting protocol operations like that.

regards, tom lane

#3James Sewell
james.sewell@gmail.com
In reply to: Tom Lane (#2)
Re: COPY table FROM STDIN via SPI

No. It'd be a wire protocol break, and even if it weren't I would not
expect many clients to be able to deal with it. They're in the middle
of a query cycle (for the SELECT or CALL that got you into SPI), and
suddenly the backend asks for COPY data? What are they supposed to
send, or where are they supposed to put it for the COPY-out case?
There's just not provision for nesting protocol operations like that.

What about running a COPY directly from C - is that possible?

#4Joe Conway
mail@joeconway.com
In reply to: James Sewell (#3)
Re: COPY table FROM STDIN via SPI

On 7/11/23 22:52, James Sewell wrote:

No.  It'd be a wire protocol break, and even if it weren't I would not
expect many clients to be able to deal with it.  They're in the middle
of a query cycle (for the SELECT or CALL that got you into SPI), and
suddenly the backend asks for COPY data?  What are they supposed to
send, or where are they supposed to put it for the COPY-out case?
There's just not provision for nesting protocol operations like that.

What about running a COPY directly from C - is that possible?

https://www.postgresql.org/docs/current/libpq-copy.html

--
Joe Conway
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

#5Noname
chap@anastigmatix.net
In reply to: Joe Conway (#4)
Re: COPY table FROM STDIN via SPI

On 2023-07-12 14:18, Joe Conway wrote:

On 7/11/23 22:52, James Sewell wrote:

What about running a COPY directly from C - is that possible?

https://www.postgresql.org/docs/current/libpq-copy.html

Or is the question about a COPY kicked off from server-side
C code (following up a question about SPI)?

If the idea is to kick off a COPY that reads from the connected
client's STDIN, the wire protocol doesn't really have a way to
work that out with the client, as Tom pointed out.

Or is the goal for some server-side code to quickly populate
a table from some file that's readable on the server and has
the same format that COPY FROM expects?

Regards,
-Chap

#6Joe Conway
mail@joeconway.com
In reply to: Noname (#5)
Re: COPY table FROM STDIN via SPI

On 7/12/23 14:43, chap@anastigmatix.net wrote:

On 2023-07-12 14:18, Joe Conway wrote:

On 7/11/23 22:52, James Sewell wrote:

What about running a COPY directly from C - is that possible?

https://www.postgresql.org/docs/current/libpq-copy.html

Or is the question about a COPY kicked off from server-side
C code (following up a question about SPI)?

If the idea is to kick off a COPY that reads from the connected
client's STDIN, the wire protocol doesn't really have a way to
work that out with the client, as Tom pointed out.

Or is the goal for some server-side code to quickly populate
a table from some file that's readable on the server and has
the same format that COPY FROM expects?

You can still use this in a server-side extension in the same way that
dblink works. Perhaps ugly, but I have used it in the past and it worked
*really* well for us.

--
Joe Conway
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com