Re: [SQL] how to create rule as on delete

2005-10-24 Thread Stewart Ben (RBAU/EQS4) *
> If I add the DO INSTEAD,the record can be inserted > into 'maytable_log' and also still remain in the table > 'maytable'. Which is exactly not exist at all. It just > show it as im using the DO INSTEAD. > > My problem is, how to insert the deleted record into > table 'mytable_log' without showin

Re: [SQL] automatic update or insert

2005-10-24 Thread Stewart Ben (RBAU/EQS4) *
> Currently i have implemented this as a stored procedure in the plpgsql > language. This means that in my stored procedure i first do a > select to > find out if the row exists or not, then i do a insert or update > depending if the row existed. > > Unfortunately, stored procedures seems awfull

Re: [SQL] Problem while using start transaction ans commit;

2005-10-18 Thread Stewart Ben (RBAU/EQS4) *
Sri, > I have a small problem in using nested transactions while > working on Postgres 8.0. This is a known problem with Postgres 8.0 - there is no support for nested transactions (which occurs when calling functions). Your best bet would be to raise an exception within B or C - this will cause

Re: [SQL] Question about functions

2005-10-17 Thread Stewart Ben (RBAU/EQS4) *
Mike, > I am trying to run this function but the return is not > correct. If I run the select statement from the psql command > line it works. My guess is that the WHERE clause could be > causing the problem. Then again, it may be how I am using > the FOR loop. The ides column is of type T

Re: [SQL] Update timestamp on update

2005-10-12 Thread Stewart Ben (RBAU/EQS4) *
> The problem is that we treat the PL languages as add-ons and therefore > the documentation of the "core" system shouldn't rely on them ... but > that leaves us presenting C-code triggers as the only examples in > chapter 35. There is a paragraph in there suggesting you go look at > the PL langu

Re: [SQL] SEVEN cross joins?!?!?

2005-10-12 Thread Stewart Ben (RBAU/EQS4) *
> Splitting locations into subsets (like 2,2,3) doesn't work > because it is possible that low values in one location can be offset by > high values in another location, and still result in an excellent combo. > > The good news is these suggestions got me thinking outside > the box. I think I

[SQL] Scripting GRANT on functions

2005-10-05 Thread Stewart Ben (RBAU/EQS4) *
Is there any easy way to script granting privileges to a number of functions? I've got as far as the following code before realising that I'll need to pass in the arguments, and the arguments are stored as OIDs in pg_proc. Is there any easy way, such as GRANT FUNCTION OID 12345? ---CODE---

Re: [SQL] Sending function parametars within EXECUTE ''SELECT...

2005-09-28 Thread Stewart Ben (RBAU/EQS4) *
> Is there a way to assing variable a value returned from query that > accesses the temporary table in a way you explained above? > > For instance, I can do: > > myValue := col2 FROM tmpTbl WHERE someValue = somethingElse... If I'm parsing this correctly, all you need do is: SELECT col2 INTO my

Re: [SQL] changing a column's position in table, how do you do that

2005-09-27 Thread Stewart Ben (RBAU/EQS4) *
Ferindo, > Is there a way to change the position attribute of a column > in a table? AFAIK, there's no way to change this easily. The best way to do it would be as follows: BEGIN WORK; LOCK TABLE mytable IN ACCESS EXCLUSIVE MODE; ALTER TABLE mytable ADD COLUMN col_to_move_2 coltype; UPDATE myt

Re: [SQL] how to do 'deep queries'?

2005-09-26 Thread Stewart Ben (RBAU/EQS4) *
> Is there supported syntax to do 'deep' queries? That is where > A relates to B relates to C, returning fields from each table? > > This doesn't seem to work. Is there a google-able term for > this sort of query? > > select >foo.aaa, >bar.bbb, >baz.ccc > > from >foo,bar,baz >

Re: [SQL] Functions, transactions and RETURN

2005-09-22 Thread Stewart Ben (RBAU/EQS4) *
Hate to reply to my own posts, but I thought the solution I've come across may help others with problems implementing savepoints and transactions in functions. This function implements rollbacks whilst still returning a valid row instead of an exception. A temporary variable is used to get around

[SQL] Functions, transactions and RETURN

2005-09-22 Thread Stewart Ben (RBAU/EQS4) *
After reading up on Postgres documentation, it seems that transactions and savepoints are not available to functions, and savepoints are implemented via BEGIN.. EXCEPTION.. END blocks. I have a function returning an int4 with the following proposed structure: -