Doctrine 2 - COALESCE and CONCAT - doctrine-orm

I have this DQL Query:
$repository->createQuery("SELECT f.id, COALESCE(f.name,
CONCAT(f.floor_number, ' NP')) as name FROM ".__NAMESPACE__.'\\Floor f
WHERE f.building = ?1')
->setParameter(1, $this->building);
but it doesn't work - i get
[Syntax Error] line 0, col 36: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '('
The reason is usage of CONCAT inside COALESCE.... is there any way how to make this work (without native query)?

This problem was fixed by an improvement to the DQL parser in Doctrine 2.4. Upgrade to 2.4 and this query will work.

Related

tableby in papaja with twocolumn classoption

I use the wonderful function tableby to have some summary statistics of my population and I also use the amazing package papaja to write my article.
Here is my code for the use of tableby.
DemoGroup <- tableby (Group ~ Age + education + logMAR + QIT + IRP + ICV + AQ + otherDiag, data=demoShort)
summary(DemoGroup,digits = 1, digits.p =3, booktabs = T, title = "(\\#tab:demo) Demo")
I need my document in a two-column fashion (and use the two-column classoption). However, when I try to knit my document, I have this error related to my table (everything works fine in a single column document):
I was unable to find any missing LaTeX packages from the error log 2022_MMN_FS_TSA_WO.log.
! Package longtable Error: longtable not in 1-column mode.
Error: LaTeX failed to compile 2022_MMN_FS_TSA_WO.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.
Is there a way to fix this error?
Thank you for your help,
Chers,
Adeline

Oracle Window function not working in SnowFlake

i am working on Oracle to Snowflake migration.
while migrating oracle window functions to snowflake getting below error, could you let me know, alternate way for oracle function in snowflake.
SELECT
COL1,
COL2, ...,
SUM(SUM(TAB1.COL1)) OVER (PARTITION BY
TAB1.COL2,
TAB1.COL3,
TAB1.COL4,
TAB1.COL5,
TAB1.COL6,
TAB1.COL7,
TAB1.COL8,
TAB1.COL9,
TAB1.COL10,
ORDER BY MAX(CALENDAR_TAB.DATE_COLUMN) RANGE BETWEEN INTERVAL '21' DAY PRECEDING AND CURRENT ROW)/4 AS COLMN
FROM TAB1,CALENDAR_TAB
JOIN
GROUP BYCOL1,
COL2, ...
Below is the error message:
QL Error [1003] [42000]: SQL compilation error:
syntax error line 75 at position 60 unexpected 'INTERVAL'.
syntax error line 75 at position 78 unexpected 'PRECEDING'.
Per the documentation for Snowflake, here is the syntax:
https://docs.snowflake.com/en/sql-reference/functions-analytic.html#window-syntax-and-usage
slidingFrame ::=
{
ROWS BETWEEN <N> { PRECEDING | FOLLOWING } AND <N> { PRECEDING | FOLLOWING }
| ROWS BETWEEN UNBOUNDED PRECEDING AND <N> { PRECEDING | FOLLOWING }
| ROWS BETWEEN <N> { PRECEDING | FOLLOWING } AND UNBOUNDED FOLLOWING
}
It might not like the INTERVAL and the quoted number.
The Window frame document is a good place to start.
If I read the Oracle syntax correctly, the window frame your are using for the MAX is value based aka (interval '21' day) which Snowflake does not support, it only supports N rows based logic. If you have 1 row per day, and always 1 row, then you can use the row count logic, but otherwise this is not supported.
Which means you to join back to your own data tables and apply the prior time filter on the join.

Impala with Sas 9.4 : not import data with create table

creating a table with Sas and Impala I can't import data with many columns (more than 1500). The table is created but the data is not written and the following error is generated:
ERROR: CLI execute error: [Cloudera][ImpalaODBC] (110) Error while executing a query in Impala:
[HY000] : AnalysisException: Syntax error in line 1: ...,xxx`) VALUES ( ? , ? , ? , ? , ? , ? , ? , ...
^ Encountered: Unexpected character Expected: CASE, CAST, DEFAULT, EXISTS, FALSE, IF, INTERVAL, NOT, NULL, TRUNCATE, TRUE, IDENTIFIER
Thank you
I try to create a view or a table with engine SAS Impala (ODBC impala ClouderaImpalaODBC-2.5.36.1009-1.x86_64) RedHat 6.8. And I get this error:
ERROR: CLI execute error: [Cloudera] [ImpalaODBC] (110) Error while executing a query in Impala: [HY000]: AnalysisException: Syntax
error in line 1: ... King ((a.trns_dt between {d '31.10.2015'} and {d '^ 2 ... Encountered:
Unexpected character Expected: CASE, CAST, EXISTS, FALSE, IF, INTERVAL, NOT NULL, TRUNCATE, TRUE, IDENTIFIER Caused BY:
Exception: Syntax error
We have seen that characters that are passed impala can not read such. "{}".

python replace string function throws asterix wildcard error

When i use * i receive the error
raise error, v # invalid expression
error: nothing to repeat
other wildcard characters such as ^ work fine.
the line of code:
df.columns = df.columns.str.replace('*agriculture', 'agri')
am using pandas and python
edit:
when I try using / to escape, the wildcard does not work as i intend
In[44]df = pd.DataFrame(columns=['agriculture', 'dfad agriculture df'])
In[45]df
Out[45]:
Empty DataFrame
Columns: [agriculture, dfad agriculture df]
Index: []
in[46]df.columns.str.replace('/*agriculture*','agri')
Out[46]: Index([u'agri', u'dfad agri df'], dtype='object')
I thought the wildcard should output Index([u'agri', u'agri'], dtype='object)
edit:
I am currently using hierarchical columns and would like to only replace agri for that specific level (level = 2).
original:
df.columns[0] = ('grand total', '2005', 'agriculture')
df.columns[1] = ('grand total', '2005', 'other')
desired:
df.columns[0] = ('grand total', '2005', 'agri')
df.columns[1] = ('grand total', '2005', 'other')
I'm looking at this link right now: Changing columns names in Pandas with hierarchical columns
and that author says it will get easier at 0.15.0 so I am hoping there are more recent updated solutions
You need to the asterisk * at the end in order to match the string 0 or more times, see the docs:
In [287]:
df = pd.DataFrame(columns=['agriculture'])
df
Out[287]:
Empty DataFrame
Columns: [agriculture]
Index: []
In [289]:
df.columns.str.replace('agriculture*', 'agri')
Out[289]:
Index(['agri'], dtype='object')
EDIT
Based on your new and actual requirements, you can use str.contains to find matches and then use this to build a dict to map the old against new names and then call rename:
In [307]:
matching_cols = df.columns[df.columns.str.contains('agriculture')]
df.rename(columns = dict(zip(matching_cols, ['agri'] * len(matching_cols))))
Out[307]:
Empty DataFrame
Columns: [agri, agri]
Index: []

Query for only integers Rails 2.3

My environment is Ruby 1.8.7-p358 with Rails 2.3.11. I am trying to query for all accounts that have a first_name containing only numbers (they are all 3 digit integers, i.e. 001, 143, 815, etc.). I have been trying to use this query:
Account.find(:all, :conditions => ["first_name LIKE ?", "[^0-9][^0-9][^0-9]"])
All I get in return is => [].
If I use the same query only with NOT LIKE I get all accounts, including the ones where first_name is an integer.
I've also tried using:
Account.find(:all, :conditions => ["first_name REGEXP ?", "[^0-9][^0-9][^0-9]"])
but that only gives me:
ActiveRecord::StatementInvalid: PGError: ERROR: syntax error at or near "REGEXP"
LINE 1: SELECT * FROM "accounts" WHERE (first_name REGEXP '[0-9][0-9...
^
: SELECT * FROM "accounts" WHERE (first_name REGEXP '[0-9][0-9][0-9]') ORDER BY first_name ASC
from /Users/kyle/.rvm/gems/ruby-1.8.7-p358#popcorn_recruiter_portal/gems/activerecord-2.3.11/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `log'
from /Users/kyle/.rvm/gems/ruby-1.8.7-p358#popcorn_recruiter_portal/gems/activerecord-2.3.11/lib/active_record/connection_adapters/postgresql_adapter.rb:520:in `execute'
from /Users/kyle/.rvm/gems/ruby-1.8.7-p358#popcorn_recruiter_portal/gems/activerecord-2.3.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1002:in `select_raw'
from /Users/kyle/.rvm/gems/ruby-1.8.7-p358#popcorn_recruiter_portal/gems/activerecord-2.3.11/lib/active_record/connection_adapters/postgresql_adapter.rb:989:in `select'
from /Users/kyle/.rvm/gems/ruby-1.8.7-p358#popcorn_recruiter_portal/gems/activerecord-2.3.11/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
from /Users/kyle/.rvm/gems/ruby-1.8.7-p358#popcorn_recruiter_portal/gems/activerecord-2.3.11/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
from /Users/kyle/.rvm/gems/ruby-1.8.7-p358#popcorn_recruiter_portal/gems/activerecord-2.3.11/lib/active_record/base.rb:665:in `find_by_sql'
from /Users/kyle/.rvm/gems/ruby-1.8.7-p358#popcorn_recruiter_portal/gems/activerecord-2.3.11/lib/active_record/base.rb:1582:in `find_every'
from /Users/kyle/.rvm/gems/ruby-1.8.7-p358#popcorn_recruiter_portal/gems/activerecord-2.3.11/lib/active_record/base.rb:619:in `find'
from (irb):189
from :0
Are regular expressions not allowed? How am I able to find each account with a first_name that's equal to a three digit integer?
The like operator does not evaluate regular expressions. In instead you can use both similar to:
select '980' similar to '[0-9][0-9][0-9]';
?column?
----------
t
Or ~:
select '980' ~ '[0-9][0-9][0-9]';
?column?
----------
t
(1 row)