pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedSELECT returnig a constant
5+ messages / 4 participants
[nested] [flat]
* SELECT returnig a constant
@ 2019-10-15 13:28 stan <stanb@panix.com>
2019-10-15 13:35 ` Re: SELECT returnig a constant Ray O'Donnell <ray@rodonnell.ie>
0 siblings, 1 reply; 5+ messages in thread
From: stan @ 2019-10-15 13:28 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
I used to be able to return a constant value in a SELECT statement in
ORACLE. I need to populate a table for testing, and I was going to do so
like this:
SELECT
employee.id ,
project.proj_no ,
work_type.type ,
'rate' 1
FROM employee
CROSS JOIN project
CROSS JOIN work_type;
This statement works correctly, till I add the last "'rate' 1 line, then it
returns a syntax error.
How can I do this?
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SELECT returnig a constant
2019-10-15 13:28 SELECT returnig a constant stan <stanb@panix.com>
@ 2019-10-15 13:35 ` Ray O'Donnell <ray@rodonnell.ie>
2019-10-15 14:25 ` Re: SELECT returnig a constant Geoff Winkless <pgsqladmin@geoff.dj>
2019-10-15 16:15 ` Re: SELECT returnig a constant Ray O'Donnell <ray@rodonnell.ie>
0 siblings, 2 replies; 5+ messages in thread
From: Ray O'Donnell @ 2019-10-15 13:35 UTC (permalink / raw)
To: stan <stanb@panix.com>; pgsql-general@lists.postgresql.org
On 15/10/2019 14:28, stan wrote:
> I used to be able to return a constant value in a SELECT statement in
> ORACLE. I need to populate a table for testing, and I was going to do so
> like this:
>
> SELECT
> employee.id ,
> project.proj_no ,
> work_type.type ,
> 'rate' 1
> FROM employee
> CROSS JOIN project
> CROSS JOIN work_type;
>
> This statement works correctly, till I add the last "'rate' 1 line, then it
> returns a syntax error.
I don't think you can use a number as a column name. Give it a different
name and it should work:
SELECT .... , 'rate' my_constant_name FROM ...
Ray.
--
Raymond O'Donnell // Galway // Ireland
ray@rodonnell.ie
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SELECT returnig a constant
2019-10-15 13:28 SELECT returnig a constant stan <stanb@panix.com>
2019-10-15 13:35 ` Re: SELECT returnig a constant Ray O'Donnell <ray@rodonnell.ie>
@ 2019-10-15 14:25 ` Geoff Winkless <pgsqladmin@geoff.dj>
2019-10-15 15:58 ` Re: SELECT returnig a constant Michael Lewis <mlewis@entrata.com>
1 sibling, 1 reply; 5+ messages in thread
From: Geoff Winkless @ 2019-10-15 14:25 UTC (permalink / raw)
To: Ray O'Donnell <ray@rodonnell.ie>; +Cc: stan <stanb@panix.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
On Tue, 15 Oct 2019 at 14:35, Ray O'Donnell <ray@rodonnell.ie> wrote:
>
> On 15/10/2019 14:28, stan wrote:
> > I used to be able to return a constant value in a SELECT statement in
> > ORACLE. I need to populate a table for testing, and I was going to do so
> > like this:
> >
> > SELECT
> > employee.id ,
> > project.proj_no ,
> > work_type.type ,
> > 'rate' 1
> > FROM employee
> > CROSS JOIN project
> > CROSS JOIN work_type;
> >
> > This statement works correctly, till I add the last " 'rate' 1 line, then it
> > returns a syntax error.
>
> I don't think you can use a number as a column name. Give it a different
> name and it should work:
Well you can but only if you quote the column alias
SELECT
employee.id ,
project.proj_no ,
work_type.type ,
'rate' "1"
FROM employee
CROSS JOIN project
CROSS JOIN work_type;
but I really wouldn't recommend it. That way madness lies.
Geoff
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SELECT returnig a constant
2019-10-15 13:28 SELECT returnig a constant stan <stanb@panix.com>
2019-10-15 13:35 ` Re: SELECT returnig a constant Ray O'Donnell <ray@rodonnell.ie>
2019-10-15 14:25 ` Re: SELECT returnig a constant Geoff Winkless <pgsqladmin@geoff.dj>
@ 2019-10-15 15:58 ` Michael Lewis <mlewis@entrata.com>
0 siblings, 0 replies; 5+ messages in thread
From: Michael Lewis @ 2019-10-15 15:58 UTC (permalink / raw)
To: Geoff Winkless <pgsqladmin@geoff.dj>; +Cc: Ray O'Donnell <ray@rodonnell.ie>; stan <stanb@panix.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
On Tue, Oct 15, 2019 at 8:25 AM Geoff Winkless <pgsqladmin@geoff.dj> wrote:
> On Tue, 15 Oct 2019 at 14:35, Ray O'Donnell <ray@rodonnell.ie> wrote:
> >
> > On 15/10/2019 14:28, stan wrote:
> > > I used to be able to return a constant value in a SELECT statement in
> > > ORACLE. I need to populate a table for testing, and I was going to do
> so
> > > like this:
> > >
> > > SELECT
> > > employee.id ,
> > > project.proj_no ,
> > > work_type.type ,
> > > 'rate' 1
> > > FROM employee
> > > CROSS JOIN project
> > > CROSS JOIN work_type;
> > >
> > > This statement works correctly, till I add the last " 'rate' 1 line,
> then it
> > > returns a syntax error.
>
I would assume you have the value and the alias backwards and you want
SELECT 1 AS "rate"
Both the double quotes around the alias and the AS keyword are optional.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SELECT returnig a constant
2019-10-15 13:28 SELECT returnig a constant stan <stanb@panix.com>
2019-10-15 13:35 ` Re: SELECT returnig a constant Ray O'Donnell <ray@rodonnell.ie>
@ 2019-10-15 16:15 ` Ray O'Donnell <ray@rodonnell.ie>
1 sibling, 0 replies; 5+ messages in thread
From: Ray O'Donnell @ 2019-10-15 16:15 UTC (permalink / raw)
To: stan <stanb@panix.com>; pgsql-general
On 15/10/2019 15:01, stan wrote:
> Thanks, as you can see from my SOLVED reply, I go that part figured out.
> Now I am trying to figure out how to complete this. The SELECT returns more
> than 1 row, and when I put that in the VALUES clause this does not work.
Please reply to the list, rather than to me - reply-all should do the
trick. :-)
You're using cross-joins, which returns the cartesian product of the
tables concerned, without any WHERE clause.... so if the tables are big
you'll return a LOT of data.
Ray.
--
Raymond O'Donnell // Galway // Ireland
ray@rodonnell.ie
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2019-10-15 16:15 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-10-15 13:28 SELECT returnig a constant stan <stanb@panix.com>
2019-10-15 13:35 ` Ray O'Donnell <ray@rodonnell.ie>
2019-10-15 14:25 ` Geoff Winkless <pgsqladmin@geoff.dj>
2019-10-15 15:58 ` Michael Lewis <mlewis@entrata.com>
2019-10-15 16:15 ` Ray O'Donnell <ray@rodonnell.ie>
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