Thread

  1. Bitwise operators in SQL

    Arcady Genkin <a.genkin@utoronto.ca> — 2001-05-25T16:17:19Z

    I'm writing SQL code for dynamic page generation in PHP.  I'd like to
    be able to determine whether a certain class of users has access to
    certain pages.  I was thinking of doing it the usual way: set
    bitmasks, e.g. STUDENT=1, INSTRUCTOR=2, STAFF=4, etc., and store
    permissions from bitwise AND of applicable masks in the table that
    keeps info about each page.  But the problem is that there are no
    bitwise operators among Postgres's supported operators.  So, I cannot
    write something like
    
    select name from pages where access&2>0;
    
    Is there a standard way to approach this kind of problem?
    
    Many thanks,
    -- 
    Arcady Genkin
    
    
  2. Re: Bitwise operators in SQL

    Peter Eisentraut <peter_e@gmx.net> — 2001-05-25T18:12:22Z

    Arcady Genkin writes:
    
    > But the problem is that there are no
    > bitwise operators among Postgres's supported operators.  So, I cannot
    > write something like
    >
    > select name from pages where access&2>0;
    >
    > Is there a standard way to approach this kind of problem?
    
    Upgrading.
    
    -- 
    Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter
    
    
    
  3. Re: Bitwise operators in SQL

    Arcady Genkin <a.genkin@utoronto.ca> — 2001-05-25T20:25:11Z

    Peter Eisentraut <peter_e@gmx.net> writes:
    
    > Arcady Genkin writes:
    > 
    > > But the problem is that there are no
    > > bitwise operators among Postgres's supported operators.  So, I cannot
    > > write something like
    > >
    > > select name from pages where access&2>0;
    > >
    > > Is there a standard way to approach this kind of problem?
    > 
    > Upgrading.
    
    Indeed, thanks.  I was reading the docs for 7.0, and didn't notice
    that 7.1 has bitwise operators.
    
    Thanks a lot,
    -- 
    Arcady Genkin