Обсуждение: does parser still parse those comment out lines?

Поиск
Список
Период
Сортировка

does parser still parse those comment out lines?

От
weiping He
Дата:
see the little test below:
--------------------8<--------------------------------------
drop function test();
create or replace function test() returns integer as '
begin
-- raise NOTICE ''can't comment out!'';
raise notice ''didn''''t comment out'';
return 1;
end;' language 'plpgsql';

laser_uni=# \i test17.sql
psql:test17.sql:1: ERROR:  RemoveFunction: function test() does not exist
psql:test17.sql:4: ERROR:  parser: parse error at or near "t" at
character 84
psql:test17.sql:5: ERROR:  parser: parse error at or near "raise" at
character 1
psql:test17.sql:6: ERROR:  parser: parse error at or near "return" at
character 1
psql:test17.sql:7: WARNING:  COMMIT: no transaction in progress
COMMIT
psql:test17.sql:7: ERROR:  parser: parse error at or near "' language '"
at character 1
-----------------8<------------------------------------------------------
while change it to:

------------------------8<---------------------------------------------
drop function test();
create or replace function test() returns integer as '
begin
-- raise NOTICE ''cant comment out!'';
raise notice ''didn''''t comment out'';
return 1;
end;' language 'plpgsql';
------------------------8<---------------------------------------------
would be OK, so, the parser still parse those commented lines?
Is it a bug?

regards

Laser


Re: does parser still parse those comment out lines?

От
Tom Lane
Дата:
weiping He <laser@zhengmai.com.cn> writes:

> create or replace function test() returns integer as '
> begin
> -- raise NOTICE ''can't comment out!'';
                       ^

You have to double that quote mark, too.  The string-literal parser
doesn't pay any attention to what's inside the string; the fact that
this area of the string would be a comment according to plpgsql's
rules doesn't change what the parser is going to think is the end of
the string literal.

            regards, tom lane


Re: does parser still parse those comment out lines?

От
Ken Williams
Дата:
I'm not a Pg developer, but that looks like expected behavior to me.
It seems analogous to the following Perl code:

   my $string = ' $x = 4; # can't put quotes here either
                  $y = 2 + $x; ';
   eval $string;

Quote-finding happens before comment removal - otherwise you could
never put comment characters inside literal strings (and expect them to
stay there), which would be a real pain.

Seems like the first thing you need to do is make sure everything in
between the first ' and the last ' is a valid string with all its
quotes escaped, and then make sure the string contents make up valid
SQL.

  -Ken


On Saturday, April 19, 2003, at 01:10  AM, weiping He wrote:

> see the little test below:
> --------------------8<--------------------------------------
> drop function test();
> create or replace function test() returns integer as '
> begin
> -- raise NOTICE ''can't comment out!'';
> raise notice ''didn''''t comment out'';
> return 1;
> end;' language 'plpgsql';
>
> laser_uni=# \i test17.sql
> psql:test17.sql:1: ERROR:  RemoveFunction: function test() does not
> exist
> psql:test17.sql:4: ERROR:  parser: parse error at or near "t" at
> character 84
> psql:test17.sql:5: ERROR:  parser: parse error at or near "raise" at
> character 1
> psql:test17.sql:6: ERROR:  parser: parse error at or near "return" at
> character 1
> psql:test17.sql:7: WARNING:  COMMIT: no transaction in progress
> COMMIT
> psql:test17.sql:7: ERROR:  parser: parse error at or near "' language
> '"
> at character 1
> -----------------
> 8<------------------------------------------------------
> while change it to:
>
> ------------------------8<---------------------------------------------
> drop function test();
> create or replace function test() returns integer as '
> begin
> -- raise NOTICE ''cant comment out!'';
> raise notice ''didn''''t comment out'';
> return 1;
> end;' language 'plpgsql';
> ------------------------8<---------------------------------------------
> would be OK, so, the parser still parse those commented lines?
> Is it a bug?
>
> regards
>
> Laser
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
> majordomo@postgresql.org
>