sql DO in rule 9.0rc1

Started by A.M.over 15 years ago6 messagesgeneral
Jump to latest
#1A.M.
agentm@themactionfaction.com

Is there a technical limitation which prevents DO from being used in rules or am I missing something with this?

CREATE RULE test_update AS ON UPDATE TO test DO INSTEAD DO $$
BEGIN;
RAISE NOTICE 'hello';
END;
$$;

Cheers,
M

#2Jeff Davis
pgsql@j-davis.com
In reply to: A.M. (#1)
Re: sql DO in rule 9.0rc1

On Thu, 2010-09-09 at 17:07 -0400, A.M. wrote:

Is there a technical limitation which prevents DO from being used in rules or am I missing something with this?

CREATE RULE test_update AS ON UPDATE TO test DO INSTEAD DO $$
BEGIN;
RAISE NOTICE 'hello';
END;
$$;

Cheers,
M

From the docs here:

http://www.postgresql.org/docs/9.0/static/sql-createrule.html

I see:

"Valid commands are SELECT, INSERT, UPDATE, DELETE, or NOTIFY."

And I assume that DO is a separate command that is not valid for a rule
such as this.

As a workaround, you can make a named function and do "SELECT
myfunction()" as the INSTEAD clause.

Regards,
Jeff Davis

#3A.M.
agentm@themactionfaction.com
In reply to: Jeff Davis (#2)
Re: sql DO in rule 9.0rc1

On Sep 9, 2010, at 8:31 PM, Jeff Davis wrote:

On Thu, 2010-09-09 at 17:07 -0400, A.M. wrote:

Is there a technical limitation which prevents DO from being used in rules or am I missing something with this?

CREATE RULE test_update AS ON UPDATE TO test DO INSTEAD DO $$
BEGIN;
RAISE NOTICE 'hello';
END;
$$;

Cheers,
M

From the docs here:

http://www.postgresql.org/docs/9.0/static/sql-createrule.html

I see:

"Valid commands are SELECT, INSERT, UPDATE, DELETE, or NOTIFY."

And I assume that DO is a separate command that is not valid for a rule
such as this.

As a workaround, you can make a named function and do "SELECT
myfunction()" as the INSTEAD clause.

Perhaps I should have posted to -hackers instead, but I was really wondering if there were some real technical limitation to having this implemented. Does "DO" have any sort of context which can be applied? It seems that NEW and OLD would have to be pushed into that context.

Cheers,
M

#4Merlin Moncure
mmoncure@gmail.com
In reply to: A.M. (#3)
Re: sql DO in rule 9.0rc1

On Fri, Sep 10, 2010 at 1:30 PM, A.M. <agentm@themactionfaction.com> wrote:

On Sep 9, 2010, at 8:31 PM, Jeff Davis wrote:

On Thu, 2010-09-09 at 17:07 -0400, A.M. wrote:

Is there a technical limitation which prevents DO from being used in rules or am I missing something with this?

CREATE RULE test_update AS ON UPDATE TO test DO INSTEAD DO $$
                BEGIN;
                RAISE NOTICE 'hello';
                END;
              $$;

Cheers,
M

From the docs here:

   http://www.postgresql.org/docs/9.0/static/sql-createrule.html

I see:

   "Valid commands are SELECT, INSERT, UPDATE, DELETE, or NOTIFY."

And I assume that DO is a separate command that is not valid for a rule
such as this.

As a workaround, you can make a named function and do "SELECT
myfunction()" as the INSTEAD clause.

Perhaps I should have posted to -hackers instead, but I was really wondering if there were some real technical limitation to having this implemented. Does "DO" have any sort of context which can be applied? It seems that NEW and OLD would have to be pushed into that context.

IDK...functions do everything 'DO' does, and support returning data,
which is necessary to support RETURNING. Rules are already fairly
capricious and problematic and I doubt any proposal that doesn't fix
or work around their basic flaws will get much traction.

merlin

#5Joshua D. Drake
jd@commandprompt.com
In reply to: Merlin Moncure (#4)
Re: sql DO in rule 9.0rc1

On Fri, 2010-09-10 at 13:39 -0400, Merlin Moncure wrote:

IDK...functions do everything 'DO' does, and support returning data,
which is necessary to support RETURNING. Rules are already fairly
capricious and problematic and I doubt any proposal that doesn't fix
or work around their basic flaws will get much traction.

Not to mention there have been talks of ripping them out all together.

JD

--
PostgreSQL.org Major Contributor
Command Prompt, Inc: http://www.commandprompt.com/ - 509.416.6579
Consulting, Training, Support, Custom Development, Engineering
http://twitter.com/cmdpromptinc | http://identi.ca/commandprompt

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Joshua D. Drake (#5)
Re: sql DO in rule 9.0rc1

"Joshua D. Drake" <jd@commandprompt.com> writes:

On Fri, 2010-09-10 at 13:39 -0400, Merlin Moncure wrote:

IDK...functions do everything 'DO' does, and support returning data,
which is necessary to support RETURNING. Rules are already fairly
capricious and problematic and I doubt any proposal that doesn't fix
or work around their basic flaws will get much traction.

Not to mention there have been talks of ripping them out all together.

Yeah. Proposals to add inessential features to rules are probably not
going to go far at the moment. What we need first is a design for fixing
their fundamental issues, so that we can have some reason to think
we're not going to just give up and rip 'em out :-(

regards, tom lane