dbTalk Databases Forums  

commenting sql code

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss commenting sql code in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
joseph speigle
 
Posts: n/a

Default commenting sql code - 02-19-2004 , 07:13 PM






hi,
I was wondering again (I'd asked this a while back but can't find in archives) ..... how can I make an sql comment?

For example this script .....
************************************************** *****
select mazurek(1);
-- test
SELECT count(*) as master_count FROM master;
SELECT count(*) as detail_count FROM detail;
************************************************** *****

gives me this result:
************************************************** *****
test=# \e mazurek_test.sql
mazurek
------------------------------------------
less references in master than in detail
(1 row)

test=#
************************************************** *****
which is the return value from the function, and all further output is killed by the comment.

so it produces no output after the --test.

WASN'T THAT A COMMENT?

I have also tried.... --test (without the space)
to no avail

joe
--
speigle
www.sirfsup.com

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
  #2  
Old   
Bruno LEVEQUE
 
Posts: n/a

Default Re: commenting sql code - 02-20-2004 , 05:13 AM







In your example you must use \i and not \e



On Thu, 19 Feb 2004, joseph speigle wrote:

Quote:
hi,
I was wondering again (I'd asked this a while back but can't find in archives) ..... how can I make an sql comment?

For example this script .....
************************************************** *****
select mazurek(1);
-- test
SELECT count(*) as master_count FROM master;
SELECT count(*) as detail_count FROM detail;
************************************************** *****

gives me this result:
************************************************** *****
test=# \e mazurek_test.sql
mazurek
------------------------------------------
less references in master than in detail
(1 row)

test=#
************************************************** *****
which is the return value from the function, and all further output is killed by the comment.

so it produces no output after the --test.

WASN'T THAT A COMMENT?

I have also tried.... --test (without the space)
to no avail

joe
--
speigle
www.sirfsup.com

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Bruno LEVEQUE
System Engineer
SARL NET6D
bruno.leveque (AT) net6d (DOT) com
http://www.net6d.com

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster



Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: commenting sql code - 02-20-2004 , 08:42 AM



Bruno LEVEQUE <bruno.leveque (AT) net6d (DOT) com> writes:
Quote:
In your example you must use \i and not \e
On investigation, this is actually a bug in the way \e works --- when
the file is read back into psql, it's effectively treated as a single
line, and so the comment kills more than you'd expect. I am amused to
realize that the bug is fixed in CVS tip, as a completely unintended
consequence of the flex rewrite I just did ...

But I agree that \i not \e is the preferred way to invoke a SQL file
that already exists. I am not sure if that's what Joe was trying to
do or not.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
  #4  
Old   
joseph speigle
 
Posts: n/a

Default Re: commenting sql code - 02-20-2004 , 09:00 AM



hello tom and bruno,

Thanks for solving this issue for me. Doing as you say \i and not \e correctly ignores comments. All I wanted to do BTW was what it looks like: edit an sql file from the cwd in the buffer and run it as a script when I close the buffer (I want to say vi buffer and "quit vi with :wq"). I hadn't tried loading the file with \i. I also notice now that it runs correctly doing psql -d test < file_name.sql and correctly ignores the comments, but before I wasn't sure if postgres had special comment syntax!!

On Fri, Feb 20, 2004 at 09:42:55AM -0500, Tom Lane wrote:
Quote:
Bruno LEVEQUE <bruno.leveque (AT) net6d (DOT) com> writes:
In your example you must use \i and not \e

On investigation, this is actually a bug in the way \e works --- when
the file is read back into psql, it's effectively treated as a single
line, and so the comment kills more than you'd expect. I am amused to
realize that the bug is fixed in CVS tip, as a completely unintended
consequence of the flex rewrite I just did ...

But I agree that \i not \e is the preferred way to invoke a SQL file
that already exists. I am not sure if that's what Joe was trying to
do or not.

regards, tom lane
joe
--
speigle
www.sirfsup.com

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.