Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id A0AF1930E1E for ; Fri, 3 Aug 2012 05:48:52 -0300 (ADT) Received: from mail-ob0-f174.google.com ([209.85.214.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SxDYv-0006XA-HN for pgsql-admin@postgresql.org; Fri, 03 Aug 2012 08:48:52 +0000 Received: by obbuo13 with SMTP id uo13so784220obb.19 for ; Fri, 03 Aug 2012 01:48:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=M84feoLk8J/x4vFtUYamXkshRn4KYelc4asOXtSRESg=; b=CWMnWCd8rYsFLLglkCO+qpcKg28e5GYp1m3mQzg9MIhxeGUgJs7mnfdQU7y793jqf6 HQyvK2+xKB+xXnnoIZimiE0AbwuXTzZluxNtVnveSM86NzJ60cxfMcPtb4rl4h1UBdK6 bXMFtpGkHqKyaGVJN+5MMmqsIq3jIimx1gTAE/GSqCiI76utHFTjJw16Qm3YPPYMhaCY WLrlnB/jJ+E2JRNlvIYagVd3gGLNN5pvopTg3s5oT6aTNiSWo0mGbAF8azDlV8ZaL58Y O68VfJaP9oskGT/wPS4wGE2pPOCSbT49QL1/1M/5VqybLz/LWPbX3W9eDiUgz00gY3LM vxCA== Received: by 10.182.212.36 with SMTP id nh4mr2531647obc.37.1343983716386; Fri, 03 Aug 2012 01:48:36 -0700 (PDT) Received: from ayaki.localdomain (124-169-196-180.dyn.iinet.net.au. [124.169.196.180]) by mx.google.com with ESMTPS id i2sm9088036obn.19.2012.08.03.01.48.33 (version=SSLv3 cipher=OTHER); Fri, 03 Aug 2012 01:48:35 -0700 (PDT) Message-ID: <501B905E.1050706@ringerc.id.au> Date: Fri, 03 Aug 2012 16:48:30 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 MIME-Version: 1.0 To: Laszlo Nagy CC: pgsql-admin@postgresql.org Subject: Re: need help to write a function in postgresql References: <000b01cd658e$e66ae920$b340bb60$@avineonindia.com> <501B8DB7.5050700@shopzeus.com> In-Reply-To: <501B8DB7.5050700@shopzeus.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQmR7oxu0o4mkposRdBDQ8rZQzwI0tvbRpOI+AcgG0PmHzEBm0U5P6yzCy4S0EmWZy9xGfK3 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/17 X-Sequence-Number: 39838 On 08/03/2012 04:37 PM, Laszlo Nagy wrote: > It is also better because with a view, you can also do " name is null > ". But you cannot do that with a function (unless you write > unnecessary circumstancial code.) > While I agree with you on the view - among other things, it lets the query optimiser push conditions down into the view query - there is a reasonable answer to the problem of comparing to NULL. Just use IS DISTINCT FROM, eg: WHERE name IS DISTINCT FROM _test_variable "IS DISTINCT FROM" is an equality comparison that treats null as a comparable value like any other, so "NULL IS DISTINCT FROM NULL" is false. Very handy. -- Craig Ringer