pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Strange behavior
6+ messages / 6 participants
[nested] [flat]

* Strange behavior
@ 2006-01-06 17:26 Bruno Almeida do Lago <teolupus@gmail.com>
  2006-01-07 04:47 ` Re: Strange behavior Michael Fuhr <mike@fuhr.org>
  0 siblings, 1 reply; 6+ messages in thread

From: Bruno Almeida do Lago @ 2006-01-06 17:26 UTC (permalink / raw)
  To: pgsql-general

Hello my friends!

I was making a pretty simple script to export our databases, and found a
strange (funny) behavior of psql (or bash?).

[psql8@xxxx]$ psql -Atl | cut -d"|" -f1 | grep -v template
Db_1
Db_2
Db_3
Db_4

The databases name were changed due privacy reasons (our client database),
but as you can see the command worked.

Now, when I come with the bash script:

#!/bin/bash

imprime () {
 echo `date +"%d/%m/%y %H:%M:%S |"` $*
}

BANCOS=`psql -Atl | cut -d"|" -f1 | grep -v template`
for BANCO in $BANCOS; do
    imprime "Inicio do backup da base $BANCO"
done


[psql8@webix backup_psql8]$ ./backup.sh
psql: could not send startup packet: Broken pipe


Any clues????


Best Regards,
Bruno Almeida do Lago




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Strange behavior
  2006-01-06 17:26 Strange behavior Bruno Almeida do Lago <teolupus@gmail.com>
@ 2006-01-07 04:47 ` Michael Fuhr <mike@fuhr.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Michael Fuhr @ 2006-01-07 04:47 UTC (permalink / raw)
  To: Bruno Almeida do Lago <teolupus@gmail.com>; +Cc: pgsql-general

On Fri, Jan 06, 2006 at 03:26:27PM -0200, Bruno Almeida do Lago wrote:
> #!/bin/bash
> 
> imprime () {
>  echo `date +"%d/%m/%y %H:%M:%S |"` $*
> }
> 
> BANCOS=`psql -Atl | cut -d"|" -f1 | grep -v template`
> for BANCO in $BANCOS; do
>     imprime "Inicio do backup da base $BANCO"
> done
> 
> 
> [psql8@webix backup_psql8]$ ./backup.sh
> psql: could not send startup packet: Broken pipe

What version of PostgreSQL are you using?  What operating system
and version?  Does anything show up in the postmaster or system
logs?  How repeatable is the problem?  Does it happen with a one-line
script that executes just a simple psql command?

We've seen previous reports of "Broken pipe" that turned out to be
caused by exhausted resources -- could that be the problem?

-- 
Michael Fuhr



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Strange behavior
@ 2020-10-10 15:59 Olivier Leprêtre <o.lepretre@gmail.com>
  2020-10-10 16:36 ` Re: Strange behavior Francisco Olarte <folarte@peoplecall.com>
  2020-10-10 17:58 ` Re: Strange behavior David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Olivier Leprêtre @ 2020-10-10 15:59 UTC (permalink / raw)
  To: pgsql-general

Hi,

 

I’m surprised by this behavior I noticed in pgadmin3 and postgresql 9.6

 

Suppose those two tables

create table test1 (v1 text)

create table test2 (v2 text)

insert into test1 (v1) values ('A')

insert into test2 (v2) values ('B')

 

query select v1 from test2 return v2 column doesn’t exists. Right.

 

But the following query does not return any error but only an empty result
set.

select v1 from test1 where v1 not in (select v1 from test2)

 

In other words, a wrong query returns a valid result. This happens because
v1 is a column from test1, (select vx from test2) will return an error as
expected. 

 

Did I missed something ?

 

Thanks,

 

Olivier



-- 
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Strange behavior
  2020-10-10 15:59 Strange behavior Olivier Leprêtre <o.lepretre@gmail.com>
@ 2020-10-10 16:36 ` Francisco Olarte <folarte@peoplecall.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Francisco Olarte @ 2020-10-10 16:36 UTC (permalink / raw)
  To: Olivier Leprêtre <o.lepretre@gmail.com>; +Cc: pgsql-general

Olivier:

On Sat, Oct 10, 2020 at 6:13 PM Olivier Leprêtre <o.lepretre@gmail.com> wrote:

> I’m surprised by this behavior I noticed in pgadmin3 and postgresql 9.6
...

> select v1 from test1 where v1 not in (select v1 from test2)


This is called a correlated subquery ( google and search for it, it is
even in wikipedia ). It has many uses.

Basically, it refers to the v1 from the outside query.

Get in the habit of using (potentially aliased ) column names whenever
you have any moderately complex query, i.e. if the inner v1 would have
been v2 ( due to a typo ), writing your query as :

select t1.v1 from test1 as t1 wher t1.v1 not in ( select t2.v1 from
test2 as t2 )

Would have caught it.

Francisco Olarte.





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Strange behavior
  2020-10-10 15:59 Strange behavior Olivier Leprêtre <o.lepretre@gmail.com>
@ 2020-10-10 17:58 ` David G. Johnston <david.g.johnston@gmail.com>
  2020-10-10 19:07   ` Re: Strange behavior Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 6+ messages in thread

From: David G. Johnston @ 2020-10-10 17:58 UTC (permalink / raw)
  To: Olivier Leprêtre <o.lepretre@gmail.com>; +Cc: pgsql-general

On Sat, Oct 10, 2020 at 9:13 AM Olivier Leprêtre <o.lepretre@gmail.com>
wrote:

This has nothing to do with pgAdmin, or any other client interface.

In other words, a wrong query returns a valid result. This happens because
> v1 is a column from test1, (select vx from test2) will return an error as
> expected.
>

https://wiki.postgresql.org/wiki/FAQ#Why_doesn.27t_PostgreSQL_report_a_column_not_found_error_when_u...
I am pondering trying to get the FAQ entry incorporated into the actual
documentation.

David J.

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Strange behavior
  2020-10-10 15:59 Strange behavior Olivier Leprêtre <o.lepretre@gmail.com>
  2020-10-10 17:58 ` Re: Strange behavior David G. Johnston <david.g.johnston@gmail.com>
@ 2020-10-10 19:07   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2020-10-10 19:07 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Olivier Leprêtre <o.lepretre@gmail.com>; pgsql-general

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> I am pondering trying to get the FAQ entry incorporated into the actual
> documentation.

Not sure how much it'd help, but we have warnings against mistakes
that are far less common than this one, so sure why not.

Taking a quick gander at the docs, it seems like the thing to do would be
to add something to the head text in 9.23. Subquery Expressions, and then
remove any duplicative statements from the individual 9.23.x subsections.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2020-10-10 19:07 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-01-06 17:26 Strange behavior Bruno Almeida do Lago <teolupus@gmail.com>
2006-01-07 04:47 ` Michael Fuhr <mike@fuhr.org>
2020-10-10 15:59 Strange behavior Olivier Leprêtre <o.lepretre@gmail.com>
2020-10-10 16:36 ` Francisco Olarte <folarte@peoplecall.com>
2020-10-10 17:58 ` David G. Johnston <david.g.johnston@gmail.com>
2020-10-10 19:07   ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox