Re: how to amend SQL standard to add comments? - Mailing list pgsql-general

From Tom Lane
Subject Re: how to amend SQL standard to add comments?
Date
Msg-id 11419.1336331141@sss.pgh.pa.us
Whole thread Raw
In response to Re: how to amend SQL standard to add comments?  (Thomas Kellerer <spam_eater@gmx.net>)
List pgsql-general
Thomas Kellerer <spam_eater@gmx.net> writes:
> Aleksey Tsalolikhin wrote on 06.05.2012 19:24:
>> Situation:  When a system administrator or database administrator looks at
>> a gnarly SQL query chewing up system resources, there is no way to tell
>> by looking at the query server-side which application it came from, what its
>> purpose is, and who the author or responsible party is.
>>
>> Data: in ANSI SQL standard, you can put single-line comments by preceeding
>> the line with a double-hyphen.  These comments will be thrown away by the
>> database client and the server will never see them.  Hence the metadata
>> (the data about the query itself) is lost.
>>
>> I propose it'd be a benefit, in today's day of distributed and inter-dependent
>> systems, to pass that data along with the query so that it could be used
>> in troubleshooting if needed.
>>
>> An SQL comment may look something like
>>
>> SELECT STUDENT_ID from STUDENTS
>> WHERE LAST_NAME = 'Smith' and FIRST_NAME = 'Joe'
>> COMMENT 'Query Author: Bob Programmer.   Purpose: Pull the student ID
>> number, we'll need it to enroll the student for classes.';

> You can use multi-line comments with /* .. */ to send this information to the server:

Quite aside from the fact that the standard already has two perfectly
good comment syntaxes, ISTM that most of the gripe here is about
behaviors that are outside the standard's scope.

(1) "there is no way to tell by looking at the query server-side which
application it came from" ... Really?  PG has application_name, and
I suspect other SQL databases make more info available than that about
where a query came from.  The text of the query isn't the only available
communication channel, nor necessarily the best one.

(2) "These comments will be thrown away by the database client" ... how
many cases have you checked?  psql does discard single-line comments,
which is something maybe we should change; but I'm not aware of any
other PG-related clients that do that, and it doesn't seem very likely
that clients of other SQL databases do it either.  Parsing out comments
is a complex, expensive thing and there's seldom a good reason to do it
client-side.

            regards, tom lane

pgsql-general by date:

Previous
From: Clemens Eisserer
Date:
Subject: Is there a tool for checking database integrity
Next
From: Tomas Vondra
Date:
Subject: Re: Is there a tool for checking database integrity