Rules

--001636c5bf51a697e804890b718d
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi Fellows,

I have a table with 55 columns or so, plus one extra column of datatype
geometry, I am using PostGIS.
I intend to split my table into 3 tables. So each may have 25 to 30 columns
each.

I've created a View which relates all 3 tables with their pk and fk
accordingly. This VIEW has a RULE .....

*ON INSERT TO public.mytable DO INSTEAD*
I listed 3 ACTIONS in order to insert data into all 3 different tables.

I am having trouble getting the main table=C2=B4s primary key value. I use =
the
currval('mytable_sequence_id')
It works fine only if I do not insert multiple records at once. If I do
insert multiple records, the currval gets the last value and not each
inserted value. Hence, all my records in my 2 related tables have foreign
key =3D to the last primary key.

I guess I am doing something wrong, either I am missing something or my
approach is incorrect.

Do you know how should I accomplish this ? Any ideas ?


Thanks in advanced.


Ricardo

--001636c5bf51a697e804890b718d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi Fellows,<div><br></div><div>I have a table with 55 columns or so, plus o=
ne extra column of datatype geometry, I am using PostGIS.</div><div>I inten=
d to split my table into 3 tables. So each may have 25 to 30 columns each.<=
/div>
<div><br></div><div>I've =C2=A0created a View which relates all 3 table=
s with their pk and fk accordingly. This VIEW has a RULE .....=C2=A0</div><=
div><br></div><div><font class=3D"Apple-style-span" color=3D"#3333FF"><b><f=
ont class=3D"Apple-style-span" color=3D"#3366FF">ON INSERT TO public.mytabl=
e DO INSTEAD</font></b>=C2=A0</font></div>
<div>I listed 3 ACTIONS in order to insert data into all 3 different tables=
..</div><div><br></div><div>I am having trouble getting the main table=C2=B4=
s primary key value. I use the currval('mytable_sequence_id')</div>=
<div>
It works fine only if I do not insert multiple records at once. If I do ins=
ert multiple records, the currval gets the last value and not each inserted=
value. Hence, all my records in my 2 related tables have foreign key =3D t=
o the last primary key.</div>
<div><br></div><div>I guess I am doing something wrong, either I am missing=
something or my approach is incorrect.</div><div><br></div><div>Do you kno=
w how should I accomplish this ? Any ideas ?</div><div><br></div><div><br>
</div><div>Thanks in advanced.</div><div><br></div><div><br></div><div>Rica=
rdo</div>

--001636c5bf51a697e804890b718d--
Ricardo Bayley [ Di, 15 Juni 2010 08:09 ] [ ID #2043108 ]
Datenbanken » gmane.comp.db.postgresql.admin » Rules

Vorheriges Thema: Fatal Error during PITR Recovery
Nächstes Thema: check_postgres_bloat