1

I have some SQL code in the following style:

"CREATE TABLE IF NOT EXISTS test ( \n\
\  id INTEGER PRIMARY KEY, \n\
\  symbol TEXT NOT NULL, \n\
\  date TEXT NOT NULL, \n\
\  val DECIMAL(10, 2) NOT NULL, \n\
\"

I'd like the datatypes to be aligned. In other words:

"CREATE TABLE IF NOT EXISTS test ( \n\
\  id     INTEGER PRIMARY KEY, \n\
\  symbol TEXT NOT NULL, \n\
\  date   TEXT NOT NULL, \n\
\  val    DECIMAL(10, 2) NOT NULL, \n\
\"

I thought using align-regexp with the pattern [A-Z]+ would work, but it does not. Using C-u M-x align-regexp with \(\s-*\)[A-Z]+ doesn't work either. Instead, it replaces the two spaces before the column names with a single space. I do not understand why this is.

So, my questions:

  1. Why doesn't align-regexp with [A-Z]+ work? Searching based on the same pattern correctly identifies the text.

  2. What is the right regexp that would get this alignment?

1 Answer 1

1

Becase align-regexp is, by default, case-insensitive. Evaluate (setq case-fold-search nil) before align-regexp.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.