Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] dollar quoting

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>,"Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] dollar quoting
Date: 2004-02-15 14:36:58
Message-ID: 402F840A.9020208@dunslane.net (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches

Tom Lane wrote:

>Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>  
>
>>Tom Lane wrote:
>>    
>>
>>>... But how about
>>>42$foo$
>>>This is a syntax error in 7.4, and we propose to redefine it as an
>>>integer literal '42' followed by a dollar-quote start symbol.
>>>      
>>>
>
>  
>
>>The test should not succeed anywhere in the string '42$foo$'.
>>    
>>
>
>No, it won't.  The problem is that it should, because the backend will
>see that as '42' followed by a $foo$ quote start.
>

Ok, I see what you are saying. This mismatch would only happen on 
invalid input, though. I believe that what I did will work on all legal 
input.

I think that this might be cured by having psql recognise a legal 
identifier or keyword and eating it as a word, rather than treating it 
as just another set of bytes in the stream. That would enable us to 
avoid the lookback in the dollar-quote recognition test altogether. The 
attached patch does it that way - the keyword/id test needs to come 
right at the end of the loop to avoid clashing with backslash commands, 
btw.

I *think* that this way psql will recognise the start of a dollar quote 
iff the backend lexer would.

>
>  
>
>>Interacting with lexer states would probably be ... unpleasant. Matching 
>>a stream oriented lexer with a line oriented CLI would be messy I suspect.
>>    
>>
>
>I think it would not be that bad.  We'd have to run the lexer on the
>command input buffer and see what state it terminates in.
>
>  
>

Yeah. I am not enough of a flex wizard to undertake the task, though. It 
would take me lots of time. If we make a decision that we really need 
this in order to do dollar quoting in psql I would need some substantial 
help, at least.

cheers

andrew

Attachment: dq-amd3.patch
Description: text/plain (8.9 KB)

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2004-02-15 16:26:53
Subject: Re: [pgsql-hackers-win32] Sync vs. fsync during checkpoint
Previous:From: Florian WeimerDate: 2004-02-15 13:05:16
Subject: Re: [pgsql-hackers-win32] Sync vs. fsync during checkpoint

pgsql-patches by date

Next:From: Tom LaneDate: 2004-02-15 16:42:40
Subject: Re: [HACKERS] dollar quoting
Previous:From: Thomas HallgrenDate: 2004-02-15 14:21:40
Subject: Re: Some new SPI functions

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group