dolthub / doltgresql

DoltgreSQL - Version Controlled PostgreSQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`call dolt_branch("br1")` errors

macneale4 opened this issue · comments

Starting with a completely empty database, I can't create a branch.

$ psql -h localhost -d db1
psql (16.0, server 15.0)
Type "help" for help.

db1=> create table tbl (pk int);
--
(0 rows)

db1=> insert into tbl values (1);
--
(0 rows)

INSERT 0 1
db1=> call dolt_add(".");
 status
--------
      0
(1 row)

db1=> call dolt_commit("-m", "look ma");
               hash
----------------------------------
 6ippk4be9u9q7hil4je37ugfbg766qf3
(1 row)

db1=> call dolt_branch("br1");
ERROR:  column "br1" could not be found in any table in scope (errno 1105) (sqlstate HY000)

error in the log provides no additional info:

2023-10-27T15:11:30-07:00 WARN [conn 1] error running query {connectTime=2023-10-27T15:09:09-07:00, connectionDb=db1, error=column "br1" could not be found in any table in scope} column "br1" could not be found in any table in scope (errno 1105) (sqlstate HY000)

It looks like the parser will sometimes strip out the string quotations for commands that don't explicitly create their own Vitess AST. So call dolt_branch("br1"); becomes call dolt_branch(br1);. Emphasis on the sometimes portion, as call dolt_branch("other"); retains the quotations. This is why it's interpreting this as a column. Need to dig into what's causing this.

So this is an interesting issue. There are actually two problems here, and neither of them are what you would expect.

The first one is that the repro is actually incorrect Postgres. I got tripped up as well because we're used to MySQL, but in Postgres, " is not a string identifier. MySQL uses backticks to mean identifier, but Postgres uses double quotes. So single quotes are for strings. MySQL makes both single and double quotes apply to strings. Postgres doesn't use backticks at all.

https://www.postgresql.org/docs/15/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

The second issue is the opposite of the first, in that the two preceding calls should be failing (dolt_add and dolt_commit), but they were succeeding. Well, they actually fail now, and that's due to the big AST conversion that I did a little while ago. Before that, it was parsing ".", "-m", and "look ma" as column identifiers, however at that time we were still sending strings to the engine. So the string conversion function looked at the strings, determined that they should retain their quotes, and we passed our still-double-quoted strings to the engine. The single dot needs quoting to remain an identifier, "-m" could be interpreted as a negation without the quotes, and "look ma" has a space that needs to be preserved. On the flip side, "br1" would still be valid without the quotes, so they were removed for that string version, and thus caused the error in the engine.

Interesting how all of this works. Either way, we now do the correct behavior!