From: | Stuart Rison <stuart(at)ludwig(dot)ucl(dot)ac(dot)uk> |
---|---|
To: | Chris Bitmead <chris(dot)bitmead(at)bigfoot(dot)com> |
Cc: | pgsql-general(at)postgreSQL(dot)org |
Subject: | Re: [GENERAL] How to do this in SQL? |
Date: | 1999-03-30 15:50:12 |
Message-ID: | v04003a07b326a26d4f2e@[128.40.242.190] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-sql |
>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(at)ludwig(dot)ucl(dot)ac(dot)uk |
+-------------------------+--------------------------------------+
From | Date | Subject | |
---|---|---|---|
Next Message | Jackson, DeJuan | 1999-03-30 17:26:55 | RE: [GENERAL] Performance |
Previous Message | Herouth Maoz | 1999-03-30 15:13:48 | Re: [GENERAL] How to do this in SQL? |
From | Date | Subject | |
---|---|---|---|
Next Message | Oliver Smith | 1999-03-30 16:00:33 | Date operation efficiency |
Previous Message | Herouth Maoz | 1999-03-30 15:13:48 | Re: [GENERAL] How to do this in SQL? |