Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.postgresql > #609

help with stored procedure

X-Received by 10.182.2.39 with SMTP id 7mr15479950obr.45.1416248989592; Mon, 17 Nov 2014 10:29:49 -0800 (PST)
X-Received by 10.50.118.9 with SMTP id ki9mr305913igb.16.1416248989503; Mon, 17 Nov 2014 10:29:49 -0800 (PST)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!h15no2125238igd.0!news-out.google.com!c9ni14081igv.0!nntp.google.com!h15no2125230igd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.databases.postgresql
Date Mon, 17 Nov 2014 10:29:48 -0800 (PST)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=98.119.130.248; posting-account=Ju0XtgoAAAAC2pZPNDXfkUL2Bdc0lSuk
NNTP-Posting-Host 98.119.130.248
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <99fbb4b4-ba4d-4351-bd9d-8c33fd978489@googlegroups.com> (permalink)
Subject help with stored procedure
From David Gerber <gerbdla@gmail.com>
Injection-Date Mon, 17 Nov 2014 18:29:49 +0000
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com comp.databases.postgresql:609

Show key headers only | View raw


I have the following stored procedure.  
 def up
    execute <<-SPROC
      CREATE OR REPLACE function Adjusters_By_Team_Count (IN org_id int, IN start_timestamp timestamp, IN end_timestamp timestamp, IN approve_deny bigint, IN deny_approve bigint)

      RETURNS TABLE (
          user_id int,
          user_first_name varchar,
          user_last_name varchar,
          name varchar,
          action varchar,
          count bigint,
          decision varchar,
          denial_approval_count bigint,
          approval_denial_count bigint
         )
       AS $$

         SELECT users.id AS user_id, users.first_name AS user_first_name, users.last_name AS user_last_name,
         teams.name as team_name, action as action,count(dg.id) AS count,decision as decision, CAST(0 AS BIGINT),CAST(0 AS BIGINT)

    FROM determination_groups dg
         JOIN reviews rev  ON dg.review_id = rev.id
         JOIN users users  ON rev.user_id = users.id
         JOIN team_members ON users.id = team_members.user_id
         JOIN teams ON teams.id = team_members.team_id
       WHERE dg.action IS NOT NULL AND
        rev.organization_id = $1 AND
        rev.created_at >= $2 AND rev.created_at <= $3

    GROUP BY users.id,action,teams.name,decision
    ORDER BY users.id DESC



    RETURN;
    $$ LANGUAGE sql;
    SPROC
  end

I have two fields that need to be incremented based on value of two fields
so basically if action and decision = true then make denial_approval_count + 1.  I am thinking I would query the created table with some kind of cursor after the the order by function but I am new to psql.  Thanks any help would be great!

Back to comp.databases.postgresql | Previous | Next | Find similar


Thread

help with stored procedure David Gerber <gerbdla@gmail.com> - 2014-11-17 10:29 -0800

csiph-web