[SQL] Hidden Select
I have a query that joins several table with some restrictions. I want to take out those restrictions from the query and create a view that does not show the fields that are used to restrict the data, but in some way, i can restrict that data when i call the view. Is it possible to hide some fields in the view so it could be possible to restrict that data Best Regards Luis Sousa ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])
[SQL] Rule ON DELETE, to perform to DELETE querys !
I have a view over a join of tables and when it's performed over the view a delete i want to delete records in two different tables. The code that i wrote was: CREATE RULE "deletetables" AS ON DELETE TO "tables" DO INSTEAD ( DELETE FROM table2 WHERE id = OLD.id; DELETE FROM table1 WHERE id=OLD.id ); table2 references table1 by the field id only for update. I don't them to be referenced by delete ! When i execute: DELETE FROM tables WHERE id=1; i got these message from postgres: pqReadData() -- backend closed the channel unexpectedly. This probably means the backend terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Failed. The records exists in both tables !!! This already happen with some of you How can i do this Thanks Luis Sousa ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster
Re: [SQL] Getting row with id=max(id)
Gerald Gutierrez <[EMAIL PROTECTED]> writes: > I'd like to get the row with ID=4. I've tried: > SELECT * FROM mytable WHERE id=(SELECT MAX(id) FROM mytable); > The subquery can take a /really/ long time on a table that is large. The query: > SELECT * FROM mytable ORDER BY id DESC LIMIT 1; > doesn't seem to help very much. It should help a lot, if you have an index on id. Have you vacuum analyzed the table recently? regards, tom lane ---(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
[SQL] Index usage
Hi All, The index created by me is not being used while doing select. I found that out by using the EXPLAIN. For example: Table department has dept_num dept_desc Table 'employee' looks like this: emp_num primary key, emp_name, dept_num (this is by way of foreign key relation from department table) Now, I create an index on the employee table using 'dept_num' as the attribute. And when I run select which looks like: Explain Select * from employee where dept_num = 'Finance'; It does not use the index and tells me that a Sequential scan will be done on the table employee. How do I fix this? Thanx in advance, Subra __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://www.postgresql.org/search.mpl
Re: [SQL] Index usage
On Fri, 8 Jun 2001, Subra Radhakrishnan wrote: > Hi All, > > The index created by me is not being used while doing > select. I found that out by using the EXPLAIN. For > example: > > Table department has > > dept_num > dept_desc > > > Table 'employee' looks like this: > > emp_num primary key, > emp_name, > dept_num (this is by way of foreign key relation from > department table) > > Now, I create an index on the employee table using > 'dept_num' as the attribute. And when I run select > which looks like: > > Explain Select * from employee where dept_num = > 'Finance'; > > It does not use the index and tells me that a > Sequential scan will be done on the table employee. > > How do I fix this? Have you run vacuum analyze, what's the full schema (with types) and the explain output? ---(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