Carlos Escalera Alonso
Carlos Escalera Alonso

Reputation: 2363

Count of newline in databases

How databases count newlines (carriage return CR, line feed LF). For example with a column type varchar(10):

abcdef
gh

Will be count as 9 or 10?

Edit: I tested with PostgresSQL and it gives 9, is it the same for the others?

Upvotes: 0

Views: 535

Answers (3)

Joe Taras
Joe Taras

Reputation: 15389

The result is 9:

I've tried your query on Sql Fiddle with MySql 5.5.32 version, Postgres 9.3.1, Sql Server 2012.

MySql Sql Fiddle trial

Postgres 9.3 Sql Fiddle Trial

Sql Server 2012 Sql Fiddle Trial

Upvotes: 1

Ravinder Reddy
Ravinder Reddy

Reputation: 24002

Please try below snippet

mysql> select length('abcdef
    '> gh');
+---------------------+
| length('abcdef
gh') |
+---------------------+
|                   9 |
+---------------------+
1 row in set (0.00 sec)

Upvotes: 0

Superman
Superman

Reputation: 881

SELECT LENGTH(your_column_name_here) FROM your_table;

Upvotes: 0

Related Questions