Re: [SQL] Question about One to Many relationships

2006-03-24 Thread PFC
And I want to link the band to the album, but, if the album is a compilation it'll be linked to multiple band.ids, so i can't just add a column like: For a compilation, you should link a band to a track, not an album. This opens another can of worms... I would use the following t

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] Expressing a result set as an array (and vice versa)?

2006-03-27 Thread PFC
SELECT array_accum( DISTINCT list_id ) FROM bookmarks; array_accum --- {1,2,3,4,5,7} Couldn't you just use array()? Yes, you can do this : SELECT ARRAY( SELECT something with one column ); However, array_accum() as an aggregate is more interesting because you can

Re: [SQL] Most efficient way to hard-sort records

2006-05-07 Thread PFC
Is it possible to do this : CREATE TABLE sorted (order_no SERIAL PRIMARY KEY, other columns...) INSERT INTO sorted (columns) SELECT * FROM main_table INNER JOIN key_table ON main_table.id = key_table.main_table_id WHERE key = 'param' ORDER BY value SELECT The SERIAL will automat

Re: [SQL] Most efficient way to hard-sort records

2006-05-07 Thread PFC
Another version along that line ? # create sequence counterseq start 1; -- (set/reset whenever a counter is needed) # select main_table.*, nextval('counterseq') as position2 into sorted_main_table from main_table, keytable where main_table.id = keytable.main_table_id order by value

Re: [SQL] Efficient Searching of Large Text Fields

2006-06-13 Thread PFC
2. What functions or libraries are available to make such searching easy to implement well? the tsearch2 module does that, and has a substantial advantage over a solution you might reimplement : it's already done (and it works). Try it... ---(end of broadcast)-

Re: [SQL] sessions and prepared statements

2006-06-16 Thread PFC
in PHP for example, where there are multiple sessions and which you get is random: how do you know if the session you're in has prepared a particular statement? and/or how do you get a list of prepared statements? last, is there any after login trigger that one could use to prepare st

<    1   2