SQL What's The Different

So i tried to learn about SQL and create database, why the first syntax for create database error even though it is same with the second syntax?

postgres-> CREATE DATABASE first_database;
ERROR: syntax error at or near “CREATE”
LINE 2: CREATE DATABASE first_database;
^
postgres=> CREATE DATABASE first_database;
CREATE DATABASE

it seems like, its a cli issue, look at “scenario -1” after postgres its “->” where as in “senario-2” its in correct form “=>” thus its valid and not for previous command

happy coding :slight_smile:

They aren’t the same. A line starting = is the first line. If you hit enter without terminating a query ( ;), it will just give you a new line, which starts with a -

Edit: just for clarity, this line

postgres-> CREATE DATABASE first_database;

That’s the end of a query. I don’t know what the start of it is from the picture, but it’s like you writing

postgres=> SELECT * FROM my_table
postgres-> CREATE DATABASE first_database;

That’s a single query split across two lines, but it’s not valid SQL. So it errors. But

postgres=> CREATE DATABASE first_database;

That’s a single query on a single line, works totally fine.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.