Re: what am I doing wrong with this query?

From: Tino Wildenhain <tino(at)wildenhain(dot)de>
To: Tony Caduto <tony_caduto(at)amsoftwaredesign(dot)com>
Cc: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: what am I doing wrong with this query?
Date: 2006-01-20 17:21:19
Message-ID: 43D11C0F.8010707@wildenhain.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Brian Dimeler 2006-01-20 17:26:42 sequences not restoring properly
Previous Message Tom Lane 2006-01-20 17:14:35 Re: Creation of tsearch2 index is very slow