Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > column default ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 3556 of 3717
Post > Topic >>

column default dependant on another columns value

by fhevia@[EMAIL PROTECTED] ("Fernando Hevia") Jul 1, 2008 at 05:12 PM

Hi list,
 
Given a table with columns seconds and minutes, how can I have minutes be
computed automatically at the insert statement?
 
I tried:
 
ALTER TABLE table1 ALTER COLUMN minutes SET default (seconds/60);
 
Postgres' answer was:
ERROR:  cannot use column references in default expression
 
So I gave rules a look but it seems rules apply to the entire row.
 
CREATE RULE "my_rule" AS ON 
INSERT TO table1
WHERE minutes is null
DO INSTEAD 
INSERT INTO table1 (column1, column2, seconds, minutes) 
VALUES(new.column1, new.column2, new.seconds, new.seconds/60);
 
Is this correct? Is there another (better/simpler) way to achieve this?
 
Regards,
Fernando
 


-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 5 Posts in Topic:
column default dependant on another columns value
fhevia@[EMAIL PROTECTED]   2008-07-01 17:12:30 
Re: column default dependant on another columns value
richard.broersma@[EMAIL P  2008-07-01 13:44:46 
Re: column default dependant on another columns value
fhevia@[EMAIL PROTECTED]   2008-07-01 18:51:27 
Re: column default dependant on another columns value
tgl@[EMAIL PROTECTED] (T  2008-07-01 18:24:24 
Re: column default dependant on another columns value
fhevia@[EMAIL PROTECTED]   2008-07-02 10:52:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 4:10:21 CDT 2008.