[SQL] More efficient OR

2005-02-16 Thread Keith Worthington
Hi All,

In several of my SQL statements I have to use a WHERE clause that contains
mutiple ORs.  i.e.

WHERE column1 = 'A' OR
  column1 = 'B' OR
  column1 = 'C'

Is there a more efficient SQL statement that accomplishes the same limiting
functionality?

Kind Regards,
Keith

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [SQL] More efficient OR

2005-02-16 Thread Reinoud van Leeuwen
On Wed, Feb 16, 2005 at 11:02:59AM -0500, Keith Worthington wrote:
> Hi All,
> 
> In several of my SQL statements I have to use a WHERE clause that contains
> mutiple ORs.  i.e.
> 
> WHERE column1 = 'A' OR
>   column1 = 'B' OR
>   column1 = 'C'
> 
> Is there a more efficient SQL statement that accomplishes the same limiting
> functionality?

I do not know wheter it is more efficient in terms of execution, but I can
read this more efficiently:

WHERE column1 in ('A', 'B', 'C')


-- 
__
"Nothing is as subjective as reality"
Reinoud van Leeuwen[EMAIL PROTECTED]
http://www.xs4all.nl/~reinoud
__

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [SQL] More efficient OR

2005-02-16 Thread Scott Marlowe
On Wed, 2005-02-16 at 10:02, Keith Worthington wrote:
> Hi All,
> 
> In several of my SQL statements I have to use a WHERE clause that contains
> mutiple ORs.  i.e.
> 
> WHERE column1 = 'A' OR
>   column1 = 'B' OR
>   column1 = 'C'
> 
> Is there a more efficient SQL statement that accomplishes the same limiting
> functionality?

The in() construct is (nowadays) basically the same as ORing multiple
columns;

where column1 in ('A','B','C')

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


Re: [SQL] More efficient OR

2005-02-16 Thread Sean Davis
Could 'in' or 'between' do what you want?  I know that using 'in' is 
equivalent to what you have below.  Could 'between' be more 
efficient--you could do explain analyze on various options to see what 
the actual plan would be.

Sean
On Feb 16, 2005, at 11:02 AM, Keith Worthington wrote:
Hi All,
In several of my SQL statements I have to use a WHERE clause that 
contains
mutiple ORs.  i.e.

WHERE column1 = 'A' OR
  column1 = 'B' OR
  column1 = 'C'
Is there a more efficient SQL statement that accomplishes the same 
limiting
functionality?

Kind Regards,
Keith
---(end of 
broadcast)---
TIP 7: don't forget to increase your free space map settings

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


[SQL] Relation in tables

2005-02-16 Thread lucas
Hello all...
I am starting in Postgresql...
And I have a question:
I am developing a DB system to manage products, but the products may be
separated by departaments (with its respectives coluns)... Like:

CREATE TABLE products(
   id   serial  primary key,
   desc valchar(100),
   ...
);

Okay, but the products is typed by "amount departament" and this departament
should not have access to other coluns like "values, Money, etc...".
The "finances departament" may modify the data into products table, but this
departament should not have access to coluns like "amounts, etc...".

I' ve tried to create the products table with INHERITS but its not right...
look:

CREATE TABLE prod_amounts (
   amount_min   numeric,
   amount_cur   numeric,
   amount_max   numeric,
   ...
) INHERITS products;

CREATE TABLE prod_values (
   buy_value   money,
   sen_value   money,
   ...
) INHERITS products;

Okay, but the problem is: I can INSERT a prod_amounts normaly and automaticaly
the products table will be filled, but when i try to modify the data in
prod_amounts (references in products) there is no data
I think its not right ( I am sure :/ ).
How Can I do it???
How Can I References Between Prod_amounts and Prod_Values automaticaly?
remembering the Amounts departament may not access the Values departament data
and the Values departament may not access the amounts data... And the products
will be registred (typed) in Amount departament

Thanks for all.

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [SQL] More efficient OR

2005-02-16 Thread Keith Worthington
> > Hi All,
> >
> > In several of my SQL statements I have to use a WHERE clause
> > that contains mutiple ORs.  i.e.
> >
> > WHERE column1 = 'A' OR
> >   column1 = 'B' OR
> >   column1 = 'C'
> >
> > Is there a more efficient SQL statement that accomplishes the
> > same limiting functionality?
> >
> > Kind Regards,
> > Keith
> >
>
> Scott wrote:
> The in() construct is (nowadays) basically the same as
> ORing multiple columns;
> 
> where column1 in ('A','B','C') 
> 
> 
> Sean Davis wrote
> Could 'in' or 'between' do what you want?  I know that using 'in'
> is equivalent to what you have below.  Could 'between' be more 
> efficient--you could do explain analyze on various options to see 
> what the actual plan would be.
> 
> Sean

Thanks Scott and Sean for the post.

It sounds like IN will save some typing and code space but not decrease the
execution time.

BETWEEN won't work for my real life query because the limiting values are
quite disparate.

Kind Regards,
Keith

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [SQL] More efficient OR

2005-02-16 Thread KÖPFERL Robert
At least for between, I read that pgSQL rewrites it to a  (a -Original Message-
> From: Keith Worthington [mailto:[EMAIL PROTECTED]
> Sent: Mittwoch, 16. Februar 2005 17:36
> To: PostgreSQL SQL
> Cc: Sean Davis; Scott Marlowe
> Subject: Re: [SQL] More efficient OR
> 
> 
> > > Hi All,
> > >
> > > In several of my SQL statements I have to use a WHERE clause
> > > that contains mutiple ORs.  i.e.
> > >
> > > WHERE column1 = 'A' OR
> > >   column1 = 'B' OR
> > >   column1 = 'C'
> > >
> > > Is there a more efficient SQL statement that accomplishes the
> > > same limiting functionality?
> > >
> > > Kind Regards,
> > > Keith
> > >
> >
> > Scott wrote:
> > The in() construct is (nowadays) basically the same as
> > ORing multiple columns;
> > 
> > where column1 in ('A','B','C') 
> > 
> > 
> > Sean Davis wrote
> > Could 'in' or 'between' do what you want?  I know that using 'in'
> > is equivalent to what you have below.  Could 'between' be more 
> > efficient--you could do explain analyze on various options to see 
> > what the actual plan would be.
> > 
> > Sean
> 
> Thanks Scott and Sean for the post.
> 
> It sounds like IN will save some typing and code space but 
> not decrease the
> execution time.
> 
> BETWEEN won't work for my real life query because the 
> limiting values are
> quite disparate.
> 
> Kind Regards,
> Keith
> 
> ---(end of 
> broadcast)---
> TIP 5: Have you checked our extensive FAQ?
> 
>http://www.postgresql.org/docs/faq
> 

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [SQL] Relation in tables

2005-02-16 Thread KÖPFERL Robert
You may possibly solve the problem with the inheritted tables with the
RULE-System of pgsql. But this seems oversized to me. 
You could rather create several tables, each with its matching
rights/privileges and 'connect' them via an 1:1 relation.
The 'real' way such thing is normally done is to write stored procedures
which are accessible (Executable) only by those departments that may. If you
give these procs SECURITY DEFINER, you can restrict access to the actual
tables to only the procedure's owner

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Mittwoch, 16. Februar 2005 17:43
> To: pgsql-sql@postgresql.org
> Subject: [SQL] Relation in tables
> 
> 
> Hello all...
> I am starting in Postgresql...
> And I have a question:
> I am developing a DB system to manage products, but the 
> products may be
> separated by departaments (with its respectives coluns)... Like:
> 
> CREATE TABLE products(
>id   serial  primary key,
>desc valchar(100),
>...
> );
> 
> Okay, but the products is typed by "amount departament" and 
> this departament
> should not have access to other coluns like "values, Money, etc...".
> The "finances departament" may modify the data into products 
> table, but this
> departament should not have access to coluns like "amounts, etc...".
> 
> I' ve tried to create the products table with INHERITS but 
> its not right...
> look:
> 
> CREATE TABLE prod_amounts (
>amount_min   numeric,
>amount_cur   numeric,
>amount_max   numeric,
>...
> ) INHERITS products;
> 
> CREATE TABLE prod_values (
>buy_value   money,
>sen_value   money,
>...
> ) INHERITS products;
> 
> Okay, but the problem is: I can INSERT a prod_amounts normaly 
> and automaticaly
> the products table will be filled, but when i try to modify 
> the data in
> prod_amounts (references in products) there is no data
> I think its not right ( I am sure :/ ).
> How Can I do it???
> How Can I References Between Prod_amounts and Prod_Values 
> automaticaly?
> remembering the Amounts departament may not access the Values 
> departament data
> and the Values departament may not access the amounts data... 
> And the products
> will be registred (typed) in Amount departament
> 
> Thanks for all.
> 
> ---(end of 
> broadcast)---
> TIP 9: the planner will ignore your desire to choose an index 
> scan if your
>   joining column's datatypes do not match
> 

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


[SQL] Count Columns

2005-02-16 Thread Ray Madigan
I haven't done very many complex queries in sql, and maybe Im thinking about
my problem wrong but:

Is there a way to count the number of null or not null columns in a row and
have an output column that has that count as the value?
I want to create a ranking of the row based upon the number of not null
columns are in the row.  I want to have to use as few seperate queries as
possible.

The table that i want to do the query on is either a view or a temporary
table, I guess depending on if I can do this easily or if brut force is
required, Or if I have to think of a new way to solve my problem.

The table is like

CREATE TABLE myTbl ( name varchar(5) primary key, a varchar(5), b
varchar(5), c varchar(5) );

ending table looks like

name |  a  |  b  |  c  |
foo  |  A  | |  C  |
bar  |  A  |  B  | |
baz  |  A  |  B  |  C  |

and I want the result to look like

foo 2
bar 2
baz 3

Thanks in Advance


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [SQL] More efficient OR

2005-02-16 Thread PFC
	You sound like you don't like the performance you get with OR or IN, from  
this I deduce that you have a very large list of values to OR from. These  
make huge queries which are not necessarily very fast ; also they are  
un-preparable by their very nature (ie. the planner has to look at each  
value, ponder its stats, think about it...) Basically a query with, say,  
'column IN (100 values)' will make postgres work a lot more than a query  
with 'column in (SELECT something which yields 100 values)'.

I have tested the following with good results :
- Write a very simple set returning function which takes an array as a  
parameter and RETURN NEXT each array element in turn. It's just a FOR...  
RETURN NEXT. Say you call it array_flatten( INTEGER[] ) or something.

- Then, instead of doing SELECT * FROM table WHERE id IN (1,4,77,586,1025)
do:
SELECT * FROM table WHERE id IN (SELECT * FROM  
array_flatten( '{1,4,77,586,1025}' ) );
or :
SELECT t.* FROM table t, (SELECT * FROM array_flatten( '{1,4,77,586,1025}'  
) ) foo WHERE t.id=foo.id;

The first one will do a uniqu'ing on the array, the second one will not.
You can also LEFT JOIN against your SRF to get the id's of the rows that  
were not in the table (you cannot do this with IN)

And you can PREPARE the statement to something that will take an array as  
a parameter and won't have to be parsed everytime.

Sometimes it can be a big performance boost. Try it !
However, if some value in your array matches a lot of rows in the table,  
it will be slower than the seq scan which would have been triggered by the  
planner actually seeing that value in the IN list and acting on it. But if  
you KNOW your column is unique, there is no point in forcing the planner  
to ponder each value in your list !

For an additional performance boost (likely negligible), you could sort  
your array in the function (or even in your application code) to ease the  
work of the index scanner, which will get a better cache hit rate.

If you have, say, 20.000 values to get, this is the only way.
Note that you could ask yourself why you need to get a lot of values. Are  
you fetching stuff from the database, computing a list of rows to get,  
then SELECTing them ? Then maybe you put something in the application that  
should really be in the database ?

As a side note, it would be nice :
- if that set returning function was a fast C built-in (I think there's  
one in contrib/intagg but obviously it works only for integers) because  
it's a useful tool and building brick ; same for array_accum, and some  
other commonly used five-lines aggregates and functions that everybody  
recodes once.

- if postgresql used this kind of optimization for the SELECT * FROM table  
WHERE id =ANY( array ) which currently uses a seq scan.

However, what IS nice from pg is that you can actually do the array SRF  
trick and pull a lot of rows by id's, at blazing speed, just by writing a  
three line function and tweaking your wuery.


It sounds like IN will save some typing and code space but not decrease  
the
execution time.

BETWEEN won't work for my real life query because the limiting values are
quite disparate.
Kind Regards,
Keith
---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?
   http://www.postgresql.org/docs/faq

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [SQL] Relation in tables

2005-02-16 Thread PFC

Hello all...
I am starting in Postgresql...
And I have a question:
I am developing a DB system to manage products, but the products may be
separated by departaments (with its respectives coluns)... Like:
CREATE TABLE products(
   id   serial  primary key,
   desc valchar(100),
   ...
);
Okay, but the products is typed by "amount departament" and this  
departament
should not have access to other coluns like "values, Money, etc...".
The "finances departament" may modify the data into products table, but  
this
departament should not have access to coluns like "amounts, etc...".

I' ve tried to create the products table with INHERITS but its not  
right...
look:
	Use a view per department, which show/hide the columns according to your  
liking. Give each department a schema and put everything related to it  
inside for cleanliness. Use UPDATE triggers on the views, which in fact  
write to the products table, so that the departments can only update the  
columns you like. You can even make some columns readable but not  
writeable, by raising an exception if a modification is attempted on that  
column.

	If you want to reuse your code between departments, you will want all the  
views to have the same columns, so make them return NULL for the fields  
that they cannot see.

	Finally don't forget to make the products table inaccessible the  
departments.

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


[SQL] Matching a column against values in code

2005-02-16 Thread Tim
Hello all.
I sometimes find myself needing an SQL query that will return all the 
rows of a table in which one column equals any one of a list of values I 
have in an array in code.

Does anyone know of a better way to do this than to loop through the 
array and append an "or" comparison to the sql statement, like this?

sqlString = sqlString + " or this_column='" + arrayOfValues[i] +"' ";
If someone knows a command or function I can look up in the docs, just 
say the name and I'll look there. 

Thanks a lot everyone.
--
Tim
---(end of broadcast)---
TIP 6: Have you searched our list archives?
  http://archives.postgresql.org


[SQL] GROUPing only those rows that do not contain a NULL field?

2005-02-16 Thread Simon Kinsella
Hi

I wonder if anyone can help me with a SELECT / GROUP BY problem I'm having.
I'm trying to refine a query so that my GROUP BY clause only aggregates rows
that have a non-NULL value in one of the fields, leaving other rows
'ungrouped'.

An example table, resulting from a LEFT JOIN and subselect on three tables,
might be (before grouping) :

SELECT  user_group_id, user_id, topic_id FROM user_groups NATURAL JOIN users
LEFT JOIN
(SELECT user_id, topic_id FROM topic_participants WHERE topic_id = 567) AS a
USING (user_id)


user_group_id   |  user_id   |   topic_id
-
1  101   NULL   
1  102   567
1  103   567
2  101   NULL
2  106   567
3  101   NULL
3  104   567
3  102   567
4  103   567
4  104   567
5  105   NULL
6  103   567
6  104   567

(topic id is either a single value, or NULL if the user is not part of the
topic)

For UI reasons I would like this result collapsed thus:

user_group_id   |  user_id   |   topic_id
-
1  101   NULL   
1  102   567
1  103   567
2  101   NULL
2  106   567
3  101   NULL
3  104   567
5  105   NULL

Note that for all rows where topic_id IS NOT NULL, only one row per user_id
is returned (user_group_id is not relevant for these rows).

Can this aggregation be achieved with a DISTINCT ON / GROUP BY clause? (Or
anything else). I haven't managed to find anything that leaves the
NULL-field rows unscathed so far.

Thanks in advance for any help!

Simon K




---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


[SQL] how to select custom value when exists otherwise select default

2005-02-16 Thread patrick

I use a select like this:
SELECT sometables
WHERE field0='a' or field0='b' or field0='c'
and field4='m' or field4='n'
ORDER BY field0;

m.field4 is default value
n.field4 is custom value

I want only n(custom) if it exists ortherwise I want m(default)
but I do not want both!

I mean I have this result:
table{
field0 {a,a,b,c}
field1 {d,d,e,f}
field2 {g,g,h,i}
field3 {j,j,k,l}
field4 {m,n,m,m}
}
a.filed0 has 2 results, one for m(default) and one for n(optionnal)
b and c have no custom value so field4 is set to m for them

and I want this result:
table{
field0 {a,b,c}
field1 {d,e,f}
field2 {g,h,i}
field3 {j,k,l}
field4 {n,m,m}
}

of course I'm looking for only one request to do that, and I'd rather a
lighter one ;-)

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [SQL] Count Columns

2005-02-16 Thread Bruno Wolff III
On Wed, Feb 16, 2005 at 10:09:05 -0800,
  Ray Madigan <[EMAIL PROTECTED]> wrote:
> 
> Is there a way to count the number of null or not null columns in a row and
> have an output column that has that count as the value?

One way to do this would be to create a CASE clause for each column that
returns 1 or 0 depending on whether the column is null or not and add
these expressions up.

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


[SQL] Trigger

2005-02-16 Thread Eugen Gass
Hi,

I'm trying to create a trigger on PostgreSQL

it should be like an oracle(sql) sample code:

create or replace trigger frei_polygon_sync
after INSERT on frei_polygon
Referencing NEW as newROW
for each row
Begin
 :newRow.objektid :=  :newRow.gid;
 :
end;

Can sombody help me to do the same on Postrgres

Thanks 

Best Regards

EG

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [SQL] Order of columns in a table important in a stored procedure?

2005-02-16 Thread Richard Gintz
Pardon me ya'll, but can you tell me what a "saisies" is?
Thanks,
Dick

-- 
Richard Gintz
Airlink Systems
7600 Burnet Rd.  
Suite 515
Austin, TX  78757

PH: 512-231-1240 x108
FX: 512-231-9884
EM: [EMAIL PROTECTED]



Quoting Marc SCHAEFER <[EMAIL PROTECTED]>:

> Hi,
> 
> I use a FOR one_row IN loop where one_row is of type saisies%ROWTYPE.
> The loop does a SELECT on a table, bennes, changing a few values.
> 
> The idea is that the function should return some bennes rows, but
> with additional information, which makes the returned rows
> a saisies table-like row set.
> 
> I have however noticed that if the SELECT is *NOT* in the correct order
> for the table saisies, funny errors happen (such as type constraints --
> obviously columns are mixed).
> 
> What I do not understand is that I use AS in order to name the columns,
> I would think PostgreSQL could get the column names paired.
> 
> This is annoying since it means that any change to the data structure,
> such as adding columns may make my functions non working.
> 
> This is however an old version of PSQL (7.1 I think).
> 
> For reference:
> 
> CREATE OR REPLACE FUNCTION f_fa_montre(VOID)
>RETURNS SETOF saisies
>AS '
> DECLARE
>one_row saisies%ROWTYPE;
> BEGIN
>FOR one_row IN
>   SELECT NULL as idsaisie,
>  b.no_client AS num_client,
>  b.lieu_entreposage_b5 AS chantier,
>  DATE_TRUNC(\'month\', CURRENT_DATE) AS dates,
>  \'0\' AS num_bon,
>  NULL AS num_art
>   FROM bennes b
>   WHERE (type_fact_p = b.type_fact)
>LOOP
>   -- here I do some changes to the one_row, BTW
>   RETURN NEXT one_row;
>END LOOP;
> 
>RETURN;
> END;'
> LANGUAGE 'plpgsql';
> 
> The issue: if I exchange num_bon and dates above the query fails.
> 
> Thank you for any idea.
> 
> 
> ---(end of broadcast)---
> TIP 9: the planner will ignore your desire to choose an index scan if your
>   joining column's datatypes do not match
> 



This message was sent using IMP, the Internet Messaging Program.

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [SQL] [GENERAL] How to view the list of tables?

2005-02-16 Thread Shridhar Daithankar
On Tuesday 15 Feb 2005 3:46 pm, Konstantin Danilov wrote:
> Hello, list!
> I need to view the list of tables in a database. In MySQL I can do it with
> the command "SHOW TABLES". What about PostgreSQL? Can I also see somehow
> the datatypes of tables' fields?

In psql, you can try '\dt' and '\d table name'. Type \? for more commands..

 Shridhar

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


Re: [SQL] Matching a column against values in code

2005-02-16 Thread PFC
	This has been discussed a few hours ago on the mailing list on the  
subject '[SQL] More efficient OR'

On Fri, 11 Feb 2005 10:12:52 -0600, Tim <[EMAIL PROTECTED]> wrote:
Hello all.
I sometimes find myself needing an SQL query that will return all the  
rows of a table in which one column equals any one of a list of values I  
have in an array in code.

Does anyone know of a better way to do this than to loop through the  
array and append an "or" comparison to the sql statement, like this?

sqlString = sqlString + " or this_column='" + arrayOfValues[i] +"' ";
If someone knows a command or function I can look up in the docs, just  
say the name and I'll look there. Thanks a lot everyone.

--
Tim
---(end of broadcast)---
TIP 6: Have you searched our list archives?
   http://archives.postgresql.org

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
 joining column's datatypes do not match


UPDATE TRIGGER on view WAS: Re: [SQL] Relation in tables

2005-02-16 Thread Keith Worthington
On Wed, 16 Feb 2005 19:56:25 +0100, PFC wrote
> [snip] Use UPDATE triggers on the 
> views, which in fact  write to the products table [snip]

You can DO that!?!

Are you saying that a client can DELETE or INSERT or UPDATE a view and through
a trigger you can make this happen?  Way cool.  Can you provide a simple 
example?

And all this time I thought that you couldn't write to a view.

Kind Regards,
Keith

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [SQL] Order of columns in a table important in a stored procedure?

2005-02-16 Thread Geoffrey
Richard Gintz wrote:
Pardon me ya'll, but can you tell me what a "saisies" is?
More than one saisy???
--
Until later, Geoffrey
---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
 joining column's datatypes do not match


Re: [SQL] Order of columns in a table important in a stored procedure?

2005-02-16 Thread PFC
French verb "saisir" : here, to enter data in a system by typing it.
noun "saisie" : the action of doing so.
	It has other meanings :
	"Saisir" :
		- (commonly) to grab or get hold of something swiftly
		- (sometimes) to understand something
		- (lawspeak) that is also what the Oracle layers do to your house when  
they find out about your benchmark publications. More in the "grab" sense.

On Wed, 16 Feb 2005 15:51:00 -0500, Geoffrey <[EMAIL PROTECTED]> wrote:
Richard Gintz wrote:
Pardon me ya'll, but can you tell me what a "saisies" is?
More than one saisy???

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?
  http://www.postgresql.org/docs/faq


Re: UPDATE TRIGGER on view WAS: Re: [SQL] Relation in tables

2005-02-16 Thread Tom Lane
PFC <[EMAIL PROTECTED]> writes:
> You can create an ON UPDATE/INSERT trigger on a view which intercepts the  
> UPDATE/INSERT to the view (which would otherwise fail) and do whatever you  
> want with it, including doing the operation on the real table.

This might work for INSERT but I really doubt it'll work for UPDATE or
DELETE.

You may be able to make it work with rules, though there are lots of
pitfalls in that approach.

regards, tom lane

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: UPDATE TRIGGER on view WAS: Re: [SQL] Relation in tables

2005-02-16 Thread PFC

And all this time I thought that you couldn't write to a view.
You can't.
But you can make it seem so you can.
	You can create an ON UPDATE/INSERT trigger on a view which intercepts the  
UPDATE/INSERT to the view (which would otherwise fail) and do whatever you  
want with it, including doing the operation on the real table.

Search for "postgresql materialized views" for some examples.
---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?
  http://www.postgresql.org/docs/faq


Re: [SQL] Making NULL entries appear first when ORDER BY ASC

2005-02-16 Thread Andreas Joseph Krogh
On Wednesday 16 February 2005 04:47, Bruno Wolff III wrote:
> > Now, as you see, touples with NULL in the "start_time"-field appear
> > "after" the others. I would like to make all entries where start_time IS
> > NULL apear *before* all the others. Any idea how to achieve this?
>
> SELECT start_date, start_time, end_time, title
> FROM onp_crm_activity_log
> WHERE start_date IS NOT NULL
> ORDER BY start_date ASC, start_time IS NOT NULL ASC, start_time ASC;
>
> This assumes you want the NULL start times first within a particular
> date. Otherwise change the order in the ORDER BY clause.

Thanks! This si, IMO, the cleanest solution as it doesn't involve any 
COALESCE.

-- 
Andreas Joseph Krogh <[EMAIL PROTECTED]>
Senior Software Developer / Manager
gpg public_key: http://dev.officenet.no/~andreak/public_key.asc
+-+
OfficeNet AS| The most difficult thing in the world is to |
Hoffsveien 17   | know how to do a thing and to watch |
PO. Box 425 Skøyen  | somebody else doing it wrong, without   |
0213 Oslo   | comment.|
NORWAY  | |
Phone : +47 22 13 01 00 | |
Direct: +47 22 13 10 03 | |
Mobile: +47 909  56 963 | |
+-+


pgpFAljpSkpCk.pgp
Description: PGP signature


Re: [SQL] Trigger

2005-02-16 Thread Michael Fuhr
On Wed, Feb 16, 2005 at 02:44:30PM +0100, Eugen Gass wrote:
> 
> I'm trying to create a trigger on PostgreSQL

See the "Server Programming" part of the documentation (substitute
the appropriate version of PostgreSQL in the links):

http://www.postgresql.org/docs/8.0/static/server-programming.html
http://www.postgresql.org/docs/8.0/static/triggers.html
http://www.postgresql.org/docs/8.0/static/plpgsql.html
http://www.postgresql.org/docs/8.0/static/plpgsql-trigger.html

If you still have trouble then please post the PostgreSQL code you
tried, describe what you'd like to happen, and explain what actually
does happen.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


[SQL]

2005-02-16 Thread dawnsky
I don't want to recieve any letters from www.postgresql.org .thank u 

--
侬好上海热门专题大盘点
http://sh.online.sh.cn/special/2004huati/
网络相册:快乐让世界分享
http://album.online.sh.cn
给你最爱的人一点诱惑,一点惊喜,还有。。
http://telmedia.allyes.com/banner/xinqite.htm
--

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq