Ir S
Ir S

Reputation: 495

postgresql insert into bytea field

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?

Upvotes: 3

Views: 5851

Answers (1)

hruske
hruske

Reputation: 2253

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

Upvotes: 3

Related Questions