X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6D6659DCBB9 for ; Tue, 7 Feb 2006 10:27:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63608-06 for ; Tue, 7 Feb 2006 10:27:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp3.lc.anpe.fr (unknown [80.124.143.18]) by postgresql.org (Postfix) with ESMTP id D7D0A9DCBB2 for ; Tue, 7 Feb 2006 10:27:02 -0400 (AST) Received: from HOMERE03.anpe.fr (localhost.localdomain [127.0.0.1]) by smtp3.lc.anpe.fr (antivirus) with ESMTP id 272DA73CCD for ; Tue, 7 Feb 2006 15:27:01 +0100 (CET) Received: from [10.0.32.170] ([10.0.32.170]) by HOMERE03.anpe.fr with Microsoft SMTPSVC(6.0.3790.1830); Tue, 7 Feb 2006 15:26:43 +0100 Message-ID: <43E8AE37.1080205@anpe.fr> Date: Tue, 07 Feb 2006 15:27:03 +0100 From: Patrick JACQUOT User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Cc: pgsql-sql@postgresql.org Subject: Re: problem referencing an attrib which is not unique References: <450bdf80602070531w78b687bdj15e640945b15b49@mail.gmail.com> <450bdf80602070545v56252a49g8dfe0d0d04ae9065@mail.gmail.com> In-Reply-To: <450bdf80602070545v56252a49g8dfe0d0d04ae9065@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 07 Feb 2006 14:26:43.0769 (UTC) FILETIME=[84DB6A90:01C62BF2] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.166 required=5 tests=[AWL=-0.023, MISSING_HEADERS=0.189] X-Spam-Score: 0.166 X-Spam-Level: X-Archive-Number: 200602/61 X-Sequence-Number: 24071 Vic Rowan wrote: > > > ---------- Forwarded message ---------- > From: *Vic Rowan* > > Date: Feb 7, 2006 2:31 PM > Subject: problem referencing an attrib which is not unique > To: pgsql-sql@postgresql.org > > > hello everybody, > > I need some thing like this below for an application which stores log > messages in multiple languages. The table 'event_msg' stores > predefined messages in multiple languages which can be populated with > place holder values from the application. (These of course are > language independent). So, the event_id associates these predefined > messages from both the tables so that displaying a log message is as > simple as looking up the event_id from the 'logs' table and similarly > looking up the event_id and language from the 'event_msg' table to > retreive the predefined_msg with the correct language - the > application determines the lang from a settings file - and combining > them to display the log message. > > CREATE TABLE event_msg ( > event_id varchar(30) NOT NULL, > language char(2) NOT NULL, > predefined_msg varchar(250) NOT NULL, > PRIMARY KEY (event_id, language) > ); > > CREATE TABLE logs ( > id int NOT NULL, > event_id varchar(30) REFERENCES event_msg (event_id) NOT NULL, > placeholder_values varchar(250), > priority varchar(20) NOT NULL, > timestamp Date NOT NULL, > primary key (id) > ); > > > The problem I am facing is the event_id from logs is not able to > reference event_id from event_msg as its not unique. > There are as many entries for each event_id as there are languages > supported in the 'event_msg' table. > I would be glad if somebody could suggest some work around here to the > above structure. Or alternately do I need to alter the table structure > altogether and if so what is the better way of doing this? > > Thanks in advance for any help offered. > > Cheers, > Vic Rowan. > I think you need three tables One to list the allowable events, which will be used as reference CREATE TABLE eventlist ( event_id varchar(30) PRIMARY-KEY ); One to give the messages translations CREATE TABLE messagetranslations( event-id varchar(30) references eventlist (event_id) NOT NULL language char(2) not null event-translation varchar(250) PRIMARY KEY (event_id, language) ); and your log table CREATE TABLE logs ( id int NOT NULL, event_id varchar(30) REFERENCES eventlist (event_id) NOT NULL, placeholder_values varchar(250), priority varchar(20) NOT NULL, timestamp Date NOT NULL, primary key (id) ); btw, event-id could be just an integer. If, as I understand, event-id is so large a string, it's probably because it contains the english name of the event. Just put it in an occurrence of messagetranslation, with language = 'EN' other thing : with only 2 chars as language id, how do you distinguish EN-US and EN-UK (or whatever id the latter can have assigned)?. hth P. Jacquot