Re: Composite types as parameters

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Composite types as parameters
Дата
Msg-id 8732.1624807614@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Composite types as parameters  (Elijah Stone <elronnd@elronnd.net>)
Ответы Re: Composite types as parameters  (Elijah Stone <elronnd@elronnd.net>)
Список pgsql-hackers
Elijah Stone <elronnd@elronnd.net> writes:
> On Sat, 26 Jun 2021, Tom Lane wrote:
>> If it still doesn't work, please provide a more concrete example.

> Thanks, unfortunately adding the explicit cast doesn't help.  I've 
> attached a minimal runnable example.

So your problem is that you're explicitly saying that the input is
of generic-RECORD type.  You should let the server infer its type,
instead, which it can easily do from context in this example.
That is, pass zero as the type OID, or leave out the paramTypes
array altogether.  The example works for me with this change:

@@ -30,13 +30,13 @@
 
        // error:
        check(PQexecParams(c, "INSERT INTO tab VALUES($1, 8);",
-                       1, &(Oid){RECORDOID}, &(const char*){recbuf},
+                       1, &(Oid){0}, &(const char*){recbuf},
                        &(int){rec - recbuf}, &(int){1/*binary*/},
                        1/*binary result*/));
 
        // error as well:
        check(PQexecParams(c, "INSERT INTO tab VALUES($1::some_record, 8);",
-                       1, &(Oid){RECORDOID}, &(const char*){recbuf},
+                       1, &(Oid){0}, &(const char*){recbuf},
                        &(int){rec - recbuf}, &(int){1},
                        1));

In more complicated cases you might need to fetch the composite
type's actual OID and pass that.  But I'd go with the lazy approach
until forced to do differently.

> Is there a 
> way to discover the OID of a composite type?  And is the wire format the 
> same as for a generic record?

Same as for any other type: SELECT 'mytypename'::regtype::oid.
And yes.

            regards, tom lane



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Julien Rouhaud
Дата:
Сообщение: Re: Deparsing rewritten query
Следующее
От: Peter Geoghegan
Дата:
Сообщение: Re: Farewell greeting