Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > PostgreSQL > CREATE OR REPLACE RULE my_view

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-26-07, 15:18
dbtomek dbtomek is offline
Registered User
 
Join Date: Aug 2005
Posts: 15
Red face CREATE OR REPLACE RULE my_view

Greetings!
I'm in some desperate need of help creating a rule on a view.

I've created a view:
Code:
CREATE VIEW init_contact_view AS SELECT * FROM init_contact -- roaster_grinders is has only 1 col: 'roasters_grinders_id' bigint LEFT OUTER JOIN roasters_grinders ON init_contact.contact_id = roasters_grinders.roasters_grinders_id;
... selecting from it works fine:
Code:
SELECT * FROM init_contact_view ORDER BY contact_id;

... here's where the problems starts, sometimes the view contains nulls in the 'roasters_grinders_id' col and I need to have bigint of -1 value instead.

So I'm trying to replace all nulls with bigints and I've tried several times to create a rule for, but keep screwing something up. Yes, I'm very new at this and I'd really appreciate any feedback/help.

Here's where I've given up for the moment:
Code:
CREATE OR REPLACE RULE update_my_view AS ON SELECT TO init_contact_view DO instead update SET roasters_grinders.roasters_grinders_id = '-1' WHERE roasters_grinders_id IS NULL;
It gives th is: ERROR: syntax error at or near "roasters_grinders"

Yes, I'm very new at this and I'd really appreciate any feedback/help.

Thank you in advance.
Reply With Quote
  #2 (permalink)  
Old 06-26-07, 17:12
rski rski is offline
Registered User
 
Join Date: Nov 2006
Posts: 12
Maybe it's because u write

set roasters_grinders.roasters_grinders_id = '-1'

change the definition to
CREATE OR REPLACE RULE update_my_view AS ON
SELECT TO init_contact_view
DO instead update roasters_grinders
SET roasters_grinders_id = '-1'
WHERE roasters_grinders_id IS NULL;

PS
Jestes z Polski ?
Reply With Quote
  #3 (permalink)  
Old 06-26-07, 17:28
dbtomek dbtomek is offline
Registered User
 
Join Date: Aug 2005
Posts: 15
... tak, dzieki ;-)
Reply With Quote
  #4 (permalink)  
Old 07-11-07, 15:09
dbtomek dbtomek is offline
Registered User
 
Join Date: Aug 2005
Posts: 15
I got it to work, but silly me, all I really needed was the coalesce() function when selecting from the view and creating a join:

coalesce ( roasters_grinders_id, -1 ) as roasters_grinders_id,

... so I get a 'temporary' -1 instead of a null.
t
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On