Return-Path: owner-postman
Received: from localhost (localhost [127.0.0.1]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with SMTP id IAA28399 for postgres-dist; Tue, 23 Nov 1993 08:11:32 -0800
Resent-From: POSTGRES mailing list <postman@postgres.Berkeley.EDU>
Resent-Message-Id: <199311231611.IAA28399@nobozo.CS.Berkeley.EDU>
X-Authentication-Warning: nobozo.CS.Berkeley.EDU: Host localhost didn't use HELO protocol
Sender: owner-postman@postgres.Berkeley.EDU
X-Return-Path: owner-postman
Received: from chsun.eunet.ch (chsun.chuug.ch [146.228.10.15]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with ESMTP id IAA28390 for <postgres@nobozo.CS.Berkeley.EDU>; Tue, 23 Nov 1993 08:11:27 -0800
Received: from gavdos.UUCP by chsun.eunet.ch (8.6.4/1.34)
	id RAA05418; Tue, 23 Nov 1993 17:13:17 +0100
Received: by gavdos.pr.net.ch (4.1/jpv-1.0)
	id AA24796; Mon, 22 Nov 93 09:35:31 +0100
Date: Mon, 22 Nov 93 09:35:31 +0100
From: jpv@gavdos.pr.net.CH (Jean-Paul Vetterli)
Message-Id: <9311220835.AA24796@gavdos.pr.net.ch>
To: postgres@postgres.Berkeley.EDU
Subject: Re: Managing key-value pairs
Resent-To: postgres-dist@postgres.Berkeley.EDU
Resent-Date: Tue, 23 Nov 93 08:11:32 -0800
Resent-XMts: smtp

> From: dunkel@spin.chem.utah.edu (Reinhard Dunkel)
> Message-Id: <9311220311.AA21809@spin.chem.utah.edu>
> 
> [...]
> I am trying to use Postgres 4.1 (RS/6000-370, AIX 3.2.4) to manage
> key-value pairs for a graphical user interface. I am embarrassed to
> admit that I have problems to make this easiest of all database
> applications work smoothly. I would greatly appreciate any help on the
> following problems:
> 
> PROBLEM 1: I have to enforce that my "param" attribute values (keys)
> are unique in a database relation.  However, the command "create foo
> (param=char16, value=text) key (param)\g" is documented in the
> reference manual but the message "WARN:Nov 21 18:10:13:RelationCreate:
> KEY not yet supported" sounds discouraging. So before writing a
> key-value pair I query the database to see if the key is known and
> then either replace or append the tupel.  This approach takes two
> database accesses (one second overhead with libpq each). Is there a
> better way to do this?
> [...]

One approach to enforce uniqueness is to use rules. 
Example: 

---- cut here ----
#  this is a spog script: %spog -f <thisfile>
#  it is idempotent 
#
#  create key-value table:
create kv (k = char16,\
	v = text)
#
#  uniqueness *and* integrity:
define rule kv_r is \
	on append to kv \
	where kv.k = new.k or new.k ISNULL \
	do instead nothing
#
#  data:
append kv (k = "K1", v = "K1's value")
append kv (k = "K2", v = "K2's value")
append kv (k = "K3", v = "K3's value")
append kv (k = "K4", v = "K4's value")
append kv (k = "K5", v = "etc.")
---- cut here ----

I hope this can help.


Jean-Paul Vetterli 		
Route des Pommiers 19		email:	jpv@gavdos.pr.net.CH 		
CH-1723 Marly			phone:	++77 34 38 27 		
Switzerland			fax:	++37 46 53 09 
