pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stuart Rison <stuart@ludwig.ucl.ac.uk>
To: Chris Bitmead <chris.bitmead@bigfoot.com>
Cc: pgsql-general@postgreSQL.org
Subject: Re: [GENERAL] How to do this in SQL?
Date: Tue, 30 Mar 1999 16:50:12 +0100
Message-ID: <v04003a07b326a26d4f2e@[128.40.242.190]> (raw)
In-Reply-To: <3700E388.3E3A77E1@bigfoot.com>

>Let's say I had a table...
>CREATE TABLE book (
>   author oid,
>   name text );
>and...
>CREATE TABLE author (
>   name text );
>
>and I wanted to create a book pointing to author with name 'Tolstoy'. I
>want to do something like...
>
>INSERT INTO book(name,author) values('War and Peace',
>      (SELECT oid FROM author WHERE name = 'Tolstoy'));
>
>but this doesn't work. What is the correct syntax?
>

try \h insert in psql for a description of the correct syntax.

Your query becomes:

INSERT INTO book(author,name)
	SELECT oid,'War and Peace'
	FROM author
	WHERE name='Tolstoy';

Stuart.


+-------------------------+--------------------------------------+
| Stuart Rison            | Ludwig Institute for Cancer Research |
+-------------------------+ 91 Riding House Street               |
| Tel. (0171) 878 4041    | London, W1P 8BT, UNITED KINGDOM.     |
| Fax. (0171) 878 4040    | stuart@ludwig.ucl.ac.uk              |
+-------------------------+--------------------------------------+





view thread (5+ messages)

Message-ID: <v04003a07b326a26d4f2e@[128.40.242.190]>
Permalink:  ../v04003a07b326a26d4f2e@%5B128.40.242.190%5D/
Also on:    postgresql.org/message-id/v04003a07b326a26d4f2e@[128.40.242.190]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: stuart@ludwig.ucl.ac.uk, chris.bitmead@bigfoot.com, pgsql-general@postgreSQL.org
  Subject: Re: [GENERAL] How to do this in SQL?
  In-Reply-To: <v04003a07b326a26d4f2e@[128.40.242.190]>
  References: <3700E388.3E3A77E1@bigfoot.com> <v04003a07b326a26d4f2e@[128.40.242.190]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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