Hi All,
Let's say
white space = ' '
empty string = ''
coalesce should return the first non null value.
Test Case:
create table testCoalesce ( colvarchar varchar, colchar char);
insert into testCoalesce (colvarchar, colchar) values (' ', ' ');
select coalesce(colvarchar, colchar), length(coalesce(colvarchar,
colchar)) from testCoalesce
return an empty string ''
I understand that char does not store the trailing spaces. That explain
where the empty string come from. But the result should have been the white
space ' '.
This can be simulated on h2 version 1.4.182.
Thank you.
Rgds,
jay
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.samples;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import org.h2.tools.DeleteDbFiles;
/**
* A very simple class that shows how to load the driver, create a database,
* create a table, and insert some data.
*/
public class TestCoalesceCharVchar {
/**
* Called when ran from command line.
*
* @param args
* ignored
*/
public static void main(String... args) throws Exception {
// delete the database named 'test' in the user home directory
DeleteDbFiles.execute("~", "test", true);
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test");
Statement stat = conn.createStatement();
// this line would initialize the database
// from the SQL script file 'init.sql'
// stat.execute("runscript from 'init.sql'");
stat.execute("create table testCoalesce ( colvarchar varchar, colchar char)");
stat.execute("insert into testCoalesce (colvarchar, colchar) values (' ', ' ')");
ResultSet rs = stat
.executeQuery("select coalesce(colvarchar, colchar) from testCoalesce");
while (rs.next()) {
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
System.out.println("Column Name :"
+ rs.getMetaData().getColumnName(i));
System.out.println("Column Value :" + rs.getString(i));
System.out.println("Column Value Length :"
+ rs.getString(i).length());
}
}
stat.close();
conn.close();
}
}