PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 14th, 2003, 01:40 PM
cliffyman cliffyman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Washington DC, USA
Posts: 156 cliffyman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 7 sec
Reputation Power: 13
Send a message via AIM to cliffyman
help with table constraint

I have a table that is defined as follows:

Code:
  Column   |          Type          |                               Modifiers                                
-----------+------------------------+------------------------------------------------------------------------
 fs_id     | integer                | not null default nextval('public.extranet_filesystem_fs_id_seq'::text)
 parent_id | integer                | not null default 0
 fs_name   | character varying(255) | not null
 fs_type   | character varying(4)   | not null default 'file'
Indexes: extranet_filesystem_pkey primary key btree (fs_id),
         extranet_filesystem_u1 unique btree (parent_id, fs_name)
Check constraints: "extranet_filesystem_fs_type" ((fs_type = 'file'::character varying) OR (fs_type = 'dir'::character varying))
Foreign Key constraints: $1 FOREIGN KEY (parent_id) REFERENCES extranet_filesystem(fs_id) ON UPDATE CASCADE ON DELETE CASCADE


Basically, this table is mirroring a file system in a very simple way.

What I want to do is set up a constraint / check so that when a record is added, it takes the parent_id being passed in the INSERT statement, looks at the record whose fs_id equals the parent_id, and makes sure that the fs_type for that record is 'dir' and not 'file'.

Can I do this with standard constraints or do I need to use some PL/pgSQL features? Anyone have a few hints? Thanks!


-Cliff

Reply With Quote
  #2  
Old March 18th, 2003, 02:14 AM
ultraslacker's Avatar
ultraslacker ultraslacker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 56 ultraslacker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
You can define your own function (plpgsql or whatever) and use it in a CHECK constraint.

http://www.ca.postgresql.org/docs/a...ok/node132.html
__________________
Casuistry Agnostic

Reply With Quote
  #3  
Old March 18th, 2003, 11:43 AM
cliffyman cliffyman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Washington DC, USA
Posts: 156 cliffyman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 7 sec
Reputation Power: 13
Send a message via AIM to cliffyman
Thanks, that's exactly what I wanted to know. Time to delve into PL/pgsql!


-Cliff

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > help with table constraint

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap