Rules

Started by Albert Bartoszkoover 24 years ago8 messageshackersgeneral
Jump to latest
#1Albert Bartoszko
albertb@nt.kegel.com.pl
hackersgeneral

AFAIR (Postgres 6.5 - 7.1.3):

cd /usr/src/postgresql-X.X.X/src/interfaces/libpq++/examples
[postgres@xxx examples]$ /usr/local/pgsql/bin/psql
Password:
Welcome to psql, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

postgres=# \i testlibpq2.sql
CREATE
CREATE
psql:testlibpq2.sql:5: ERROR: parser: parse error at or near ""
psql:testlibpq2.sql:5: ERROR: parser: parse error at or near "]"
postgres=# \q
[postgres@komuna examples]$ cat testlibpq2.sql
CREATE TABLE TBL1 (i int4);

CREATE TABLE TBL2 (i int4);

CREATE RULE r1 AS ON INSERT TO TBL1 DO [INSERT INTO TBL2 values (new.i);
NOTIFY TBL2];
[postgres@komuna examples]$

What is wrong?

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Albert Bartoszko (#1)
hackersgeneral
Re: Rules

"Albert Bartoszko" <albertb@nt.kegel.com.pl> writes:

[ src/interfaces/libpq++/examples/testlibpq2.sql fails ]
What is wrong?

As best I can tell, psql is falling down on the job: it's not treating
square brackets as something to be matched up, as it does with
parentheses. It ships this command to the backend as two separate
queries. Trying it with psql -e shows what's happening:

regression=# CREATE RULE r1 AS ON INSERT TO TBL1 DO [INSERT INTO TBL2 values (new.i); NOTIFY TBL2];
CREATE RULE r1 AS ON INSERT TO TBL1 DO [INSERT INTO TBL2 values (new.i);
ERROR: parser: parse error at or near ""
NOTIFY TBL2];
ERROR: parser: parse error at or near "]"
regression=#

While this clearly ought to be fixed, I think it's a bit late in the
cycle to consider fixing it for 7.2, especially seeing as how no
functionality is lost (multi-rule actions work fine if you put
parentheses rather than square brackets around them).

For 7.3, we should either fix psql or remove the option to use square
brackets in rule action lists. Comments anyone?

regards, tom lane

#3Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Albert Bartoszko (#1)
hackersgeneral
Re: Rules

On Wed, 28 Nov 2001, Albert Bartoszko wrote:

AFAIR (Postgres 6.5 - 7.1.3):

cd /usr/src/postgresql-X.X.X/src/interfaces/libpq++/examples
[postgres@xxx examples]$ /usr/local/pgsql/bin/psql
Password:
Welcome to psql, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

postgres=# \i testlibpq2.sql
CREATE
CREATE
psql:testlibpq2.sql:5: ERROR: parser: parse error at or near ""
psql:testlibpq2.sql:5: ERROR: parser: parse error at or near "]"
postgres=# \q
[postgres@komuna examples]$ cat testlibpq2.sql
CREATE TABLE TBL1 (i int4);

CREATE TABLE TBL2 (i int4);

CREATE RULE r1 AS ON INSERT TO TBL1 DO [INSERT INTO TBL2 values (new.i);
NOTIFY TBL2];

It works for me with () rather than [], although both are in the help.

#4Mårten Gustafsson
marten@ditt.as
In reply to: Tom Lane (#2)
hackersgeneral
Re: [GENERAL] Rules

For 7.3, we should either fix psql or remove the option to use square
brackets in rule action lists. Comments anyone?

Do we really need square brackets?

Just my 2c,
Marten.

#5Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#2)
hackersgeneral
Re: Rules

Tom Lane writes:

For 7.3, we should either fix psql or remove the option to use square
brackets in rule action lists. Comments anyone?

I'd certainly be for removing this since no one could ever really have
used this, but this feature seems so unusual, perhaps there was a reason
for it?

--
Peter Eisentraut peter_e@gmx.net

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#5)
hackersgeneral
Re: Rules

Peter Eisentraut <peter_e@gmx.net> writes:

Tom Lane writes:

For 7.3, we should either fix psql or remove the option to use square
brackets in rule action lists. Comments anyone?

I'd certainly be for removing this since no one could ever really have
used this, but this feature seems so unusual, perhaps there was a reason
for it?

My guess is that the syntax predates psql, or at least predates psql's
current ideas about splitting up queries. It's possible that someone
out there is entering square-bracket-delimited rule lists via a non-psql
interface, but I doubt it. I'd vote for elimination of the syntax,
I think.

regards, tom lane

#7Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#5)
hackersgeneral
Re: Rules

Tom Lane writes:

For 7.3, we should either fix psql or remove the option to use square
brackets in rule action lists. Comments anyone?

I'd certainly be for removing this since no one could ever really have
used this, but this feature seems so unusual, perhaps there was a reason
for it?

Added to TODO:

* Remove brackets as multi-statement rule grouping, must use parens

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#8Jan Wieck
JanWieck@Yahoo.com
In reply to: Tom Lane (#6)
hackersgeneral
Re: Rules

Tom Lane wrote:

Peter Eisentraut <peter_e@gmx.net> writes:

Tom Lane writes:

For 7.3, we should either fix psql or remove the option to use square
brackets in rule action lists. Comments anyone?

I'd certainly be for removing this since no one could ever really have
used this, but this feature seems so unusual, perhaps there was a reason
for it?

My guess is that the syntax predates psql, or at least predates psql's
current ideas about splitting up queries. It's possible that someone
out there is entering square-bracket-delimited rule lists via a non-psql
interface, but I doubt it. I'd vote for elimination of the syntax,
I think.

You're right. The [] syntax was used in Postgres 4.2 and well
supported by monitor(1).

Adding the parens as alternative was - uhm - a workaround for
not beeing able to get square brackets through psql at some
point, but I'm not sure if that was in 6.4 or 6.5.

Anyway, let's rip out the square brackets.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com