pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Use of '&' as table prefix in query
10+ messages / 4 participants
[nested] [flat]

* Use of '&' as table prefix in query
@ 2021-07-12 17:25  Rich Shepard <rshepard@appl-ecosys.com>
  0 siblings, 2 replies; 10+ messages in thread

From: Rich Shepard @ 2021-07-12 17:25 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Long ago I wrote a query which was greatly improved (i.e., it actually
worked as intended) by help here):

/* This query selects all activity information for a named person */

SELECT p.lname, p.fname, p.loc_nbr, p.job_title, p.direct_phone, p.active,
        o.org_name,
        l.loc_nbr, l.loc_name,
        a.act_date, a.act_type, a.notes, a.next_contact
FROM People AS p
      JOIN Organizations AS o ON o.org_nbr = p.org_nbr
      JOIN Locations AS l ON l.org_nbr = o.org_nbr and l.loc_nbr = p.loc_nbr
      JOIN Activities AS a ON a.person_nbr = p.person_nbr
WHERE p.lname = &p.lname AND p.fname = &p.fname;

I did not save the reason why the ampersand is used in the WHERE row selection
phrase and want now to learn why it's there. Probably needed to concatenate
separate names?

TIA,

Rich





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

* Re: Use of '&' as table prefix in query
@ 2021-07-12 17:36  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Tom Lane @ 2021-07-12 17:36 UTC (permalink / raw)
  To: Rich Shepard <rshepard@appl-ecosys.com>; +Cc: pgsql-general@lists.postgresql.org

Rich Shepard <rshepard@appl-ecosys.com> writes:
> Long ago I wrote a query which was greatly improved (i.e., it actually
> worked as intended) by help here):

> SELECT ...
> WHERE p.lname = &p.lname AND p.fname = &p.fname;

> I did not save the reason why the ampersand is used in the WHERE row selection
> phrase and want now to learn why it's there. Probably needed to concatenate
> separate names?

AFAICS this is invoking a prefix operator named "&".  There is no such
operator built into Postgres.  Maybe psql's "\do+ &" would jog your
memory about where yours came from.

			regards, tom lane





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

* Re: Use of '&' as table prefix in query
@ 2021-07-12 17:42  Rob Sargent <robjsargent@gmail.com>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Rob Sargent @ 2021-07-12 17:42 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 7/12/21 11:25 AM, Rich Shepard wrote:
> Long ago I wrote a query which was greatly improved (i.e., it actually
> worked as intended) by help here):
>
> /* This query selects all activity information for a named person */
>
> SELECT p.lname, p.fname, p.loc_nbr, p.job_title, p.direct_phone, 
> p.active,
>        o.org_name,
>        l.loc_nbr, l.loc_name,
>        a.act_date, a.act_type, a.notes, a.next_contact
> FROM People AS p
>      JOIN Organizations AS o ON o.org_nbr = p.org_nbr
>      JOIN Locations AS l ON l.org_nbr = o.org_nbr and l.loc_nbr = 
> p.loc_nbr
>      JOIN Activities AS a ON a.person_nbr = p.person_nbr
> WHERE p.lname = &p.lname AND p.fname = &p.fname;
>
These look like value substitutions, usually done on the client at it 
sends the sql.  How is this sql getting to the server (presumably after 
substitution).





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

* Re: Use of '&' as table prefix in query
@ 2021-07-12 17:45  Rich Shepard <rshepard@appl-ecosys.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 10+ messages in thread

From: Rich Shepard @ 2021-07-12 17:45 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On Mon, 12 Jul 2021, Tom Lane wrote:

> AFAICS this is invoking a prefix operator named "&". There is no such
> operator built into Postgres. Maybe psql's "\do+ &" would jog your memory
> about where yours came from.

tom,

I thought it wasn't part of postgres. I've no idea why it's there, but I'll
remove it and see what happens.

Thanks!

Rich





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

* Re: Use of '&' as table prefix in query
@ 2021-07-12 17:47  Rich Shepard <rshepard@appl-ecosys.com>
  parent: Rob Sargent <robjsargent@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Rich Shepard @ 2021-07-12 17:47 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On Mon, 12 Jul 2021, Rob Sargent wrote:

> These look like value substitutions, usually done on the client at it
> sends the sql. How is this sql getting to the server (presumably after
> substitution).

Rob,

I was running queries from the psql back then. Now I'm adding a GUI
(tkinter) and using psycopg2.

Thanks,

Rich





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

* Re: Use of '&' as table prefix in query
@ 2021-07-12 17:48  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  1 sibling, 0 replies; 10+ messages in thread

From: Adrian Klaver @ 2021-07-12 17:48 UTC (permalink / raw)
  To: Rich Shepard <rshepard@appl-ecosys.com>; pgsql-general@lists.postgresql.org

On 7/12/21 10:45 AM, Rich Shepard wrote:
> On Mon, 12 Jul 2021, Tom Lane wrote:
> 
>> AFAICS this is invoking a prefix operator named "&". There is no such
>> operator built into Postgres. Maybe psql's "\do+ &" would jog your memory
>> about where yours came from.
> 
> tom,
> 
> I thought it wasn't part of postgres. I've no idea why it's there, but I'll
> remove it and see what happens.

Before you do that see Rob's post.

> 
> Thanks!
> 
> Rich
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





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

* Re: Use of '&' as table prefix in query
@ 2021-07-12 17:50  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Adrian Klaver @ 2021-07-12 17:50 UTC (permalink / raw)
  To: Rich Shepard <rshepard@appl-ecosys.com>; pgsql-general@lists.postgresql.org

On 7/12/21 10:45 AM, Rich Shepard wrote:
> On Mon, 12 Jul 2021, Tom Lane wrote:
> 
>> AFAICS this is invoking a prefix operator named "&". There is no such
>> operator built into Postgres. Maybe psql's "\do+ &" would jog your memory
>> about where yours came from.
> 
> tom,
> 
> I thought it wasn't part of postgres. I've no idea why it's there, but I'll
> remove it and see what happens.

You should also follow Tom's suggestion and do:

\do+ &

in psql.

> 
> Thanks!
> 
> Rich
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





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

* Re: Use of '&' as table prefix in query
@ 2021-07-12 17:51  Rob Sargent <robjsargent@gmail.com>
  parent: Rich Shepard <rshepard@appl-ecosys.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Rob Sargent @ 2021-07-12 17:51 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 7/12/21 11:47 AM, Rich Shepard wrote:
> On Mon, 12 Jul 2021, Rob Sargent wrote:
>
>> These look like value substitutions, usually done on the client at it
>> sends the sql. How is this sql getting to the server (presumably after
>> substitution).
>
> Rob,
>
> I was running queries from the psql back then. Now I'm adding a GUI
> (tkinter) and using psycopg2.
>
> Thanks,
>
> Rich
>
>
Having a hard time seeing the value in p.lname = p.lname and straight sql.






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

* Re: Use of '&' as table prefix in query
@ 2021-07-12 18:02  Rich Shepard <rshepard@appl-ecosys.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Rich Shepard @ 2021-07-12 18:02 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On Mon, 12 Jul 2021, Adrian Klaver wrote:


> You should also follow Tom's suggestion and do:
> \do+ &
> in psql.

It's the bitwise 'and':
# \do+ &
                                        List of operators
    Schema   | Name | Left arg type | Right arg type | Result type |   Function   | Description 
------------+------+---------------+----------------+-------------+--------------+-------------
  pg_catalog | &    | bigint        | bigint         | bigint      | int8and      | bitwise and
  pg_catalog | &    | bit           | bit            | bit         | bitand       | bitwise and
  pg_catalog | &    | inet          | inet           | inet        | inetand      | bitwise and
  pg_catalog | &    | integer       | integer        | integer     | int4and      | bitwise and
  pg_catalog | &    | macaddr       | macaddr        | macaddr     | macaddr_and  | bitwise and
  pg_catalog | &    | macaddr8      | macaddr8       | macaddr8    | macaddr8_and | bitwise and
  pg_catalog | &    | smallint      | smallint       | smallint    | int2and      | bitwise and
(7 rows)

which doesn't seem appropriate in this context.

Thanks,

Rich





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

* Re: Use of '&' as table prefix in query
@ 2021-07-12 18:04  Rich Shepard <rshepard@appl-ecosys.com>
  parent: Rob Sargent <robjsargent@gmail.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Rich Shepard @ 2021-07-12 18:04 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On Mon, 12 Jul 2021, Rob Sargent wrote:

> Having a hard time seeing the value in p.lname = p.lname and straight sql.

Me, too. That's why I wanted an explanation. Seems to me I added it sometime
for no valid reason. As I've not run that query in a very long time I'll
clean up the query and test it with the next opportunity.

Rich





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


end of thread, other threads:[~2021-07-12 18:04 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 17:25 Use of '&' as table prefix in query Rich Shepard <rshepard@appl-ecosys.com>
2021-07-12 17:36 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-07-12 17:45   ` Rich Shepard <rshepard@appl-ecosys.com>
2021-07-12 17:48     ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-07-12 17:50     ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-07-12 18:02       ` Rich Shepard <rshepard@appl-ecosys.com>
2021-07-12 17:42 ` Rob Sargent <robjsargent@gmail.com>
2021-07-12 17:47   ` Rich Shepard <rshepard@appl-ecosys.com>
2021-07-12 17:51     ` Rob Sargent <robjsargent@gmail.com>
2021-07-12 18:04       ` Rich Shepard <rshepard@appl-ecosys.com>

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