We help IT Professionals succeed at work.

Issue to run query

Hi,
What is wrong below? Is it the place to run query?
8a.png
Comment
Watch Question

Most Valuable Expert 2012
Distinguished Expert 2019

Commented:

Nothing is wrong with the syntax.  If you are using copy/paste, make sure there aren't any special characters in the text.

Bill PrewTest your restores, not your backups...
Expert of the Year 2019
Top Expert 2016

Commented:
I suspect the problem is because you have broken the single SQL query across multiple input lines.  

Try typing it all on a single line to see if that works, like below.  If that works then you will have to look for information on how the psql command line wants you to input multiple lines, I don't recall off hand.

SELECT * FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information schema';

Open in new window


»bp
Bill PrewTest your restores, not your backups...
Expert of the Year 2019
Top Expert 2016

Commented:
Sorry, I'd still try the test above, but I see that the prompt did change in your screenshot, so it appears it handled the multi-line input okay.

Did you type those lines in, or paste them?  As mentioned above, if pasted it could be a non-visible character (like a TAB) that is causing a problem perhaps?


»bp
HuaMin ChenProblem resolver

Author

Commented:
Thanks a lot.
I run it in one line below but there is issue happened.
9d.png
Most Valuable Expert 2012
Distinguished Expert 2019

Commented:

Are you pasting it in or manually typing it in?


I still say invalid character.  If you are using a UTF editor, it might not be a space character you are pasting.

HuaMin ChenProblem resolver

Author

Commented:
Thanks.
I further get problem below. Please help.
10a.png
Most Valuable Expert 2012
Distinguished Expert 2019

Commented:

You aren't answering our questions.


Are you physically typing into the psql window or pasting the command into it?

Bill PrewTest your restores, not your backups...
Expert of the Year 2019
Top Expert 2016

Commented:
So you are no longer getting the error on the "*" in the query, what did you do differently to get past that???


»bp
HuaMin ChenProblem resolver

Author

Commented:
I am pasting query into that.

Yes, original issue has been resolved.
Most Valuable Expert 2012
Distinguished Expert 2019

Commented:

>> I am pasting query into that.


Then you need to make sure you are pasting what you think you are pasting.  Something you are pasting isn't correct.

Bill PrewTest your restores, not your backups...
Expert of the Year 2019
Top Expert 2016
Commented:
You need to try TYPING the whole query in, not PASTING it.  That will help determine if there are "special characters" in the source that you are COPYING from, and help guide a solution for that mode.  But do a test TYPING first.


»bp
HuaMin ChenProblem resolver

Author

Commented:
It is strange. Nothing is special below:

SELECT * FROM pg_catalog.pg_tables WHERE schemaname <> 'pg_catalog' AND schemaname <> 'information_schema';

Open in new window

Most Valuable Expert 2012
Distinguished Expert 2019
Commented:

Not really sure what to tell you.  The syntax is correct.


Something in between what you copy from and when you paste it into the psql window is messing with it.


If you are running psql from a Windows CMD prompt, might be the codepage of the CMD prompt.

Bill PrewTest your restores, not your backups...
Expert of the Year 2019
Top Expert 2016

Commented:

You could also save the query to a file, and then just reference the file in the postgres command where you are pasting.  Try saving to a file and then referencing the file like:


\i query.sql