[SQL] adding not null constraints on columns

2003-02-11 Thread Susan
Title: Message



Is there a way to add not null constraints 
on a column after the column has been created?  Any help would be 
appreciated.  Thanks.
 


The most likely way for the world to be destroyed, most experts agree, is by 
accident. That's where we come in; we're computer professionals. We cause 
accidents. 
Nathaniel Borenstein (1957 - )
 
[EMAIL PROTECTED]

 
<><><>

Re: [SQL] Create function statement with insert statement

2003-03-17 Thread Susan Hoddinott
Hi Chris,

Pleased to (finally) report success.  Here are the solutions:

INSERT
-
DROP FUNCTION orderinsert() ;

CREATE OR REPLACE FUNCTION orderinsert() RETURNS OPAQUE AS '
BEGIN
   IF NEW.CUSTOMER_ID ISNULL THEN
  RAISE EXCEPTION "CUSTOMER_ID cannot be NULL value" ;
   END IF ;
   IF NEW.CUSTOMER_SESSION ISNULL THEN
  RAISE EXCEPTION "CUSTOMER_SESSION cannot be NULL value" ;
   END IF ;

   INSERT INTO HEXORDERS ( CUSTOMER_ID, ORDER_KEY, DISTRIBUTOR_ID,
ORDER_AMOUNT, ORDER_GST )
   VALUES ( NEW.CUSTOMER_ID, NEW.CUSTOMER_SESSION, 1, 0, 0 ) ;

   RETURN NEW ;
END ;
' LANGUAGE 'plpgsql' ;


DROP TRIGGER HEXCUST_TRIGGER1 ON HEXCUSTOMERS;

CREATE TRIGGER HEXCUST_TRIGGER1
AFTER INSERT ON HEXCUSTOMERS
FOR EACH ROW EXECUTE PROCEDURE orderinsert() ;


UPDATE
--
DROP FUNCTION orderupdate() ;

CREATE OR REPLACE FUNCTION orderupdate() RETURNS OPAQUE AS '
BEGIN
   IF NEW.ORDER_ID ISNULL THEN
  RAISE EXCEPTION ''ORDER_ID cannot be NULL value'' ;
   END IF ;
   IF NEW.CUSTOMER_ID ISNULL THEN
  RAISE EXCEPTION ''CUSTOMER_ID cannot be NULL value'' ;
   END IF ;

   UPDATE HEXORDERS
  SET ORDER_AMOUNT =

   SELECT SUM(CUSTITEM_QUANTITY * (ITEM_BASEPRICE +
((CUSTITEM_USERS - 1) * ITEM_USEPRICE)))
   FROM HEXCUSTITEMS, HEXITEMS
   WHERE HEXCUSTITEMS.CUSTOMER_ID = NEW.CUSTOMER_ID
   AND HEXCUSTITEMS.ORDER_ID = NEW.ORDER_ID
   AND HEXCUSTITEMS.ITEM_ID = HEXITEMS.ITEM_ID
   GROUP BY HEXCUSTITEMS.ORDER_ID,
HEXCUSTITEMS.CUSTOMER_ID ),
  ORDER_GST =

  SELECT SUM((CUSTITEM_QUANTITY * (ITEM_BASEPRICE +
((CUSTITEM_USERS - 1) * ITEM_USEPRICE))) * .1::numeric)
  FROM HEXCUSTITEMS, HEXITEMS
  WHERE HEXCUSTITEMS.CUSTOMER_ID = NEW.CUSTOMER_ID
  AND HEXCUSTITEMS.ORDER_ID = NEW.ORDER_ID
  AND HEXCUSTITEMS.ITEM_ID = HEXITEMS.ITEM_ID
  AND CUSTITEM_GST = TRUE
  GROUP BY HEXCUSTITEMS.ORDER_ID, HEXCUSTITEMS.CUSTOMER_ID )
   WHERE ORDER_ID = NEW.ORDER_ID
   AND CUSTOMER_ID = NEW.CUSTOMER_ID ;

   RETURN NEW ;
END ;
' LANGUAGE 'plpgsql' ;

DROP TRIGGER HEXCUSTITEMS_TRIGGER1 ON HEXCUSTITEMS;

CREATE TRIGGER HEXCUSTITEMS_TRIGGER1
AFTER INSERT OR UPDATE ON HEXCUSTITEMS
FOR EACH ROW EXECUTE PROCEDURE orderupdate() ;

DROP TRIGGER HEXCUSTITEMS_TRIGGER3 ON HEXCUSTITEMS;

CREATE TRIGGER HEXCUSTITEMS_TRIGGER3
AFTER DELETE ON HEXCUSTITEMS
FOR EACH ROW EXECUTE PROCEDURE orderupdate() ;

I still need to test each case but it now creates without errors.  Thanks
for all your assistance.

Regards



- Original Message -
From: "Christoph Haller" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, March 17, 2003 7:25 PM
Subject: Re: [SQL] Create function statement with insert statement


> >
> > I can select from this table although the output is slightly
> different:
> >
> >  lanname  | lanispl | lanpltrusted | lanplcallfoid | lancompiler
> > --+-+--+---+-
> >  internal | f   | f| 0 | n/a
> >  C| f   | f| 0 | /bin/cc
> >  sql  | f   | f| 0 | postgres
> > (3 rows)
> >
> That's ok, it changed slightly between versions.
>
> Did you make any progress?
>
> >
> > Try re-writing your function in PL/pgSQL. BTW, I think I saw from your
>
> > other post that you don't have PL/pgSQL installed in the database you
> > are using. See the createlang program or CREATE LANGUAGE statement:
> >
>
http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/app-createlang.h
tml
>
> >
>
http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/sql-createlangua
ge.html
>
> >
> I think Joe is right. Try PL/pgSQL, it's much more flexible anyway.
>
> Regards, Christoph
>
>
>
> ---(end of broadcast)---
> TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly


[SQL] unsubscribe

2007-02-08 Thread Susan Evans

Unsubscribe



Susan Evans
Haywood County Schools
NCWISE Coordinator
216 Charles Street
Clyde, NC 28721

828-627-8314 (Phone)
828-627-8277 (Fax)
216 Charles Street
Clyde, NC 28721




---(end of broadcast)---
TIP 6: explain analyze is your friend


[SQL] unsubscribe

2007-03-15 Thread Susan Evans

unsubscribe

--
Susan Evans
Haywood County Schools
NCWISE Coordinator
216 Charles Street
Clyde, NC 28721

828-627-8314 (Phone)
828-627-8277 (Fax)
216 Charles Street
Clyde, NC 28721




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

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


[SQL] unsubscribe

2007-03-22 Thread Susan Evans

unsubscribe

--
Susan Evans
Haywood County Schools
NCWISE Coordinator
216 Charles Street
Clyde, NC 28721

828-627-8314 (Phone)
828-627-8277 (Fax)
216 Charles Street
Clyde, NC 28721




---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
  choose an index scan if your joining column's datatypes do not
  match