Re: [SQL] DROP TRIGGER

2004-01-18 Thread Tom Lane
sad <[EMAIL PROTECTED]> writes: > ... now the database seems damaged in strange manner: > Postgres cannot drop nor create some triggers > (he was thinking about an hour on the query then i have cancelled) Could you try it again and get a stack trace to show exactly where it's hung up?

Re: [SQL] How can I get the last element out of GROUP BY sets?

2004-01-18 Thread Tom Lane
Robert Creager <[EMAIL PROTECTED]> writes: > ... one piece of data I need is the last value for each GROUP BY > period. Alas, I cannot figure out how to do this. SELECT DISTINCT ON (rather than GROUP BY) could get this done for you. regards, tom lane

Re: [SQL] Execute permissions for stored functions

2004-01-18 Thread Tom Lane
Paul Hart <[EMAIL PROTECTED]> writes: > In RDBMSs such as Oracle, stored PL/SQL functions run with the > permissions of the user that creates the function. Users who are given > EXECUTE privileges then call the function with the permissions of the > creator of the function. Use "SECURITY DEFINE

Re: [SQL] Left joins with multiple tables

2004-01-18 Thread Denis
Hi Colin, Try select id, name, a.field1, b.field2, c.field3 from people p left outer join a on (a.person_id = p id) left outer join b on (b.person_id = p.id) left outer join c on (c.person_id = p.id); HTH Denis - Original Message - From: "Colin Fox" <[EM

Re: [SQL] help with limiting query results

2004-01-18 Thread Tom Lane
"OizOne" <[EMAIL PROTECTED]> writes: > I would need to create a query that selects each hostname only once with > username that has the latest timestamp in the logontime column. SELECT DISTINCT ON is a convenient way to do this. See the "weather reports" example in the SELECT reference page for a

[SQL] How can I get the last element out of GROUP BY sets?

2004-01-18 Thread Robert Creager
I'm trying to produce summary data from a table (using PGSQL 7.4.1): CREATE TABLE readings( "when" timestamp, value integer ); The summary will be based on various time periods. I've been using date_trunc( 'hour', "when" ) and GROUP BY for the min/max/average readings with no problems. But, one

Re: [SQL] Problem with LEFT JOIN

2004-01-18 Thread Tom Lane
"Thomas Wegner" <[EMAIL PROTECTED]> writes: > Hello, whats wrong with this SQL?: > SELECT L.*, A."lastname" AS firma_value, T."string_val1" AS type_value > FROM "lists" L, "typecode" T > LEFT JOIN "adressen" A ON A."id_adressen"=L."firma" > WHERE T."id_typecode"=L."lists_type" > ORDER BY L."id_lis

[SQL] Execute permissions for stored functions

2004-01-18 Thread Paul Hart
Hi all, From what I've seen in the archives, questions like this have kind of been answered in the past, but I was wondering if there have been any changes in this area, or if anyone has good ideas on how to do what I'm about to ask :) In RDBMSs such as Oracle, stored PL/SQL functions run with

Re: [SQL] Is it possible in PostgreSQL?

2004-01-18 Thread Jim Johannsen
This is what I use to flatten a table, the syntax may not be postgresql correct but you will get idea. SELECT a.name ,SUM (CASE WHEN EXTRACT(month from a.date) = 1 THEN a.quantity ELSE 0 END) AS '01'

Re: [SQL] Left joins with multiple tables

2004-01-18 Thread Richard Poole
On Sat, Jan 17, 2004 at 02:30:01AM +, Colin Fox wrote: > For each person in the people table, they may or may not have a record in > a, may or may not have a record in b, and may or may not have a record in > c. ... > But I'd like to be able to do something like: > > select > id, name,

Re: [SQL] Trigger to identify which column(s) updated

2004-01-18 Thread Vishal Kashyap @ [Sai Hertz And Control Systems]
Dear Jack , I suspect that the function would look something like; CREATE FUNCTION FIND_CHANGED_COLUMNS() RETURNS OPAQUE AS ' BEGIN -- FOR EACH COLUMN IN THE RECORD: -- IF ( NEW COLUMNx <> OLD COLUMNx) -- LOG THE RECORD PRIMARY KEY, COLUMN NAME, OLD VALUE RETURN NEW; END; ' LANGU

Re: [SQL] Initially Deffered - FK

2004-01-18 Thread denis
Hi Stephan, Thanks for your reply. But, you will agree that result should be same JUST BEFORE and JUST AFTER commit ( assuming no one is working on the database and i am the only user connected.) Till, the commit ( or end ) is issued, if you query ADDRESS, you will get 4 rows. This is expected

[SQL] Initially Deffered - FK

2004-01-18 Thread denis
Hi all, I am using : PostgreSQL 7.2.3 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7) I am facing strange problem.. I have created two tables: create table contact (id int constraint contact_pk primary key, name text ); create table address (id int constr

[SQL] DROP TRIGGER

2004-01-18 Thread sad
hi all again i have little complex database was used in tests of a program in ordinal way (no manual expirements with pg_catalog have done) now the database seems damaged in strange manner: Postgres cannot drop nor create some triggers (he was thinking about an hour on the query then i have can

[SQL] Trigger to identify which column(s) updated

2004-01-18 Thread Jack Kerkhof
Does anyone know how to write a trigger that would identify which columns have actually changed in an update (and then log them to an archive). I suspect that the function would look something like; CREATE FUNCTION FIND_CHANGED_COLUMNS() RETURNS OPAQUE AS ' BEGIN -- FOR EACH COLUMN IN THE RE

[SQL] help with limiting query results

2004-01-18 Thread OizOne
Hi, I have the following table in postgres: hostname | username| logontime --+---+ ws1 | rautaonn | 2004-01-13 21:25:01.100336 ws1 | administrator | 2004-01-13 21:25:07.706546 ws1 | testuser | 2004

[SQL] problem with function trigger

2004-01-18 Thread jclaudio
Hi I'm trying to update a table column with a pl/pgsql function and a trigger. But I didn't managed to make it work so far. Here's my  function code : CREATE FUNCTION public.calcul_impact() RETURNS opaque AS ' DECLARE id_line integer; quantity integer; single_price real; total_cost real; am

[SQL] Unique field key or several fks ?

2004-01-18 Thread Katarn
Hi, I would like to know opinions about which approach is better: Having a table with a field that works as a unique key, or having several fks that work as a combined key ( all the fks fields )? Thanks in advance, K. ---(end of broadcast)--- TI

Re: [SQL] Transpose rows to columns

2004-01-18 Thread Luis C. Ferreira (aka lcf)
El Lun 12 Ene 2004 22:12, David Witham escribió: >DW: Hi, >DW: >DW: I have a query that returns data like this: >DW: >DW: cust_idcust_name month costrevenue margin >DW: 991234 ABC 2003-07-01 10 15 5 >DW: 991234

Re: [SQL] Triggers

2004-01-18 Thread Benoît BOURNON
I try pgmail and that is well running ... fo security, do not use attachment files with your mail ... try pgmail, you need to use pl/tclu ... Ben Sai Hertz And Control Systems wrote: Dear Uzo , Hi, does postgresql support the ability to email as in SQL Server? I want to create a trigger which

[SQL] Left joins with multiple tables

2004-01-18 Thread Colin Fox
Hi, all. I've got a bit of a problem here. I have 4 tables - people, a, b, c (not the original names). For each person in the people table, they may or may not have a record in a, may or may not have a record in b, and may or may not have a record in c. Handling the first table (a) is easy: sel

[SQL] Problem with LEFT JOIN

2004-01-18 Thread Thomas Wegner
Hello, whats wrong with this SQL?: SELECT L.*, A."lastname" AS firma_value, T."string_val1" AS type_value FROM "lists" L, "typecode" T LEFT JOIN "adressen" A ON A."id_adressen"=L."firma" WHERE T."id_typecode"=L."lists_type" ORDER BY L."id_lists" I get this: ERROR: relation "l" does not exist T

Re: [SQL] Is it possible in PostgreSQL?

2004-01-18 Thread Chris Travers
Moving thread over to SQL list as it belongs there.   Bronx:  This certainly is possible, but IMO, not in one query.  Actually doing it will be relatively complex.  For purposes of maintenance, I am thinking that doing this would be better handled by wrapping at least one view.   CREATE VIEW