[SQL] Visual and PostgreSQL

2006-03-05 Thread Michael Louie Loria
Hello, Does anybody have a site links for visual basic and postgresql? What are your opinions about VB/MySQL and VB/PostgreSQL? Thanks, Michael Louie Loria LoRz Technology Solutions http://www.lorztech.com signature.asc Description: OpenPGP digital signature

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > A SQL-language function like this should get inlined into the query, > so that you don't lose any performance compared to writing out the > full expression each time. I think what's going on here is that he doesn't really want a function in the programming s

Re: [SQL] Help with distinctly non-intuitive rule behaviour

2006-03-05 Thread Tom Lane
"Simon Kinsella" <[EMAIL PROTECTED]> writes: > CREATE RULE rule_soft_delete_user AS ON DELETE TO users > WHERE user_departed > now() > DO INSTEAD > UPDATE users SET user_departed = now() > WHERE user_id = OLD.user_id; This is run before the delete. However, since it's a conditional

[SQL] Help with distinctly non-intuitive rule behaviour

2006-03-05 Thread Simon Kinsella
Hello, Can this possibly be right? >From my troubleshooting of a DELETE rule it appears that the rule's WHERE condition sees the *results* of the rule-actions. Apart from being pretty odd, this is a proving to be a big problem in my situation. Here is a cut-down example: Given a table 'users',

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Stephan Szabo
On Sun, 5 Mar 2006 [EMAIL PROTECTED] wrote: > On Sun, Mar 05, 2006 at 11:38:46AM -0800, Stephan Szabo wrote: > > > But imagine instead that this function is more generic. You know > > > that you're trying to get something that's equal to x and equal to > > > y, but you don't know (until the func

Re: [SQL] functions in WHERE clause

2006-03-05 Thread sramsay
On Sun, Mar 05, 2006 at 11:38:46AM -0800, Stephan Szabo wrote: > > But imagine instead that this function is more generic. You know > > that you're trying to get something that's equal to x and equal to > > y, but you don't know (until the function is called) what those > > rvalues should be. In

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Stephan Szabo
On Sun, 5 Mar 2006 [EMAIL PROTECTED] wrote: > On Sun, Mar 05, 2006 at 01:16:40PM -0500, Tom Lane wrote: > > [EMAIL PROTECTED] writes: > > That would work fine if you said RETURNS SETOF ltree. > > > > That should work too, except that you are trying to return a record > > not an ltree value. Try "

Re: [SQL] functions in WHERE clause

2006-03-05 Thread sramsay
On Sun, Mar 05, 2006 at 01:16:40PM -0500, Tom Lane wrote: > [EMAIL PROTECTED] writes: > That would work fine if you said RETURNS SETOF ltree. > > That should work too, except that you are trying to return a record > not an ltree value. Try "RETURN NEXT tree.ltree". > > > Because SETOF won't work

Re: [SQL] Check/unique constraint question

2006-03-05 Thread Jeff Frost
On Sun, 5 Mar 2006, Michael Glaesemann wrote: On Mar 5, 2006, at 17:25 , Jeff Frost wrote: I believe you're looking for what is called a partial index. http://www.postgresql.org/docs/current/interactive/indexes-partial.html create unique index foo_partial_idx on foo (id) where active; Than

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Tom Lane
[EMAIL PROTECTED] writes: > You can't do this: > CREATE FUNCTION xpath(lquery) RETURNS ltree AS $$ > SELECT ltree FROM event WHERE ltree ~ $1; > $$ LANGUAGE SQL; That would work fine if you said RETURNS SETOF ltree. > But I also can't get this kind of thing to work: > CREATE FUNCTION xpath(lq

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Tom Lane
[EMAIL PROTECTED] writes: > I've got one of these: > SELECT * from some_table WHERE > test_for_equality_is_syntactically_ugly; > What I'd like to do is encapsulate the WHERE clause in a function, You mean like replacing SELECT * from some_table WHERE x = 42 AND y = 77 with create function mytes

Re: [SQL] Check/unique constraint question

2006-03-05 Thread Karsten Hilbert
On Sun, Mar 05, 2006 at 12:02:58PM +0300, Nikolay Samokhvalov wrote: > Unfortunately, at the moment Postgres doesn't support subqueries in > CHECK constraints, so it's seems that you should use trigger to check > what you need The OP could also use a check constraint with a function if everything

Re: [SQL] functions in WHERE clause

2006-03-05 Thread sramsay
On Sun, Mar 05, 2006 at 10:26:35AM -0700, Michael Fuhr wrote: > On Sun, Mar 05, 2006 at 10:16:52AM -0500, [EMAIL PROTECTED] wrote: > > I've got one of these: > > > > SELECT * from some_table WHERE > > test_for_equality_is_syntactically_ugly; > > > > What I'd like to do is encapsulate the WHERE cl

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Michael Fuhr
On Sun, Mar 05, 2006 at 10:16:52AM -0500, [EMAIL PROTECTED] wrote: > I've got one of these: > > SELECT * from some_table WHERE > test_for_equality_is_syntactically_ugly; > > What I'd like to do is encapsulate the WHERE clause in a function, > but I'm having no end of trouble. Would a view work?

[SQL] functions in WHERE clause

2006-03-05 Thread sramsay
Hi All, I've got one of these: SELECT * from some_table WHERE test_for_equality_is_syntactically_ugly; What I'd like to do is encapsulate the WHERE clause in a function, but I'm having no end of trouble. The WHERE clause expects the function to return a boolean value. I can certainly return a

Re: [SQL] Check/unique constraint question

2006-03-05 Thread Michael Glaesemann
On Mar 5, 2006, at 17:25 , Jeff Frost wrote: And would like to make a unique constraint which would only check the uniqueness of id if active=true. I believe you're looking for what is called a partial index. http://www.postgresql.org/docs/current/interactive/indexes-partial.html Note, I'v

Re: [SQL] Check/unique constraint question

2006-03-05 Thread Volkan YAZICI
On Mar 05 12:02, Nikolay Samokhvalov wrote: > Unfortunately, at the moment Postgres doesn't support subqueries in > CHECK constraints I don't know how feasible this is but, it's possible to hide subqueries that will be used in constraints in procedures. Here's an alternative method to Nikolay's:

Re: [SQL] Check/unique constraint question

2006-03-05 Thread Nikolay Samokhvalov
just a better way (workaround for subqueries in check constraints...): CREATE OR REPLACE FUNCTION id_is_valid( val INTEGER ) RETURNS boolean AS $BODY$ BEGIN IF val IN ( SELECT id FROM foo WHERE active = TRUE AND id = val ) THEN RETURN FALSE; ELSE RETURN TRUE

Re: [SQL] Check/unique constraint question

2006-03-05 Thread Nikolay Samokhvalov
Unfortunately, at the moment Postgres doesn't support subqueries in CHECK constraints, so it's seems that you should use trigger to check what you need, smth like this: CREATE OR REPLACE FUNCTION foo_check() RETURNS trigger AS $BODY$ BEGIN IF NEW.active = TRUE AND NEW.id IN ( SELECT id

[SQL] Check/unique constraint question

2006-03-05 Thread Jeff Frost
I have a table with the following structure: Column | Type | Modifiers +-+--- active | boolean | not null default true id | integer | not null (other columns left out) And would like to make a unique constraint which would only