sql - PostgreSQL: How to search a list of strings as a table? -
it's been while since i've had db work, i'm not sure how ask , know i've done in past.
how create temporary table out of list of strings (not using create temporary table)? so, if have :
'1', 'a', 'a'
'2', 'b', 'b'
'3', 'c', 'c'select field2 { {'1','a','a'}, {'2','b','b'}, {'3','c','c'} } fooarray(field1,field2,field3) field1 = '2' -- should return 'b'
hint: it's similar to...
select * unnest(array[...]);
you don't need mess around arrays @ all, can build table in-place using values:
7.7. values lists
valuesprovides way generate "constant table" can used in query without having create , populate table on-disk.
see values.
so can things this:
=> select * ( values ('1', 'a', 'a'), ('2', 'b', 'b'), ('3', 'c', 'c') ) t(id, c1, c2) id = '2'; id | c1 | c2 ----+----+---- 2 | b | b (1 row) don't forget give values alias complete column names (t(id, c1, c2)) has name.
Comments
Post a Comment