[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 ---

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 t

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 accomplis

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, I

[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

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 functionali

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, > > >

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 wri

[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

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

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

[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

[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 o

[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 re

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 retur

[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 P

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

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 tab

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 a

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 p

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 da

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 l

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 doub

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, includi

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_dat

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 h

[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 -