Skip to content

Casting types inside formula throws exception #1832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mmalyska opened this issue Aug 27, 2018 · 4 comments
Closed

Casting types inside formula throws exception #1832

mmalyska opened this issue Aug 27, 2018 · 4 comments

Comments

@mmalyska
Copy link

mmalyska commented Aug 27, 2018

NH version: 5.0.3

When we started using filters inside HBMs maps that contains formulas with postgresql type casting, NH started to throw exception:

System.ArgumentException: 'Invalid filter-parameter name format; the name should be a property path.'

After some debugging I found value that throws:
filterParameterName hase value set to :text

Example formula that throws exception:

formula="initcap(`IMIE`)::text || ' '::text || initcap(`NAZWISKO`)::text"

@fredericDelaporte
Copy link
Member

See Types cast in PostgreSQL documentation:

A type cast specifies a conversion from one data type to another. PostgreSQL accepts two equivalent syntaxes for type casts:

CAST ( expression AS type )
expression::type

The CAST syntax conforms to SQL; the syntax with :: is historical PostgreSQL usage.

Better use the syntax which is conform to SQL standard.

I do not think NHibernate's parsing logic should try to accommodate every vendor specific syntax, especially when they have standard counterparts.

@mmalyska
Copy link
Author

mmalyska commented Aug 28, 2018

Now formula looks like that
CAST(initcap(`IMIE`) AS TEXT) || CAST(' ' AS TEXT) || CAST(initcap(`NAZWISKO`) AS TEXT)

@fredericDelaporte
it gets translated to
CAST(initcap(osobyfizyc0_."IMIE") AS osobyfizyc0_.TEXT) || CAST(' ' AS osobyfizyc0_.TEXT) || CAST(initcap(osobyfizyc0_."NAZWISKO") AS osobyfizyc0_.TEXT)

The type gets translated to: osobyfizyc0_.TEXT, it should be TEXT

@fredericDelaporte
Copy link
Member

fredericDelaporte commented Aug 28, 2018

This one happens because in the case of PostgreSQL, types names are not included in dialect keywords.

(This seems to date back to 0ad0ba1 (#654), see here. @ngbrown, do you remember why is this?)

You should be able to overcome this by adding "text" to the dialect keywords list. With the session factory, it can be done with sessionFactory.Dialect.Keywords.Add("text").

@mmalyska
Copy link
Author

@fredericDelaporte Thanks, that resolved my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants