6 ms·
Funny how they say SQL gets it right, but then shows an example which is the opposite of my experience. From PostgreSQL # select '5' = 5; ?column?
by zeroimpl 5y ago
Funny how they say SQL gets it right, but then shows an example which is the opposite of my experience.
From PostgreSQL
# select '5' = 5;
?column?
--------
t
(1 row)
I believe this is standard SQL. Putting something in quotes just means it is a literal, doesn't mean it is a string. Of course if you explicitly cast it to a string, then you get an error. As in:
select '5'::text = 5;
ERROR: operator does not exist: text = integer
LINE 1: select '5'::text = 5;
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
I agree with the premise - SQL gets it right, but perhaps only in PostgreSQL?
- em500 5y ago> I agree with the premise - SQL gets it right, but perhaps only in PostgreSQL? I don't agree with the premise. Both MySQL[1] and MS SQL Server [2] do an implicit cast and then compare them as numbers. I don't know whether this is ANSI standard behavior though. [1] https://dev.mysql.com/doc/refman/8.0/en/type-conversion.html https://dev.mysql.com/doc/refman/8.0/en/type-conversion.html [2] https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-type-conversion-database-engine?view=sql-server-ver15 https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-t...