Subquery Ordinals

Subquery Ordinals

am 22.03.2005 19:25:27 von ion

Hi!
So, say I have some tables...
CREATE SEQUENCE INSERTED_SEQ;
CREATE SEQUENCE REFERER_SEQ;
CREATE TABLE INSERTED(
inserted_id int PRIMARY KEY DEFAULT nextval('inserted_seq'),
value varchar(128) NOT NULL,
ts timestamp DEFAULT NOW()
);
CREATE TABLE REFERER(
referer_id int PRIMARY KEY DEFAULT NextVal('referer_seq'),
name varchar(128) NOT NULL UNIQUE
);
CREATE TABLE REFERER_INSERTED(
referer_id int REFERENCES REFERER(REFERER_ID) ON DELETE CASCADE,
INSERTED_ID int REFERENCES INSERTED(INSERTED_ID) ON DELETE CASCADE
);
and I want to get the list of referers and the list of inserteds to
which each referer refers ordered by date with a local ordinal.
Something like
--
SELECT Name, , value from referer inner join
referer_inserted on referer.referer_id = referer_inserted.referer_id
inner join inserted on referer_inserted.inserted_id =
inserted.inserted_id ORDER BY referer.referer_id, inserted.ts asc;
--
What should 'ordinal expression' be?
If I were just getting a list of inserted, I could
CREATE TEMPORARY SEQUENCE row_number; select nextval('row_number'),
value from inserted order by ts asc;
But, I don't think that'll work here, at least not in a subquery. What
must I do?
Help!
Ion