From: lucas@presserv.org
To: pgsql-sql@postgresql.org
Subject: Function or Field?
Date: Mon, 02 May 2005 17:16:44 -0300
Message-ID: <20050502171644.dqce2vmgefi80kwo@www.presserv.org> (raw)
Hi.
What is the better way to store the last record for a translation???
I.E:
The data for the last product vendding.
What is better:
a) Create a field in "product" table and create a Trigger (before insert or
update into vendding table) to alter this field.
b) Create a view or function that check the all venddings (in vendding table)
for the specified product and return the last vendding information?
a)
CREATE TABLE products(
id serial primary key,
description varchar(50),
last_vendding date() --Is correct to use this field???
);
CREATE TABLE vendding(
id serial primary key,
date_ date,
product integer references (products)
);
CREATE TRIGGER TG_change_products_last_vendding_field on table vendding BEFORE
INSERT OR UPDATE FOR EACH ROW EXECUTE procedure
change_products_last_vendding();
b)
CREATE TABLE products (
id serial primary key,
description varchar(50)
);
CREATE TABLE vendding(
id serial primary key,
date_ date,
product integer references (products)
);
CREATE VIEW last_product_change as SELECT * from vendding order by date_ desc
limit 1; --Okay, this view will return the last record and not the last record
for a product... but its a example.
I am asking it becouse I have used CLIPPER(dbase) for my old programs and in
DBASE the view/check function that will check for each select is not
functional. And I need to create a field in all table references, but in DBASE
this fields allways broken and I need to recheck it.
Thank you.
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: lucas@presserv.org
Subject: Re: Function or Field?
In-Reply-To: <20050502171644.dqce2vmgefi80kwo@www.presserv.org>
* 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