From: Janning Vygen <vygen@gmx.de>
To: pgsql-sql@postgresql.org
Cc: Bryce Nesbitt <bryce1@obviously.com>
Subject: Re: Bitfields always atomic? Other way to store attributes?
Date: Mon, 27 Mar 2006 21:20:20 +0200
Message-ID: <200603272120.20288.vygen@gmx.de> (raw)
In-Reply-To: <44270BF6.6080109@obviously.com>
References: <44270BF6.6080109@obviously.com>
Am Sonntag, 26. März 2006 23:47 schrieb Bryce Nesbitt:
> Dear List;
>
> If I have two threads modifying the same "bit" field:
> thread1=> update table set bf=bf | '01000'
> thread2=> update table set bf=bf | '10000'
> Will this operation always be safe (e.g. result in bf='11000')?
yes, Thats what "ACID" (http://en.wikipedia.org/wiki/ACID) is all about.
> Or must
> I wrap things in
> explicit transactions?
every statement is in it's own transaction as long as you dont start one by
yourself.
> My application is to give attributes to an address table. But maybe
> there is a better way?
>
> I want to mark each addresses with attributes, e.g. the person may be a
> "friend", "on my holiday card list", "owe me money", be an "employee", a
> "volunteer on the xxx project", or none of the above.
>
> I could assign each role a bit.
>
> Or, create a string field: "Friend,Money, Emp,VolXXX".
>
> Or, create related tables:
> friend_pk, address_id
> cardlist_pk, address_id
> money_pk, address_id, amount_owed
> volunteer_pk, address_id
>
> Any thoughts?
create a table with attributes and a table with addresse "address" and then
link them via a third table address_addressattributes, something like this:
create table address (
add_id serial not null primary key,
add_name text not null,
add_street ...
...
);
create table addressattributes (
aa_id serial not null primary key,
aa_name text not null unique
);
insert into address_attributes (aa_name) values ('Friend');
insert into address_attributes (aa_name) values ('Money');
create table address_addressattributes (
add_aa_id serial primary key,
aa_id int4 not null references address_attributes (aa_id),
add_id int4 not null references address (add_id)
)
this is called a many-to-many relation.
kind regards,
janning
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: vygen@gmx.de, bryce1@obviously.com
Subject: Re: Bitfields always atomic? Other way to store attributes?
In-Reply-To: <200603272120.20288.vygen@gmx.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox