[SQL] foreign key to multiple tables depending on another column's value

2013-05-29 Thread Rodrigo Rosenfeld Rosas
Sorry, I wasn't sure what list I should be sending this question to... I have a multi-tenant-like application. We have a fields tree that we call a template, with something like this: fields(id, parent_id, name) And several other related tables. Since we started to support multiple templates

Re: [SQL] foreign key is it a real key

2012-02-13 Thread John Fabiani
On Monday, February 13, 2012 04:50:47 PM Andreas Kretschmer wrote: > John Fabiani wrote: > > Hi, > > I have read a few articles and I'm not sure if it's me or the authors > > but I do not believe my question was answered. > > > > If I have table that has a PK and a FK - will the planner use the F

Re: [SQL] foreign key is it a real key

2012-02-13 Thread Andreas Kretschmer
John Fabiani wrote: > Hi, > I have read a few articles and I'm not sure if it's me or the authors but I > do > not believe my question was answered. > > If I have table that has a PK and a FK - will the planner use the FK just > same > as it would use the PK? IOW's is a FK also an index use

[SQL] foreign key is it a real key

2012-02-13 Thread John Fabiani
Hi, I have read a few articles and I'm not sure if it's me or the authors but I do not believe my question was answered. If I have table that has a PK and a FK - will the planner use the FK just same as it would use the PK? IOW's is a FK also an index used by the planner? I have a lagacy tab

Re: [SQL] foreign key question

2011-01-05 Thread Jasen Betts
On 2011-01-05, Gary Stainburn wrote: > On Wednesday 05 January 2011 09:53:43 Gary Stainburn wrote: >> Now I want to set up a new access level table specific to the itinerary, >> along the lines of >> >> u_id int4 not null references users(u_id) >> fl_level int4 not null references facility_levels(

Re: [SQL] foreign key question

2011-01-05 Thread Gary Stainburn
On Wednesday 05 January 2011 09:53:43 Gary Stainburn wrote: > Now I want to set up a new access level table specific to the itinerary, > along the lines of > > u_id int4 not null references users(u_id) > fl_level int4 not null references facility_levels(16, fl_level) > > Firstly, is this possible,

[SQL] foreign key question

2011-01-05 Thread Gary Stainburn
Hi folks, I have a table which lists facilities and another table that lists access levels for those facilities. All straight forward using a foreign key set up using a normal references clause. users=# select f_id, f_desc from facilities order by f_id; f_id | f_desc

[SQL] Foreign key constraint referencing a parent table

2010-05-04 Thread David Weilers
Hi, I have a problem when inserting rows into my table tblfactuurpost that references a table tblfactuur which is a parent to tblclientfactuur. The actual row is inserted into tblfactuur. The problem is that i cannot insert the row into tblfactuurpost (which references the parent table tblfac

Re: [SQL] Foreign key - Indexing & Deadlocking.

2009-12-29 Thread Craig Ringer
On 30/12/2009 6:59 AM, Andrew Hall wrote: Hi, I'm porting some Oracle software to PostgreSQL, & have a question about best practices with foreign keys. In the Oracle environment, you're basically obliged to index all foreign keys (more specifically foreign key columns should appear on the leadi

[SQL] Foreign key - Indexing & Deadlocking.

2009-12-29 Thread Andrew Hall
Hi, I'm porting some Oracle software to PostgreSQL, & have a question about best practices with foreign keys. In the Oracle environment, you're basically obliged to index all foreign keys (more specifically foreign key columns should appear on the leading edge of an index) due to the way that

Re: [SQL] Foreign key columns

2009-11-05 Thread Scott Marlowe
On Thu, Nov 5, 2009 at 2:08 PM, Svenne Krap wrote: > Hi. > > Is there a simple way to get foreign key data... for example I found a > view, that does what I want ... > > It delivers > >   fk_table   |     fk_column      |     pk_table      | pk_column |           > constraint_name > > ---

[SQL] Foreign key columns

2009-11-05 Thread Svenne Krap
Hi. Is there a simple way to get foreign key data... for example I found a view, that does what I want ... It delivers fk_table | fk_column | pk_table | pk_column | constraint_name --++---+---+

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread PostgreSQL Admin
No problems with the design - I was not thinking with the DB hat on at first. I have been working on clustering for a while... just adjusting. Thanks everyone. :) ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread A. Kretschmer
am Tue, dem 11.12.2007, um 14:12:38 -0500 mailte PostgreSQL Admin folgendes: > This is my layout so far: > [ table-layout] > ... > Does this look correct? Yes, why not? Do you have problems? Which? I can't see problems, it's a normalized design IMHO. Andreas -- Andreas Kretschmer Kontakt: Hey

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread Alvaro Herrera
PostgreSQL Admin wrote: > This is my layout so far: > > CREATE TABLE users ( > id serial NOT NULL, > --question REFERENCES questions(id) ON DELETE CASCADE ## ON REMOVED## > ); > > CREATE TABLE questions ( > id serial NOT NULL, > questions varchar(450) NOT NULL > ); > > CREATE TABLE answers ( > i

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread PostgreSQL Admin
This is my layout so far: CREATE TABLE users ( id serial NOT NULL, --question REFERENCES questions(id) ON DELETE CASCADE ## ON REMOVED## ); CREATE TABLE questions ( id serial NOT NULL, questions varchar(450) NOT NULL ); CREATE TABLE answers ( id serial NOT NULL, question_id int REFERENCES questi

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread A. Kretschmer
am Tue, dem 11.12.2007, um 13:20:52 -0500 mailte PostgreSQL Admin folgendes: > I have a table in which people will have a number of questions to > answer. I want those pk to be placed in my user table. So if a user > answers three question I want those 3 pk's in the user table (fk). > What s

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread Erik Jones
On Dec 11, 2007, at 12:20 PM, PostgreSQL Admin wrote: I have a table in which people will have a number of questions to answer. I want those pk to be placed in my user table. So if a user answers three question I want those 3 pk's in the user table (fk). What should I be doing? You're goi

[SQL] Foreign Key for multi PK or design question

2007-12-11 Thread PostgreSQL Admin
I have a table in which people will have a number of questions to answer. I want those pk to be placed in my user table. So if a user answers three question I want those 3 pk's in the user table (fk). What should I be doing? Thanks in advance, J ---(end of broadcast)

Re: [SQL] foreign key problem

2007-09-26 Thread Ashish Karalkar
- Original Message - From: "ivan marchesini" <[EMAIL PROTECTED]> To: Sent: Monday, September 24, 2007 6:04 PM Subject: [SQL] foreign key problem Dear users, I'm trying to create constraints into a db they give me from access... I'm using pgadmin to create

[SQL] foreign key problem

2007-09-24 Thread ivan marchesini
Dear users, I'm trying to create constraints into a db they give me from access... I'm using pgadmin to create a new foreign key for the relationship between two table.. I have a table called "generalita" wich contains a column called "cod_carg": ___ select cod_carg from generalita

Re: [SQL] foreign key pointing to diff schema?

2007-08-10 Thread gherzig
> On 8/10/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> Hi all. Can i make a FK who points a table in a different schema? Or >> this >> is implemented via a trigger by my own? > > Sure. just prefix the table name with the schemaname and a . > > create schema abc; > alter user me set search_p

Re: [SQL] foreign key pointing to diff schema?

2007-08-10 Thread Scott Marlowe
On 8/10/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi all. Can i make a FK who points a table in a different schema? Or this > is implemented via a trigger by my own? Sure. just prefix the table name with the schemaname and a . create schema abc; alter user me set search_path='abc', 'pub

[SQL] foreign key pointing to diff schema?

2007-08-10 Thread gherzig
Hi all. Can i make a FK who points a table in a different schema? Or this is implemented via a trigger by my own? Thanks! Gerardo ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail

Re: [SQL] Foreign Key inter databases

2007-08-03 Thread Erik Jones
On Aug 3, 2007, at 2:24 AM, Dani Castaños wrote: Josh Tolley escribió: On 8/2/07, Dani Castaños <[EMAIL PROTECTED]> wrote: Hi all! Is it possible to have a foreign key where referenced table is in another database? Thank you in advance ---(end of broadcast)--

Re: [SQL] Foreign Key inter databases

2007-08-03 Thread Dani Castaños
Josh Tolley escribió: On 8/2/07, Dani Castaños <[EMAIL PROTECTED]> wrote: Hi all! Is it possible to have a foreign key where referenced table is in another database? Thank you in advance ---(end of broadcast)--- TIP 1: if posting/reading thro

Re: [SQL] Foreign Key inter databases

2007-08-02 Thread Josh Tolley
On 8/2/07, Dani Castaños <[EMAIL PROTECTED]> wrote: > Hi all! > > Is it possible to have a foreign key where referenced table is in > another database? > > Thank you in advance > > ---(end of broadcast)--- > TIP 1: if posting/reading through Usenet, p

[SQL] Foreign Key inter databases

2007-08-02 Thread Dani Castaños
Hi all! Is it possible to have a foreign key where referenced table is in another database? Thank you in advance ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMA

Re: [SQL] Foreign key reference counting strategy?

2006-10-14 Thread Tom Lane
Michael Fuhr <[EMAIL PROTECTED]> writes: > My intent wasn't to assert that IF EXISTS adds a new way for the > DELETE to fail. I was just pointing out that the test "if no > referencing rows exist then delete the referenced row" isn't > foolproof, viz., the DELETE can fail even though IF EXISTS sai

Re: [SQL] Foreign key reference counting strategy?

2006-10-14 Thread Michael Fuhr
On Sat, Oct 14, 2006 at 08:20:10PM -0400, Tom Lane wrote: > Michael Fuhr <[EMAIL PROTECTED]> writes: > > Unless the inserters got there first. I just tested both ways; if > > the insert acquires the lock first then the delete fails, but if the > > delete acquires the lock first then the insert fai

Re: [SQL] Foreign key reference counting strategy?

2006-10-14 Thread Tom Lane
Michael Fuhr <[EMAIL PROTECTED]> writes: > On Sat, Oct 14, 2006 at 07:58:06PM -0400, Tom Lane wrote: >> No, I don't think so, because the DELETE will already be holding >> exclusive lock on the doomed PK row, which any would-be inserters of >> matching FK rows will be blocked on. AFAICS the DELETE

Re: [SQL] Foreign key reference counting strategy?

2006-10-14 Thread Michael Fuhr
On Sat, Oct 14, 2006 at 07:58:06PM -0400, Tom Lane wrote: > Michael Fuhr <[EMAIL PROTECTED]> writes: > > On Sat, Oct 14, 2006 at 03:52:04PM +0200, Markus Schaber wrote: > >> Create an "after delete" trigger on the referencing table that checks > >> whether there still are records with the same key

Re: [SQL] Foreign key reference counting strategy?

2006-10-14 Thread Tom Lane
Michael Fuhr <[EMAIL PROTECTED]> writes: > On Sat, Oct 14, 2006 at 03:52:04PM +0200, Markus Schaber wrote: >> Create an "after delete" trigger on the referencing table that checks >> whether there still are records with the same key (IF EXISTS()), and >> deletes the referenced row otherwise. > In

Re: [SQL] Foreign key reference counting strategy?

2006-10-14 Thread Michael Fuhr
On Sat, Oct 14, 2006 at 03:52:04PM +0200, Markus Schaber wrote: > Joost Kraaijeveld wrote: > > Is there a strategy to implement reference counting for foreign keys so > > that if the last reference to the key is deleted, the record is deleted > > also? > > Create an "after delete" trigger on the r

Re: [SQL] Foreign key reference counting strategy?

2006-10-14 Thread Markus Schaber
Hi, Joost, Joost Kraaijeveld wrote: > Is there a strategy to implement reference counting for foreign keys so > that if the last reference to the key is deleted, the record is deleted > also? Create an "after delete" trigger on the referencing table that checks whether there still are records wi

[SQL] Foreign key reference counting strategy?

2006-10-14 Thread Joost Kraaijeveld
Hi, Is there a strategy to implement reference counting for foreign keys so that if the last reference to the key is deleted, the record is deleted also? TIA -- Groeten, Joost Kraaijeveld Askesis B.V. Molukkenstraat 14 6524NB Nijmegen tel: 024-3888063 / 06-51855277 fax: 024-3608416 web: www.as

Re: [SQL] Foreign Key: what value?

2006-07-06 Thread Aaron Bono
On 7/6/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: i alsways make my foreign key column data type int4.i'm not sure if i read that somewhere.  anyone, please feel free to chime in if this isn't good practice.read up on currval, nextval and that whole section.you can begin by getting the nextva

Re: [SQL] Foreign Key: what value?

2006-07-06 Thread operationsengineer1
> Hi, > How to know the value which I must set in the > foreign key field?. I have two > tables: > > > CREATE TABLE AA ( > Id SERIAL PRIMARY KEY, > data char(9) > ); > > CREATE TABLE BB ( > BB_Id integer REFERENCES AA(Id) NOT NULL, > field char(5) > ); > > > > > I i

Re: [SQL] Foreign Key: what value? -- currval()

2006-07-05 Thread Davi Leal
A. Kretschmer wrote: > Davi Leal folgendes: > > Hi, > > How to know the value which I must set in the foreign key field?. I have > > two tables: > > > > > > CREATE TABLE AA ( > > Id SERIAL PRIMARY KEY, > > data char(9) > > ); > > > > CREATE TABLE BB ( > > BB_Id integer REFERENCES

Re: [SQL] Foreign Key: what value?

2006-07-05 Thread A. Kretschmer
am 05.07.2006, um 17:19:26 +0200 mailte Davi Leal folgendes: > Hi, > How to know the value which I must set in the foreign key field?. I have two > tables: > > > CREATE TABLE AA ( > Id SERIAL PRIMARY KEY, > data char(9) > ); > > CREATE TABLE BB ( > BB_Id integer REFERENCES A

[SQL] Foreign Key: what value?

2006-07-05 Thread Davi Leal
Hi, How to know the value which I must set in the foreign key field?. I have two tables: CREATE TABLE AA ( Id SERIAL PRIMARY KEY, data char(9) ); CREATE TABLE BB ( BB_Id integer REFERENCES AA(Id) NOT NULL, field char(5) ); I insert a register on table AA, IN

Re: [SQL] Foreign key to 2 tables problem

2005-11-22 Thread John McCawley
However, if customers or suppliers can have multiple accounts, you are going to need an intermediate table, as suggested by Neil. Scratch that. If accounts can have multiple owners you'll need an intermediate table. ---(end of broadcast)---

Re: [SQL] Foreign key to 2 tables problem

2005-11-22 Thread Rod Taylor
On Tue, 2005-11-22 at 16:24 +0100, Joost Kraaijeveld wrote: > Hi, > > Is there a way to create a foreign key to 2 tables: e.g. a bankaccount > table that has a column "owner", that must point to a record in either > the customer or the supplier table? No. What you need is an owner table that cust

Re: [SQL] Foreign key to 2 tables problem

2005-11-22 Thread John McCawley
I've never seen anything like that. I'm sure it's conceivable that you could write a weird trigger for it, but you have to consider maintainability, and what your queries are going to look like. I haven't seen your datamodel, but it would seem that you could accomplish what you're looking for

Re: [SQL] Foreign key to 2 tables problem

2005-11-22 Thread Achilleus Mantzios
O Joost Kraaijeveld έγραψε στις Nov 22, 2005 : > Hi, > > Is there a way to create a foreign key to 2 tables: e.g. a bankaccount > table that has a column "owner", that must point to a record in either > the customer or the supplier table? While there are techniques to accomplish this, i see a p

Re: [SQL] Foreign key to 2 tables problem

2005-11-22 Thread Neil Saunders
As far as I'm aware, not without using an intermediatary table (id, cust_id, supplier_id) . Otherwise, how would you know which table the foreign key was referencing? That said, an intermediatary table isn't a very clean solution; What problem are you trying to solve, exactly? Kind Regards, Neil

[SQL] Foreign key to 2 tables problem

2005-11-22 Thread Joost Kraaijeveld
Hi, Is there a way to create a foreign key to 2 tables: e.g. a bankaccount table that has a column "owner", that must point to a record in either the customer or the supplier table? TIA -- Groeten, Joost Kraaijeveld Askesis B.V. Molukkenstraat 14 6524NB Nijmegen tel: 024-3888063 / 06-51855277

Re: [SQL] Foreign key with check?

2005-07-27 Thread Bruno Wolff III
On Wed, Jul 27, 2005 at 16:08:19 -0400, Jeff Boes <[EMAIL PROTECTED]> wrote: > Given a table like this: > > create table primary ( > a integer primary key, > b boolean > ); > > And another like this: > > create table secondary ( > a integer, > some_other_fields > ); > > > I would lik

[SQL] Foreign key with check?

2005-07-27 Thread Jeff Boes
Given a table like this: create table primary ( a integer primary key, b boolean ); And another like this: create table secondary ( a integer, some_other_fields ); I would like a foreign key constraint on the "secondary" table that looks something like: foreign key (a, true) reference

Re: [SQL] Foreign key pg_dump issue and serial column type

2005-06-29 Thread Tom Lane
"Vsevolod (Simon) Ilyushchenko" <[EMAIL PROTECTED]> writes: > However, when I pg_dump the database and import it on another server, > the tables are exported alphabetically, so when the 'people_roles' table > is created with its foreign keys, the table 'roles' does not exist yet. > Thus, the for

[SQL] Foreign key pg_dump issue and serial column type

2005-06-29 Thread Vsevolod (Simon) Ilyushchenko
Hi, As a relative newbie to postgres, I've run into to weirdisms that I don't quite know how to handle: 1. I have a many-to-many table 'people_roles' containing fields 'person_code' and 'role_code'. It links tables 'people' and 'roles'. There are foreign key constraints: ALTER TABLE PEOPLE

Re: [SQL] foreign key on pg_shadow

2005-06-14 Thread Tom Lane
"M.D.G. Lange" <[EMAIL PROTECTED]> writes: > No matter what ON DELETE constraint I created, the system will not allow > me to create a foreign key, as pg_shadow is a system catalog. We do not support foreign keys (or indeed triggers of any kind) on system catalogs. I don't foresee that happening

[SQL] foreign key on pg_shadow

2005-06-14 Thread M.D.G. Lange
Dear list, Upon designing our application we thought that the following setup would be a good idea to implement security: Using the pg_shadow table as it is: | pg_shadow | +-+ | usename | | usesysid| | usecreatedb | | usesuper| | usecatupd | | passwd | | valunt

Re: RE : [SQL] Foreign key

2005-03-30 Thread Michael Fuhr
On Wed, Mar 30, 2005 at 02:09:05PM +0200, [EMAIL PROTECTED] wrote: > > Thanks for your answers but i make the modifications, the same error returned. > Here my script : > ... > Create table Salariés (Nom_salarié VARCHAR(20), >Prénom VARCHAR(20), > Fonction VARC

Re: [SQL] Foreign key

2005-03-27 Thread Bruno Wolff III
On Fri, Mar 25, 2005 at 16:31:16 +0100, [EMAIL PROTECTED] wrote: > > When i add table with foreign key in my database, this error return : < > number of referencing and referenced colums for foreign key disagree>. > > How resolve this problem ? Besides what Mike said, one other thing to rememb

Re: [SQL] Foreign key

2005-03-26 Thread Michael Fuhr
On Fri, Mar 25, 2005 at 04:31:16PM +0100, [EMAIL PROTECTED] wrote: > > When i add table with foreign key in my database, this error return : < > number of referencing and referenced colums for foreign key disagree>. Apparently the referencing key (the foreign key specification) has a different num

[SQL] Foreign key

2005-03-26 Thread ASAKALAL
Hello,   When i add table with foreign key in my database, this error return : « number of referencing and referenced colums for foreign key disagree». How resolve this problem ?   Thanks   alain SAKALALA Mailto:[EMAIL PROTECTED]  

Re: [SQL] Foreign Key relationship between two databases

2005-01-27 Thread Stephan Szabo
On Thu, 27 Jan 2005, Sandeep Gaikwad wrote: > I can give foreign key relationship between two tables of same > database. Can I give foreign key relationship between tables of two > databases ? Plz, let me know if possible & send me how can I do that? Unfortunately, that's not really current

[SQL] Foreign Key relationship between two databases

2005-01-27 Thread Sandeep Gaikwad
Hi, I am using postgres 7.3.4. I am new to postgres. I can give foreign key relationship between two tables of same database. Can I give foreign key relationship between tables of two databases ? Plz, let me know if possible & send me how can I do that? Thanks & Regards, Sandeep. --

Re: [SQL] foreign key problems

2005-01-05 Thread Stephan Szabo
On Wed, 5 Jan 2005, Stephan Szabo wrote: > > On Wed, 5 Jan 2005, [iso-8859-2] BARTKO, Zoltán wrote: > > > Ok, so I made some changes (manual "inheritance" of PK and FK > > constraints), but nevertheless I get still the same dumb error. I made > > a dump of the DB via pg_dump, it is available at >

Re: [SQL] foreign key problems

2005-01-05 Thread Stephan Szabo
On Wed, 5 Jan 2005, [iso-8859-2] BARTKO, Zoltán wrote: > Ok, so I made some changes (manual "inheritance" of PK and FK > constraints), but nevertheless I get still the same dumb error. I made > a dump of the DB via pg_dump, it is available at > > http://de.geocities.com/bartkozo/dump.tgz > > DRec

Re: [SQL] foreign key problems

2005-01-05 Thread BARTKO, Zoltán
Ok, so I made some changes (manual "inheritance" of PK and FK constraints), but nevertheless I get still the same dumb error. I made a dump of the DB via pg_dump, it is available at http://de.geocities.com/bartkozo/dump.tgz DRecord was dropped, the columns moved into DObject. I still have no ide

Re: [SQL] foreign key problems

2005-01-04 Thread Stephan Szabo
On Tue, 4 Jan 2005, [iso-8859-2] BARTKO, Zoltán wrote: > if I create the tables that are in the attached file, I can't insert > rows into the AAttachment table, even though the rows in DObject with > the given primary key exist (PgSQL 8.0 rc1 complains about > (ownerid)=(insert the number here) n

[SQL] foreign key problems

2005-01-04 Thread BARTKO, Zoltán
Dear all, I have a problem: if I create the tables that are in the attached file, I can't insert rows into the AAttachment table, even though the rows in DObject with the given primary key exist (PgSQL 8.0 rc1 complains about (ownerid)=(insert the number here) not available in DObject. The same h

Re: [SQL] Foreign Key Non-Null Problem in 8.0

2004-10-30 Thread Stephan Szabo
On Wed, 27 Oct 2004, Jon Uhal wrote: > I'm having trouble trying to get my databases setup so that when I > delete a row from the base table, all related information is removed as > well. I've been testing this with PostgreSQL version (postmaster > (PostgreSQL) 8.0.0beta1) on a Windows 2000 Pro m

[SQL] Foreign Key Non-Null Problem in 8.0

2004-10-30 Thread Jon Uhal
I'm having trouble trying to get my databases setup so that when I delete a row from the base table, all related information is removed as well.  I've been testing this with PostgreSQL version (postmaster (PostgreSQL) 8.0.0beta1) on a Windows 2000 Pro machine.  I have been unsuccessful in tr

Re: [SQL] FOREIGN KEY and AccessExclusiveLock

2004-09-30 Thread Achilleus Mantzios
O Achilleus Mantzios έγραψε στις Sep 29, 2004 : > > Hmm, (something went wrong with some mailer) And again hope it gets right this time... > > Tom Lane wrote: > > We're adding a trigger to it. > >From the docs:

Re: [SQL] FOREIGN KEY and AccessExclusiveLock

2004-09-29 Thread Achilleus Mantzios
Hmm, (something went wrong with some mailer) Tom Lane wrote: > We're adding a trigger to it. >From the docs: ACCESS EXCLUSIVE Conflicts with locks of all modes (ACCESS SHARE, ROW SHARE, ROW EXCLUSIVE, SHARE UPDATE EX

Re: [SQL] FOREIGN KEY and AccessExclusiveLock

2004-09-28 Thread Achilleus Mantzios
O Tom Lane έγραψε στις Sep 28, 2004 : > Achilleus Mantzios <[EMAIL PROTECTED]> writes: > > Whats the purpose of the AccessExclusiveLock on parent table? > > We're adding a trigger to it. >From the docs: Acquired by the ALTER TABLE, DROP TABLE, REINDEX, CLUSTER, and VACUUM FULL commands. This is

Re: [SQL] FOREIGN KEY and AccessExclusiveLock

2004-09-28 Thread Achilleus Mantzios
O Tom Lane έγραψε στις Sep 28, 2004 : > Achilleus Mantzios <[EMAIL PROTECTED]> writes: > > Whats the purpose of the AccessExclusiveLock on parent table? > > We're adding a trigger to it. >From the docs: Acquired by the ALTER TABLE, DROP TABLE, REINDEX, CLUSTER, and VACUUM FULL commands. This i

Re: [SQL] FOREIGN KEY and AccessExclusiveLock

2004-09-28 Thread Tom Lane
Achilleus Mantzios <[EMAIL PROTECTED]> writes: > Whats the purpose of the AccessExclusiveLock on parent table? We're adding a trigger to it. regards, tom lane ---(end of broadcast)--- TIP 8: explain analyze is your friend

[SQL] FOREIGN KEY and AccessExclusiveLock

2004-09-28 Thread Achilleus Mantzios
Hi, all the below are for PostgreSQL 7.4.2. I noticed that during ALTER TABLE kid ADD CONSTRAINT "parcon" FOREIGN KEY (parid) on parent(id) pgsql tries to acquire an AccessExclusiveLock on *both* kid (which is pretty natural since it adheres with the docs, and it is an alter command) *and* pare

Re: [SQL] foreign key, create table, and transactions

2002-10-18 Thread Stephan Szabo
On Fri, 11 Oct 2002, Jeffrey Green wrote: > > Hello. I was wondering if anybody's run across the problem of > > creating tables with foreign key constraints out of order. What I > > mean by this is that say I want a table called that has a > > foreign key reference to a table . If I define pic

[SQL] foreign key, create table, and transactions

2002-10-18 Thread Jeffrey Green
Hello. I was wondering if anybody's run across the problem of creating tables with foreign key constraints out of order. What I mean by this is that say I want a table called that has a foreign key reference to a table . If I define pictures before table, I keep getting an error (Relation "

Re: [SQL] foreign key problem

2002-10-09 Thread Laurette Cisneros
7.2.3. It's a mystery as to how this happened but there is a program we use to copy rows from one version to another. For some reason the person who wrote it disabled triggers before copying rows to a new version then re-enabled the triggers. If someone made changes while the triggers were off

Re: [SQL] foreign key, on delete cascade...

2002-10-08 Thread Stephan Szabo
On Tue, 8 Oct 2002, Mathieu Arnold wrote: > I found in an old pgsql dump something like : > > UPDATE "pg_class" SET "reltriggers" = 0 WHERE "relname" ~* 'TABLE NAME'; > > inserts > > BEGIN TRANSACTION; > CREATE TEMP TABLE "tr" ("tmp_relname" name, "tmp_reltriggers" smallint); > INSERT INTO "

[SQL] foreign key, on delete cascade...

2002-10-08 Thread Mathieu Arnold
Hi I found in an old pgsql dump something like : UPDATE "pg_class" SET "reltriggers" = 0 WHERE "relname" ~* 'TABLE NAME'; inserts BEGIN TRANSACTION; CREATE TEMP TABLE "tr" ("tmp_relname" name, "tmp_reltriggers" smallint); INSERT INTO "tr" SELECT C."relname", count(T."oid") FROM "pg_class"

Re: [SQL] foreign key problem

2002-10-07 Thread Stephan Szabo
On Mon, 7 Oct 2002, Laurette Cisneros wrote: > > I have two tables: > > create table table1 > ( vers integer, > table1_id text NOT NULL, > desc text, > PRIMARY KEY (rev, table1)id) > ); > > create table tab

Re: [SQL] foreign key problem

2002-10-07 Thread Josh Berkus
Laurette, > How is this possible? I've tried to reproduce this, but haven't been able > to yet. This has happened to use several times. Oh, forgot question 2: SELECT version()? -- -Josh Berkus Aglio Database Solutions San Francisco ---(end of broadcast)---

Re: [SQL] foreign key problem

2002-10-07 Thread Josh Berkus
Laurette, > How is this possible? I've tried to reproduce this, but haven't been able > to yet. This has happened to use several times. Question 1: Can you experimentally create a record in table1, a matching record in table 2, and then delete the record in table1? It's possible that your

[SQL] foreign key problem

2002-10-07 Thread Laurette Cisneros
I have two tables: create table table1 ( vers integer, table1_id text NOT NULL, desc text, PRIMARY KEY (rev, table1)id) ); create table table2 ( vers integer, othertble_i

Re: [SQL] Foreign key

2001-08-02 Thread Jan Wieck
Lorenzo De Vito wrote: > What's the best way to build a relation between two tables ? > I know that Foreign key is no longer supported. Who told you so? Jan -- #==# # It's easier to get forgiveness for being wrong than fo

Re: [SQL] Foreign key problem

2001-06-25 Thread Stephan Szabo
On 25 Jun 2001, Itai Zukerman wrote: > According to the documentation for CREATE TABLE: > > In addition, the referenced columns are supposed to be the columns > of a UNIQUE constraint in the referenced table, however Postgres > does not enforce this. > > Well, it looks like PostgreSQL *do

Re: [SQL] Foreign key problem

2001-06-25 Thread Itai Zukerman
Je Mon, 25 Jun 2001 09:34:01 +0200 (CEST), Andreas Tille <[EMAIL PROTECTED]> scribis: > CREATE TABLE ResKulturDetail > ( > IdLabNr int, > IdIndex smallint > ); > > CREATE TABLE ResKulturDetailDay > ( > IdLabNr int, > IdIndex smallint > ); > > CREATE INDEX IX_IdLabNr_KulturDe

[SQL] Foreign key problem

2001-06-25 Thread Andreas Tille
Hello, I tried to track down the database definitions from a more complex database which I have to convert from MS SQL to PostgreSQL. I have only one last syntactical error. Here is the striped down code to the shortest snipped which shows the problem: CREATE TABLE ResKulturDetail ( IdLabN

Re: [SQL] Foreign key to base table with rows in inherited tables

2001-06-12 Thread Stephan Szabo
Yes, you cannot currently do this. Check past discussions on mailing lists for more details. Inheritance and constraints is pretty dodgy right now (for instance, Reservationfile.datafileNr is not unique). On Tue, 5 Jun 2001, Mikael Kjellström wrote: > I've declared a foreign key in table File

[SQL] Foreign key to base table with rows in inherited tables

2001-06-12 Thread Mikael Kjellström
I've declared a foreign key in table FileId referencing the primary key in Datafile. Datafile in itself does'nt have any rows, but Reservationfile, inheriting from Datafile has. I can't insert a row in FileId because no row is found in Datafile: this is not what I expected. I've tried suffixi

Re: [SQL] Foreign Key between different databases

2001-04-11 Thread Cedar Cox
AFAIK, not easily. There was a post to the hackers list recently with code for a "database connector" function. Using this it may be possible to write your own referential integrity triggers that reference the other database.. maybe not. I didn't look much into the code. There might be someth

[SQL] Foreign Key between different databases

2001-04-10 Thread Stan van de Mortel
Hello, I've a table in a database and I want to create a column that is a foreign key to a table in an other database. When I try ...,foreign key (x) references otherdb.table(x) it says 'parse error at or near "."'. Is there an other way to create this kind of foreign key? Stan van de Mortel [[

Re: [SQL] Foreign key referencing subclasses.

2001-03-23 Thread Johannes Grødem
>> CREATE TABLE resource_record( >> rrid SERIAL >> -- etc. >> ); > There is no primary key for this table. Just write PRIMARY KEY after > SERIAL. There is. I accidentally left it out in the post. > CREATE INDEX soa_record_pkey ON soa_record ( rrid ); > You could also state the referenced f

Re: [SQL] Foreign key referencing subclasses.

2001-03-22 Thread Stephan Szabo
On Thu, 22 Mar 2001, [iso-8859-1] Johannes Grødem wrote: > Hi, > > it seems I can't have a foreign key that references some subclass. Postgres > says it can't figure out what its primary key is. The primary key is defined > in the superclass. Unique/primary key doesn't inherit to subclasses.

Re: [SQL] Foreign key referencing subclasses.

2001-03-22 Thread Christof Glaser
Hi Johannes, On Thursday, 22. March 2001 15:18, Johannes Grødem wrote: > Hi, > > it seems I can't have a foreign key that references some subclass. > Postgres says it can't figure out what its primary key is. The > primary key is defined in the superclass. > > I have something like this: > > CR

[SQL] Foreign key referencing subclasses.

2001-03-22 Thread Johannes Grødem
Hi, it seems I can't have a foreign key that references some subclass. Postgres says it can't figure out what its primary key is. The primary key is defined in the superclass. I have something like this: CREATE TABLE resource_record( rrid SERIAL -- etc. ); CREATE TABLE soa_record( -- b

Re: [SQL] Foreign key constraint

2000-12-12 Thread Jie Liang
Recovery try use: pg_dump -t tbname -f outfile dbname use vi erase f key from outfile, drop old table, reload them. Jie LIANG Internet Products Inc. 10350 Science Center Drive Suite 100, San Diego, CA 92121 Office:(858)320-4873 [EMAIL PROTECTED] www.ipinc.com

[SQL] Foreign key constraint

2000-12-12 Thread Sivagami .
  Hi,   I have a question. I tried adding a Foreign Key constraint to a table via the ALTER TABLE command. But the records in the table did not match with those in the Parent table. Now my Alter table command, instead of giving me an error of kind - 'records do not match',  has gone into a k

Re: [SQL] FOREIGN KEY errors.

2000-12-11 Thread Joseph Shraibman
Script to reproduce the problem. It drops the tables at the end of the script. Stephan Szabo wrote: > > There was a bug (which should be fixed for 7.1) that got the > arguments wrong for the alter time check of the existing data. > I think I should be able to get a patch together to fix it once

Re: [SQL] FOREIGN KEY errors.

2000-12-08 Thread Stephan Szabo
There was a bug (which should be fixed for 7.1) that got the arguments wrong for the alter time check of the existing data. I think I should be able to get a patch together to fix it once I get a copy of the 7.0.3 source. Can you send the table schema as well so I can test it out? Stephan Szab

[SQL] FOREIGN KEY errors.

2000-12-07 Thread Joseph Shraibman
When trying to alter a table and add a foreign key, I am getting this error if the table has any data in it: playpen=# alter table message add FOREIGN KEY (pod,originator) REFERENCES usertable (podkey,userkey); NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KE

Re: [SQL] foreign key take too much time to check

2000-08-07 Thread Mark Volpe
Try creating the tables without the constraint first, then populate them, and then add the foreign key constaint as the last step using ALTER TABLE/ADD CONSTRAINT. Mark Jie Liang wrote: > > Hi, there, > > I want add a constraint to my tables: > I have 2 tables: > 1. Table_A(id int 4 primary k

[SQL] foreign key take too much time to check

2000-08-07 Thread Jie Liang
Hi, there, I want add a constraint to my tables: I have 2 tables: 1. Table_A(id int 4 primary key, item text, ..), 2. Table_B(id int4, cid int4, constraint b_fk foreign key (id) refereneces Table_A(id) on delete cascade on update cascade); Table_A has ~900,000 rows, Table_B has ~1,200,000

  1   2   >