Search Postgresql Archives

Re: what am I doing wrong with this query?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tony Caduto schrieb:
> select  array_to_string(conkey,',') from pg_constraint where contype =
> 'p' and conrelid = 17059
> 
> returns a value of 1,2,18 for the array to string function,
> 
> when I do this it does not return true:
> 
> select case when 18 in (array_to_string(conkey,',')) then true else
> false end from pg_constraint where contype = 'p' and conrelid = 17059

When you try:

SELECT (array_to_string(conkey,',')); You will see
why. It basically produces:

('1,2,18') which isnt by far equivalent to (1,2,18)


> but this one does return true
> 
> select case when 18 in (1,2,18) then true else false end from
> pg_constraint where contype = 'p' and conrelid = 17059
> 
> How come the function does not work in the IN statement?  I tried
> casting it to a varchar, but that did not work either.

Its all horribly wrong ;)
1.) Try to avoid arrays in favour of real tables - queries are
    easy and fast

2.) if you cant avoid, try WHERE 18 ANY conkey; or the like.
    Look up the documentation for real syntax. Dont mix
    text/char/varchar with what you type.

HTH
Tino


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux