[SQL] inner join and limit

2010-05-26 Thread Michele Petrazzo - Unipex
Hi list, I have two table that are so represented: t1: id int primary key ... other t2: id int primary key t1id int fk(t1.id) somedate date ... other data t1: 1 | abcde 2 | fghi data t2: 1 | 1 | 2010-05-23 2 | 1 | 2010-05-24 3 | 1 | 2010-05-25 4 | 2 | 2010-05-22 5 | 2 | 2010-05-26 I'm trying t

[SQL] Rules and sequences

2010-05-26 Thread Ben Morrow
I am trying to implement a fairly standard 'audit table' setup, but using rules instead of triggers (since it should be more efficient). However, I'm running into problems when one of the audited tables has a 'serial' column that is allowed to default: create table foo (id serial, bar text);

Re: [SQL] inner join and limit

2010-05-26 Thread Rolando Edwards
I can only see a LIMIT 1 possible. If someone can come up with LIMIT N on this one, please let us all know. rolando=# drop table if exists t2; DROP TABLE rolando=# drop table if exists t1; DROP TABLE rolando=# create table t1 ( id int primary key, title varchar(10) ); NOTICE: CREATE TABLE / PRIM

Re: [SQL] inner join and limit

2010-05-26 Thread Luigi Antognini
Hello Here a suggestion for your problem. SELECT a.id AS t1_id, d.id AS t2_id, d.somedate AS t2_somedate FROM t1 a JOIN ( SELECT id, t1id, somedate FROM t2 b WHERE (t1id, somedate) IN ( SELECT t1id, somedate FROM t2 c WHERE c.t1id = b.t1id ORDE

Re: [SQL] inner join and limit

2010-05-26 Thread Tim Landscheidt
Michele Petrazzo - Unipex wrote: > I have two table that are so represented: > t1: > id int primary key > ... other > t2: > id int primary key > t1id int fk(t1.id) > somedate date > ... other > data t1: > 1 | abcde > 2 | fghi > data t2: > 1 | 1 | 2010-05-23 > 2 | 1 | 2010-05-24 > 3 | 1 | 2010-

Re: [SQL] inner join and limit

2010-05-26 Thread Rolando Edwards
I found a good solution. drop table if exists t3; drop table if exists t2; drop table if exists t1; create table t1 ( id int primary key, title varchar(10) ); insert into t1 values (1,'abcde'),(2,'fghi'); create table t2 (id int primary key,t1id int not null references t1 (id) ,somedate date); in

Re: [SQL] Rules and sequences

2010-05-26 Thread Tom Lane
Ben Morrow writes: > I am trying to implement a fairly standard 'audit table' setup, but > using rules instead of triggers (since it should be more efficient). Rules are sufficiently tricky that I would never, ever rely on them for auditing. Use a simple AFTER trigger instead.

[SQL] cast record type to array?

2010-05-26 Thread Gerardo Herzig
Hi all. Im not being able to cast a record variable into an array. Im writing a trigger, and i would like to store NEW (and OLD) as text[]. There is a way to do it in plpgsql? (w/o any contrib modules) thanks! Gerardo -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes

Re: [SQL] Rules and sequences

2010-05-26 Thread A. Kretschmer
In response to Tom Lane : > Ben Morrow writes: > > I am trying to implement a fairly standard 'audit table' setup, but > > using rules instead of triggers (since it should be more efficient). > > Rules are sufficiently tricky that I would never, ever rely on them for > auditing. Use a simple AFT