Hi,

In <cad21aoc_dhfs97dkwtl+2nvgboyrmn9xvyre8w2sudgghb-...@mail.gmail.com>
  "Re: Make COPY format extendable: Extract COPY TO format implementations" on 
Wed, 10 Jan 2024 15:33:22 +0900,
  Masahiko Sawada <sawada.m...@gmail.com> wrote:

>> We can use the satic const struct approach by choosing one
>> of the followings:
>>
>> ...
>>
>> 4. ... other idea?
> 
> It's a just idea but the fourth idea is to provide a convenient macro
> to make it easy to construct the CopyFormatRoutine. For example,
> 
> #define COPYTO_ROUTINE(...) (Node *) &(CopyToFormatRoutine) {__VA_ARGS__}
> 
> static const CopyFormatRoutine testfmt_copyto_handler = {
>     .type = T_CopyFormatRoutine,
>     .is_from = true,
>     .routine = COPYTO_ROUTINE (
>         .start_fn = testfmt_copyto_start,
>         .onerow_fn = testfmt_copyto_onerow,
>         .end_fn = testfmt_copyto_end
>         )
> };
> 
> Datum
> copy_testfmt_handler(PG_FUNCTION_ARGS)
> {
>     PG_RETURN_POINTER(& testfmt_copyto_handler);
> }

Interesting. But I feel that it introduces another (a bit)
tricky mechanism...

BTW, we also need to set .type:

     .routine = COPYTO_ROUTINE (
         .type = T_CopyToFormatRoutine,
         .start_fn = testfmt_copyto_start,
         .onerow_fn = testfmt_copyto_onerow,
         .end_fn = testfmt_copyto_end
         )


Thanks,
-- 
kou


Reply via email to