Re: [SQL] replace null with 0 in subselect ?

2002-10-16 Thread Tom Lane
Stephan Szabo <[EMAIL PROTECTED]> writes: > Coalesce((select max(pos)+1 from tab2), 0) > should work. Small comment: it's probably noticeably faster to do (select Coalesce(max(pos), 0) +1 from tab2) I think that the former will result in two evaluations of the sub-select in the typical c

Re: [SQL] getting the current date

2002-10-16 Thread Bruce Momjian
Joseph Syjuco wrote: > > how can i get the current date (without the time part) in sql. I tried > doing a select now() but it also gives me the time part test=> SELECT CURRENT_DATE; date 2002-10-17 (1 row) -- Bruce Momjian| http://candle.pha.p

[SQL] getting the current date

2002-10-16 Thread Joseph Syjuco
how can i get the current date (without the time part) in sql. I tried doing a select now() but it also gives me the time part TIA joseph ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster

Re: [SQL] Slow performance on MAX(primary_key)

2002-10-16 Thread Charles H. Woloszynski
Keith: I think it would be great to get the optimizer to do something smart on such a simple (and common) query. I am porting an app to Postgresql and I am not looking forward to having to fix all the postgres-ism that seem trivial like this. Postgres gets a bad rap for this kinda simple q

Re: [SQL] Slow performance on MAX(primary_key)

2002-10-16 Thread Keith Gray
Richard Huxton wrote: >>> As of now, Max() doesn't utilizes the indices hence >>>it always do a sequential scan. >>Is this likely to be sorted in 7.2 ? >>Is anyone looking at this? > As I understand, the problem is that the optimisation only applies for simple > cases... Getting MIN() adn

Re: [SQL] Help with SQL

2002-10-16 Thread Eric L. Blevins
This is what I ended up with: SELECT c1.uid, count1, count2 FROM (SELECT uid, count(uid) AS count1 FROM triangulated WHERE uid != 'anonymus' AND uid != 'anonymous' AND uid != '' GROUP BY uid) AS c1 LEFT JOIN (SELECT uid,count(uid) AS count2 FROM points WHERE uid != 'anonymus' AND uid != 'anonymou

Re: [SQL] Help with SQL

2002-10-16 Thread Oliver Elphick
On Wed, 2002-10-16 at 19:26, Eric L. Blevins wrote: > I've got 2 SQL statements I would like to combine into one. ... > statement 1: SELECT uid, count(uid) FROM triangulated WHERE uid != 'anonymus' AND >uid > != 'anonymous' AND uid != '' GROUP BY uid ORDER BY count DESC LIMIT 10; ... > statemen

[SQL] Help with SQL

2002-10-16 Thread Eric L. Blevins
I'm new to postgres. I've got 2 SQL statements I would like to combine into one.   I think I need to use a sub select or join I am not sure. Any help would be appreciated!   statement 1: SELECT  uid, count(uid)  FROM triangulated WHERE uid != 'anonymus' AND uid!= 'anonymous' AND uid != '' GRO

[SQL] Quick contraint question

2002-10-16 Thread Vincent Stoessel
I have a table that has a frild called ID. I will be inserting data into that field that will either be a unique number or blank, Is there a way to do this either at table creation time or by using some check() voodoo? Thanks. -- Vincent Stoessel Linux Systems Developer vincent xaymaca.com ---

Re: [SQL] Use of reference table ('look-up-table') and FK constraint

2002-10-16 Thread Josh Berkus
Charles, CREATE TABLE phone_types ( type VARCHAR(10) NOT NULL PRIMARY KEY ); INSERT INTO phone_types VALUE ( 'Work' ); INSERT INTO phone_types VALUE ( 'Home' ); etc ... CREATE TABLE phone ( phone_id Identifier_type IDENTITY, phone_number varchar(20

Re: [SQL] Use of reference table ('look-up-table') and FK constraint

2002-10-16 Thread Stephan Szabo
On 16 Oct 2002, Charles Hauser wrote: > In fits and starts I am working through converting a sybase schema -> > postgres and am hoping to gain some insight on the use of reference > tables ('look-up-table') and FK constraints. > > In the example below I believe the sybase RULE Phone_type_rule is

[SQL] Use of reference table ('look-up-table') and FK constraint

2002-10-16 Thread Charles Hauser
Hi, In fits and starts I am working through converting a sybase schema -> postgres and am hoping to gain some insight on the use of reference tables ('look-up-table') and FK constraints. In the example below I believe the sybase RULE Phone_type_rule is used to restrict input, so that the only v

Re: [SQL] replace null with 0 in subselect ?

2002-10-16 Thread Stephan Szabo
On Wed, 16 Oct 2002, Albrecht Berger wrote: > Hello, > I have a statement like this : > > INSERT INTO tab1 (c1, c2, c3) VALUES (1,2, SELECT MAX(pos)+1 FROM tab2); Coalesce is your friend. :) Coalesce((select max(pos)+1 from tab2), 0) should work. ---(end of broadcast)

Re: [SQL] set difference

2002-10-16 Thread Tom Lane
=?iso-8859-1?Q?Domoszlai_L=E1szl=F3?= <[EMAIL PROTECTED]> writes: > So, do you think a DIFFERENCE or EXCEPT SYMMETRIC clause will be reasonable > feauture for postgresql? I doubt it; haven't heard a request for it before, and AFAICS there's no such thing in the SQL spec...

Re: [SQL] set difference

2002-10-16 Thread Domoszlai László
Tom Lane wrote: > > I would like to make symmetrical(set) difference in a query. > > But the simpliest way I could find is > > > select id from a > > except > > select id from b > > union > > select id from b > > except > > select id from a > > > Is there any better solution for this problem?

[SQL] pg_atoi() error

2002-10-16 Thread alexandre :: aldeia digital
Hi, Table xxx: (...) CPF numeric(11,0) (...) Select x,y,CPF from xxx where CPF='12345678901' Generate the error: error reading "12345678901": Numerical result out of range The corversor recognize the 'number' like a integer and not like a numeric type ??? I use Win ODBC-7.2.00.3 and Post-7.

Re: [SQL] replace null with 0 in subselect ?

2002-10-16 Thread Ian Barwick
On Wednesday 16 October 2002 12:07, Albrecht Berger wrote: > Hello, > I have a statement like this : > > INSERT INTO tab1 (c1, c2, c3) VALUES (1,2, SELECT MAX(pos)+1 FROM tab2); > > This works fine if the subselect returns a value, but if it returns > null there is a problem. In this case a 0 has

[SQL] Locking that will delayed a SELECT

2002-10-16 Thread Ludwig Lim
Hi: Suppose I have a transaction (T1) which executes a complicated stored procedure. While T1 is executing, trasaction #2 (T2) begins to execute. T1 take more time to execute that T2 in such a way that T2 finished earlier than T1. The result is that t2 returns set of data before it can

[SQL] replace null with 0 in subselect ?

2002-10-16 Thread Albrecht Berger
Hello, I have a statement like this : INSERT INTO tab1 (c1, c2, c3) VALUES (1,2, SELECT MAX(pos)+1 FROM tab2); This works fine if the subselect returns a value, but if it returns null there is a problem. In this case a 0 has to be inserted. Is there any pg function which solves this problem ? I