Thread: Query and the number of row result
Hi All; After doing a SELECT query, how can I know the number of returned rows from this query? If it returned 5 rows or 1 row ornon? Regards Bilal
On Sun, Aug 30, 2009 at 06:56:59PM -0700, bilal ghayyad wrote: > Hi All; > > After doing a SELECT query, how can I know the number of returned > rows from this query? If it returned 5 rows or 1 row or non? Lots of language bindings have this. Which language(s) are you using? Cheers, David. -- David Fetter <david@fetter.org> http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter@gmail.com Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate
Postgresql. Is there alot of Postgresql? How can I know mine? Regards Bilal --- On Sun, 8/30/09, David Fetter <david@fetter.org> wrote: > From: David Fetter <david@fetter.org> > Subject: Re: [GENERAL] Query and the number of row result > To: "bilal ghayyad" <bilmar_gh@yahoo.com> > Cc: pgsql-general@postgresql.org > Date: Sunday, August 30, 2009, 10:12 PM > On Sun, Aug 30, 2009 at 06:56:59PM > -0700, bilal ghayyad wrote: > > Hi All; > > > > After doing a SELECT query, how can I know the number > of returned > > rows from this query? If it returned 5 rows or 1 row > or non? > > Lots of language bindings have this. Which > language(s) are you using? > > Cheers, > David. > -- > David Fetter <david@fetter.org> > http://fetter.org/ > Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: > dfetter > Skype: davidfetter XMPP: david.fetter@gmail.com > > Remember to vote! > Consider donating to Postgres: http://www.postgresql.org/about/donate >
On Sun, Aug 30, 2009 at 07:35:42PM -0700, bilal ghayyad wrote: > Postgresql. > > Is there alot of Postgresql? How can I know mine? Are you connecting from C? PHP? Perl? Python? Ruby? Cheers, David. -- David Fetter <david@fetter.org> http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter@gmail.com Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate
Just writing a Function in the PostgreSQL it self (so it is sql scripting). It is not from any development language. Regards Bilal --- On Sun, 8/30/09, David Fetter <david@fetter.org> wrote: > From: David Fetter <david@fetter.org> > Subject: Re: [GENERAL] Query and the number of row result > To: "bilal ghayyad" <bilmar_gh@yahoo.com> > Cc: pgsql-general@postgresql.org > Date: Sunday, August 30, 2009, 10:41 PM > On Sun, Aug 30, 2009 at 07:35:42PM > -0700, bilal ghayyad wrote: > > Postgresql. > > > > Is there alot of Postgresql? How can I know mine? > > Are you connecting from C? PHP? Perl? > Python? Ruby? > > Cheers, > David. > -- > David Fetter <david@fetter.org> > http://fetter.org/ > Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: > dfetter > Skype: davidfetter XMPP: david.fetter@gmail.com > > Remember to vote! > Consider donating to Postgres: http://www.postgresql.org/about/donate >
Which client do you use to access to db? GUI (pgAdmin?)? Command-line? Either way, it should give you row number... -----Original Message----- From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of bilal ghayyad Sent: Monday, August 31, 2009 4:11 AM To: David Fetter Cc: pgsql-general@postgresql.org Subject: Re: [GENERAL] Query and the number of row result Just writing a Function in the PostgreSQL it self (so it is sql scripting). It is not from any development language. Regards Bilal --- On Sun, 8/30/09, David Fetter <david@fetter.org> wrote: > From: David Fetter <david@fetter.org> > Subject: Re: [GENERAL] Query and the number of row result > To: "bilal ghayyad" <bilmar_gh@yahoo.com> > Cc: pgsql-general@postgresql.org > Date: Sunday, August 30, 2009, 10:41 PM > On Sun, Aug 30, 2009 at 07:35:42PM > -0700, bilal ghayyad wrote: > > Postgresql. > > > > Is there alot of Postgresql? How can I know mine? > > Are you connecting from C? PHP? Perl? > Python? Ruby? > > Cheers, > David. > -- > David Fetter <david@fetter.org> > http://fetter.org/ > Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: > dfetter > Skype: davidfetter XMPP: david.fetter@gmail.com > > Remember to vote! > Consider donating to Postgres: http://www.postgresql.org/about/donate > -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
On Mon, Aug 31, 2009 at 04:10:48AM -0700, bilal ghayyad wrote: > Just writing a Function in the PostgreSQL it self (so it is sql > scripting). It is not from any development language. You mean you're using plpgsql? If so then the plpgsql docs are available here and should help: http://www.postgresql.org/docs/current/static/plpgsql.html -- Sam http://samason.me.uk/
On Monday 31 August 2009 4:10:48 am bilal ghayyad wrote: > Just writing a Function in the PostgreSQL it self (so it is sql scripting). > It is not from any development language. > > Regards > Bilal > If you move to pl/pgsql you could use GET DIAGNOSTICS: (http://www.postgresql.org/docs/8.4/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS) It has ROW_COUNT. -- Adrian Klaver aklaver@comcast.net
I am talking in case I am writing a script for a function, and I need to know the number of the returned rows of the query,then I will do IF statement based on that number, how? Regards Bilal --- On Mon, 8/31/09, Naoko Reeves <naoko@lawlogix.com> wrote: > From: Naoko Reeves <naoko@lawlogix.com> > Subject: RE: [GENERAL] Query and the number of row result > To: "bilal ghayyad" <bilmar_gh@yahoo.com> > Cc: pgsql-general@postgresql.org > Date: Monday, August 31, 2009, 10:21 AM > Which client do you use to access to > db? GUI (pgAdmin?)? Command-line? > Either way, it should give you row number... > > -----Original Message----- > From: pgsql-general-owner@postgresql.org > [mailto:pgsql-general-owner@postgresql.org] > On Behalf Of bilal ghayyad > Sent: Monday, August 31, 2009 4:11 AM > To: David Fetter > Cc: pgsql-general@postgresql.org > Subject: Re: [GENERAL] Query and the number of row result > > Just writing a Function in the PostgreSQL it self (so it is > sql scripting). It is not from any development language. > > Regards > Bilal > > --- On Sun, 8/30/09, David Fetter <david@fetter.org> > wrote: > > > From: David Fetter <david@fetter.org> > > Subject: Re: [GENERAL] Query and the number of row > result > > To: "bilal ghayyad" <bilmar_gh@yahoo.com> > > Cc: pgsql-general@postgresql.org > > Date: Sunday, August 30, 2009, 10:41 PM > > On Sun, Aug 30, 2009 at 07:35:42PM > > -0700, bilal ghayyad wrote: > > > Postgresql. > > > > > > Is there alot of Postgresql? How can I know > mine? > > > > Are you connecting from C? PHP? Perl? > > Python? Ruby? > > > > Cheers, > > David. > > -- > > David Fetter <david@fetter.org> > > http://fetter.org/ > > Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: > > dfetter > > Skype: davidfetter XMPP: david.fetter@gmail.com > > > > Remember to vote! > > Consider donating to Postgres: http://www.postgresql.org/about/donate > > > > > > > -- > Sent via pgsql-general mailing list (pgsql-general@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-general >
bilal ghayyad <bilmar_gh@yahoo.com> wrote: > I am talking in case I am writing a script for a function, > and I need to know the number of the returned rows of the > query, then I will do IF statement based on that number, > how? > [...] Presuming that you are talking about a function written in PL/pgSQL, you will have to count them yourself or issue a second query "SELECT COUNT(*) FROM [...]". For the special case that you want to find out whether no row at all was found, you can look at "IF (NOT) FOUND". Tim
On 31/08/2009 18:00, Tim Landscheidt wrote: > Presuming that you are talking about a function written in > PL/pgSQL, you will have to count them yourself or issue a > second query "SELECT COUNT(*) FROM [...]". For the special > case that you want to find out whether no row at all was > found, you can look at "IF (NOT) FOUND". In pl/pgsql you can also issue a GET DIAGNOSTICS command which gets the row count: http://www.postgresql.org/docs/8.4/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS ...although it is still has to be done as a second query, as in your suggestions above. Ray. ------------------------------------------------------------------ Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland rod@iol.ie Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals ------------------------------------------------------------------
On 2009-08-31, bilal ghayyad <bilmar_gh@yahoo.com> wrote: > Just writing a Function in the PostgreSQL it self (so it is sql scripting). It is not from any development language. plpgsql or sql ? plpgsql has "GET DIAGNOSTICS": GET DIAGNOSTICS integer_var = ROW_COUNT; bye.