T
T
Troodi Larson2018-03-03 23:07:38
PostgreSQL
Troodi Larson, 2018-03-03 23:07:38

Why is postgre not outputting lines when a valid request is made?

select * from proxy where user='40'
There is such a sql query, the user attribute is an integer. Where did I go wrong? If I remove the quotes, it throws an error:

ERROR:  operator does not exist: name = integer
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

And with quotes it displays "nothing" i.e. zero fields.
Where did I go wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2018-03-03
@troodi

And with quotes it displays "nothing" i.e. zero fields.

With what exactly?
user='40'
'user'='40'
"user"='40'

These are three completely different conditions that do completely different things.
user is a reserved word required by the standard. According to the standard, I’m not sure what it means in the where context, you need to look for it (it can only be reserved as part of create user and the like), and in postgresql it means the name of the current user. It has type name, which provokes an error.
Those. the first condition basically has nothing to do with any user tables.
'user' is just a text constant. Nobody interferes in the condition to compare one constant with another, where 1=1 in some query builders from here.
"user" - access to the object, ignoring reserved words. That is, if you have a user field in the proxy table, then the request should be written as
But the general practice is to not use reserved words as identifiers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question