dbTalk Databases Forums  

[DOCS] psql man page error?

mailing.database.pgsql-docs mailing.database.pgsql-docs


Discuss [DOCS] psql man page error? in the mailing.database.pgsql-docs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Simon Riggs
 
Posts: n/a

Default [DOCS] psql man page error? - 12-05-2006 , 05:58 AM







On the psql man page there is an example of how to perform multiple line
psql script as part of the -c option description.

The example given is

echo "\x \\ select * from foo;" | psql

which gives

prompt> echo "\x \\ select * from foo;" | psql
Expanded display is on.
invalid command \

i.e. doesn't work on bash. With bash the command should be:

echo -e "\x \n select * from foo;" | psql

which gives

prompt> echo -e "\x \n select * from foo;" | psql
Expanded display is on.
ERROR: relation "foo" does not exist

Does this mean there are multiple forms of the echo command, or is this
example just wrong?

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com



---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Reply With Quote
  #2  
Old   
Jeff Frost
 
Posts: n/a

Default Re: [DOCS] psql man page error? - 12-05-2006 , 11:23 AM






On Tue, 5 Dec 2006, Simon Riggs wrote:

Quote:
which gives

prompt> echo "\x \\ select * from foo;" | psql
Expanded display is on.
invalid command \

i.e. doesn't work on bash. With bash the command should be:

echo -e "\x \n select * from foo;" | psql

which gives

prompt> echo -e "\x \n select * from foo;" | psql
Expanded display is on.
ERROR: relation "foo" does not exist

Does this mean there are multiple forms of the echo command, or is this
example just wrong?
I believe that /bin/echo and the bash built-in used to be slightly different,
although reviewing both man pages on my FC5 system seem to indicate that they
have the same command-line arguments.

It's also possible that I'm thinking back to my Solaris (2.5.1) days when the
built-in tcsh echo was in fact different than /bin/echo. That's why all my
scripts seem to call the binary and not the built-in.

Another possibility is that the original author had the options set in his
xpg_echo environment variable and forgot about it...or his distro was setting
it in a profile.d file.

--
Jeff Frost, Owner <jeff (AT) frostconsultingllc (DOT) com>
Frost Consulting, LLC http://www.frostconsultingllc.com/
Phone: 650-780-7908 FAX: 650-649-1954

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


Reply With Quote
  #3  
Old   
Bruce Momjian
 
Posts: n/a

Default Re: [DOCS] psql man page error? - 12-05-2006 , 11:41 AM



Simon Riggs wrote:
Quote:
On the psql man page there is an example of how to perform multiple line
psql script as part of the -c option description.

The example given is

echo "\x \\ select * from foo;" | psql

which gives

prompt> echo "\x \\ select * from foo;" | psql
Expanded display is on.
invalid command \

i.e. doesn't work on bash. With bash the command should be:

echo -e "\x \n select * from foo;" | psql

which gives

prompt> echo -e "\x \n select * from foo;" | psql
Expanded display is on.
ERROR: relation "foo" does not exist

Does this mean there are multiple forms of the echo command, or is this
example just wrong?
Intersting. This example has been around since at least 2002. The SGML
looks like this:

<application>psql</application>, like this: <literal>echo "\x \\
select * from foo;" | psql</literal>.

and I suppose the asumption was that the \\ would be at the end of the
output line, but in fact both HTML and manual pages just put the \\
anywhere on the line. I think the proper fix is:

<application>psql</application>, like this: <literal>echo -e
"\\x\nSELECT * FROM foo;" | psql</literal>.

I think all modern operating systems understand echo -e at this point.
Change applied to HEAD and 8.2.X.

--
Bruce Momjian bruce (AT) momjian (DOT) us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


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

Default Re: [DOCS] psql man page error? - 12-05-2006 , 12:15 PM



Bruce Momjian <bruce (AT) momjian (DOT) us> writes:
Quote:
I think the proper fix is:

application>psql</application>, like this: <literal>echo -e
"\\x\nSELECT * FROM foo;" | psql</literal>.

I think all modern operating systems understand echo -e at this point.
No, they don't, and neither does the Single Unix Spec:
http://www.opengroup.org/onlinepubs/.../xcu/echo.html

So your version of the example depends on non-standards-compliant
echo behavior, which is not better than before.

regards, tom lane

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


Reply With Quote
  #5  
Old   
Simon Riggs
 
Posts: n/a

Default Re: [DOCS] psql man page error? - 12-05-2006 , 01:58 PM



On Tue, 2006-12-05 at 13:14 -0500, Tom Lane wrote:
Quote:
Bruce Momjian <bruce (AT) momjian (DOT) us> writes:
I think the proper fix is:

application>psql</application>, like this: <literal>echo -e
"\\x\nSELECT * FROM foo;" | psql</literal>.

I think all modern operating systems understand echo -e at this point.

No, they don't, and neither does the Single Unix Spec:
http://www.opengroup.org/onlinepubs/.../xcu/echo.html

So your version of the example depends on non-standards-compliant
echo behavior, which is not better than before.
So the -e is wrong, but the rest of the change was right. Guess we just
need to add a comment about "(you may need to use the -e option on echo
to get this to work on your OS)."

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com



---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


Reply With Quote
  #6  
Old   
Bruce Momjian
 
Posts: n/a

Default Re: [DOCS] psql man page error? - 12-05-2006 , 05:17 PM



Tom Lane wrote:
Quote:
Bruce Momjian <bruce (AT) momjian (DOT) us> writes:
I think the proper fix is:

application>psql</application>, like this: <literal>echo -e
"\\x\nSELECT * FROM foo;" | psql</literal>.

I think all modern operating systems understand echo -e at this point.

No, they don't, and neither does the Single Unix Spec:
http://www.opengroup.org/onlinepubs/.../xcu/echo.html

So your version of the example depends on non-standards-compliant
echo behavior, which is not better than before.
Well, at least my example works on _some_ operating systems, while the
previous worked on none of them, so it is _better_.

I can't think of a good way to do this except converting the example to
a <programlisting> block that will not change newlines:

echo '\x
SELECT * FROM foo;' | psql

Is that what people want?

--
Bruce Momjian bruce (AT) momjian (DOT) us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

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


Reply With Quote
  #7  
Old   
Simon Riggs
 
Posts: n/a

Default Re: [DOCS] psql man page error? - 12-05-2006 , 05:26 PM



On Tue, 2006-12-05 at 18:16 -0500, Bruce Momjian wrote:
Quote:
Tom Lane wrote:
Bruce Momjian <bruce (AT) momjian (DOT) us> writes:
I think the proper fix is:

application>psql</application>, like this: <literal>echo -e
"\\x\nSELECT * FROM foo;" | psql</literal>.

I think all modern operating systems understand echo -e at this point.

No, they don't, and neither does the Single Unix Spec:
http://www.opengroup.org/onlinepubs/.../xcu/echo.html

So your version of the example depends on non-standards-compliant
echo behavior, which is not better than before.

Well, at least my example works on _some_ operating systems, while the
previous worked on none of them, so it is _better_.

I can't think of a good way to do this except converting the example to
a <programlisting> block that will not change newlines:

echo '\x
SELECT * FROM foo;' | psql

Is that what people want?
Well, it works, but IMHO its not as clear.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com



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


Reply With Quote
  #8  
Old   
Bruce Momjian
 
Posts: n/a

Default Re: [DOCS] psql man page error? - 12-05-2006 , 10:30 PM



Simon Riggs wrote:
Quote:
On Tue, 2006-12-05 at 18:16 -0500, Bruce Momjian wrote:
Tom Lane wrote:
Bruce Momjian <bruce (AT) momjian (DOT) us> writes:
I think the proper fix is:

application>psql</application>, like this: <literal>echo -e
"\\x\nSELECT * FROM foo;" | psql</literal>.

I think all modern operating systems understand echo -e at this point.

No, they don't, and neither does the Single Unix Spec:
http://www.opengroup.org/onlinepubs/.../xcu/echo.html

So your version of the example depends on non-standards-compliant
echo behavior, which is not better than before.

Well, at least my example works on _some_ operating systems, while the
previous worked on none of them, so it is _better_.

I can't think of a good way to do this except converting the example to
a <programlisting> block that will not change newlines:

echo '\x
SELECT * FROM foo;' | psql

Is that what people want?

Well, it works, but IMHO its not as clear.
Well, it is even worse because some versions of echo automatically
interpret backslashes, so it would have to be \\x. I am thinking we
should just leave it as I have it now, unless we want to use 'awk' or
'perl' where we know the backslash behavior.

--
Bruce Momjian bruce (AT) momjian (DOT) us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

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


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

Default Re: [DOCS] psql man page error? - 12-05-2006 , 11:43 PM



Bruce Momjian <bruce (AT) momjian (DOT) us> writes:
Quote:
Well, it is even worse because some versions of echo automatically
interpret backslashes, so it would have to be \\x. I am thinking we
should just leave it as I have it now, unless we want to use 'awk' or
'perl' where we know the backslash behavior.
The example as you have it now is directly contradictory to the
published spec.

I agree with Simon's suggestion to remove "-e" from the example
(thereby making it spec-compliant) and add a parenthetical remark
suggesting that standards-challenged versions of echo might need "-e".

regards, tom lane

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


Reply With Quote
  #10  
Old   
Peter Eisentraut
 
Posts: n/a

Default Re: [DOCS] psql man page error? - 12-06-2006 , 05:05 AM



Am Dienstag, 5. Dezember 2006 18:41 schrieb Bruce Momjian:
Quote:
application>psql</application>, like this: <literal>echo "\x \\
select * from foo;" | psql</literal>.

and I suppose the asumption was that the \\ would be at the end of the
output line, but in fact both HTML and manual pages just put the \\
anywhere on the line.
Which is correct. Removing the \\ alters the point of the example.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

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


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 - 2013, Jelsoft Enterprises Ltd.