Обсуждение: new line in psotgres
Can anyone please tell me what is the character for a new line in postgres ?
I mean how does a new line get stored in postgres ?
Is it "\n" or "\\n" or something else ?
Thanks,
Jas
On Aug 6, 2007, at 12:28 , Jasbinder Singh Bali wrote: > Can anyone please tell me what is the character for a new line in > postgres ? > I mean how does a new line get stored in postgres ? > Is it "\n" or "\\n" or something else ? Newlines (ASCII 10) are stored as the newline character in the database encoding. E'\n' is a newline literal (or just '\n' in Postgres versions prior to 8.1, IIRC). Newline also represents itself, e.g., ' '. Michael Glaesemann grzm seespotcode net
On Mon, 2007-08-06 at 13:28 -0400, Jasbinder Singh Bali wrote: > Hi, > Can anyone please tell me what is the character for a new line in > postgres ? > I mean how does a new line get stored in postgres ? > Is it "\n" or "\\n" or something else ? > You can just put the newline directly in the SQL: INSERT INTO mytable(myattr) VALUES('first line second line third line'); Regards, Jeff Davis
Also, would E'\n' work ?
I really did not understand if word newline is a key word for a newline character in postgres.
Thanks,
~Jas
On Mon, 2007-08-06 at 13:28 -0400, Jasbinder Singh Bali wrote:
> Hi,
> Can anyone please tell me what is the character for a new line in
> postgres ?
> I mean how does a new line get stored in postgres ?
> Is it "\n" or "\\n" or something else ?
>
You can just put the newline directly in the SQL:
INSERT INTO mytable(myattr) VALUES('first line
second line
third line');
Regards,
Jeff Davis
you can include newline in postgre using literal E create table table (text varchar(50)); insert into Table (text) values (E'This is the first part \\n And this is the second'); -- View this message in context: http://postgresql.1045698.n5.nabble.com/new-line-in-psotgres-tp1885914p5777583.html Sent from the PostgreSQL - general mailing list archive at Nabble.com.
On Nov 9, 2013, at 12:08, abdullatheef <latheefvkpadi@gmail.com> wrote: > you can include newline in postgre using literal E > > create table table (text varchar(50)); > insert into Table (text) values (E'This is the first part \\n And this is > the second'); Or like this: development=> begin; BEGIN development=> create table t1 (text text); CREATE TABLE development=> insert into t1 values ('This is line 1. development'> This is line 2.'); INSERT 0 1 development=> select * from t1; text ----------------- This is line 1.+ This is line 2. (1 row) Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.
The second methods have different characteristics...On Nov 9, 2013, at 12:08, abdullatheef <latheefvkpadi@gmail.com> wrote:> you can include newline in postgre using literal E > > create table table (text varchar(50)); > insert into Table (text) values (E'This is the first part \\n And this is > the second');Or like this: development=> begin; BEGIN development=> create table t1 (text text); CREATE TABLE development=> insert into t1 values ('This is line 1. development'> This is line 2.'); INSERT 0 1 development=> select * from t1; text -----------------This is line 1.+This is line 2. (1 row) Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.-- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
-- test.sql
CREATE TABLE t1
(
id SERIAL PRIMARY KEY,
payload text
);
-- method 1
INSERT INTO t1
(payload)
VALUES
(E'This is the first part \\n And this is the second');
-- method 2
INSERT INTO t1
(payload)
VALUES
('This is line 1.
This is line 2.');
TABLE t1;
######## results:
gavin=> \i test.sql
DROP TABLE
psql:SQL.sql:8: NOTICE: CREATE TABLE will create implicit sequence "t1_id_seq" for serial column "t1.id"
psql:SQL.sql:8: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t1_pkey" for table "t1"
CREATE TABLE
INSERT 0 1
INSERT 0 1
id | payload
----+--------------------------------------------------
1 | This is the first part \n And this is the second
2 | This is line 1. +
| This is line 2.
(2 rows)
Cheers,
Gavin
I had another thought...On 10/11/13 02:38, Alban Hertroys wrote:The second methods have different characteristics...On Nov 9, 2013, at 12:08, abdullatheef <latheefvkpadi@gmail.com> wrote:> you can include newline in postgre using literal E > > create table table (text varchar(50)); > insert into Table (text) values (E'This is the first part \\n And this is > the second');Or like this: development=> begin; BEGIN development=> create table t1 (text text); CREATE TABLE development=> insert into t1 values ('This is line 1. development'> This is line 2.'); INSERT 0 1 development=> select * from t1; text -----------------This is line 1.+This is line 2. (1 row) Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.-- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
-- test.sql
CREATE TABLE t1
(
id SERIAL PRIMARY KEY,
payload text
);
-- method 1
INSERT INTO t1
(payload)
VALUES
(E'This is the first part \\n And this is the second');
-- method 2
INSERT INTO t1
(payload)
VALUES
('This is line 1.
This is line 2.');
TABLE t1;
######## results:
gavin=> \i test.sql
DROP TABLE
psql:SQL.sql:8: NOTICE: CREATE TABLE will create implicit sequence "t1_id_seq" for serial column "t1.id"
psql:SQL.sql:8: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t1_pkey" for table "t1"
CREATE TABLE
INSERT 0 1
INSERT 0 1
id | payload
----+--------------------------------------------------
1 | This is the first part \n And this is the second
2 | This is line 1. +
| This is line 2.
(2 rows)
Cheers,
Gavin
I redid the above, and included at test with 'E' & '\n' - just one slash before the 'n'. The other changes are mostly cosmetic.
So now we have 2 methods that produce identical output (ignoring the id).
/*
* Split lines text values
*
* splitline01.sql
*/
DROP TABLE IF EXISTS t1;
CREATE TABLE t1
(
id SERIAL PRIMARY KEY,
payload text
);
-- method 1
INSERT INTO t1
(payload)
VALUES
(E'This is the first part \\n And this is the second');
-- method 2
INSERT INTO t1
(payload)
VALUES
(E'This is the first part \n And this is the second');
-- method 3
INSERT INTO t1
(payload)
VALUES
('This is the first part
And this is the second');
TABLE t1;
##################################
gavin=> \i splitline01.sql
DROP TABLE
psql:splitline01.sql:12: NOTICE: CREATE TABLE will create implicit sequence "t1_id_seq" for serial column "t1.id"
psql:splitline01.sql:12: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t1_pkey" for table "t1"
CREATE TABLE
INSERT 0 1
INSERT 0 1
INSERT 0 1
id | payload
----+--------------------------------------------------
1 | This is the first part \n And this is the second
2 | This is the first part +
| And this is the second
3 | This is the first part +
| And this is the second
(3 rows)
Cheers,
Gavin
On 11/9/2013 5:33 PM, Gavin Flower wrote: > > I redid the above, and included at test with 'E' & '\n' - just one > slash before the 'n'. The other changes are mostly cosmetic. E'....\\n....' would be required if you were entering the string in a programming language that itself used \ as an escape, as this way it would pass a literal \ to postgres, which would use that to escape the n -- john r pierce 37N 122W somewhere on the middle of the left coast