[SQL] wrong answer

2007-08-21 Thread A. R. Van Hook
I have a simple (and incorrect queuer) that gives the wrong answer. Can someone show me the correct syntax? t select sum(s.ref), r.value, s.ref from registry as s left join referralkey as r on (s.ref = r.cd) group by s.ref, r.value order by r.value, s.ref sum | value | ref

Re: [SQL] wrong answer

2007-08-21 Thread Richard Huxton
A. R. Van Hook wrote: I have a simple (and incorrect queuer) that gives the wrong answer. Can someone show me the correct syntax? t select sum(s.ref), r.value, s.ref from registry as s ^^^ Simple typo - you've used sum() not count() qs select count(*) from registry where ref =3

[SQL] Join question

2007-08-21 Thread tyrrill_ed
Hey All, I have a query I'm trying to speed up, and I was hoping someone could help me. I have a three tables a and b hold data, and c just references between a and b: create table a ( a_id int, x int ); create table b ( b_id int, x int ); create table c ( a_id int, b_id int

Re: [SQL] Join question

2007-08-21 Thread Richard Broersma Jr
--- [EMAIL PROTECTED] wrote: create table c ( a_id int, b_id int ); I am doing a query like this: SELECT a.x, max(b.x) FROM a, b, c WHERE a.a_id = c.a_id AND b.b_id = c.b_id GROUP by a.x; I only need to get one row from b for each row in a, and it really doesn't matter which

Re: [SQL] Join question

2007-08-21 Thread Richard Broersma Jr
oops... I meant DISTINCT ON ( a_id ) --- Richard Broersma Jr [EMAIL PROTECTED] wrote: SELECT a.x, b.x FROM ( SELECT DISTINCT ON ( a_id ) a_id, b_id ^^ FROM c ) AS c( a_id, b_id ) INNER JOIN a ON c.a_id = a.id INNER JOIN b

[SQL] SELECT syntax synopsis: column_definition?

2007-08-21 Thread Richard Broersma Jr
Can any one give an example of the difference between a column_alias and a column_definition when using a function in the FROM clause? from the manual: http://www.postgresql.org/docs/8.2/interactive/sql-select.html function_name ( [ argument [, ...] ] ) [ AS ] alias [ ( column_alias [, ...] |

Re: [SQL] Join question

2007-08-21 Thread Michael Glaesemann
On Aug 21, 2007, at 12:48 , [EMAIL PROTECTED] wrote: SELECT a.x, max(b.x) FROM a, b, c WHERE a.a_id = c.a_id AND b.b_id = c.b_id GROUP by a.x; Shouldn't affect performance, but another way to write this which you may find more readable is to list your join conditions with the joins

[SQL] Make a SQL statement not run trigger

2007-08-21 Thread Jon Collette
Is it possible to run an insert,update, or delete and have it not launch a trigger like it normally would? For example could I set a value DONOTRUN = True; insert into contacts Where the trigger on contacts would call a function that would have an IF statment for that DONOTRUN value?

Re: [SQL] Make a SQL statement not run trigger

2007-08-21 Thread Rodrigo De León
On 8/21/07, Jon Collette [EMAIL PROTECTED] wrote: Is it possible to run an insert,update, or delete and have it not launch a trigger like it normally would? alter table disable trigger ... http://www.postgresql.org/docs/8.2/static/sql-altertable.html ---(end of

Re: [SQL] Make a SQL statement not run trigger

2007-08-21 Thread Jon Collette
Thanks for the reply. It looks like this will disable the trigger for all connections to the database. So if the chance occured that another connection was using the table at the same time it wouldn't launch the trigger either? am I wrong? I hope so ;) Rodrigo De León wrote: On 8/21/07,

Re: [SQL] Make a SQL statement not run trigger

2007-08-21 Thread Scott Marlowe
On 8/21/07, Jon Collette [EMAIL PROTECTED] wrote: Is it possible to run an insert,update, or delete and have it not launch a trigger like it normally would? For example could I set a value DONOTRUN = True; insert into contacts The closest thing to a session variable for pgsql is going

Re: [SQL] Make a SQL statement not run trigger

2007-08-21 Thread Thomas Kellerer
Jon Collette wrote on 21.08.2007 23:26: Is it possible to run an insert,update, or delete and have it not launch a trigger like it normally would? For example could I set a value DONOTRUN = True; insert into contacts Where the trigger on contacts would call a function that would have an

Re: [SQL] Make a SQL statement not run trigger

2007-08-21 Thread Jon Collette
Good Idea. However some of my triggers use the DELETE action as well. So I can't use this method. Thomas Kellerer wrote: Jon Collette wrote on 21.08.2007 23:26: Is it possible to run an insert,update, or delete and have it not launch a trigger like it normally would? For example could I

Re: [SQL] Make a SQL statement not run trigger

2007-08-21 Thread Jon Collette
I think this will work for what I need. I have been messing around with this using select into /select True as donothing into temporary table table_trigger_name; then run statement that I want to be ignored / The trigger would have a select upon the table_trigger_name to determine if it

Re: [SQL] Make a SQL statement not run trigger

2007-08-21 Thread Scott Marlowe
On 8/21/07, Jon Collette [EMAIL PROTECTED] wrote: I think this will work for what I need. I have been messing around with this using select into /select True as donothing into temporary table table_trigger_name; then run statement that I want to be ignored / The trigger would have a select

Re: [SQL] SELECT syntax synopsis: column_definition?

2007-08-21 Thread Michael Glaesemann
On Aug 21, 2007, at 14:34 , Richard Broersma Jr wrote: Can any one give an example of the difference between a column_alias and a column_definition when using a function in the FROM clause? from the manual: http://www.postgresql.org/docs/8.2/interactive/sql-select.html function_name ( [

Re: [SQL] SELECT syntax synopsis: column_definition?

2007-08-21 Thread Michael Glaesemann
On Aug 21, 2007, at 18:04 , Michael Glaesemann wrote: So the *form* is right, but I don't know of an example that works. CREATE TABLE foos ( foo text PRIMARY KEY , title text NOT NULL ); INSERT INTO foos (foo, title) values ('foo', 'the great') , ('bar', 'the extravagant') , ('baz',

Re: [SQL] SELECT syntax synopsis: column_definition?

2007-08-21 Thread Gregory Stark
Michael Glaesemann [EMAIL PROTECTED] writes: ERROR: a column definition list is only allowed for functions returning record So the *form* is right, but I don't know of an example that works. postgres=# create function testf() returns record as 'select 1' language sql; CREATE FUNCTION

Re: [SQL] SELECT syntax synopsis: column_definition?

2007-08-21 Thread Scott Marlowe
On 8/21/07, Gregory Stark [EMAIL PROTECTED] wrote: Michael Glaesemann [EMAIL PROTECTED] writes: ERROR: a column definition list is only allowed for functions returning record So the *form* is right, but I don't know of an example that works. postgres=# create function testf() returns

Re: [SQL] SELECT syntax synopsis: column_definition?

2007-08-21 Thread Alvaro Herrera
Gregory Stark wrote: Michael Glaesemann [EMAIL PROTECTED] writes: ERROR: a column definition list is only allowed for functions returning record So the *form* is right, but I don't know of an example that works. postgres=# create function testf() returns record as 'select 1'

Re: [SQL] SELECT syntax synopsis: column_definition?

2007-08-21 Thread Richard Broersma Jr
--- Alvaro Herrera [EMAIL PROTECTED] wrote: Any function declared as returning SETOF RECORD needs it, when you don't use OUT params. Before OUT params existed, it was the only way to use those functions. Thanks everyone for the exposition! It makes sense. Regards, Richard Broersma Jr.

[SQL] raw data into table process

2007-08-21 Thread novice
I am trying to record the following entries into a table. I'm curious to know if there's an efficient/effective way of doing this? This entries come from an ancient datalogger (note: separated by space and uses YY/MM/DD format to record date) Plain file sample.dat 3665 OK BS

Re: [SQL] SELECT syntax synopsis: column_definition?

2007-08-21 Thread Tom Lane
Gregory Stark [EMAIL PROTECTED] writes: I haven't quite figured out how this is useful though. It probably makes more sense if you use plpgsql but I still don't quite see what the use case is. IIRC, the case that actually convinced people to allow it was dblink. You want to be able to do