[SQL] what does this error mean?

2001-08-08 Thread Carolyn Lu Wong
When trying to delete data from a table, get the following error: ExecutePlan: (junk) `ctid' is NULL!=ODBC.QueryDef Please advice. ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/users-lounge/docs/faq

Re: [SQL] Problem with aggregate functions and GROUP BY

2001-08-08 Thread Josh Berkus
Alex, > which is the highest value of 'sortby' for each value of 'fk'. > > I would think that the SQL to achieve this is: > > SELECT * FROM test GROUP BY fk HAVING sortby = MAX(sortby); You need a subselect for this: SELECT test.* FROM test, (SELECT max(sortby) as maxsort, fk

Re: [SQL] REFERENCES constraint

2001-08-08 Thread Stephan Szabo
On Wed, 8 Aug 2001, Cedar Cox wrote: > > Two questions (maybe they are silly..) > > 1. Can a column reference more than one table? (This assumes you use a > single sequence to generate the IDs for both "tbla" and "tblb". I guess > you would also have the problem of enforcing a unique index.

Re: [SQL] REFERENCES constraint

2001-08-08 Thread Jan Wieck
Josh Berkus wrote: > Cedar, > > > 1. Can a column reference more than one table? (This assumes you use > > a > > single sequence to generate the IDs for both "tbla" and "tblb". I > > guess > > you would also have the problem of enforcing a unique index. Say > > what?! > > A unique index across

Re: [SQL] Functions returning more than one value

2001-08-08 Thread Grigoriy G. Vovk
May be, in a far future, will be better to have a stored procedures which will able to accept input arguments and output arguments? Aug 8, 09:26 -0700, Josh Berkus wrote: > Chris, > > > The called function (test2() in the example) will MODIFY the two > > arguments > > and then return a true val

Re: [SQL] Problem with aggregate functions and GROUP BY

2001-08-08 Thread Tom Lane
"Alex Page" <[EMAIL PROTECTED]> writes: > I'm trying to write a query that returns the rows containing the > most recent values for each foreign key. The best way to do this (on every dimension except portability :-() is SELECT DISTINCT ON. See the weather-report example in the SELECT reference

Re: [SQL] REFERENCES constraint

2001-08-08 Thread Grigoriy G. Vovk
As for me it is looking as not good normalized structure. After normalization should not be any questions, I think... Aug 8, 19:02 +0300, Cedar Cox wrote: > > Two questions (maybe they are silly..) > > 1. Can a column reference more than one table? (This assumes you use a > single sequence to g

Re: [SQL] REFERENCES constraint

2001-08-08 Thread Josh Berkus
Cedar, (sorry for the double posting, folks) > 2. Can a column reference another column in the same table? eg.. > > CREATE TABLE bloo ( > id int4, > p_id int4 REFERENCES bloo (id) > -- or > --p_id int4 REFERENCES (id) > ) You don't do this with REFERENCES ... you do it with a

Re: [SQL] Functions returning more than one value

2001-08-08 Thread Josh Berkus
Chris, > The called function (test2() in the example) will MODIFY the two > arguments > and then return a true value. After test2() has run, the value of the > two > arguments 'has changed' to what test2() has assigned to them. I understand, now. You're trying to replicate the functionality pro

[SQL] Problem with aggregate functions and GROUP BY

2001-08-08 Thread Alex Page
I'm having real trouble with aggregate functions. I have a table which tracks the value of a field in another table over time - it contains a foreign key to the row in the other table, the value, and a timestamp to sort by. I'm trying to write a query that returns the rows containing the most rece

Re: [SQL] REFERENCES constraint

2001-08-08 Thread Josh Berkus
Cedar, > 1. Can a column reference more than one table? (This assumes you use > a > single sequence to generate the IDs for both "tbla" and "tblb". I > guess > you would also have the problem of enforcing a unique index. Say > what?! > A unique index across multiple tables.. absurd :) eg..

[SQL] RE: RE: Referencing named attribute in where clause doesn't work with7.1.2?

2001-08-08 Thread Jeff Eckermann
I suggest the best place to put your tests is in the WHERE clause. They are out of place in the JOIN clauses, even though this (apparently) works as you expect, because they do not represent a joining of fields. Also, easier to read and understand in the WHERE clause. On joins in general: there

[SQL] REFERENCES constraint

2001-08-08 Thread Cedar Cox
Two questions (maybe they are silly..) 1. Can a column reference more than one table? (This assumes you use a single sequence to generate the IDs for both "tbla" and "tblb". I guess you would also have the problem of enforcing a unique index. Say what?! A unique index across multiple tables

Re: [SQL] Functions returning more than one value

2001-08-08 Thread Chris Ruprecht
Josh, the two functions are just a tiny example of what I want to do which is: call a function with 2 or more arguments (v_val1 and v_val2). The called function (test2() in the example) will MODIFY the two arguments and then return a true value. After test2() has run, the value of the two argume

Re: [SQL] RE: Referencing named attribute in where clause doesn't work with7.1.2?

2001-08-08 Thread Andreas Joseph Krogh
Jeff Eckermann wrote: > > The WHERE clause is evaluated before your SELECT list is determined, so the > aliased value cannot be used. > You can put further NOT NULL tests into the subqueries to make sure that > null values are not returned. > Question: why not just join the tables explicitly? :-

[SQL] RE: Referencing named attribute in where clause doesn't work with 7.1.2?

2001-08-08 Thread Jeff Eckermann
The WHERE clause is evaluated before your SELECT list is determined, so the aliased value cannot be used. You can put further NOT NULL tests into the subqueries to make sure that null values are not returned. Question: why not just join the tables explicitly? The more usual SQL approach would be

Re: [SQL] Referencing named attribute in where clause doesn't workwith 7.1.2?

2001-08-08 Thread Peter Eisentraut
Andreas Joseph Krogh writes: > Hi, this is my first post to this list so please... > I have problems getting this query to work, any ideas? > > select article.title_text_key, > (select on_text.text_value from on_text where > on_text.text_key = title_text_key > AND NOT title_text_key i

Re: [SQL] Referencing named attribute in where clause doesn't workwith 7.1.2?

2001-08-08 Thread Andreas Joseph Krogh
Thomas Good wrote: > > On Wed, 8 Aug 2001, Andreas Joseph Krogh wrote: > > > Hi, this is my first post to this list so please... > > I have problems getting this query to work, any ideas? > > > > select article.title_text_key, > > (select on_text.text_value from on_text where > > on_text.t

Re: [SQL] Referencing named attribute in where clause doesn't workwith 7.1.2?

2001-08-08 Thread Thomas Good
On Wed, 8 Aug 2001, Andreas Joseph Krogh wrote: > Hi, this is my first post to this list so please... > I have problems getting this query to work, any ideas? > > select article.title_text_key, > (select on_text.text_value from on_text where > on_text.text_key = title_text_key > AND

[SQL] Functions returning more than one value

2001-08-08 Thread Chris Ruprecht
Hi all, How can I get more than one value back from a function? I have a situation here, where a function needs to return a value - but also needs to indicate from which type of record the value comes. The most elegant would be something like the 2 functions listed below. They don't work, since

[SQL] Referencing named attribute in where clause doesn't work with 7.1.2?

2001-08-08 Thread Andreas Joseph Krogh
Hi, this is my first post to this list so please... I have problems getting this query to work, any ideas? select article.title_text_key, (select on_text.text_value from on_text where on_text.text_key = title_text_key AND NOT title_text_key is NULL AND on_text.lang_id = (s

Re: [SQL] Are circular REFERENCES possible ?

2001-08-08 Thread Gary Stainburn
Hi all, On Tuesday 07 August 2001 7:35 pm, Tom Lane wrote: > Jan Wieck <[EMAIL PROTECTED]> writes: > > The point is that we based our implementation of foreign keys > > on the SQL3 specs. DEFERRED is not in SQL-92 AFAIK. > > I still have a concern about this --- sure, you can set up the