[SQL] Question about One to Many relationships

2006-03-24 Thread Todd Kennedy
Hi, This should be a simple idea, but I've been going back and forth on it with various people in my tech group. So I've got two tables, one for albums and one for bands, for simplicity's sake, they look like this: CREATE TABLE bands ( id serial PRIMARY KEY, name varchar(64) NOT NULL CHECK(

Re: [SQL] Question about One to Many relationships

2006-03-24 Thread D'Arcy J.M. Cain
On Fri, 24 Mar 2006 11:52:31 -0500 Todd Kennedy [EMAIL PROTECTED] wrote: So I've got two tables, one for albums and one for bands, for simplicity's sake, they look like this: CREATE TABLE bands ( id serial PRIMARY KEY, name varchar(64) NOT NULL CHECK( name ''), UNIQUE(name) ); CREATE

Re: [SQL] Question about One to Many relationships

2006-03-24 Thread Milorad Poluga
Child table references a not-existing table: ('band' insted of 'bands') Error: ERROR: relation band does not exist CREATE TABLE bands ( CREATE TABLE bands_on_album ( - - - band_id integer REFERENCES band (id), - - - Regards, Milorad Poluga [EMAIL PROTECTED]

Re: [SQL] Question about One to Many relationships

2006-03-24 Thread Todd Kennedy
We're not concerned with the track info. This is a listing of album information, hence the one to many relationship between the album and the artist. and for the record, i should correct myself. he said it was bad not wrong. but i hadn't given him all the details. But. Yes. Thank you all

Re: [SQL] Question about One to Many relationships

2006-03-24 Thread D'Arcy J.M. Cain
On Fri, 24 Mar 2006 13:34:34 -0500 Joe [EMAIL PROTECTED] wrote: Todd Kennedy wrote: They haven't responded me as of yet. There should be a band associated with each album -- this is handled in code, but other than that this is the only relational db way I can think of to do it. But if a

Re: [SQL] Question about One to Many relationships

2006-03-24 Thread Joe
Todd Kennedy wrote: They haven't responded me as of yet. There should be a band associated with each album -- this is handled in code, but other than that this is the only relational db way I can think of to do it. But if a band can have songs in many albums and an album can have songs from

Re: [SQL] Custom type

2006-03-24 Thread george young
On Wed, 22 Mar 2006 13:07:33 -0800 Bryce Nesbitt [EMAIL PROTECTED] threw this fish to the penguins: Terry Lee Tucker wrote: rnd=# \h comment Command: COMMENT Description: define or change the comment of an object ..I believe this is what you need. Cool! That's a great feature.

[SQL] Find min and max values across two columns?

2006-03-24 Thread Amos Hayes
Hello. I've recently begun to use PostgreSQL in earnest (working with data as opposed to just having clever applications tuck it away in there) and have hit a wall with something. I'm trying to build a query that among other things, returns the minimum and maximum values contained in

[SQL] generate_series to return row that doesn't exist in table...

2006-03-24 Thread MaXX
Hi, I have a table wich contains aggregated data, table stats_activity logtime timestamptz, count int given this dataset 2006-03-24 03:00:00+01;55 2006-03-24 04:00:00+01;33 2006-03-24 06:00:00+01;46 2006-03-24 07:00:00+01;63 2006-03-24 08:00:00+01;88 I want to get this in order

Re: [SQL] generate_series to return row that doesn't exist in

2006-03-24 Thread Scott Marlowe
On Fri, 2006-03-24 at 14:30, MaXX wrote: Hi, I have a table wich contains aggregated data, table stats_activity logtime timestamptz, count int given this dataset 2006-03-24 03:00:00+01;55 2006-03-24 04:00:00+01;33 2006-03-24 06:00:00+01;46 2006-03-24 07:00:00+01;63

Re: [SQL] Find min and max values across two columns?

2006-03-24 Thread Rod Taylor
On Fri, 2006-03-24 at 15:19 -0500, Amos Hayes wrote: Hello. I've recently begun to use PostgreSQL in earnest (working with data as opposed to just having clever applications tuck it away in there) and have hit a wall with something. I'm trying to build a query that among other things,

Re: [SQL] Custom type

2006-03-24 Thread Tom Lane
george young gry@ll.mit.edu writes: But not if you specify the object: newschm3=# \d+ fffg Table public.fffg Column | Type | Modifiers | Description +-+---+- t | text| | i | integer | | This seems

Re: [SQL] Find min and max values across two columns?

2006-03-24 Thread Tom Lane
Amos Hayes [EMAIL PROTECTED] writes: I'm trying to build a query that among other things, returns the minimum and maximum values contained in either of two columns. I think you might be looking for select greatest(max(columnA), max(columnB)) from tab; select

Re: [SQL] Find min and max values across two columns?

2006-03-24 Thread Tom Lane
Rod Taylor [EMAIL PROTECTED] writes: The reason for the subselect is to prevent multiple calculations of individual column aggregates. I believe it *may* be calculated multiple times otherwise this would work just as well: select case when max(a) max(b) then max(a) else max(b) end as max

Re: [SQL] Find min and max values across two columns?

2006-03-24 Thread Rod Taylor
On Fri, 2006-03-24 at 16:20 -0500, Tom Lane wrote: Rod Taylor [EMAIL PROTECTED] writes: The reason for the subselect is to prevent multiple calculations of individual column aggregates. I believe it *may* be calculated multiple times otherwise this would work just as well: select case

[SQL] Expressing a result set as an array (and vice versa)?

2006-03-24 Thread Don Maier
Good day, Is it possible to construct an array from an appropriate select expression that generates a result set of unknown cardinality? To focus on the simple case: Is it possible to construct a one- dimensional array from a select of a single column in a table with an unknown number of

[SQL] SQL Query Newbie Help

2006-03-24 Thread Julie Robinson
Given the two tables at the bottom of this email, I'm having trouble coming up with a SQL statement that returns all rows in the quality_control_reset table where there is only one row for the most recent quality_control_range. Help? Example: In table quality_control_reset: id |

Re: [SQL] SQL Query Newbie Help

2006-03-24 Thread Julie Robinson
This works, but is there a better solution? select * from quality_control_reset T where date = ( select max(date) from quality_control_reset where qualitycontrolrange = T.qualitycontrolrange); Julie Robinson wrote: Given the two tables at the bottom of this email, I'm having trouble

Re: [SQL] Find min and max values across two columns?

2006-03-24 Thread Amos Hayes
Your tips were great and I have hunted down the relevant pages in the docs. Thanks guys! -- Amos On 24-Mar-06, at 4:20 PM, Rod Taylor wrote: On Fri, 2006-03-24 at 16:20 -0500, Tom Lane wrote: Rod Taylor [EMAIL PROTECTED] writes: The reason for the subselect is to prevent multiple

[SQL] Index on nullable column

2006-03-24 Thread Daniel Caune
Hi, Is an index on a nullable column useful for retrieving rows having that column null? SELECT PlayerID FROM PlayerLoginSession WHERE EndTime IS NULL; Regards, -- Daniel CAUNE Ubisoft Online Technology (514) 4090 2040 ext. 5418 ---(end of

Re: [SQL] SQL Query Newbie Help

2006-03-24 Thread Stephan Szabo
On Fri, 24 Mar 2006, Julie Robinson wrote: This works, but is there a better solution? select * from quality_control_reset T where date = ( select max(date) from quality_control_reset where qualitycontrolrange = T.qualitycontrolrange); If you can use PostgreSQL extensions

Re: [SQL] Expressing a result set as an array (and vice versa)?

2006-03-24 Thread PFC
CREATE OR REPLACE FUNCTION foreach( liste INTEGER[] ) RETURNS SETOF INTEGER AS $$ DECLARE i INTEGER; BEGIN FOR i IN 1..icount(liste) LOOP RETURN NEXT liste[i]; END LOOP; END; $$ LANGUAGE plpgsql; CREATE AGGREGATE array_accum ( sfunc = array_append, basetype = anyelement,

Re: [SQL] Index on nullable column

2006-03-24 Thread Tom Lane
Daniel Caune [EMAIL PROTECTED] writes: Is an index on a nullable column useful for retrieving rows having that column null? Nope, because IS NULL isn't an indexable operator. You can make an end-run around that with a partial index, eg create index fooi on foo(f1) where f1 is null

[SQL] regarding join

2006-03-24 Thread AKHILESH GUPTA
hi all, below I have created two tables in pgsql with field name as 'name' and 'id' as their datatype 'varchar(15)' and 'integer'. One of the table is:- chemical= select * from test1; name | id ---+ akhil | 1 b | 2 c | 3 d | 4 e | 5 f | 6 (6 rows) Another table is:-chemical= select *

Re: [SQL] regarding join

2006-03-24 Thread Andreas Kretschmer
AKHILESH GUPTA [EMAIL PROTECTED] schrieb: hi all, below I have created two tables in pgsql with field name as 'name' and 'id' as their datatype 'varchar(15)' and 'integer'. i want the output as:- ... a UNION of this 2 tables: test=# select * from test1 union select * from test3 order by