Unix Technical Forum

SELECT Rules or stored procedure

This is a discussion on SELECT Rules or stored procedure within the Pgsql General forums, part of the PostgreSQL category; --> I have a query that takes two tables (join) and does something on it. Lets say these tables are ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 08:54 AM
Assad Jarrahian
 
Posts: n/a
Default SELECT Rules or stored procedure

I have a query that takes two tables (join) and does something on it.
Lets say these tables are A and B.
What I need is that everytime one of the tables (A) has its rows
selected, I want to update the count (which is a column in A) for that
row.

I am not sure what is the best way to do this.
1)I could create a dummy view and do a RULE on that (I am not sure how
to get access to the row's that have been selected).
2) I could create a storedprocedure. Get all the rows to be returned
and then, loop through the rows and update the column and then return
it.

Q1) Which way is better?
q2) How does one get access to the rows just selected in the CREATE
RULE computation?

thanks.
-assad

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 08:56 AM
Jim C. Nasby
 
Posts: n/a
Default Re: SELECT Rules or stored procedure

On Tue, Jan 17, 2006 at 09:55:42PM -0700, Assad Jarrahian wrote:
> I have a query that takes two tables (join) and does something on it.
> Lets say these tables are A and B.
> What I need is that everytime one of the tables (A) has its rows
> selected, I want to update the count (which is a column in A) for that
> row.
>
> I am not sure what is the best way to do this.
> 1)I could create a dummy view and do a RULE on that (I am not sure how
> to get access to the row's that have been selected).
> 2) I could create a storedprocedure. Get all the rows to be returned
> and then, loop through the rows and update the column and then return
> it.
>
> Q1) Which way is better?
> q2) How does one get access to the rows just selected in the CREATE
> RULE computation?


Via NEW and OLD. Read Chapter 34 of the documentation.
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 08:57 AM
Andrew - Supernews
 
Posts: n/a
Default Re: SELECT Rules or stored procedure

On 2006-01-19, "Jim C. Nasby" <jnasby@pervasive.com> wrote:
> On Tue, Jan 17, 2006 at 09:55:42PM -0700, Assad Jarrahian wrote:
>> q2) How does one get access to the rows just selected in the CREATE
>> RULE computation?

>
> Via NEW and OLD. Read Chapter 34 of the documentation.


He's talking about a SELECT rule. A SELECT rule is no more and no less than
a view - you can do nothing with select rules that you can't do with a
normal view.

(You can only have one SELECT rule, it must be named _RETURN, and it must
be a DO INSTEAD SELECT rule. If you put such a rule on a plain table, you
will find that the table changes into a view.)

--
Andrew, Supernews
http://www.supernews.com - individual and corporate NNTP services
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:32 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com