Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kn3NY-0000Hq-Bv for pgsql-general@arkaria.postgresql.org; Wed, 09 Dec 2020 17:35:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kn3NX-0006Qp-AI for pgsql-general@arkaria.postgresql.org; Wed, 09 Dec 2020 17:35:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kn3NW-0006Qi-U6 for pgsql-general@lists.postgresql.org; Wed, 09 Dec 2020 17:35:51 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kn3NU-0001i1-3y for pgsql-general@lists.postgresql.org; Wed, 09 Dec 2020 17:35:50 +0000 Received: by mail-ed1-x52d.google.com with SMTP id c7so2469692edv.6 for ; Wed, 09 Dec 2020 09:35:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=qKoRg/JDYz+j+epvL0mcIbmkmTjJHexEV9ebA0W0uDg=; b=Zww3TYMPIweUF7iZso24F6Hbe3EuNJ144EfcpOUYsQgVlw8X5o2csRjPjeBdqS+8gh yOKgCNYTOYdLUe93GrLO9B8rRXvG+nLnKQAHJelSuiQ3wp+qGJ4CpzAyhv6zIvY4xITK Ox1CJrz9uI3HG0UElJTIVra0aG2vjSE0ehB0akkziIuWsedp3145ecSBS6z7x7XLKu5a Hs1LurY9+G/SYbibQD6ATwVEIFLpxkOUDbriLJt+nYTZUfa8Fp3SkblQSJYqiQH3cucU 76WaZzP85AcUU4xivPwJaGMOlvDdW7viplpPk8Mi8M9fQuTI4IjYx0FbPaKFkjADFLWz AI9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=qKoRg/JDYz+j+epvL0mcIbmkmTjJHexEV9ebA0W0uDg=; b=LMl+d9+Ig3DJ/t+BgaHsMnPKMjpYDP90d0Pqq5Dagwuv2YhJFNKU7wIdpcGWqdfs+m +tjPbWVMRAGKdlynEP6Dom5KAeYHih5rmcPjJwwFzstK6c9kcF+axuhFlhwM+Jkcefdn +zbsfsXLWndBFpAvMikBUSHMbmaGfgL+YOsaaE6cBkaVhRNqecePa5ZSArnVl/LUCFKR 1+jGSrm2E7S7/YmaMzNsdyHgAFMHjuRGADrRGXL8Vhp29NtFadaeVn64Ob9Tz1pZecZH 0S5BXoF+To8RbKXtGbqoRWAv78LtAI5uGMtsQzGFcwu+Ps/aPNuOx+zgccFiKds9gTJv KaUg== X-Gm-Message-State: AOAM5334kZ0wt4t7HBR5AmDlDr0EzIfrmje1jfgOrMbfhoifILUlugtw PVksj1TPJSBctch9910+ykLkSQ== X-Google-Smtp-Source: ABdhPJyCtAKKkIZV/AriZtQb2ygvKuZLrX5lZScgOW2jHHxEBCzAyNnzRmrHN/3hOQQ8LPskzPiG9A== X-Received: by 2002:a05:6402:20a:: with SMTP id t10mr2963528edv.119.1607535345864; Wed, 09 Dec 2020 09:35:45 -0800 (PST) Received: from localhost.localdomain (217-149-171-44.nat.highway.telekom.at. [217.149.171.44]) by smtp.gmail.com with ESMTPSA id eb14sm2252673edb.20.2020.12.09.09.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 09:35:45 -0800 (PST) Message-ID: <60cacfc9020ff0ed37793e5eb71cf2794f97c445.camel@cybertec.at> Subject: Re: User input to queries From: Laurenz Albe To: Rich Shepard , pgsql-general@lists.postgresql.org Date: Wed, 09 Dec 2020 18:35:44 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 2020-12-09 at 09:03 -0800, Rich Shepard wrote: > While I develop the application's GUI I use the database from the command > line (psql). While some queries are self-contained others need user input. > I've not found a search term that locates this information in the > postgres-12 user manual and my web searches suggest that using '&' should > work. > > I tried the latter with this query but postgres didn't like it. (There may > well be other errors in it so don't hesitate to point out my mistakes.) > > ------ > /* This query selects all activity information for a named person */ > > /* Specify columns */ > 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 > /* Specify tables. */ > 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 > /* Specify rows */ > WHERE p.lname = &p.lname AND p.fname = &p.fname; > ----- > > Suggestions on what I should read to learn more about this subject are > appreciated. You probably need the \prompt psql command: \prompt 'What is "p.lname"' p_lname \prompt 'What is "p.fname"' p_fname SELECT ... WHERE p.lname = :p_lname AND p.fname = :p_fname; Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com