Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql insert into bytea field

Tags:

postgresql

I have procedure:

create or replace function add_task( _g uuid, _name character varying, _ind bytea, _rate integer, _type integer )
returns void as 
$$
begin       
    insert into tasks (g, name, ind, rate, type) values (_g, _name, _ind, _rate, _type);    
end;
$$
language plpgsql;

I need to insert bytea field (_ind). The data is represented as bytes sequence and may be various.

std::vector<uint8_t> data = { 0x01, 0x02, 0x03 };
tr.exec("SELECT add_task_type('" + guid + "', '" + name + "', ......

How I can insert bytea field using SELECT string query?

like image 556
Ir S Avatar asked Apr 13 '26 11:04

Ir S


1 Answers

The most straight forward way would be to use hex format.

SELECT E'\\xDEADBEEF';

See http://www.postgresql.org/docs/9.1/static/datatype-binary.html#AEN5285

like image 133
hruske Avatar answered Apr 16 '26 03:04

hruske



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!