Re: [SQL] May I have an assistance on CREATE TABLE Command

2008-09-17 Thread Bart Degryse
I think (one of) the point(s) of id fields is not to change them. You can update the region_name field (eg a correct a misspelling), but the id stays the same. That way the district stays connected to the same region. >>> James Kitambara <[EMAIL PROTECTED]> 2008-09-17 8:50 >>> Hello Mambers o

Re: [SQL] May I have an assistance on CREATE TABLE Command

2008-09-17 Thread James Kitambara
  Thank you !   But I think that there is a solution.   If it happens that you have the following data in your tables REGION -- region_id  | region_name --    11| Dodoma    22| Tabora    99    | Dar es Salaa

Re: [SQL] May I have an assistance on CREATE TABLE Command

2008-09-17 Thread Richard Huxton
James Kitambara wrote: > For this UPDATE I wanted, when I change the region _id from '99' to > '33' of the last ROW in REGION table AUTOMATICALLY to change the > last three ROWS of the DISTRICT table which reference to '99', 'Dar > es Salaam'. > > If I do this, I will get the error message "You

Re: [SQL] May I have an assistance on CREATE TABLE Command

2008-09-17 Thread Bart Degryse
The idea of id's is that they are meaningless, so saying "this row was supposed to be 33" is senseless. If you want Dar es Salaam to be 33 because eg it's the postal code, then add a column postal_code to your region table but keep the id to make the reference. >>> James Kitambara <[EMAIL PROTEC

Re: [SQL] surrogate vs natural primary keys

2008-09-17 Thread Seb
On Tue, 16 Sep 2008 20:34:51 -0600, "Scott Marlowe" <[EMAIL PROTECTED]> wrote: [...] > create table t2 ( > d1 varchar(200), > d2 int8, > d3 varchar(1000), > foreign key t2_fk references t1(c1,c2) ); Thanks Scott, I guess you meant: CREATE TABLE t2 ( d1 varchar(200), d2 i

Re: [SQL] surrogate vs natural primary keys

2008-09-17 Thread Scott Marlowe
On Wed, Sep 17, 2008 at 7:20 AM, Seb <[EMAIL PROTECTED]> wrote: > On Tue, 16 Sep 2008 20:34:51 -0600, > "Scott Marlowe" <[EMAIL PROTECTED]> wrote: > > [...] > >> create table t2 ( >> d1 varchar(200), >> d2 int8, >> d3 varchar(1000), >> foreign key t2_fk references t1(c1,c2) ); > > T

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2008-09-17 Thread Raphael Bauduin
HI, On Sat, Aug 11, 2007 at 9:07 PM, hubert depesz lubaczewski <[EMAIL PROTECTED]> wrote: > On Sat, Aug 11, 2007 at 02:45:09AM -0500, Javier Fonseca V. wrote: >> I think that it's working alright except for the next line: > > doing this in plpgsql is very complicated (or even impossible assuming >

Re: [SQL] surrogate vs natural primary keys

2008-09-17 Thread Richard Broersma
On Wed, Sep 17, 2008 at 7:45 AM, Scott Marlowe <[EMAIL PROTECTED]> wrote: >> CREATE TABLE t2 ( >>d1 varchar(200), >>d2 int8, >>d3 varchar(1000), >>PRIMARY KEY (d1, d2) >>FOREIGN KEY (d1, d2) REFERENCES t1(c1, c2) ); >> >> thereby avoiding repeating multiple pieces of >> informa

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2008-09-17 Thread Raphael Bauduin
On Wed, Sep 17, 2008 at 5:45 PM, hubert depesz lubaczewski <[EMAIL PROTECTED]> wrote: > On Wed, Sep 17, 2008 at 05:08:39PM +0200, Raphael Bauduin wrote: >> Would you have a little example on how you would do it? > > show us what you have done - it will be easier to find/fix/explain than > to write

[SQL] prepared query plan did not update

2008-09-17 Thread Emi Lu
Good morning, I tried to use prepared query plan to update columns, but it did not update at all. PREPARE pname(varchar) AS UPDATE t1 SETcol1 = false WHERE col1 AND col2 = '$1' ; EXECUTE pname( 'value' ) Could someone tell me where I did wrong please? Thanks alot! -- Sent vi

Re: [SQL] prepared query plan did not update

2008-09-17 Thread Igor Neyman
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Emi Lu Sent: Wednesday, September 17, 2008 2:55 PM To: pgsql-sql@postgresql.org Subject: [SQL] prepared query plan did not update Good morning, I tried to use prepared query plan to update columns, but i

Re: [SQL] prepared query plan did not update

2008-09-17 Thread Emi Lu
I tried to use prepared query plan to update columns, but it did not update at all. PREPARE pname(varchar) AS UPDATE t1 SETcol1 = false WHERE col1 AND col2 = '$1' ; EXECUTE pname( 'value' ) Could someone tell me where I did wrong please? WHERE col1 AND col2 = '$1' ; Are

Re: [SQL] prepared query plan did not update

2008-09-17 Thread Stephan Szabo
On Wed, 17 Sep 2008, Emi Lu wrote: > Good morning, > > I tried to use prepared query plan to update columns, but it did not > update at all. > > PREPARE pname(varchar) AS > UPDATE t1 > SETcol1 = false > WHERE col1 AND > col2 = '$1' ; I don't think you want those quotes in the second

Re: [SQL] prepared query plan did not update

2008-09-17 Thread Emi Lu
Stephan Szabo wrote: On Wed, 17 Sep 2008, Emi Lu wrote: Good morning, I tried to use prepared query plan to update columns, but it did not update at all. PREPARE pname(varchar) AS UPDATE t1 SETcol1 = false WHERE col1 AND col2 = '$1' ; I don't think you want those quotes in the

Re: [SQL] prepared query plan did not update

2008-09-17 Thread Stephan Szabo
On Wed, 17 Sep 2008, Emi Lu wrote: > Stephan Szabo wrote: > > On Wed, 17 Sep 2008, Emi Lu wrote: > > > >> Good morning, > >> > >> I tried to use prepared query plan to update columns, but it did not > >> update at all. > >> > >> PREPARE pname(varchar) AS > >> UPDATE t1 > >> SETcol1 = false > >

Re: [SQL] May I have an assistance on CREATE TABLE Command

2008-09-17 Thread Robert Edwards
You could: INSERT INTO REGION VALUES (33, 'New Dar'); UPDATE DISTRICT SET region_id = 33 WHERE region_id = 99; DELETE FROM REGION WHERE region_id = 99; UPDATE REGION SET region_name = 'Dar es Salaam' WHERE region_id = 33; Of course, if there is no uniqueness constraint on region_name then yo

Re: [SQL] surrogate vs natural primary keys

2008-09-17 Thread Steve Midgley
To: pgsql-sql@postgresql.org From: Seb <[EMAIL PROTECTED]> Subject: Re: surrogate vs natural primary keys Date: Mon, 15 Sep 2008 17:56:31 -0500 Organization: Church of Emacs Lines: 20 Message-ID: <[EMAIL PROTECTED]> References: <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> X-Archive-Numbe