question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

char / character in both MySQL and SQLite

See original GitHub issue

Issue type:

[x] question [x] bug report [x] feature request [ ] documentation issue

Database system/driver:

[x] mysql / mariadb [x] sqlite

TypeORM version:

[x] latest [x] 0.2.6

Steps to reproduce or a small repository showing the problem:

I want to have a fixed length char in both MySQL and SQLite.

If I use type: 'character' I get:

DataTypeNotSupportedError: Data type “character” in “Entity.column” is not supported by “mysql” database

If I use type: 'char' I get:

Data type “char” in “Entity.column” is not supported by “sqlite” database.

I checked other issues and I found that this was addressed in issue #343 by adding a fixedLength option, but then was removed in commit #f1c566f2efc206170533171110aed0980cd1360b, when database specific types were introduced.

Is there any way I can get around this?

If not, Wouldn’t it make sense to have a some generic types like char that can be mapped in every database? Or re-introduce String + fixedLength type?

Whichever option, I would be glad to contribute if someone approves.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
chriszrccommented, Dec 27, 2019

@pmoleri Ah, thanks for the clarification, I rarely use the later type, seems postgres has spoiled me:

“Different from other database systems, in PostgreSQL, there is no performance difference among three character types. In most situation, you should use text or varchar, and varchar(n) if you want PostgreSQL to check for the length limit.”

http://www.postgresqltutorial.com/postgresql-char-varchar-text/

0reactions
pmolericommented, Dec 27, 2019

It makes a difference to the DBMS.

  • varchar 128: I’m storing a variable length string up to 128 chars
  • character 128: I’m always storing 128 chars.

The DBMS optimizes these 2 in different ways.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CHAR and VARCHAR Data Types in Different Database ...
In this article, we will look at how CHAR and VARCHAR data types behave in: MySQL; PostgreSQL; SQLite; Oracle; MS SQL Server ...
Read more >
SQLite MYSQL character encoding - Stack Overflow
I have a strange situation where the following code works however XCode warns it is deprecated... NSString *col1 = [NSString stringWithCString:(char *) ...
Read more >
Datatypes In SQLite
Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity.
Read more >
SQLite LIKE - Querying Data Based On Pattern Matching
In this tutorial, you have learned how to use SQLite LIKE operator to query data based on pattern matching using two wildcard characters...
Read more >
MySQL LIKE operator - w3resource
(A bug: SQLite only understands upper/lower case for ASCII characters by default. The LIKE operator is case sensitive by default for unicode ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found