Thread

  1. Using PL/pgSQL text argument in 'IN (INT,INT,...)' clause

    Axel Rau <axel.rau@chaos1.de> — 2010-10-25T10:14:22Z

    Good morning,
    
    I have a function argument blah of type text containing something like
         33,44,55,66
    . Can I cast it in some way to use it in an IN clause as integers like
         UPDATE foo SET x = y WHERE id IN ( blah );
    or need I revert to dynamic SQL (EXECUTE...) ?
    
    Thanks, Axel
    ---
    axel.rau@chaos1.de  PGP-Key:29E99DD6  +49 151 2300 9283  computing @  
    chaos claudius
    
    
    
  2. Re: Using PL/pgSQL text argument in 'IN (INT,INT,...)' clause

    Dmitry Igrishin <dmitigr@gmail.com> — 2010-10-29T17:07:16Z

    Hey Axel,
    
    How about this solution:
    UPDATE foo SET x = y WHERE ANY(string_to_array(blah, ',')) = id;
    ?
    
    2010/10/25 Axel Rau <Axel.Rau@chaos1.de>
    
    > Good morning,
    >
    > I have a function argument blah of type text containing something like
    >    33,44,55,66
    > . Can I cast it in some way to use it in an IN clause as integers like
    >    UPDATE foo SET x = y WHERE id IN ( blah );
    > or need I revert to dynamic SQL (EXECUTE...) ?
    >
    > Thanks, Axel
    > ---
    > axel.rau@chaos1.de  PGP-Key:29E99DD6  +49 151 2300 9283  computing @ chaos
    > claudius
    >
    >
    > --
    > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
    > To make changes to your subscription:
    > http://www.postgresql.org/mailpref/pgsql-sql
    >
    
    
    
    -- 
    // Dmitriy.
    
  3. Re: Using PL/pgSQL text argument in 'IN (INT,INT,...)' clause

    Dmitry Igrishin <dmitigr@gmail.com> — 2010-10-29T17:11:31Z

    Ooops, sorry
    UPDATE foo SET x = y WHERE id = ANY(string_to_array(blah, ',')::integer[]);
    
    2010/10/29 Dmitriy Igrishin <dmitigr@gmail.com>
    
    > Hey Axel,
    >
    > How about this solution:
    > UPDATE foo SET x = y WHERE ANY(string_to_array(blah, ',')) = id;
    > ?
    >
    > 2010/10/25 Axel Rau <Axel.Rau@chaos1.de>
    >
    > Good morning,
    >>
    >> I have a function argument blah of type text containing something like
    >>    33,44,55,66
    >> . Can I cast it in some way to use it in an IN clause as integers like
    >>    UPDATE foo SET x = y WHERE id IN ( blah );
    >> or need I revert to dynamic SQL (EXECUTE...) ?
    >>
    >> Thanks, Axel
    >> ---
    >> axel.rau@chaos1.de  PGP-Key:29E99DD6  +49 151 2300 9283  computing @
    >> chaos claudius
    >>
    >>
    >> --
    >> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
    >> To make changes to your subscription:
    >> http://www.postgresql.org/mailpref/pgsql-sql
    >>
    >
    >
    >
    > --
    > // Dmitriy.
    >
    >
    >
    
    
    -- 
    // Dmitriy.