[SQL] Table History

2004-12-16 Thread Richard Sydney-Smith
Title: Message A database I maintain has a central transaction table ( FTRANS) I would like an second table FTRANS_IMAGE to maintain a historical view of ftrans. So if records in FTRANS are altered we can trace the effect of those changes in FTRANS_IMAGE.   I expect this has been done MANY

Re: [SQL] [NOVICE] FUNCTION, TRIGGER and best practices

2004-12-16 Thread Josh Berkus
Keith, > Can triggers and functions have the same name? Yes. > Is this a good practice? It can be. If the function does nothing but power the trigger, sure. Or you can use prefixes or suffixes to distinguish them. For example, if you had an audit trigger on the companies table, you might

Re: [SQL] plpgsql.. SELECT INTO ... WHERE FIELD LIKE

2004-12-16 Thread Christopher Browne
Oops! [EMAIL PROTECTED] ("Yudie") was seen spray-painting on a wall: > How in plpgsql use LIKE with a variable? > > let say I want to do this query: > SELECT INTO RS id FROM customer WHERE firstname LIKE keyword% LIMIT 1; > > keyword is a variable, in this case I want to find name like 'Jo%' >

Re: [SQL] plpgsql.. SELECT INTO ... WHERE FIELD LIKE

2004-12-16 Thread Christopher Browne
Try: SELECT INTO RS ID FROM CUSTOMER WHERE FIRSTNAME LIKE KEYWORD || ''%'' LIMIT 1; You append KEYWORD and a '%' together using ||. You need to use doubled quotes inside the quoted environment; one gets stripped off so that the stored procedure will contain the query SELECT INTO RS ID FRO

Re: [SQL] plpgsql.. SELECT INTO ... WHERE FIELD LIKE

2004-12-16 Thread Michael Fuhr
On Thu, Dec 16, 2004 at 05:53:43PM -0600, Yudie wrote: > How in plpgsql use LIKE with a variable? > > let say I want to do this query: > > SELECT INTO RS id FROM customer WHERE firstname LIKE keyword% LIMIT 1; > > keyword is a variable, in this case I want to find name like 'Jo%' Use the

[SQL] plpgsql.. SELECT INTO ... WHERE FIELD LIKE

2004-12-16 Thread Yudie
How in plpgsql use LIKE with a variable?   let say I want to do this query:   SELECT INTO RS id FROM customer WHERE firstname LIKE keyword% LIMIT 1;   keyword is a variable, in this case I want to find name like 'Jo%'     Full functio

Re: [SQL] [despammed] question about index

2004-12-16 Thread Andreas Kretschmer
am 16.12.2004, um 8:10:25 -0600 mailte Bruno Wolff III folgendes: > On Thu, Dec 16, 2004 at 12:01:39 +0100, > Andreas Kretschmer <[EMAIL PROTECTED]> wrote: > > > > > > considering that almost 70% of the rows will be with 'VALUE1', 20% > > > will be with 'VALUE2' and 10% will be with 'VALUE3' o

Re: [SQL] [despammed] question about index

2004-12-16 Thread Bruno Wolff III
On Thu, Dec 16, 2004 at 12:01:39 +0100, Andreas Kretschmer <[EMAIL PROTECTED]> wrote: > > > > considering that almost 70% of the rows will be with 'VALUE1', 20% > > will be with 'VALUE2' and 10% will be with 'VALUE3' on the average. > > > > should I create an index to speedup the counts or not

Re: [SQL] Query aid

2004-12-16 Thread Roberto Fichera
At 12.21 16/12/2004, you wrote: Am Donnerstag, 16. Dezember 2004 11:34 schrieb Roberto Fichera: > Hi all, > > I have a table acct as (username, terminatedate, terminatecause) > I would like to build a query which returns three columns orderd by data > like: > > date_trunc( 'day', terminatedate ) |

Re: [SQL] question about index

2004-12-16 Thread D'Arcy J.M. Cain
On Thu, 16 Dec 2004 11:41:54 +0100 Jerome Alet <[EMAIL PROTECTED]> wrote: > For a future databas, I plan to have got a table with a text field > which can contain only three different values, say "VALUE1", > "VALUE2", and "VALUE3" Can it increase? That is, can a "VALUE4" be added half way thro

Re: [SQL] Query aid

2004-12-16 Thread Janning Vygen
Am Donnerstag, 16. Dezember 2004 11:34 schrieb Roberto Fichera: > Hi all, > > I have a table acct as (username, terminatedate, terminatecause) > I would like to build a query which returns three columns orderd by data > like: > > date_trunc( 'day', terminatedate ) | count(cause1) | count(cause2) >

Re: [despammed] [SQL] question about index

2004-12-16 Thread Andreas Kretschmer
am 16.12.2004, um 11:41:54 +0100 mailte Jerome Alet folgendes: > Hi, > > For a future databas, I plan to have got a table with a text field > which can contain only three different values, say "VALUE1", > "VALUE2", and "VALUE3" Why text-fields for this task? I would prefer a smallint for this

[SQL] question about index

2004-12-16 Thread Jerome Alet
Hi, For a future databas, I plan to have got a table with a text field which can contain only three different values, say "VALUE1", "VALUE2", and "VALUE3" this table may have, over the course of one year, several million rows for a size around 2 Gb or more. I'd be interested in having :

[SQL] Query aid

2004-12-16 Thread Roberto Fichera
Hi all, I have a table acct as (username, terminatedate, terminatecause) I would like to build a query which returns three columns orderd by data like: date_trunc( 'day', terminatedate ) | count(cause1) | count(cause2) where cause1/2 are two type of termination cause from the field terminatecause.