12
endor
5y

endor's first magical adventures with PostgreSQL

"Alright, got the docker image up and running, and I'm connected to the db, both from console and from Datagrip! Cool, let's get started with the tutorial!"
*cue montage of me using Datagrip to create my first schema, then the first table, then insert a bunch of data to try things out*

"Cool, now let's see if I can view my data from the console"
db1-# select * from my_schema.table1
db1-# [nothing]

"*Ahem*, I said:"
db1-# select * from my_schema.table1
db1-# [nothing]

db1-# select * from my_schema.table1
db1-# [cricket noises]

"Wut, why can't I see the data that I inserted? Wtf is going on?"

*30 minutes later*
"Alright, I have no idea what's going on, so let's try inserting the data from console and see if Datagrip can see it"

db1-# insert into my_schema.table1(id, name, field2, field3) values (1, 'Mike', null, 123), (2, 'Jake', 0, 456);
ERROR: syntax error at or near "SELECT"
LINE 2: SELECT
^

"Wait, what?"

db1-# insert into my_schema.table1(id, name, field2, field3) values (1, 'Mike', null, 123), (2, 'Jake', 0, 456);
INSERT 0 2

"Wtf? Haaang on... "

db1-# select * from my_schema.table1;
id | name | field2 | field3
----+------+--------+--------
1 | Mike | | 123
2 | Jake | 0 | 456
1 | Mike | | 123
2 | Jake | 0 | 456
(4 rows)

*eye twitches*

Comments
  • 2
    I swear that blinking cursor in the terminal is actually PostgreSQL looking at me with the most stupid condescending smile on its face
  • 4
    @NoMad yep, that's exactly what was missing, and it took me an hour to realize.

    The thing is, if you miss the semicolon in the terminal it will look as if the command went through but failed - but it's actually still waiting for that semicolon!

    So in my case, it was as if I had typed "select * from ..." three times in a row on the same line.

    Then, when I sent the INSERT command the first time, it appended that to the three selects, and tried to execute that entire garbled mess in a single run (which obviously failed).

    *Then*, when I sent the insert command the second time (immediately afterwards), there was no junk anymore, so it just executed it correctly, adding the data to the stuff that I had already inserted through Datagrip, resulting in 4 total lines.

    And if you think that's confusing, yes.
  • 3
    I've done this so many tines that I barely even noticed it might be confusing for new people. 🙄
  • 2
    @Root this

    Nowdays I know that when pg doesn't respond to me with a success message I need to add the semicolon
Add Comment