Choosing hardcoded values ββin Informix DB
I need to select hardcoded values ββin one column so I can join them with a table in Informix DB. Therefore, I try to do something like this in different ways:
select a from ( values (1), (2), (3) ) ;
And I expect to get results:
1 2 3
I think in another DB this or some other options I tried will return values. However, this does not work in Informix.
Can anyone suggest a solution that works in Informix please?
source to share
While what Gordon Linoff suggests will certainly work, there are also more compact notation available using Informix-specific syntax.
For example:
SELECT a
FROM TABLE(SET{1, 2, 3}) AS t(a)
This will generate a list of integers rather happily (and briefly). You can use LIST or MULTISET instead of SET. MULTISET can have duplicate elements, unlike SET; LIST preserves order and also allows for repeating.
Very often you don't find that the order isn't preserved with simple values ββ- just a few items in the list. Ordering is not guaranteed for SET or MULTISET; if order matters, use LIST.
For information on this, see the IBM Informix 12.10 tutorial under Collection Constructors . No, it's not obvious how you get to it - I started with SELECT
, then FROM
, then "Select from a collection variable" and from there to "Expression"; I spent a few seconds looking at it stupidly, then looked at "constructor expressions" and thus "collector constructors".
source to share