Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Dimitri Fontaine Newsgroups: comp.databases.postgresql Subject: Re: SQL command gives different result when done in function Date: Mon, 29 May 2017 11:20:31 +0200 Organization: A noiseless patient Spider Lines: 16 Message-ID: References: <28abb49e-321a-45ac-9562-16f0bc301c46@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="187b117db01b397870c298e755165ead"; logging-data="13112"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/EsJCbCWgUHagj+qqh4Cv" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (darwin) Cancel-Lock: sha1:aDKodVSjk11WkL/C6RIWiN30aNU= sha1:eVquFc5N+eXts/N+3CV5ApmP2ms= Xref: csiph.com comp.databases.postgresql:783 neojustebelmont@gmail.com writes: > Now I put that SQL into a function. And when the function is called, it > instead gave out "C", which also fulfilled the date and product_id > requirement. > > Is there a way I could get "A" no matter what? Hopefully without adding > extra WHERE clauses The only way to know in which order you get the rows in SQL is to use the ORDER BY clause. I don't think it makes any sense to use the LIMIT clause without an ORDER BY clause, apart from interactive data discovery at the prompt. -- Dimitri Fontaine PostgreSQL DBA, Architecte