SPI_execute_plan and vardata

Started by Арсен Арутюнянalmost 9 years ago3 messagesgeneral
Jump to latest

Hello

I can't:convert char* to Datum

Datum Values[2];

Values[0]-is integer type 
but Values[1] is string type so 

Values[0] = SET_4_BYTES(227);

please assist how can i convert som char* string to Datum

Values[1] = CONVERT_STRING_TO DATUM(char *); etc

best
--
Арсен Арутюнян

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Арсен Арутюнян (#1)
Re: SPI_execute_plan and vardata

=?UTF-8?B?0JDRgNGB0LXQvSDQkNGA0YPRgtGO0L3Rj9C9?= <arutar@bk.ru> writes:

Datum Values[2];

Values[0]-is integer type 
but Values[1] is string type so 

Values[0] = SET_4_BYTES(227);

This is really bad practice. It might accidentally work, but the
right way to do it is more like

Values[0] = Int32GetDatum(227);

or possibly Int64GetDatum if you're thinking of bigint rather than int4.

please assist how can i convert som char* string to Datum

You're not being too clear about which "string type" you have in mind,
but if it's text, good practice would be

Values[1] = CStringGetTextDatum(char-*-ptr);

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

In reply to: Tom Lane (#2)
Re[2]: [GENERAL] SPI_execute_plan and vardata

Thank you

next question - how i can call pg_notify or NOTIFY query from c function

Arsen

Show quoted text

Пятница, 23 июня 2017, 0:33 +03:00 от Tom Lane <tgl@sss.pgh.pa.us>:

=?UTF-8?B?0JDRgNGB0LXQvSDQkNGA0YPRgtGO0L3Rj9C9?= < arutar@bk.ru > writes:

Datum Values[2];

Values[0]-is integer type 
but Values[1] is string type so 

Values[0] = SET_4_BYTES(227);

This is really bad practice. It might accidentally work, but the
right way to do it is more like

Values[0] = Int32GetDatum(227);

or possibly Int64GetDatum if you're thinking of bigint rather than int4.

please assist how can i convert som char* string to Datum

You're not being too clear about which "string type" you have in mind,
but if it's text, good practice would be

Values[1] = CStringGetTextDatum(char-*-ptr);

regards, tom lane