Questions tagged [varchar]
Normally refers to a variable length string data type.
162 questions
1 vote
1 answer
82 views
partitioning by varchar column
have a log table that stores execution logs for many different functions. Each row contains the function name, and the table has millions of rows. To improve performance and manage the data better, I ...
2 votes
1 answer
121 views
Ignoring trailing spaces when grouping by varchar type in Redshift
I created a table in Redshift and entered data as below. create table public.temp ( id int, name varchar(20) ); insert into public.temp (id, name) values (1, 'bob'), (2, 'bob '); And when ...
0 votes
1 answer
79 views
Postgresql: Any benefits of specific lengths of varchar [duplicate]
Are there any optimization benefits (storage/query speed/...) of choosing specific lengths for VARCHAR columns in PostgreSQL? Like, 2^n-1 or something similar?
-1 votes
1 answer
95 views
MySQL Storage: VARCHAR vs. TEXT [duplicate]
I'm comparing the storage efficiency of VARCHAR and TEXT data types in MySQL 8, using the InnoDB storage engine and the default utf8mb4 character set with utf8mb4_general_ci collation. I want to ...
0 votes
1 answer
87 views
Explanation needed for my result
I am new to string handling in SQL server and was wondering what makes the below code return the result it returns. Could I please have a detailed explanation? My code: Select CAST(CAST(CAST('08' as ...
-1 votes
2 answers
804 views
Why should you always write "varchar" with the length in brackets behind it? Often, you get the right outcome without doing so
"Often, you get the right outcome without doing so." Example: select CONVERT(varchar, getdate(), 112) outputs 20240417 I saw this in quite a few places on Stack Exchange until I found a ...
0 votes
1 answer
157 views
Will NVARCHAR(max) columns benefit from row compression?
I have a table that I believe owes most of its size to a huge NVARCHAR(max) column. I do not know how to test where most of its size comes from. Regardless, would such a table benefit from row ...
0 votes
0 answers
103 views
Reduce varchar column size in a production database
We have a database running on AWS Aurora Mysql with version 8.0.mysql_aurora.3.04.1 as a regional database. There is a table in it with a column with varchar size 200. We want to reduce it to varchar(...
-1 votes
3 answers
662 views
How can a column's data type be safely reduced from NVARCHAR(max)?
My biggest table owes most of its size to a stupid NVARCHAR(max) column that I wager could easily be NVARCHAR(4000) or smaller. What steps can I take to become confident that this change is safe to ...
1 vote
1 answer
246 views
Why does Redshift ignore length when grouping by VARCHAR of only spaces?
Imagine I have a column name that is n rows and the nth entry is equal to REPEAT(' ', n). For SELECT DISTINCT name FROM table I would expect to receive n rows because each name is unique by definition....
2 votes
1 answer
211 views
Column accepting more characters than defined
I have a column defined as character varying(20). But it is accepting more than 20 characters. I've already searched but couldn't find anything about it (maybe I'm searching wrong). Has anyone ...
2 votes
1 answer
1k views
Why does is JSON_EXTRACT's return value treated differently depending on the operator?
I'm using MySQL 8.0 (inside Azure Database for MySQL Server). I've noticed some strange behavior while querying with the "json_extract" functionality. In the example below, I am querying a ...
2 votes
1 answer
572 views
CHAR and VARCHAR lengths for multibyte characters
I have a table with ~100mln rows. One of the columns is a VARCHAR(64) with utf8mb4 encoding for storing user nicknames (others are few integers). The data in that column has MAX(LENGTH()) == 42 and ...
2 votes
3 answers
181 views
Find "naked" varchars
It is clear that omitting the length from a varchar is a bad thing. Unfortunately I am now working with a code base where this has happened. Extensively. I would like to correct this. The first step ...
0 votes
2 answers
383 views
Varchar for columns that store numerics/ids?
There is a table that has a column defined as follows: text_id varchar(255) NOT NULL I know that using varchar is optimal for storing text because it allows for variable length columns but in this ...