From: Avivi on
Hi

Does Pgtcl support COPY FROM STDIN ?

Thanks
Avi
From: jr4412 on
On Jan 8, 9:27 pm, Avivi <aviv...(a)gmail.com> wrote:
> Hi
>
> Does Pgtcl support COPY FROM STDIN ?
>
> Thanks
> Avi

where is the stdin going to come from? external to script (command-
line) or internal (puts)?
From: Avivi on
On Jan 8, 10:25 pm, jr4412 <jr4...(a)googlemail.com> wrote:
> On Jan 8, 9:27 pm, Avivi <aviv...(a)gmail.com> wrote:
>
> > Hi
>
> > Does Pgtcl support COPY FROM STDIN ?
>
> > Thanks
> > Avi
>
> where is the stdin going to come from? external to script (command-
> line) or internal (puts)?

JR

Thanks for responding.
Either way.
I was able to initiate the COPY, verified via pg_result.
I tried "puts $dbHandle $Line" and it failed, which I believe is to be
expected.
I need help with writing to the handle.
If there is more than one way, I would like to know all of them.

Thanks again
Avi
From: George Petasis on
στις 8/1/2010 23:27, O/H Avivi έγραψε:
> Hi
>
> Does Pgtcl support COPY FROM STDIN ?
>
> Thanks
> Avi

Perhaps unrelated, but there is a tcl package called
"pgintcl". This implements everything in Tcl, using a socket.
Perhaps if you fail to find a solution, this extension may come handy,
at least for some transactions...

George
From: Avivi on
On Jan 9, 9:54 pm, ljb <ljb1...(a)pobox.com> wrote:
> peta...(a)iit.demokritos.gr wrote:
> > ???????? 8/1/2010 23:27, O/H Avivi ????????????:
> >> Hi
>
> >> Does Pgtcl support COPY FROM STDIN ?
>
> >> Thanks
> >> Avi
>
> > Perhaps unrelated, but there is a tcl package called
> > "pgintcl". This implements everything in Tcl, using a socket.
> > Perhaps if you fail to find a solution, this extension may come handy,
> > at least for some transactions...
>
> With pgintcl (mine!) you can do the copy, but not with puts. It has a
> special set of calls you use.
>
> Both libpq-based implementations of pgtcl ("pgtcl", and "pgtcl-ng" (also
> mine!)) support copy as follows. To copy in to a table, you execute a "COPY
> mytable FROM STDIN", check the result handle status is PGRES_COPY_IN, then
> you "puts" tab-separated fields using the connection handle as a Tcl stream.
> At the end, you put the end marker "\.", and the result status should be
> PGRES_COMMAND_OK.
>
> For copy out, you send COPY mytable TO STDOUT, check status, then read
> from the connection handle until it gets EOF, and check status again.

George, Thanks for the information, I will definitely keep that in
mind.

JR, LJB: Thank you too. Here are my "issues":

This is a snippet from the program (please disregard typos):

set dbHandle [ pg_connect -conninfo [ dbname = xyz ]
set copyString "copy xyz ( date, value ) from stdin"
set resHandle [ pg_exec $dbHandle $copyString ]
set result [ pg_result $resHandle -status ]
puts "RESULT: <$resHandle> $result"

# pg_result $resHandle -clear ;# clear #1

set date "2010-01-11"
for { set i 0 } { $i <= 5 } { incr i } { {
puts $dbHandle "$date $i"
}

puts $dbHandle {.}
set result [ pg_result $resHandle -status ]
Print 9 "RESULT: <$resHandle> $result"

The problems:

1. If I un-comment-out "clear #1", I am getting:

RESULT: <pgsql5.0> PGRES_COPY_IN
error writing "pgsql5": file busy
while executing
"puts $dbHandle "$date $i""

2. If I comment-out "clear #1", I am getting:
RESULT: <pgsql5.0> PGRES_COPY_IN
RESULT: <pgsql5.0> PGRES_COPY_IN
and nothing was actually written to the DB.

#1 - the [ pg_result -clear ] interferes with [ puts ], why?

#2 baffles me since I exapcted to see PGRES_COMMAND_OK, as you
suggested.
However, [ pg_result -status ] returns a new status *only* after a new
[ pg_exec ] which was not issued before/after "puts $dbHandle {.}"
Aren't we missing something here?

Again, many thanks to all of you
Avi