F
F
farit822022-03-13 22:50:25
PostgreSQL
farit82, 2022-03-13 22:50:25

Golang jetbrains not reading db in sql?

Hello. Why can't I read sql query in golang jetbrains for example select * from "Groups" Error in Groups. To fix the error, I had to wrap it in quotes.\"Groups"\. Does anyone know a solution or have experienced this. Are the queries going to be more difficult? and I won't be able to solve all the mistakes so easily.
fora8284 on the forum Draw the attention of the administration to this message

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2022-03-13
@deliro

1. Goland, not Golang. Golang is a language, and what's from JetBrains is an IDE named Goland
2. Learn SQL syntax. "error" has nothing to do with Golan(d|g)
3.

Are the queries going to be more difficult?
What you wrote is the most elementary request. It's easier just SELECT 1; Obviously it will be more difficult.

G
galaxy, 2022-03-14
@galaxy

If I understand the question correctly (and this is not easy), then because the SQL language is case insensitive, i.e. the following queries are equivalent:

select * from Groups;
select * from groups;
select * from GROUPS;
SELECT * FROM groups;
SeLeCt * FrOm GrOuPs;

If you take the name of a table/column (or other database object) in quotation marks, it becomes (at least according to the SQL standard) case-sensitive, i.e. "group"/"Groups"/"gRoUps" - will be different identifiers (for example, all three such tables can exist in the database at the same time).
If there are no quotes, standard identifiers are compared after being cast to upper-case. In Postgres, this is a bit different: unquoted identifiers are converted to lower-case there.
Those. in other words, the query create table Groups ...will create a table in Postgres named groups. The query select * from GrOupS;will also look for a table named groups.
When using quotes, the query create table "Groups" ...will create a table named Groups. The query select * from "GrOupS";will also look for a table named GrOupS.
spoiler
Речь выше только про Postgresql. Другие СУБД могут вести (и ведут) себя по-другому. Так, в mysql поведение идентификаторов зависит от ОС (точнее, от того, case sensitive/insensitive ее файловая система) и от конфигурации БД.

This is usually not a problem until you start using quoted and unquoted identifiers at the same time. For example, which is most likely the case in your case, the table is created by the query
create table Groups ...
-- реальное имя таблицы - groups

When you make a query select * from "Groups", the call goes to a table that does not exist Groups.
In general, figure out what the name of the table in the database is (in the psql command \dt, or look at the properties of the table in your environment). If it's not lower-case, use quotation marks with the exact name (e.g. select * from "GROUPS"), otherwise it's better to do without quotation marks at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question