Do you need surrounding parantheses in Postgres SELECT statement?Select datatype of the field in postgresHow do you find the row count for all your tables in PostgresIn postgres (plpgsql), how to make a function that returns select * on a variable table_name?Slow select distinct query on postgresGenerating a UUID in Postgres for Insert statement?postgres multiple JDBC select statements in batchPostgres SELECT with multiple select asSelect distinct last messages by pairs in postgreshow to write select statement for a function in postgresPostgres: Build select Query from output of a query

Best material to absorb as much light as possible

Why would Ryanair allow me to book this journey through a third party, but not through their own website?

Did 20% of US soldiers in Vietnam use heroin, 95% of whom quit afterwards?

Is the Unsullied name meant to be ironic? How did it come to be?

A steel cutting sword?

How to patch glass cuts in a bicycle tire?

First Match - awk

A married couple

Find the three digit Prime number P from the given unusual relationships

What does $!# mean in Shell scripting?

Why does the hash of infinity have the digits of π?

Is it rude to call a professor by their last name with no prefix in a non-academic setting?

Website returning plaintext password

Can the Grave cleric's Sentinel at Death's Door feature turn a critical hit into a miss, while adamantine armor does not?

Can I install a back bike rack without attachment to the rear part of the frame?

Can a person survive on blood in place of water?

How to deal with a colleague who is being aggressive?

Have 1.5% of all nuclear reactors ever built melted down?

What was the idiom for something that we take without a doubt?

How to cut a climbing rope?

What is the function of the corrugations on a section of the Space Shuttle's external tank?

Need to read my home electrical meter

What does 気楽 mean when attached to ビール or お酒?

Make 24 using exactly three 3s



Do you need surrounding parantheses in Postgres SELECT statement?


Select datatype of the field in postgresHow do you find the row count for all your tables in PostgresIn postgres (plpgsql), how to make a function that returns select * on a variable table_name?Slow select distinct query on postgresGenerating a UUID in Postgres for Insert statement?postgres multiple JDBC select statements in batchPostgres SELECT with multiple select asSelect distinct last messages by pairs in postgreshow to write select statement for a function in postgresPostgres: Build select Query from output of a query






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I noticed that there is different output for this



SELECT id,name,description FROM table_name;



as opposed to this



SELECT (id,name,description) FROM table_name;



Is there any big difference between the two?



What is the purpose of this?










share|improve this question




























    1















    I noticed that there is different output for this



    SELECT id,name,description FROM table_name;



    as opposed to this



    SELECT (id,name,description) FROM table_name;



    Is there any big difference between the two?



    What is the purpose of this?










    share|improve this question
























      1












      1








      1








      I noticed that there is different output for this



      SELECT id,name,description FROM table_name;



      as opposed to this



      SELECT (id,name,description) FROM table_name;



      Is there any big difference between the two?



      What is the purpose of this?










      share|improve this question














      I noticed that there is different output for this



      SELECT id,name,description FROM table_name;



      as opposed to this



      SELECT (id,name,description) FROM table_name;



      Is there any big difference between the two?



      What is the purpose of this?







      postgresql






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 2:11









      pukpuk

      8,1052284163




      8,1052284163






















          2 Answers
          2






          active

          oldest

          votes


















          2














          The following query actually is selecting a ROW type value:



          SELECT (id, name, description) FROM table_name;


          This syntax by itself would not be very useful, and more typically you would use this if you were doing an INSERT INTO ... SELECT into a table which had a row type in its definition. Here is an example of how you might use this.



          CREATE TYPE your_type AS (
          id INTEGER,
          name VARCHAR,
          description VARCHAR
          );

          CREATE TABLE your_table (
          id INTEGER,
          t your_type
          );

          INSERT INTO your_table (id, t)
          SELECT 1, (id, name, description)
          FROM table_name;


          From the Postgres documentation on composite types:




          Whenever you create a table, a composite type is also automatically created, with the same name as the table, to represent the table's row type.




          So you have already been working with row types, whether or not you knew it.






          share|improve this answer






























            3














            create table table_name(id int, name text, description text);
            insert into table_name
            values (1, 'John', 'big one');

            select (id, name, description), id, name, description
            from table_name;

            row | id | name | description
            --------------------+----+------+-------------
            (1,John,"big one") | 1 | John | big one
            (1 row)


            The difference is important. Columns enclosed in parenthesis form a row constructor known also as a composite value, returned in a single column. Usually, separate columns are preferred as a query result. Row constructors are necessary when a row as a whole is needed (e.g. in the VALUES of the above INSERT command). They are also used as values of composite types.






            share|improve this answer

























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320143%2fdo-you-need-surrounding-parantheses-in-postgres-select-statement%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              The following query actually is selecting a ROW type value:



              SELECT (id, name, description) FROM table_name;


              This syntax by itself would not be very useful, and more typically you would use this if you were doing an INSERT INTO ... SELECT into a table which had a row type in its definition. Here is an example of how you might use this.



              CREATE TYPE your_type AS (
              id INTEGER,
              name VARCHAR,
              description VARCHAR
              );

              CREATE TABLE your_table (
              id INTEGER,
              t your_type
              );

              INSERT INTO your_table (id, t)
              SELECT 1, (id, name, description)
              FROM table_name;


              From the Postgres documentation on composite types:




              Whenever you create a table, a composite type is also automatically created, with the same name as the table, to represent the table's row type.




              So you have already been working with row types, whether or not you knew it.






              share|improve this answer



























                2














                The following query actually is selecting a ROW type value:



                SELECT (id, name, description) FROM table_name;


                This syntax by itself would not be very useful, and more typically you would use this if you were doing an INSERT INTO ... SELECT into a table which had a row type in its definition. Here is an example of how you might use this.



                CREATE TYPE your_type AS (
                id INTEGER,
                name VARCHAR,
                description VARCHAR
                );

                CREATE TABLE your_table (
                id INTEGER,
                t your_type
                );

                INSERT INTO your_table (id, t)
                SELECT 1, (id, name, description)
                FROM table_name;


                From the Postgres documentation on composite types:




                Whenever you create a table, a composite type is also automatically created, with the same name as the table, to represent the table's row type.




                So you have already been working with row types, whether or not you knew it.






                share|improve this answer

























                  2












                  2








                  2







                  The following query actually is selecting a ROW type value:



                  SELECT (id, name, description) FROM table_name;


                  This syntax by itself would not be very useful, and more typically you would use this if you were doing an INSERT INTO ... SELECT into a table which had a row type in its definition. Here is an example of how you might use this.



                  CREATE TYPE your_type AS (
                  id INTEGER,
                  name VARCHAR,
                  description VARCHAR
                  );

                  CREATE TABLE your_table (
                  id INTEGER,
                  t your_type
                  );

                  INSERT INTO your_table (id, t)
                  SELECT 1, (id, name, description)
                  FROM table_name;


                  From the Postgres documentation on composite types:




                  Whenever you create a table, a composite type is also automatically created, with the same name as the table, to represent the table's row type.




                  So you have already been working with row types, whether or not you knew it.






                  share|improve this answer













                  The following query actually is selecting a ROW type value:



                  SELECT (id, name, description) FROM table_name;


                  This syntax by itself would not be very useful, and more typically you would use this if you were doing an INSERT INTO ... SELECT into a table which had a row type in its definition. Here is an example of how you might use this.



                  CREATE TYPE your_type AS (
                  id INTEGER,
                  name VARCHAR,
                  description VARCHAR
                  );

                  CREATE TABLE your_table (
                  id INTEGER,
                  t your_type
                  );

                  INSERT INTO your_table (id, t)
                  SELECT 1, (id, name, description)
                  FROM table_name;


                  From the Postgres documentation on composite types:




                  Whenever you create a table, a composite type is also automatically created, with the same name as the table, to represent the table's row type.




                  So you have already been working with row types, whether or not you knew it.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 24 at 2:42









                  Tim BiegeleisenTim Biegeleisen

                  248k13103163




                  248k13103163























                      3














                      create table table_name(id int, name text, description text);
                      insert into table_name
                      values (1, 'John', 'big one');

                      select (id, name, description), id, name, description
                      from table_name;

                      row | id | name | description
                      --------------------+----+------+-------------
                      (1,John,"big one") | 1 | John | big one
                      (1 row)


                      The difference is important. Columns enclosed in parenthesis form a row constructor known also as a composite value, returned in a single column. Usually, separate columns are preferred as a query result. Row constructors are necessary when a row as a whole is needed (e.g. in the VALUES of the above INSERT command). They are also used as values of composite types.






                      share|improve this answer





























                        3














                        create table table_name(id int, name text, description text);
                        insert into table_name
                        values (1, 'John', 'big one');

                        select (id, name, description), id, name, description
                        from table_name;

                        row | id | name | description
                        --------------------+----+------+-------------
                        (1,John,"big one") | 1 | John | big one
                        (1 row)


                        The difference is important. Columns enclosed in parenthesis form a row constructor known also as a composite value, returned in a single column. Usually, separate columns are preferred as a query result. Row constructors are necessary when a row as a whole is needed (e.g. in the VALUES of the above INSERT command). They are also used as values of composite types.






                        share|improve this answer



























                          3












                          3








                          3







                          create table table_name(id int, name text, description text);
                          insert into table_name
                          values (1, 'John', 'big one');

                          select (id, name, description), id, name, description
                          from table_name;

                          row | id | name | description
                          --------------------+----+------+-------------
                          (1,John,"big one") | 1 | John | big one
                          (1 row)


                          The difference is important. Columns enclosed in parenthesis form a row constructor known also as a composite value, returned in a single column. Usually, separate columns are preferred as a query result. Row constructors are necessary when a row as a whole is needed (e.g. in the VALUES of the above INSERT command). They are also used as values of composite types.






                          share|improve this answer















                          create table table_name(id int, name text, description text);
                          insert into table_name
                          values (1, 'John', 'big one');

                          select (id, name, description), id, name, description
                          from table_name;

                          row | id | name | description
                          --------------------+----+------+-------------
                          (1,John,"big one") | 1 | John | big one
                          (1 row)


                          The difference is important. Columns enclosed in parenthesis form a row constructor known also as a composite value, returned in a single column. Usually, separate columns are preferred as a query result. Row constructors are necessary when a row as a whole is needed (e.g. in the VALUES of the above INSERT command). They are also used as values of composite types.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 24 at 2:50

























                          answered Mar 24 at 2:41









                          klinklin

                          62k66395




                          62k66395



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320143%2fdo-you-need-surrounding-parantheses-in-postgres-select-statement%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                              155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해