how to traverse a bytea value in pl/pgsql

From: "Jules Alberts" <jules(dot)alberts(at)arbodienst-limburg(dot)nl>
To: pgsql-novice(at)postgresql(dot)org
Subject: how to traverse a bytea value in pl/pgsql
Date: 2002-12-18 09:30:26
Message-ID: 200212180930.gBI9UYbH025680@artemis.cuci.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello everyone,

I'm working on a function that will give me the table + column another
table + column is referenced to. The function looks like this:

---------------------------------------------------------
create function getreftable(text, text) returns text as '
declare
TABL alias for $1;
COLM alias for $2;
rs RECORD;
begin
for rs in select tgnargs, tgargs from pg_trigger join pg_class
on tgrelid=pg_class.oid
where tgisconstraint = true and relname = TABL loop
-- check out tgargs
end loop;
return ''FIXME'';
end;
' language 'plpgsql'
---------------------------------------------------------

The selection works fine, but now I have to find a way to traverse
tgargs. It's of the datatype "bytea" (which sounds C-ish, but I'm not a
C programmer) and has a value like:

<unnamed>\000cust\000land\000UNSPECIFIED\000land\000code

I'm looking for something like this (in a sort of semi-code):

SEPERATOR := ''\000'';
FOR (i := 1; i <= rs.tgnargs; i++) {
raise notice ''%'', byteaslice(rs.tgargs, SEPERATOR, i);
}

I experimented with functions like byteacat(), strpos(), substr() etc.,
but none does what I want. Can anybody tell me how to do this? Thanks a
lot IA!

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Jules Alberts 2002-12-18 10:28:52 Re: how to traverse a bytea value in pl/pgsql
Previous Message Tommy Eriksson 2002-12-18 08:31:18 Default transaction isolation level.