Q:

How to make trigger on two tables?

I have a two tables which insert using jdbc. For example its parcelsTable and filesTableAnd i have some cases:
1. INSERT new row in both tables.
2. INSERT new row only in parcelsTable.
TABLES:
DROP parcelsTable;
CREATE TABLE(
 num serial PRIMARY KEY,
 parcel_name text,
 filestock_id integer
)

DROP filesTable;
CREATE TABLE(
 num serial PRIMARY KEY,
 file_name text,
 files bytea
)

I want to set parcelsTable.filestock_id=filesTable.num when i have INSERT in both tables using TRIGGER.
Its possible? How to know that i insert in both tables?

A:

You don't need to use a trigger to get the foreign key value in this case.  Since you have it set as serial you can access the latest value using currval. Run something like this this from your app:
insert into filesTable (file_name, files) select 'f1', 'asdf';
insert into parcelsTable (parcel_name, filestock_id) select 'p1', currval('filesTable_num_seq');

Note that this should only be used when inserting one record at a time to grab individual key values from currval.  I'm calling the default sequence name of table_column_seq, which you should be able to use unless you've explicitly declared something different.
I would also recommend explicitly declaring nullability and the relationship:
CREATE TABLE parcelsTable (
  ...
  filestock_id integer NULL REFERENCES filesTable (num)
);

Here is a working demo at SqlFiddle.

