[SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread Javier Fonseca V.
Hello. I'm doing a Trigger Procedure in pl/pgSQL. It makes some kind of auditing. I think that it's working alright except for the next line: EXECUTE 'INSERT INTO ' || quote_ident(somedynamictablename) || ' SELECT new.*'; PostgreSQL keeps telling me: "ERROR: NEW used in query that is not in a

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread Pavel Stehule
NEW is only plpgsql variable. It isn't visible on SQL level. You cannot use new.*, you can: execute 'INSERT ...' || 'VALUES(' || new.a || ',' || new.b regards Pavel 2007/8/11, Javier Fonseca V. <[EMAIL PROTECTED]>: > > > Hello. > > I'm doing a Trigger Procedure in pl/pgSQL. It makes some k

Re: [SQL] Best Fit SQL query statement

2007-08-11 Thread hubert depesz lubaczewski
On Fri, Aug 10, 2007 at 08:13:46PM -0500, Rodrigo De León wrote: > On 8/10/07, hubert depesz lubaczewski <[EMAIL PROTECTED]> wrote: > > unfortunatelly this query will be hard to optimize. > > Uh, how about > > SELECT MAX(t1) > FROM t1 > WHERE '9849' LIKE t1 || '%'; it will not help much as th

Re: [SQL] Index usage in order by with multiple columns in order-by-clause

2007-08-11 Thread Andreas Joseph Krogh
On Friday 10 August 2007 23:30:14 Tom Lane wrote: > Andreas Joseph Krogh <[EMAIL PROTECTED]> writes: > > Is there a way I can have multiple columns in the ORDER BY clause, each > > with different ASC/DESC-order and still use an index to speed up sorting? > > A btree index isn't magic, it's just an

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread Tom Lane
"Pavel Stehule" <[EMAIL PROTECTED]> writes: > NEW is only plpgsql variable. It isn't visible on SQL level. Correct, but: > You cannot use new.*, you can: > execute 'INSERT ...' || 'VALUES(' || new.a || ',' || new.b You're both overthinking the problem. In recent releases (at least since 8.

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread Pavel Stehule
2007/8/11, Tom Lane <[EMAIL PROTECTED]>: > "Pavel Stehule" <[EMAIL PROTECTED]> writes: > > NEW is only plpgsql variable. It isn't visible on SQL level. > > Correct, but: > > > You cannot use new.*, you can: > > execute 'INSERT ...' || 'VALUES(' || new.a || ',' || new.b > > You're both overthin

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread Javier Fonseca V.
Yes Tom, you're right, but the real problem is that I need to use an EXECUTE statement because my table name is dynamic. In your example, you used logt as a static table name, and that doesn't need an EXECUTE statement. So I think that I'll have to rewrite a Trigger Procedure for each table and t

Re: [SQL] Index usage in order by with multiple columns in order-by-clause

2007-08-11 Thread hubert depesz lubaczewski
On Fri, Aug 10, 2007 at 04:53:12PM +0200, Andreas Joseph Krogh wrote: > I have the following test-case: > > CREATE TABLE test( > name varchar PRIMARY KEY, > value varchar NOT NULL, > created timestamp not null > ); > > create index test_lowernamevalue_idx ON test ((lower(name) || lower(value)));

Re: [SQL] Trigger Procedure Error: NEW used in query that is not in a rule

2007-08-11 Thread hubert depesz lubaczewski
On Sat, Aug 11, 2007 at 02:45:09AM -0500, Javier Fonseca V. wrote: > I think that it's working alright except for the next line: doing this in plpgsql is very complicated (or even impossible assuming that any table can have the same trigger). i would rather suggest using pl/perl - writing somethin

Re: [SQL] Index usage in order by with multiple columns in order-by-clause

2007-08-11 Thread Andreas Joseph Krogh
On Saturday 11 August 2007 21:05:22 hubert depesz lubaczewski wrote: > On Fri, Aug 10, 2007 at 04:53:12PM +0200, Andreas Joseph Krogh wrote: > > I have the following test-case: > > > > CREATE TABLE test( > > name varchar PRIMARY KEY, > > value varchar NOT NULL, > > created timestamp not null > > );

Re: [SQL] Index usage in order by with multiple columns in order-by-clause

2007-08-11 Thread Tom Lane
Andreas Joseph Krogh <[EMAIL PROTECTED]> writes: > On Friday 10 August 2007 23:30:14 Tom Lane wrote: >> Reverse-sorted index columns are possible but not well supported in >> existing PG releases (you need a custom operator class, and the planner >> is not all that bright about using them). 8.3 wi

Re: [SQL] Index usage in order by with multiple columns in order-by-clause

2007-08-11 Thread Andreas Joseph Krogh
On Saturday 11 August 2007 21:55:49 Tom Lane wrote: > Andreas Joseph Krogh <[EMAIL PROTECTED]> writes: > > On Friday 10 August 2007 23:30:14 Tom Lane wrote: > >> Reverse-sorted index columns are possible but not well supported in > >> existing PG releases (you need a custom operator class, and the