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

Initialising bit values inside stored procedure.

From: HK <harikrishnan(at)midascomm(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Initialising bit values inside stored procedure.
Date: 2003-03-21 13:06:01
Message-ID: Pine.LNX.4.33.0303211739210.5295-100000@mallard.midascomm.com (view raw or flat)
Thread:
Lists: pgsql-novice
hi all,
	I have a table 
	privileges (version text, profile text, 
	            readbits bit[], writebits bit[]);

The readbits and writebits is 4000 bits long.

The operation i am trying to do is.
(eg) insert into privileges (version, profile) values ('ver100', 'prf100');
For version ver100 and profile prf100 the readbits and writebits must have all 
bits set to 0.

So i wrote a stored procedure which will update the bitsets.

create function testproc(text,text) returns int as '
declare 
version alias for $1;
profile alias for $2;
flatbits text;
count int := 0;

begin
flatbits = ''\\\'{''; 
-- for inserting the '{ in the array
while count < 4000
loop
	flatbits = flatbits||''0,'';
	count := count + 1;
end loop;
flatbits = flatbits||''}\\\''';
-- for closing the bit set }'
end;

insert into privileges(version, profile, flatbits, flatbits);

' language 'plpgsql';


When i try to run this as 
testdb=# select testproc('ver100', 'prf100');
ERROR: Attribute 'readbits' is of type '_bit' but expression is of type 'text'
You will need to rewrite or cast the expression

Casting the value to bit in stored procedure also doesnt help.
i used 
insert into privileges(version, profile, flatbits::bit[], flatbits::bit[]);

ERROR: Cannot case type 'text' to '_bit'

Can anybody help me in this regard.

TIA.
-- 
regards,
hari
      __
     / /    __  _  _  _  _ __  __         -o) 
    / /__  / / / \\// //_// \\ \\/ /         /\\\\  Making things happen
   /____/ /_/ /_/\\/ /___/  /_/\\_\\        _\\_v-  


pgsql-novice by date

Next:From: Tom LaneDate: 2003-03-21 14:44:57
Subject: Re: age / timestamp
Previous:From: A.BhuvaneswaranDate: 2003-03-21 12:13:03
Subject: Re: table sequence

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