Re: massive quotes?

From: miko(at)idocs(dot)com (Miko O'Sullivan)
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: massive quotes?
Date: 2003-09-13 21:14:39
Message-ID: db27ea77.0309131314.75f06bdc@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

jon(at)endpoint(dot)com (Jon Jensen) wrote in message news:<Pine(dot)LNX(dot)4(dot)58(dot)0309111950010(dot)7142(at)louche(dot)swelter(dot)net>...
> INSERT INTO sometable (5, <<\.
> a
> very long
> string
> \.
> );

I'm delighted to hear that here docs are being discussed for postgres.
In the world of Perl here docs make life SO MUCH easier by allowing
for independent quoting scopes. Jon, I'm totally in agreement with you
that here docs would be a valuable addition to postgres. I'd like to
propose a few modifications on the syntax you suggest above.

In Perl, the rule for here docs is NOT "it starts immediately after
the definition of the terminator" (as in your example). The rule is
"it starts on the first line after the end of the command in which the
terminator appears". There's a very good reason for this distinction.
That reason is that it allows the command to be succinct, usually a
single line, and the here doc stays completely separate. So, your
example would like this instead:

INSERT INTO sometable (5, <<'(END)');
a
very long
string
(END)

Notice that the entire INSERT command is on one line. Very easy to
read. Note also that the terminator definition is quoted, which
simplifies any concerns about special characters ending the terminator
definition.

One other small tweak. In Perl 5 the rule is that the terminator must
be flush to the left of the line. That means that here docs can mess
up otherwise nicely indented code. That issue is being fixed in Perl
6, where the terminator can be indented with the rest of the code.
Each line of the contents of the here doc are left trimmed by the same
amount of whitespace as the indentation of the terminator. I suggest
we do the same on postgres:

if some_test() then
INSERT INTO sometable (5, <<'(END)');
a
very long
string
blah blah
(END)
end;

In this example, the very long strong is evaluated such that each line
actually begins with the alphanumeric character, except the last line
("blah blah") which begins with four spaces.

-Miko

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-09-13 22:30:14 Re: memory allocation and powers of two
Previous Message Larry Rosenman 2003-09-13 20:47:44 Link.shared help