-2

After following a 2-day SQL training, I wanted to practice for myself in the same database. I used dbgate and postgreSQL. I wanted a query which returns an overview of the initials that movies start with. Or an overview of the initials that first names of actors start with.

I read the postgresql documenten on the left function and the left-function example in an sql online tutorial and as far as I know, I did exactly the same but I do get an error telling me that there is a syntax error near '(' in line 1. I don't understand what is going wrong and would like to know how I have to adjust the query.

SELECT      Left(first_name, 1),
            count(*)
FROM        actors
ORDER BY    COUNT(*);

enter image description here

I had this example: enter image description here

adjusted it for my question/situation:

SELECT      Left(first_name, 1) as initial
            COUNT(*)
FROM        actors
GROUP BY    initial
ORDER BY    initial;

But still, this is the outcome: enter image description here

Even this simple query doesn't work:

SELECT  Left('ABCD', 1);

The same syntax error near '('.

I am using PostgreSQL 15 and DBGate.

DutchArjo
  • 319
  • 3
  • 8
  • 29
  • You need a GROUP BY here. – jarlh Aug 31 '23 at 08:30
  • What have you tried to resolve the problem? Where are you stuck? – Nico Haase Aug 31 '23 at 08:30
  • I tried a different variable. I tried to write a new query. I search on internet if I am doing something wrong and came on this page: https://www.postgresqltutorial.com/postgresql-string-functions/postgresql-left/ – DutchArjo Aug 31 '23 at 08:39
  • https://dbfiddle.uk/XDkDTQBE – jarlh Aug 31 '23 at 08:42
  • 1
    What does `select version();` return? – jarlh Aug 31 '23 at 08:50
  • no such function: version – DutchArjo Aug 31 '23 at 08:52
  • 1
    Seems like you aren't using Postgresql. (You should get something similar to "PostgreSQL 15.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-10), 64-bit",) – jarlh Aug 31 '23 at 08:52
  • that's weird because I installed it last saturday, together with PGAdmin at first, but found out we were using DBGate at the training so I installed DBGate. – DutchArjo Aug 31 '23 at 08:53
  • This is probably a DBGate behavior. (I've never used that product, don't know anything about it.) – jarlh Aug 31 '23 at 08:55
  • `SELECT Left('ABCD', 1);` works perfectly fine in PostgreSQL version 15. (And older, but didn't test). – Frank Heikens Aug 31 '23 at 19:39
  • does it mean postgresql is not installed correctly or might there be a conflict because ms sql is also installed on the computer? – DutchArjo Sep 01 '23 at 07:00
  • can someone tell me what I need to add to me question or need to clarify because it is closed and needs details or clarity. – DutchArjo Sep 01 '23 at 07:01

0 Answers0