Re: ECPG bug: "unterminated quoted identifier"
От | 1250kv |
---|---|
Тема | Re: ECPG bug: "unterminated quoted identifier" |
Дата | |
Msg-id | CA+4qtLdi58jvzOacFTWBySF2gQcuC6JOMhh+cX0K=K53sq0aFw@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: ECPG bug: "unterminated quoted identifier" (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: ECPG bug: "unterminated quoted identifier"
|
Список | pgsql-bugs |
>>You can't use C literal syntax inside a SQL code
>>segment, whether or not the command would work otherwise.
I have come across cases in which there is a need to use nested double quotes inside C string literal.
This is necessary for correct access to database objects whose names contain uppercase characters.
CREATE FUNCTION "My_Func"(IN p_i INTEGER)
RETURNS INTEGER
AS
$BODY$
BEGIN
RETURN p_i + 1;
END;
$BODY$
LANGUAGE plpgsql;
int main()
{
EXEC SQL int i;
EXEC SQL EXECUTE IMMEDIATE "DO $$\n\
BEGIN\n\
:i := embeddedc.\"My_Func\"(:i);\n\
END\n\
$$";
>>segment, whether or not the command would work otherwise.
I have come across cases in which there is a need to use nested double quotes inside C string literal.
This is necessary for correct access to database objects whose names contain uppercase characters.
CREATE FUNCTION "My_Func"(IN p_i INTEGER)
RETURNS INTEGER
AS
$BODY$
BEGIN
RETURN p_i + 1;
END;
$BODY$
LANGUAGE plpgsql;
int main()
{
EXEC SQL int i;
EXEC SQL EXECUTE IMMEDIATE "DO $$\n\
BEGIN\n\
:i := embeddedc.\"My_Func\"(:i);\n\
END\n\
$$";
return 0;
}
Result: ERROR: syntax error at or near "My_Func"
I have discovered another workaround (in addition to what I showed earlier): \" could be replaced with \x22.
However, I believe that this is a bug in the ECPG lexical analyzer.
}
Result: ERROR: syntax error at or near "My_Func"
I have discovered another workaround (in addition to what I showed earlier): \" could be replaced with \x22.
However, I believe that this is a bug in the ECPG lexical analyzer.
On Tue, Oct 20, 2020 at 11:10 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
1250kv <1250kv@gmail.com> writes:
> EXEC SQL char *bar = foo;
I think it's pure luck that that doesn't throw an error.
You should not be using the EXEC SQL prefix for something
that isn't a SQL command.
Anyway, the problem you're hitting here is that as soon as you
say EXEC SQL, the syntax rules for quoted strings change.
This is not well documented, and I think it's got some bugs
in itself [1], but "EXEC SQL char *bar = "aaa\"bbb";" is just
wrong. You can't use C literal syntax inside a SQL code
segment, whether or not the command would work otherwise.
regards, tom lane
[1] https://www.postgresql.org/message-id/673825.1603223178%40sss.pgh.pa.us
В списке pgsql-bugs по дате отправления: