From: | JORGE MALDONADO <jorgemal1960(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Setting a default value for a select statement without results |
Date: | 2013-02-06 20:04:05 |
Message-ID: | CAAY=A79wHndbO4FGOU6O4-zmSJTDiDK8syiq1cpNr_=z4L7uMA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
This solution gave me the result I need, but it seems the process takes
longer when COALESCE is added.
What do you mean with the comment of "and you are happy with its performance"
?
Does it have to do with performance?
Regards,
Jorge Maldonado
On Tue, Feb 5, 2013 at 10:07 PM, Jasen Betts <jasen(at)xnet(dot)co(dot)nz> wrote:
> On 2013-02-06, JORGE MALDONADO <jorgemal1960(at)gmail(dot)com> wrote:
> > --f46d0401fb2fcb805e04d50354b1
> > Content-Type: text/plain; charset=ISO-8859-1
> >
> > I have an UPDATE query with the following general structure:
> >
> > UPDATE table1 SET (SELECT field FROM table2 WHERE conditions ORDER BY
> > order_field LIMIT 1)
>
> assuming you mean this, and you are happy with its performance.
>
> UPDATE table1 SET field1 = (SELECT field FROM table2 WHERE conditions
> ORDER BY
> order_field LIMIT 1)
>
>
> > Is it possible to assign a default value in case no results are returned
> by
> > the SELECT statement?
>
> use coalesce.
>
> UPDATE table1 SET field1 = coalesce( (SELECT field FROM table2 WHERE
> conditions ORDER BY
> order_field LIMIT 1) , default_value )
>
>
>
>
> --
> ⚂⚃ 100% natural
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
From | Date | Subject | |
---|---|---|---|
Next Message | Dev Kumkar | 2013-02-06 20:18:01 | Re: Facing authentication error on postgres 9.2 -> dblink functions |
Previous Message | Francois Payette | 2013-02-06 19:37:15 | Re: create an index on unnest |