Re: [SQL] query optimization question

2002-11-07 Thread Christoph Haller
> SELECT > project_id, > marketing_name, > COUNT(lots.lot_id) AS def_count, > COUNT(CASE WHEN dt.days_old_start_date < {d '2002-10-07'} > THEN lots.lot_id ELSE NULL END) AS def_count_less_30, > COUNT(CASE WHEN dt.days_old_start_date >= {d '2002-10-07'}

Re: [SQL] [pgsql-sql] Daily Digest V1 #983

2002-11-07 Thread vist
---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org

[SQL] Weird NULL behavior

2002-11-07 Thread Ludwig Lim
Hi: Has anyone encountered this before? SELECT CAST ( (NULL*NULL) AS NUMERIC(2,0)); returns the following error message: Cannot cast type '"char"' to '"numeric"' But the following sql statements returns NULL: select NULL: select NULL * NULL; select cast ( NULL as NUMERIC(2,0)

[SQL] Generating a cross tab (pivot table)

2002-11-07 Thread Christoph Haller
Regarding to Terry's request on multiple aggregates and Shahbaz's request for generating a cross tab ( pivot table ) in September, I've found an excellent example on a german inet page http://www.itrain.de/ I've translated it and think it's useful for many who subscribed (I hope so, maybe it was t

Re: [SQL] Weird NULL behavior

2002-11-07 Thread Tom Lane
Stephan Szabo <[EMAIL PROTECTED]> writes: > On Thu, 7 Nov 2002, Ludwig Lim wrote: >> SELECT CAST ( (NULL*NULL) AS NUMERIC(2,0)); >> Cannot cast type '"char"' to '"numeric"' > It seems to me that it's trying to decide on a type > for the expression NULL * NULL. It's a NULL, but a > NULL of what ty

Re: [SQL] query optimization question

2002-11-07 Thread terry
Actually, the ORDER BY *must* be replaced by GROUP BY since it is an aggregate query. I have implemented it, and the results are startling, I get the same value repeated for all projects i.e.: AS1 AS1-AJAX/SALEM SIDE 3 0 6 7 30 0 216 240 AU3 AU3-RIVERIDGE/AURORA 3 0 6

Re: [SQL] cast lo to oid

2002-11-07 Thread Nekta Katz
I didn't realize there was a contrib/lo, I only created the lo type as described in the psqlodbc faq. I have now installed the contrib/lo and everything is working fine. I am using PG version 7.2 thanks. From: Tom Lane <[EMAIL PROTECTED]> To: "Nekta Katz" <[EMAIL PROTECTED]> CC: [EMAIL PROTECT

[SQL] cast lo to oid

2002-11-07 Thread Nekta Katz
Hi, I have the following table create table scan_docs ( docid serial, shipno numeric(10), scanlo, type text ); when I try to create the following rule create rule "delete_scan_docs_lo" as on delete to "scan_docs" do select lo_unlink (old.scan); I get the error message "psql:

Re: [SQL] Generating a cross tab (pivot table)

2002-11-07 Thread Richard Huxton
On Thursday 07 Nov 2002 11:47 am, Christoph Haller wrote: > Regarding to Terry's request on multiple aggregates and > Shahbaz's request for generating a cross tab ( pivot table ) > in September, I've found an excellent example on a german inet page > http://www.itrain.de/ > I've translated it and t

[SQL] how to get the source table & field name of a view field

2002-11-07 Thread Prime Ho
Hi, Could you tell me how to get view field's source table and field name? another word, how could I know the view field come from? Regards, Ho ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Re: [SQL] query optimization question

2002-11-07 Thread terry
No offence taken, however it is incorrect, my SQL is pretty good. I received no other responses... And I later realized the solution to my question: (EXPERTS READ ON: If anyone can show me how to use a group by or otherwise optimize I would be grateful) This subquery: SELECT pr

[SQL] primary keys

2002-11-07 Thread Huub
Hi, I want to create a table which has 2 columns, and both columns have to be primary key (or: together they are the primary key). How can I do this using SQL? Using pgAdminII for Postgres7.2.2 on RH8. Thanks Huub ---(end of broadcast)--- TIP 4

Re: [SQL] primary keys

2002-11-07 Thread terry
A table can only have ONE primary key. It can have additional indexes with a UNIQUE restriction, thereby forcing the second field to be as good as a primary key. That is probably what you are looking for, however, you can also in PG Admin II select multiple fields as being the member of the prima

Re: [SQL] primary keys

2002-11-07 Thread Rachel.Vaudron
Hi, For example you can do something like that: CREATE TABLE "try" ( "field1"TEXT NOT NULL, "field2"INT4 NOT NULL, "field3"TEXT, PRIMARY KEY (field1, field2)); ** [EMAIL PROTECTED] Laboratoire de prehistoire d

Re: [SQL] how to get the source table & field name of a view field

2002-11-07 Thread Christoph Haller
> Could you tell me how to get view field's source table and field name? > another word, how could I know the view field come from? Within psql, use \d to learn about the view's column names and types and the view definition. If you were thinking about querying system tables to get this informa

Re: [SQL] primary keys

2002-11-07 Thread Bruno Wolff III
On Wed, Nov 06, 2002 at 15:18:38 +0100, Huub <[EMAIL PROTECTED]> wrote: > Hi, > > I want to create a table which has 2 columns, and both columns have to > be primary key (or: together they are the primary key). How can I do > this using SQL? Using pgAdminII for Postgres7.2.2 on RH8. You can u

Re: [SQL] primary keys

2002-11-07 Thread Sangeetha Rao
How do you select these sub Primary Keys? I tried using Shift-Select, Ctrl_Selec, but doesn't work. Thanks Sangeetha -Original Message- From: [EMAIL PROTECTED] [mailto:pgsql-sql-owner@;postgresql.org]On Behalf Of [EMAIL PROTECTED] Sent: Thursday, November 07, 2002 8:54 AM To: 'Huub'; [EMAI

Re: [SQL] primary keys

2002-11-07 Thread Achilleus Mantzios
On Wed, 6 Nov 2002, Huub wrote: > Hi, > > I want to create a table which has 2 columns, and both columns have to > be primary key (or: together they are the primary key). How can I do > this using SQL? Using pgAdminII for Postgres7.2.2 on RH8. I dont know the way in pgAdminII, but from psql simpl

Re: [SQL] primary keys

2002-11-07 Thread Huub
[EMAIL PROTECTED] wrote: A table can only have ONE primary key. It can have additional indexes with a UNIQUE restriction, thereby forcing the second field to be as good as a primary key. That is probably what you are looking for, however, you can also in PG Admin II select multiple fields as

Re: [SQL] how to get the source table & field name of a view field

2002-11-07 Thread Achilleus Mantzios
On Thu, 7 Nov 2002, Prime Ho wrote: > Hi, > > Could you tell me how to get view field's source table and field name? > another word, how could I know the view field come from? SELECT definition from pg_views where viewname=''; > > Regards, > Ho > > > > ---(end of broadcas

Re: [SQL] cast lo to oid

2002-11-07 Thread Tom Lane
"Nekta Katz" <[EMAIL PROTECTED]> writes: > I have the following table > create table scan_docs ( > docid serial, > shipno numeric(10), > scanlo, > type text > ); > when I try to create the following rule > create rule "delete_scan_docs_lo" as > on delete to "scan_docs" > do

[SQL] PLpgSQL FOR IN EXECUTE question

2002-11-07 Thread Christoph Haller
Consider the following PLpgSQL code fragment FOR this_record IN EXECUTE ''SELECT '' || quote_ident($1) || ''FROM '' || quote_ident($2) LOOP list := list || '', '' || this_record.$1 ; END LOOP; As expected, accessing a field via this_record.$1 does not work. Can it be d

Re: [SQL] primary keys

2002-11-07 Thread Tomasz Myrta
Uz.ytkownik Huub napisa?: > Hi, > > I want to create a table which has 2 columns, and both columns have to > be primary key (or: together they are the primary key). How can I do > this using SQL? Using pgAdminII for Postgres7.2.2 on RH8. Dependent on what you need: 1) you can create primary key bas

Re: [SQL] how to get the source table & field name of a view field

2002-11-07 Thread Ken Kennedy
On Thu, Nov 07, 2002 at 05:12:20PM +0800, Prime Ho wrote: > Hi, > > Could you tell me how to get view field's source table and field name? > another word, how could I know the view field come from? > \d view_name should give you the view definition in pqsl. -- Ken Kennedy | http://www.ke

Re: [SQL] PLpgSQL FOR IN EXECUTE question

2002-11-07 Thread Richard Huxton
On Thursday 07 Nov 2002 2:35 pm, Christoph Haller wrote: > Consider the following PLpgSQL code fragment > > FOR this_record IN > EXECUTE ''SELECT '' > > || quote_ident($1) > || ''FROM '' > || quote_ident($2) > > LOOP > list := list || '', '' || this_record.$1 ; > END LOO

Re: [SQL] Copying a rowtype variable.

2002-11-07 Thread Jean-Luc Lachance
I would personnaly like this feature (assigning a composite from another similar composite) to be added to PLPGSQL. Another nice feature would be to able to insert a composite into a table without have to name all atributes. Just my $.02 "Rison, Stuart" wrote: > > >> 2) I am looking for an eleg

Re: [SQL] Weird NULL behavior

2002-11-07 Thread Stephan Szabo
On Thu, 7 Nov 2002, Ludwig Lim wrote: > Hi: > > Has anyone encountered this before? > SELECT CAST ( (NULL*NULL) AS NUMERIC(2,0)); > > > returns the following error message: > Cannot cast type '"char"' to '"numeric"' It seems to me that it's trying to decide on a type for the expression NU

Re: [SQL] Copying a rowtype variable.

2002-11-07 Thread Rison, Stuart
Josh has submitted an appropriate report to pgsql-bugs... so perhaps it will happen! Stuart. > -Original Message- > From: Jean-Luc Lachance [mailto:jllachan@;nsd.ca] > Sent: 07 November 2002 16:29 > To: Rison, Stuart > Cc: ''[EMAIL PROTECTED]' '; 'Josh Berkus ' > Subject: Re: [SQL] Copyin

Re: [SQL] Generating a cross tab (pivot table)

2002-11-07 Thread Joe Conway
Richard Huxton wrote: On Thursday 07 Nov 2002 11:47 am, Christoph Haller wrote: Regarding to Terry's request on multiple aggregates and Shahbaz's request for generating a cross tab ( pivot table ) in September, I've found an excellent example on a german inet page http://www.itrain.de/ I've tran

Re: [SQL] PLpgSQL FOR IN EXECUTE question

2002-11-07 Thread Tom Lane
Christoph Haller <[EMAIL PROTECTED]> writes: > Consider the following PLpgSQL code fragment > FOR this_record IN > EXECUTE ''SELECT '' > || quote_ident($1) > || ''FROM '' > || quote_ident($2) > LOOP > list := list || '', '' || this_record.$1 ; > END LOOP; > As expected,

[SQL] Quartile (etc) ranking in a SQL statement?

2002-11-07 Thread Jeff Boes
Here's a puzzler: Given a query that returns rows ranked by some criteria, how can I write another query around it that will give me the (say) first quartile (top 25%)? Another way of putting it is: if I have rows that look like this: aaa | 1251 aba | 1197 cax | 1042 ... | ... axq | 23 (142 ro

Re: [SQL] Weird NULL behavior

2002-11-07 Thread Stephan Szabo
On Thu, 7 Nov 2002, Tom Lane wrote: > Stephan Szabo <[EMAIL PROTECTED]> writes: > > On Thu, 7 Nov 2002, Ludwig Lim wrote: > >> SELECT CAST ( (NULL*NULL) AS NUMERIC(2,0)); > >> Cannot cast type '"char"' to '"numeric"' > > > It seems to me that it's trying to decide on a type > > for the expression

Re: [SQL] Weird NULL behavior

2002-11-07 Thread Tom Lane
Stephan Szabo <[EMAIL PROTECTED]> writes: > On Thu, 7 Nov 2002, Tom Lane wrote: >> I am kind of inclined to remove the arithmetic operators on "char" >> (+,-,*,/) in 7.4 --- they don't seem to have any real-world uses, >> and as this example illustrates, they are perfectly positioned to >> capture

Re: [SQL] Quartile (etc) ranking in a SQL statement?

2002-11-07 Thread Jean-Luc Lachance
In a PLPGPSQL script, once you know count(*) try execute ''select * from table limit '' || int4( theCount / 4); If you want numbering, create a sequence and add nextval() to the query. JLL Jeff Boes wrote: > > Here's a puzzler: > > Given a query that returns rows ranked by some criteria, h

Re: [SQL] PLpgSQL FOR IN EXECUTE question

2002-11-07 Thread Josh Berkus
Chris, > FOR this_record IN > EXECUTE ''SELECT '' > || quote_ident($1) > || ''FROM '' > || quote_ident($2) > LOOP > list := list || '', '' || this_record.$1 ; > END LOOP; > > As expected, accessing a field via this_record.$1 > does not work. > Can it be done otherwise?

[SQL] Delete cascade for multi tables?

2002-11-07 Thread Zhidian Du
Hello, I have several tables and one table is a reference table, all other tables are master tablls of this reference table. One record in these master tables have several records in the reference table. I want to delete cascade when delete one record one reocrd in mater tables and delete th

[SQL] No promany key in parent table, how to use delete cascade?

2002-11-07 Thread Zhidian Du
Dear All, I want to dreate a delete cascade in children tables. The primary key of parent table is oid, so when I create parent table, there is no apparetly key word "primary key". The problem jumps out. When I create child table using columnn constraint on delete, the SQL says: "PRIMARY KEY

Re: [SQL] No promany key in parent table, how to use delete cascade?

2002-11-07 Thread Stephan Szabo
On Thu, 7 Nov 2002, Zhidian Du wrote: > Dear All, > > I want to dreate a delete cascade in children tables. The primary key of > parent table is oid, so when I create parent table, there is no apparetly > key word "primary key". The problem jumps out. > > When I create child table using columnn

[SQL] Alter table

2002-11-07 Thread Rachel.Vaudron
Hi, I wonder if it is possible to remove a field of a table ? I haven't found anything about this into the reference manual. Can I do something like that ?: ALTER TABLE table DROP COLUMN column; Thanks Rachel ** [EMAIL PROTECTED] Laboratoire de prehistoire

[SQL] changing numeric into int

2002-11-07 Thread Huub
Hi, I want to change 2 columns in the same table from numeric into int. Can I do this without deleting the old table and creating a new one? Data stays the same.. Thanks Huub ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ?

Re: [GENERAL] [SQL] Problem: Referential Integrity Constraints lost

2002-11-07 Thread Tom Lane
Achilleus Mantzios <[EMAIL PROTECTED]> writes: > After recreating the missing triggers should i upgrade > to 7.2.3?? Make that "before". I frankly suspect pilot error here. Triggers do not simply disappear. If you did have crash-induced corruption leading to loss of some rows in pg_trigger, it w

Re: [GENERAL] [SQL] Problem: Referential Integrity Constraints lost

2002-11-07 Thread Achilleus Mantzios
On Thu, 7 Nov 2002, Tom Lane wrote: > Achilleus Mantzios <[EMAIL PROTECTED]> writes: > > After recreating the missing triggers should i upgrade > > to 7.2.3?? > > Make that "before". > > I frankly suspect pilot error here. Triggers do not simply disappear. > If you did have crash-induced corrupti