On Thu, Nov 7, 2013 at 9:59 AM, Daniel Farina <daniel@fdr.io> wrote:
> On Thu, Nov 7, 2013 at 2:22 AM, Oliver Tonnhofer
> <notifications@github.com> wrote:
>>
>> In conn.go:
>>
>> > @@ -438,6 +470,9 @@ func (cn *conn) prepareToSimpleStmt(q, stmtName string) (_ *stmt, err error) {
>> >  }
>> >
>> >  func (cn *conn) Prepare(q string) (driver.Stmt, error) {
>> > + if len(q) >= 4 && strings.EqualFold(q[:4], "COPY") {
>>
>> .Exec() returns a Result. .Query() returns *Rows which has .Next() and .Scan(). It could (and IMO should) decode the output and return the right data types. So from the API, similar to a SELECT.
>
> This can only work if you are up for parsing the entire COPY and
> supporting every combination of options under the sun, or somehow
> restrict the forms of COPY the user is allowed to do.  Consider this
> plethora of options:
>
>  FORMAT format_name
>     OIDS [ boolean ]
>     DELIMITER 'delimiter_character'
>     NULL 'null_string'
>     HEADER [ boolean ]
>     QUOTE 'quote_character'
>     ESCAPE 'escape_character'
>     FORCE_QUOTE { ( column_name [, ...] ) | * }
>     FORCE_NOT_NULL ( column_name [, ...] )
>     ENCODING 'encoding_name'
>
> I don't *think* these are echoed back to the client form the server,
> even, so one could have a chance of knowing what is going on without
> being able to parse COPY, which seems like a bigger yak to shave than
> one might want.

Come to think of it, this also affects the ingress side.  For the case
of Go forming structured data, only the text and binary forms would
seem to matter, but how one might tell which to use?  I suppose
skimming the COPY string is not out of the question to that limited an
extent, or maybe we can start with just one format -- text.

The other use case I don't want to foreclose is writing a Go program
to load CSVs, binary COPY output, or whathaveyou with the full breadth
and depth of COPY options.  What does everyone think about
interpreting a single interface value adhering to "io.Reader" or maybe
"io.ReadCloser" to trigger this opaque, blob-based COPY?