mysql create table -> psql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • expect

    mysql create table -> psql


    Hello,

    Trying to get this MySql create table command to work, no luck.

    create sequence serial;

    CREATE TABLE outbound (
    source char(100) default '',
    destination char(100) default '',
    sport int4 default 0 NOT NULL,
    dport int4 NOT NULL default 0,
    time timestamp NOT NULL default '0000-00-00 00:00:00',
    id int8 default nextval('serial ') not null,
    constraint id PRIMARY (id)
    );


    I get a parse error:
    ERROR: parser: parse error at or near "(" at character 279


    ---------------------------(end of broadcast)---------------------------
    TIP 8: explain analyze is your friend

  • Ian Barwick

    #2
    Re: mysql create table -> psql

    On Tuesday 09 September 2003 08:10, "expect" wrote:[color=blue]
    > Hello,
    >
    > Trying to get this MySql create table command to work, no luck.
    >
    > create sequence serial;
    >
    > CREATE TABLE outbound (
    > source char(100) default '',
    > destination char(100) default '',
    > sport int4 default 0 NOT NULL,
    > dport int4 NOT NULL default 0,
    > time timestamp NOT NULL default '0000-00-00 00:00:00',
    > id int8 default nextval('serial ') not null,
    > constraint id PRIMARY (id)
    > );[/color]

    usually you would change the last two lines to:

    ....
    id SERIAL,
    PRIMARY KEY (id)
    ....

    You don't need to create a sequence in most cases,
    although I'm guessing you want to use int8 if you're storing firewall logs:

    create sequence outbound_id_seq ;

    and primary key definition as:

    ....
    id int8 default nextval('serial ') not null,
    PRIMARY KEY (id)
    ....

    You will need to do something about the timestamp
    default of zero, this is a MySQL-ism and won't work in PostgreSQL.
    Probably dropping the NOT NULL constraint and DEFAULT altogether would
    be best; if the timestamp should default to the current time,
    use DEFAULT NOW().

    Ian Barwick
    barwick@gmx.net


    ---------------------------(end of broadcast)---------------------------
    TIP 4: Don't 'kill -9' the postmaster

    Comment

    • Richard Huxton

      #3
      Re: mysql create table -> psql

      On Tuesday 09 September 2003 07:10, expect wrote:[color=blue]
      > Hello,
      >
      > Trying to get this MySql create table command to work, no luck.
      >
      > create sequence serial;
      >
      > CREATE TABLE outbound (
      > source char(100) default '',
      > destination char(100) default '',
      > sport int4 default 0 NOT NULL,
      > dport int4 NOT NULL default 0,
      > time timestamp NOT NULL default '0000-00-00 00:00:00',
      > id int8 default nextval('serial ') not null,
      > constraint id PRIMARY (id)
      > );[/color]

      In addition to everything Ian says, you probably want varchar() not char() for
      the source and destination. The char type is space-padded to the length of
      the field (MySQL strips them somehow, but can't remember how off the top of
      my head - anyway, varchar is the standard variable-length text type).

      --
      Richard Huxton
      Archonet Ltd

      ---------------------------(end of broadcast)---------------------------
      TIP 8: explain analyze is your friend

      Comment

      • Scott Cain

        #4
        Re: mysql create table -> psql

        You might want to take a look at a Perl module, SQL::Translator , which
        translates schema elements (table creates, indexes, views) from one DB's
        SQL to another. I don't know if the S::T on CPAN is up to date, so you
        might want to try their website to get the CVS version:



        Scott


        On Tue, 2003-09-09 at 02:10, expect wrote:[color=blue]
        > Hello,
        >
        > Trying to get this MySql create table command to work, no luck.
        >
        > create sequence serial;
        >
        > CREATE TABLE outbound (
        > source char(100) default '',
        > destination char(100) default '',
        > sport int4 default 0 NOT NULL,
        > dport int4 NOT NULL default 0,
        > time timestamp NOT NULL default '0000-00-00 00:00:00',
        > id int8 default nextval('serial ') not null,
        > constraint id PRIMARY (id)
        > );
        >
        >
        > I get a parse error:
        > ERROR: parser: parse error at or near "(" at character 279
        >
        >
        > ---------------------------(end of broadcast)---------------------------
        > TIP 8: explain analyze is your friend[/color]
        --
        ------------------------------------------------------------------------
        Scott Cain, Ph. D. cain@cshl.org
        GMOD Coordinator (http://www.gmod.org/) 216-392-3087
        Cold Spring Harbor Laboratory


        ---------------------------(end of broadcast)---------------------------
        TIP 7: don't forget to increase your free space map settings

        Comment

        • scott.marlowe

          #5
          Re: mysql create table -> psql

          On Tue, 9 Sep 2003, Richard Huxton wrote:
          [color=blue]
          > On Tuesday 09 September 2003 07:10, expect wrote:[color=green]
          > > Hello,
          > >
          > > Trying to get this MySql create table command to work, no luck.
          > >
          > > create sequence serial;
          > >
          > > CREATE TABLE outbound (
          > > source char(100) default '',
          > > destination char(100) default '',
          > > sport int4 default 0 NOT NULL,
          > > dport int4 NOT NULL default 0,
          > > time timestamp NOT NULL default '0000-00-00 00:00:00',
          > > id int8 default nextval('serial ') not null,
          > > constraint id PRIMARY (id)
          > > );[/color]
          >
          > In addition to everything Ian says, you probably want varchar() not char() for
          > the source and destination. The char type is space-padded to the length of
          > the field (MySQL strips them somehow, but can't remember how off the top of
          > my head - anyway, varchar is the standard variable-length text type).[/color]

          One more addition, you can use bigserial to define a serial with a big
          int. Also, you might as well drop the explicit casting of int4, since int
          = int4 right now, and in some future may be int8 when even calculator
          watches are 64 bit. Might as well have your DDL ready to take advantage
          of it.

          Also, you can move your pk def into the single field defining the pkey
          here (id).

          also note, if you didn't have a pk defined on your serial and wanted it to
          be ensured to be unique, you would need to add a unique keyword there as
          well, since autounique indexes on serials went away around V7.3 of pgsql.

          Finally, note that timestamp is a SQL spec type that does NOT do in
          postgresql what it does in MySQL (i.e. get an auto inserted timestamp on
          insert / update) so even the default now() isn't quite what you'd expect.
          If you need that field to always get updated to the latest time when
          the row is updated you'll have to write a trigger. It's a cardinal
          example in the docs, I believe.

          CREATE TABLE outbound (
          source varchar(100) default '',
          destination varchar(100) default '',
          sport int default 0 NOT NULL,
          dport int NOT NULL default 0,
          time timestamp NOT NULL default now(),
          id bigserial not null primary key
          );


          ---------------------------(end of broadcast)---------------------------
          TIP 7: don't forget to increase your free space map settings

          Comment

          • Franco Bruno Borghesi

            #6
            Re: mysql create table -> psql

            the problem is
            constraint id PRIMARY (id), it should be constraint id PRIMARY KEY (id).

            Besides that, you will have problems with '0000-00-00'... month starts
            at 1, day starts at 1, and I don't know about year 0. Maybe this field
            'time' should be NULLable, or maybe its default value should be
            '0001-01-01 00:00:00'.



            On Tue, 2003-09-09 at 03:10, expect wrote:
            [color=blue]
            > Hello,
            >
            > Trying to get this MySql create table command to work, no luck.
            >
            > create sequence serial;
            >
            > CREATE TABLE outbound (
            > source char(100) default '',
            > destination char(100) default '',
            > sport int4 default 0 NOT NULL,
            > dport int4 NOT NULL default 0,
            > time timestamp NOT NULL default '0000-00-00 00:00:00',
            > id int8 default nextval('serial ') not null,
            > constraint id PRIMARY (id)
            > );
            >
            >
            > I get a parse error:
            > ERROR: parser: parse error at or near "(" at character 279
            >
            >
            > ---------------------------(end of broadcast)---------------------------
            > TIP 8: explain analyze is your friend[/color]

            -----BEGIN PGP SIGNATURE-----
            Version: GnuPG v1.2.2 (FreeBSD)

            iD8DBQA/Xd5c21dVnhLsBV0 RAsDEAJoDdObeF/s/a2F7JEh6PPNFAZU ZbgCbBFeT
            kV1KUSx31RTHSjq XLJkdkC8=
            =WNDr
            -----END PGP SIGNATURE-----

            Comment

            • expect

              #7
              Re: mysql create table -> psql

              On Tue, 09 Sep 2003 09:36:08 -0400
              Scott Cain <cain@cshl.or g> wrote:
              [color=blue]
              > You might want to take a look at a Perl module, SQL::Translator , which
              > translates schema elements (table creates, indexes, views) from one DB's
              > SQL to another. I don't know if the S::T on CPAN is up to date, so you
              > might want to try their website to get the CVS version:
              >
              > http://sqlfairy.sourceforge.net/[/color]

              Funny name, thanks. It's amazing how I didn't find this via google.com.
              Is it just me or is google less effective than it once was? Sure seems like it.
              I think they're going to have to modify their model.
              [color=blue]
              >
              > Scott
              >
              >
              > On Tue, 2003-09-09 at 02:10, expect wrote:[color=green]
              > > Hello,
              > >
              > > Trying to get this MySql create table command to work, no luck.
              > >
              > > create sequence serial;
              > >
              > > CREATE TABLE outbound (
              > > source char(100) default '',
              > > destination char(100) default '',
              > > sport int4 default 0 NOT NULL,
              > > dport int4 NOT NULL default 0,
              > > time timestamp NOT NULL default '0000-00-00 00:00:00',
              > > id int8 default nextval('serial ') not null,
              > > constraint id PRIMARY (id)
              > > );
              > >
              > >
              > > I get a parse error:
              > > ERROR: parser: parse error at or near "(" at character 279
              > >
              > >
              > > ---------------------------(end of broadcast)---------------------------
              > > TIP 8: explain analyze is your friend[/color]
              > --
              > ------------------------------------------------------------------------
              > Scott Cain, Ph. D. cain@cshl.org
              > GMOD Coordinator (http://www.gmod.org/) 216-392-3087
              > Cold Spring Harbor Laboratory
              >
              >
              > ---------------------------(end of broadcast)---------------------------
              > TIP 7: don't forget to increase your free space map settings
              >
              >[/color]

              ---------------------------(end of broadcast)---------------------------
              TIP 7: don't forget to increase your free space map settings

              Comment

              • Dennis Gearon

                #8
                Re: mysql create table -&gt; psql

                expect wrote:
                [color=blue]
                >On Tue, 09 Sep 2003 09:36:08 -0400
                >Scott Cain <cain@cshl.or g> wrote:
                >
                >
                >[color=green]
                >>You might want to take a look at a Perl module, SQL::Translator , which
                >>translates schema elements (table creates, indexes, views) from one DB's
                >>SQL to another. I don't know if the S::T on CPAN is up to date, so you
                >>might want to try their website to get the CVS version:
                >>
                >>http://sqlfairy.sourceforge.net/
                >>
                >>[/color]
                >
                >Funny name, thanks. It's amazing how I didn't find this via google.com.
                >Is it just me or is google less effective than it once was? Sure seems like it.
                >I think they're going to have to modify their model.
                >
                >
                >[color=green]
                >>Scott
                >>
                >>
                >>On Tue, 2003-09-09 at 02:10, expect wrote:
                >>
                >>[color=darkred]
                >>>Hello,
                >>>
                >>>Trying to get this MySql create table command to work, no luck.
                >>>
                >>>create sequence serial;
                >>>
                >>>CREATE TABLE outbound (
                >>>source char(100) default '',
                >>>destinatio n char(100) default '',
                >>>sport int4 default 0 NOT NULL,
                >>>dport int4 NOT NULL default 0,
                >>>time timestamp NOT NULL default '0000-00-00 00:00:00',
                >>>id int8 default nextval('serial ') not null,
                >>>constraint id PRIMARY (id)
                >>>);
                >>>
                >>>
                >>>I get a parse error:
                >>>ERROR: parser: parse error at or near "(" at character 279
                >>>
                >>>
                >>>---------------------------(end of broadcast)---------------------------
                >>>TIP 8: explain analyze is your friend
                >>>
                >>>[/color]
                >>--
                >>------------------------------------------------------------------------
                >>Scott Cain, Ph. D. cain@cshl.org
                >>GMOD Coordinator (http://www.gmod.org/) 216-392-3087
                >>Cold Spring Harbor Laboratory
                >>
                >>
                >>---------------------------(end of broadcast)---------------------------
                >>TIP 7: don't forget to increase your free space map settings
                >>
                >>
                >>
                >>[/color]
                >
                >---------------------------(end of broadcast)---------------------------
                >TIP 7: don't forget to increase your free space map settings
                >
                >
                >[/color]
                I think google's reach into technical sites is diminishing. We generate
                SOOOOOOOOOOOO much traffic on all the open source AND closed source
                discussion groups, it's staggering.

                Jeesh, it would be intereseting to know how many words, characters, etc
                were in each of those domains. I be the folks at marc.theaimsgro up.com
                could give us an idea about thiers plus add in sourceforge, and it'd be
                a major part of it. Well, then there's the stuff on usenet that's not on
                listserves.


                ---------------------------(end of broadcast)---------------------------
                TIP 9: the planner will ignore your desire to choose an index scan if your
                joining column's datatypes do not match

                Comment

                • expect

                  #9
                  Re: mysql create table -&gt; psql

                  On Tue, 09 Sep 2003 09:36:08 -0400
                  Scott Cain <cain@cshl.or g> wrote:
                  [color=blue]
                  > You might want to take a look at a Perl module, SQL::Translator , which
                  > translates schema elements (table creates, indexes, views) from one DB's
                  > SQL to another. I don't know if the S::T on CPAN is up to date, so you
                  > might want to try their website to get the CVS version:
                  >
                  > http://sqlfairy.sourceforge.net/[/color]

                  Funny name, thanks. It's amazing how I didn't find this via google.com.
                  Is it just me or is google less effective than it once was? Sure seems like it.
                  I think they're going to have to modify their model.
                  [color=blue]
                  >
                  > Scott
                  >
                  >
                  > On Tue, 2003-09-09 at 02:10, expect wrote:[color=green]
                  > > Hello,
                  > >
                  > > Trying to get this MySql create table command to work, no luck.
                  > >
                  > > create sequence serial;
                  > >
                  > > CREATE TABLE outbound (
                  > > source char(100) default '',
                  > > destination char(100) default '',
                  > > sport int4 default 0 NOT NULL,
                  > > dport int4 NOT NULL default 0,
                  > > time timestamp NOT NULL default '0000-00-00 00:00:00',
                  > > id int8 default nextval('serial ') not null,
                  > > constraint id PRIMARY (id)
                  > > );
                  > >
                  > >
                  > > I get a parse error:
                  > > ERROR: parser: parse error at or near "(" at character 279
                  > >
                  > >
                  > > ---------------------------(end of broadcast)---------------------------
                  > > TIP 8: explain analyze is your friend[/color]
                  > --
                  > ------------------------------------------------------------------------
                  > Scott Cain, Ph. D. cain@cshl.org
                  > GMOD Coordinator (http://www.gmod.org/) 216-392-3087
                  > Cold Spring Harbor Laboratory
                  >
                  >
                  > ---------------------------(end of broadcast)---------------------------
                  > TIP 7: don't forget to increase your free space map settings
                  >
                  >[/color]

                  ---------------------------(end of broadcast)---------------------------
                  TIP 7: don't forget to increase your free space map settings

                  Comment

                  • Dennis Gearon

                    #10
                    Re: mysql create table -&gt; psql

                    expect wrote:
                    [color=blue]
                    >On Tue, 09 Sep 2003 09:36:08 -0400
                    >Scott Cain <cain@cshl.or g> wrote:
                    >
                    >
                    >[color=green]
                    >>You might want to take a look at a Perl module, SQL::Translator , which
                    >>translates schema elements (table creates, indexes, views) from one DB's
                    >>SQL to another. I don't know if the S::T on CPAN is up to date, so you
                    >>might want to try their website to get the CVS version:
                    >>
                    >>http://sqlfairy.sourceforge.net/
                    >>
                    >>[/color]
                    >
                    >Funny name, thanks. It's amazing how I didn't find this via google.com.
                    >Is it just me or is google less effective than it once was? Sure seems like it.
                    >I think they're going to have to modify their model.
                    >
                    >
                    >[color=green]
                    >>Scott
                    >>
                    >>
                    >>On Tue, 2003-09-09 at 02:10, expect wrote:
                    >>
                    >>[color=darkred]
                    >>>Hello,
                    >>>
                    >>>Trying to get this MySql create table command to work, no luck.
                    >>>
                    >>>create sequence serial;
                    >>>
                    >>>CREATE TABLE outbound (
                    >>>source char(100) default '',
                    >>>destinatio n char(100) default '',
                    >>>sport int4 default 0 NOT NULL,
                    >>>dport int4 NOT NULL default 0,
                    >>>time timestamp NOT NULL default '0000-00-00 00:00:00',
                    >>>id int8 default nextval('serial ') not null,
                    >>>constraint id PRIMARY (id)
                    >>>);
                    >>>
                    >>>
                    >>>I get a parse error:
                    >>>ERROR: parser: parse error at or near "(" at character 279
                    >>>
                    >>>
                    >>>---------------------------(end of broadcast)---------------------------
                    >>>TIP 8: explain analyze is your friend
                    >>>
                    >>>[/color]
                    >>--
                    >>------------------------------------------------------------------------
                    >>Scott Cain, Ph. D. cain@cshl.org
                    >>GMOD Coordinator (http://www.gmod.org/) 216-392-3087
                    >>Cold Spring Harbor Laboratory
                    >>
                    >>
                    >>---------------------------(end of broadcast)---------------------------
                    >>TIP 7: don't forget to increase your free space map settings
                    >>
                    >>
                    >>
                    >>[/color]
                    >
                    >---------------------------(end of broadcast)---------------------------
                    >TIP 7: don't forget to increase your free space map settings
                    >
                    >
                    >[/color]
                    I think google's reach into technical sites is diminishing. We generate
                    SOOOOOOOOOOOO much traffic on all the open source AND closed source
                    discussion groups, it's staggering.

                    Jeesh, it would be intereseting to know how many words, characters, etc
                    were in each of those domains. I be the folks at marc.theaimsgro up.com
                    could give us an idea about thiers plus add in sourceforge, and it'd be
                    a major part of it. Well, then there's the stuff on usenet that's not on
                    listserves.


                    ---------------------------(end of broadcast)---------------------------
                    TIP 9: the planner will ignore your desire to choose an index scan if your
                    joining column's datatypes do not match

                    Comment

                    Working...