Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group