[SQL] Trick to 'run' a view on two databases and combine the result ?

2005-01-14 Thread Din Adrian
Hello,
I have a 'big problem' :
I have to show some data from two identical databases so I need to run a  
querry (view, ..etc) on both databases and show the united result ...
Any ideea how to obtain this result ?
Thank You,
Adrian Din

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
---(end of broadcast)---
TIP 8: explain analyze is your friend


[SQL] Record type in sql

2005-01-17 Thread Din Adrian
Hello,
I have a little problem
I want to declare a type record for later use like that
create type record_structure1 as (id int2, nume text);
that is ok!
next in a function I want to use something like that:
select * from table as record_structure1 ?
instead of writing
select * from table as t1(id int2, nume text);
is this possible?
Thank You,
Adrian Din
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
 joining column's datatypes do not match


[SQL] private table

2005-01-26 Thread Din Adrian
Hello,
I am want to use a private table in postgresql(every client to see his own  
data).
Is this possible? How can I do it!

Thank you,
Adrian Din
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
 joining column's datatypes do not match


Re: [SQL] [PERFORM] Tunning postgresql on linux (fedora core 3)

2005-02-03 Thread Din Adrian
sorry about cc ...
this is the site:
http://www.varlena.com/varlena/GeneralBits/Tidbits/annotated_conf_e.html
but I gues is not right ... hmm
Adrian Din
On Thu, 03 Feb 2005 14:52:04 +, Richard Huxton   
wrote:

I'll repeat myself:

Please CC the mailing list as well as replying to me, so that others
can  help too.

Din Adrian wrote:
 On Thu, 03 Feb 2005 13:56:50 +, Richard Huxton
wrote:

Please CC the mailing list as well as replying to me, so that others  
can  help too.


 b) in docs say that after 7.2 seting this to false does'n turn off   
the  wall ...!? wich option does?

The docs don't say that, as far as I can see. It doesn't make sense  
to  turn off the WAL.
  hmm this is the doc about ...
 ' NOTE: Since 7.2, turning fsync off does NOT stop WAL. It does stop   
checkpointing, however. This is a change in the notes that follow Turn  
WAL  off (fsync=false) only for a read-only database or one where the  
database  can be regenerated from external software. While RAID plus  
UPSes can do a  lot to protect your data, turning off fsync means that  
you will be  restoring from backup in the event of hardware or power  
failure.'
I don't know what this is, and you don't give a URL, but it DOES NOT  
appear to be in the manuals.

You should probably read the sections of the manuals regarding "run-time  
configuration" and "write ahead logs". The manuals are quite extensive,  
are available online at http://www.postgresql.org/ and also in most  
distributions.

This is probably a good place to start.
http://www.postgresql.org/docs/8.0/interactive/runtime-config.html#RUNTIME-CONFIG-WAL
If you turn it off you should have more speed ... !!!???
Basically, as I said in my last email - fsync=true makes sure  
transaction details are safely stored on disk. If you turn this off, the  
database doesn't have to wait for the data to physically be written to  
the disk. But, if power fails then data might be in OS or disk cache and  
so lost when you restart the machine.

Please CC the mailing list if you reply to this message.
--
   Richard Huxton
   Archonet Ltd

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [SQL] SQL error: function round(double precision, integer) does not exist

2005-02-28 Thread Din Adrian
the round sintax is
round(numeric,int)
not
round (double,int)
you must cast the value into numeric:
ex: round (cast(doublecolumn as numeric),2) should work ok
Adrian Din,
Om Computer & SoftWare

On Sun, 27 Feb 2005 15:26:07 -0800, TJ O'Donnell <[EMAIL PROTECTED]> wrote:
I received the following error when executing a SQL statement:
SQL error:
ERROR:  function round(double precision, integer) does not exist
In statement:
select id,smiles,smarts,parameter,oe_count_matches(smiles,smarts) as  
count,
  round((parameter*oe_count_matches(smiles,smarts)),2) as  
psa,tpsa(smiles) as ctpsa,tpsa
  from structure,tpsa
  where id < 237610
  and oe_count_matches(smiles,smarts) > 0

order by id;
The functions described at:
http://www.postgresql.org/docs/7.4/static/functions-math.html
show that round(numeric,int) should work ok.
If I use round() without a second argument, it works OK, but
this gives a loss of precision which I do not want.
Can anyone help me with this?
Thanks,
TJ
---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?
  http://www.postgresql.org/docs/faq


Re: [SQL] PostgreSQL and Delphi 6

2005-06-16 Thread Din Adrian
we are using postgresql8 +psqlodbc8+ delphi7 ... the only problem is the  
server side cursor = doesn't work properly ... so we are using client side  
for datasets  :)




On Wed, 15 Jun 2005 23:49:29 -0400, Postgres Admin  
<[EMAIL PROTECTED]> wrote:



I have a client who wants to use Delphi as a front end to a Database, I
would like to use PostgreSQL over MSSQL and have been looking at the
psqlodbc project.  Will psqlodbc connect with Delphi 6? Basically, I'm
wondering if anyone has experience with it?   Any help will be  
appreciated.


Thanks,
J


---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if  
your

  joining column's datatypes do not match





--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

  http://www.postgresql.org/docs/faq


Re: [SQL] PostgreSQL and Delphi 6

2005-06-16 Thread Din Adrian
	Yes, the client must have the psqlodbc driver and mdac at least 2.6.  
(Mdac2.5 is verry buggy - attention win2000 and win9x must be upgraded if  
you need mdac for your app).
	When using server side cursors for a dataset the update and delete  
functions act 'strange' as not refreshing corect the affected rows or by  
showing ony ane record for 20 times instead of 20 different records ...  
(this test was done with psqlodbc8.0 - postgresql DB 8.0 - I think my  
colegs didn't test it with 8.1 yet !! ).
	So we are using client side cursors - slower then server side cursors,  
but we are satified with the results (we are developing a big ERP app for  
two years - it also works over internet on 2-3 clients with relative slow  
net connections : 56-128 Kb/s).


Adrian Din,
Om Computer & Software,
Bucuresti,Romania


On Thu, 16 Jun 2005 08:09:56 -0400, Postgres Admin  
<[EMAIL PROTECTED]> wrote:



So you installed psqlodbc 8 on the client machine with Delphi installed,
correct?  What problems did you have with cursors?  Any other  
suggestions?


Thanks a lot for the help!
J

Din Adrian wrote:

we are using postgresql8 +psqlodbc8+ delphi7 ... the only problem is
the  server side cursor = doesn't work properly ... so we are using
client side  for datasets  :)





---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])





--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [SQL] PostgreSQL and Delphi 6

2005-06-16 Thread Din Adrian
We tested also (pgExpress Driver) - is faster then psqlodbc but we have a  
problem with it:
it does requery (or refresh? - I don't remember exactly) after every post  
in database.(for us this is a problem - if you have more then 10.000 in  
current dataset loaded when you add a new record and post-it you stay 1  
min !? ) - for curiosity how do you deal with this posible problem ?


Adrian Din,
Om Computer & Software,
Bucuresti, Romania

On Thu, 16 Jun 2005 09:54:21 -0300, grupos <[EMAIL PROTECTED]> wrote:


Hi J!

We use here vitavoom from Steve Howe (www.vitavoom.com). It's a very  
good and native alternative.
It's paid but not expensive and you will have a very good and qualified  
technical supporte.


Regards,

Rodrigo Carvalhaes

Postgres Admin wrote:


I have a client who wants to use Delphi as a front end to a Database, I
would like to use PostgreSQL over MSSQL and have been looking at the
psqlodbc project.  Will psqlodbc connect with Delphi 6? Basically, I'm
wondering if anyone has experience with it?   Any help will be  
appreciated.


Thanks,
J


---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if  
your

 joining column's datatypes do not match








--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [SQL] PostgreSQL and Delphi 6

2005-06-16 Thread Din Adrian
I am sorry - I don't understand  (or my english is bad or I don't know  
what you mean).


What we did was include one "refresh" button and inserted one  
configuration that after x seconds the component refresh the screen  
(query).


So:
When the user push the 'post' button the driver automatically refresh the  
current dataset and the user have to wait many seconds (or min?!) until  
it's finish. ok?

How did you say you avoided this ?


Adrian Din,
Om Computer & SoftWare
Bucuresti, Romania



On Thu, 16 Jun 2005 10:29:38 -0300, grupos <[EMAIL PROTECTED]> wrote:


Hi Adrian,

You're right. What we did was include one "refresh" button and inserted  
one configuration that after x seconds the component refresh the screen  
(query).


If you find a better solution, please inform me.

Regards,

Rodrigo

Din Adrian wrote:

We tested also (pgExpress Driver) - is faster then psqlodbc but we have  
a  problem with it:
it does requery (or refresh? - I don't remember exactly) after every  
post  in database.(for us this is a problem - if you have more then  
10.000 in  current dataset loaded when you add a new record and post-it  
you stay 1  min !? ) - for curiosity how do you deal with this posible  
problem ?


Adrian Din,
Om Computer & Software,
Bucuresti, Romania

On Thu, 16 Jun 2005 09:54:21 -0300, grupos <[EMAIL PROTECTED]>  
wrote:



Hi J!

We use here vitavoom from Steve Howe (www.vitavoom.com). It's a very   
good and native alternative.
It's paid but not expensive and you will have a very good and  
qualified  technical supporte.


Regards,

Rodrigo Carvalhaes

Postgres Admin wrote:

I have a client who wants to use Delphi as a front end to a Database,  
I

would like to use PostgreSQL over MSSQL and have been looking at the
psqlodbc project.  Will psqlodbc connect with Delphi 6? Basically, I'm
wondering if anyone has experience with it?   Any help will be   
appreciated.


Thanks,
J


---(end of  
broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan  
if  your

 joining column's datatypes do not match














--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [SQL] UPDATEABLE VIEWS ... Examples?

2005-06-20 Thread Din Adrian

An example(found it some time ago somewhere ?! :) ):

/*
drop view a_and_b cascade;
drop table tbla cascade;
drop table tblb cascade;
*/

CREATE TABLE tbla
(
 id int4 NOT NULL,
 a int4,
 b varchar(12),
 CONSTRAINT tbla_pk PRIMARY KEY (id)
)
--WITHOUT OIDS
;

CREATE TABLE tblb
(
 id int4 NOT NULL,
 x bool,
 y timestamp,
 CONSTRAINT tblb_pk PRIMARY KEY (id),
 CONSTRAINT tblb_fk FOREIGN KEY (id) REFERENCES tbla (id) ON UPDATE CASCADE
ON DELETE CASCADE
)
--WITHOUT OIDS
;

INSERT INTO tbla VALUES ( 3, 9034, 'test1' );
INSERT INTO tbla VALUES ( 6, -23, 'test2' );
INSERT INTO tblb VALUES ( 3, false, now() );
INSERT INTO tblb VALUES ( 6, true, now() );

CREATE OR REPLACE VIEW a_and_b AS
 SELECT tbla.id, tbla.a, tbla.b, tblb.x, tblb.y
   FROM tbla
NATURAL LEFT JOIN tblb;


CREATE OR REPLACE RULE a_b_insert AS


ON INSERT TO a_and_b DO INSTEAD (
INSERT INTO tbla (id, a, b) VALUES (new.id, new.a, new.b);
INSERT INTO tblb (id, x, y) VALUES (new.id, new.x, new.y);
);

-- test your insert
INSERT INTO a_and_b VALUES (99, 123, 'text', false, now() );


CREATE OR REPLACE RULE a_and_b_del AS


ON DELETE TO a_and_b DO INSTEAD
 DELETE FROM tbla WHERE tbla.id = OLD.id;

-- test your delete
DELETE FROM a_and_b WHERE id=99;

CREATE OR REPLACE RULE a_and_b_upd AS


ON UPDATE TO a_and_b DO INSTEAD
(
   UPDATE tbla SET a = new.a, b = new.b  WHERE tbla.id = new.id;
   UPDATE tblb SET x = new.x, y = new.y  WHERE tblb.id = new.id ;
);

-- test your update
UPDATE a_and_b SET a=-333, b='neotext', x=false, y='2005-6-6' WHERE id=1;

... it works ok in pgadmin  ...

PS:
   but for me is a problem - I can't do update from delphi7 :
   Error is: "row cannot be located for updating"  ... this is because I  
do 2 updates in rule of update view and the odbc driver (psqlodbc ) or  
delphi wants to do update based on every field ... (also is no key in  
view!!!???)

   ... if anybody have a solution to this problem !?

Best Regards,
Adrian Din,
Om Computer & SoftWare
Bucuresti, Romania

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


[SQL] Help on Procedure running external function

2005-07-04 Thread Din Adrian

Hello,
I have a 'big' problem:
I am trying to run from a procedure a function witch generate a new  
document number (max from table +1 ) and after to insert a document with  
this number, but the function returns me the same number each time because  
the tranzaction is not finished and the inserts are not commited and of  
course the next document number is the same.

...

for ...
loop
nr=get_me_next_number(params);
insert into table values (nr,...)
end loop
...

...
error inserting in table .. primary_key nr .

Is any way in making the external function to 'know' that I inserted  
another row but this insert is in a tranzaction that is not finish yet ?  
ar onother solution ?


for now I 'solved'  by asking for a nr once and generate myself next  
number (+1) but this is not a correct solution (in this time somebody else  
could insert a document with the same nr as the procedure  )


thank you,
Adi


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [SQL] Help on Procedure running external function

2005-07-04 Thread Din Adrian


Yes , I know what sequence is, but our procedure for generating doc  
numbers is v. big and has manny (4) parameters  and we did'nt use sequence  
in it for this reason 


any other advice ?

thak you,
Adi

On Mon, 04 Jul 2005 14:47:16 +0200, Zac <[EMAIL PROTECTED]> wrote:


Din Adrian wrote:

Hello,
I have a 'big' problem:
I am trying to run from a procedure a function witch generate a new   
document number (max from table +1 ) and after to insert a document  
with  this number, but the function returns me the same number each  
time because  the tranzaction is not finished and the inserts are not  
commited and of  course the next document number is the same.

...
 for ...
loop
nr=get_me_next_number(params);
insert into table values (nr,...)
end loop
...
 ...
error inserting in table .. primary_key nr .
 Is any way in making the external function to 'know' that I inserted   
another row but this insert is in a tranzaction that is not finish yet  
?  ar onother solution ?
 for now I 'solved'  by asking for a nr once and generate myself next   
number (+1) but this is not a correct solution (in this time somebody  
else  could insert a document with the same nr as the procedure  )

 thank you,
Adi

I think the best solution is to use a sequence, not "select max(id) +1  
from table". Look here:

http://www.postgresql.org/docs/8.0/interactive/sql-createsequence.html
http://www.postgresql.org/docs/8.0/interactive/functions-sequence.html
Bye

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match





--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [SQL] Help on Procedure running external function

2005-07-05 Thread Din Adrian
1. the function get_me_next_number is runing from this procedure (same  
trans) but it's an external one ...
2. the second solution I'am using now (using temp a table to store each  
maxnrdoc value - but the temp table give me sometimes a relation with OID  
# does not exist - problem that I can only   solve by using only  
execute - but I don't think I can ...?! :))

here is the example:


create temp table MagMaxNrBon
(
magazie varchar(5),
MaxNrBon int8,
CONSTRAINT temp_magbon_pkey PRIMARY KEY (magazie)
);
...

select into vnrBon maxnrbon+1 from MagMaxNrBon where magazie =  
dsgroup.magazie_implicita_lansare;

if vnrbon is null
then
select into vNrBon o_gen_calc_nr_doc from o_gen_calc_nr_doc('BC'  
,vEmitent,dsgroup.magazie_implicita_lansare,dsMasterBon.dataBon);
insert into MagMaxNrBon values  
(dsgroup.magazie_implicita_lansare,vNrBon);

else
 update MagMaxNrBon set maxnrbon=vNrBon where magazie =  
dsgroup.magazie_implicita_lansare;

end if;
...

and in this way vNrBon is correct one ... I will try to use oly execute on  
insert,update and select on temp table MagMaxNrBon  (o_gen_calc_nr_doc  
is the "get_me_next_number" function)


thank you,
Adria Din


On Mon, 04 Jul 2005 17:27:20 +0200, Zac <[EMAIL PROTECTED]> wrote:


Din Adrian wrote:
 Yes , I know what sequence is, but our procedure for generating doc   
numbers is v. big and has manny (4) parameters  and we did'nt use  
sequence  in it for this reason 

 any other advice ?
I think there is no way to have any information about non committed  
transactions.
I don't know if I understand well your problem but from what I see  
"get_me_next_number" function runs in a different transaction (Why? Is  
it an externale procedure that make its own connection to the DB?)),  
otherwise it would see the new inserted number. The better solution is  
to run "get_me_next_number" in the same transaction.
Another solution (not so good but should work) is to generate by  
yourself the number (as you do) and lock the table until you end to  
prevent others inserting documents.

I hope this helps you.
Bye


 thak you,
Adi
 On Mon, 04 Jul 2005 14:47:16 +0200, Zac <[EMAIL PROTECTED]> wrote:


Din Adrian wrote:


Hello,
I have a 'big' problem:
I am trying to run from a procedure a function witch generate a new
document number (max from table +1 ) and after to insert a document   
with  this number, but the function returns me the same number each   
time because  the tranzaction is not finished and the inserts are  
not  commited and of  course the next document number is the same.

...
 for ...
loop
nr=get_me_next_number(params);
insert into table values (nr,...)
end loop
...
 ...
error inserting in table .. primary_key nr .
 Is any way in making the external function to 'know' that I  
inserted   another row but this insert is in a tranzaction that is  
not finish yet  ?  ar onother solution ?
 for now I 'solved'  by asking for a nr once and generate myself  
next   number (+1) but this is not a correct solution (in this time  
somebody  else  could insert a document with the same nr as the  
procedure  )

 thank you,
Adi

I think the best solution is to use a sequence, not "select max(id)  
+1  from table". Look here:

http://www.postgresql.org/docs/8.0/interactive/sql-createsequence.html
http://www.postgresql.org/docs/8.0/interactive/functions-sequence.html
Bye

---(end of  
broadcast)---

TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match





---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq





--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [SQL] Help on Procedure running external function

2005-07-05 Thread Din Adrian
I 'solved' my 'relation with OID  # does not exist' problem using only  
execute on temp table ...
Is no need for me to 'lock'(for update) the temp table - is temporary  
(lock at 'create temp table MagMaxNrBon')- everybody has his own copy 


Your right I should change the get_number procedure to create 'on the fly  
sequences' for each new user settings (in our app the user have the power  
to set the way of generating number for every type of document) (for that  
I need time wich I don't have now :) )...

anyway .. is working (not how I wanted but it's ok)

thank you,
Adrian Din


On Tue, 05 Jul 2005 13:47:24 +0200, Zac <[EMAIL PROTECTED]> wrote:


I think you should use 'FOR UPDATE' clause in your first "select":

select into vnrBon maxnrbon+1 from MagMaxNrBon where magazie =  
dsgroup.magazie_implicita_lansare FOR UPDATE;


In this way you lock the rows eventually returned and no one can update  
them (or select them "for update") until your transaction finished.


Is this good for you?

However IMHO you should think your procedures to use sequences...


1. the function get_me_next_number is runing from this procedure (same   
trans) but it's an external one ...
2. the second solution I'am using now (using temp a table to store  
each  maxnrdoc value - but the temp table give me sometimes a relation  
with OID  # does not exist - problem that I can only   solve by  
using only  execute - but I don't think I can ...?! :))

here is the example:
  create temp table MagMaxNrBon
(
magazie varchar(5),
MaxNrBon int8,
CONSTRAINT temp_magbon_pkey PRIMARY KEY (magazie)
);
...
 select into vnrBon maxnrbon+1 from MagMaxNrBon where magazie =   
dsgroup.magazie_implicita_lansare;

if vnrbon is null
then
select into vNrBon o_gen_calc_nr_doc from o_gen_calc_nr_doc('BC'   
,vEmitent,dsgroup.magazie_implicita_lansare,dsMasterBon.dataBon);
insert into MagMaxNrBon values   
(dsgroup.magazie_implicita_lansare,vNrBon);

else
 update MagMaxNrBon set maxnrbon=vNrBon where magazie =   
dsgroup.magazie_implicita_lansare;

end if;
...
 and in this way vNrBon is correct one ... I will try to use oly  
execute on  insert,update and select on temp table MagMaxNrBon   
(o_gen_calc_nr_doc  is the "get_me_next_number" function)

 thank you,
Adria Din
  On Mon, 04 Jul 2005 17:27:20 +0200, Zac <[EMAIL PROTECTED]> wrote:


Din Adrian wrote:

 Yes , I know what sequence is, but our procedure for generating  
doc   numbers is v. big and has manny (4) parameters  and we did'nt  
use  sequence  in it for this reason 

 any other advice ?


I think there is no way to have any information about non committed   
transactions.
I don't know if I understand well your problem but from what I see   
"get_me_next_number" function runs in a different transaction (Why?  
Is  it an externale procedure that make its own connection to the  
DB?)),  otherwise it would see the new inserted number. The better  
solution is  to run "get_me_next_number" in the same transaction.
Another solution (not so good but should work) is to generate by   
yourself the number (as you do) and lock the table until you end to   
prevent others inserting documents.

I hope this helps you.
Bye


 thak you,
Adi
 On Mon, 04 Jul 2005 14:47:16 +0200, Zac <[EMAIL PROTECTED]> wrote:


Din Adrian wrote:


Hello,
I have a 'big' problem:
I am trying to run from a procedure a function witch generate a  
newdocument number (max from table +1 ) and after to insert a  
document   with  this number, but the function returns me the same  
number each   time because  the tranzaction is not finished and the  
inserts are  not  commited and of  course the next document number  
is the same.

...
 for ...
loop
nr=get_me_next_number(params);
insert into table values (nr,...)
end loop
...
 ...
error inserting in table .. primary_key nr .
 Is any way in making the external function to 'know' that I   
inserted   another row but this insert is in a tranzaction that is   
not finish yet  ?  ar onother solution ?
 for now I 'solved'  by asking for a nr once and generate myself   
next   number (+1) but this is not a correct solution (in this  
time  somebody  else  could insert a document with the same nr as  
the  procedure  )

 thank you,
Adi

I think the best solution is to use a sequence, not "select max(id)   
+1  from table". Look here:

http://www.postgresql.org/docs/8.0/interactive/sql-createsequence.html
http://www.postgresql.org/docs/8.0/interactive/functions-sequence.html
Bye

---(end of   
broadcast)---

TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match





-

Re: [SQL] Help on Procedure running external function

2005-07-05 Thread Din Adrian

I am sorry but:
the table is TEMPORARY ... I don't need to do any lock on it 
(eventualy I should do a lock on the table where I want to insert the  
documents - the MagMaxNrBon is only a temp table used for storing the max  
document nr for each user's setings in this transaction - I did that temp  
table instead of running always the return_next_number function (the  
problem I postit first) - I run once the function for every user's  
settings - get the max doc free number, store in the temp table, do the  
insert in onother table and next time I get this number and raise by 1  
instead of running again the get_next_number function (because as I said  
-  it give the same max number (the insert into table is not 'visible') ))


...
as I said it's 'solved' ...

thank you,
Adrian Din


On Tue, 5 Jul 2005 07:39:48 -0500, Bruno Wolff III <[EMAIL PROTECTED]> wrote:


On Tue, Jul 05, 2005 at 13:47:24 +0200,
  Zac <[EMAIL PROTECTED]> wrote:

I think you should use 'FOR UPDATE' clause in your first "select":

select into vnrBon maxnrbon+1 from MagMaxNrBon where magazie =
dsgroup.magazie_implicita_lansare FOR UPDATE;

In this way you lock the rows eventually returned and no one can update
them (or select them "for update") until your transaction finished.


That doesn't work because you don't lock rows which aren't in the table
yet. You need to use a lock table instead.

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings





--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [SQL] transaction in function

2006-12-05 Thread Din Adrian
Any function runs into a single transaction so you don't need to worry  
about rolling back on exceptions - this is the standard behavior. If there  
is an exception while running any statement   inside the function it's  
rolls back automatically.



On Tue, 05 Dec 2006 17:25:31 +0200, Marian POPESCU  
<[EMAIL PROTECTED]> wrote:



Hi,

I want to write a function that updates several tables; if there is an
exception while updating, it should rollback the transaction and raise an
error.

How can this be done in pgPLSQL in PostgreSQL 8.1 ?

Thank you for helping me out on this one !



---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings