0

I'm just trying to run a few queries on a database, however, nothing seems to appear when I run my queries. I log into my database system using:

psql -h HOSTNAME -U USERNAME -d DATABASENAME

That works fine, and I'm onto the database system. However, I get no output in my queries. I typed:

SELECT title AND department 
FROM jointnames 
WHERE artist = 'John Poit';

I typed that directly after logging in, so that was the whole statement, I don't know if you're meant to include something else along with it to generate the output?

It just comes up blank? Can anyone instruct me on the right way to query a database from a command line?

4
  • 3
    String constants need to be put in single quotes: WHERE artist = 'john poit'; postgresql.org/docs/current/static/… Also: string comparison is case sensitive 'John Poit' is something different then 'john poit' Commented Feb 26, 2016 at 13:38
  • Thanks, I just tried that and got the error "argument of AND must be type boolean, not type character varying". Commented Feb 26, 2016 at 13:42
  • 1
    The AND in the SELECT list would cause that error. Column names should just be separated by commas. Commented Feb 26, 2016 at 13:48
  • Thanks! That solved the problem :) Commented Feb 26, 2016 at 13:58

1 Answer 1

1

If you want to get title and department from the table jointnames you separate the fields with a comma.

SELECT title, department 
FROM jointnames 
WHERE artist = 'John Poit';

The AND keyword is used select values based on more than one value, like:

SELECT title, department 
FROM jointnames 
WHERE artist = 'John Poit'
AND city = 'London';
Sign up to request clarification or add additional context in comments.

4 Comments

AND is also a logical operator in PostgreSQL, which is why it didn't just complain of a syntax error with it being in the SELECT list.
Thanks guys, I'm just getting used to postgreSQL and little things like this are a big help
@TomH Saw you provided an answer as a comment before I posted an answer. Pardon, not my intention.
No worries :) I'm glad that you put everything all together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.